1use std::collections::{HashMap, HashSet};
39use std::hash::{Hash, Hasher};
40use std::sync::Arc;
41
42use crate::core::compiler::unit_dependencies::build_unit_dependencies;
43use crate::core::compiler::unit_graph::{self, UnitDep, UnitGraph};
44use crate::core::compiler::UserIntent;
45use crate::core::compiler::{apply_env_config, standard_lib, CrateType, TargetInfo};
46use crate::core::compiler::{BuildConfig, BuildContext, BuildRunner, Compilation};
47use crate::core::compiler::{CompileKind, CompileTarget, RustcTargetData, Unit};
48use crate::core::compiler::{DefaultExecutor, Executor, UnitInterner};
49use crate::core::profiles::Profiles;
50use crate::core::resolver::features::{self, CliFeatures, FeaturesFor};
51use crate::core::resolver::{HasDevUnits, Resolve};
52use crate::core::{PackageId, PackageSet, SourceId, TargetKind, Workspace};
53use crate::drop_println;
54use crate::ops;
55use crate::ops::resolve::WorkspaceResolve;
56use crate::util::context::{GlobalContext, WarningHandling};
57use crate::util::interning::InternedString;
58use crate::util::{CargoResult, StableHasher};
59
60mod compile_filter;
61pub use compile_filter::{CompileFilter, FilterRule, LibRule};
62
63mod unit_generator;
64use unit_generator::UnitGenerator;
65
66mod packages;
67
68pub use packages::Packages;
69
70#[derive(Debug, Clone)]
79pub struct CompileOptions {
80 pub build_config: BuildConfig,
82 pub cli_features: CliFeatures,
84 pub spec: Packages,
86 pub filter: CompileFilter,
89 pub target_rustdoc_args: Option<Vec<String>>,
91 pub target_rustc_args: Option<Vec<String>>,
94 pub target_rustc_crate_types: Option<Vec<String>>,
96 pub rustdoc_document_private_items: bool,
99 pub honor_rust_version: Option<bool>,
102}
103
104impl CompileOptions {
105 pub fn new(gctx: &GlobalContext, intent: UserIntent) -> CargoResult<CompileOptions> {
106 let jobs = None;
107 let keep_going = false;
108 Ok(CompileOptions {
109 build_config: BuildConfig::new(gctx, jobs, keep_going, &[], intent)?,
110 cli_features: CliFeatures::new_all(false),
111 spec: ops::Packages::Packages(Vec::new()),
112 filter: CompileFilter::Default {
113 required_features_filterable: false,
114 },
115 target_rustdoc_args: None,
116 target_rustc_args: None,
117 target_rustc_crate_types: None,
118 rustdoc_document_private_items: false,
119 honor_rust_version: None,
120 })
121 }
122}
123
124pub fn compile<'a>(ws: &Workspace<'a>, options: &CompileOptions) -> CargoResult<Compilation<'a>> {
128 let exec: Arc<dyn Executor> = Arc::new(DefaultExecutor);
129 compile_with_exec(ws, options, &exec)
130}
131
132pub fn compile_with_exec<'a>(
137 ws: &Workspace<'a>,
138 options: &CompileOptions,
139 exec: &Arc<dyn Executor>,
140) -> CargoResult<Compilation<'a>> {
141 ws.emit_warnings()?;
142 let compilation = compile_ws(ws, options, exec)?;
143 if ws.gctx().warning_handling()? == WarningHandling::Deny && compilation.warning_count > 0 {
144 anyhow::bail!("warnings are denied by `build.warnings` configuration")
145 }
146 Ok(compilation)
147}
148
149#[tracing::instrument(skip_all)]
151pub fn compile_ws<'a>(
152 ws: &Workspace<'a>,
153 options: &CompileOptions,
154 exec: &Arc<dyn Executor>,
155) -> CargoResult<Compilation<'a>> {
156 let interner = UnitInterner::new();
157 let bcx = create_bcx(ws, options, &interner)?;
158 if options.build_config.unit_graph {
159 unit_graph::emit_serialized_unit_graph(&bcx.roots, &bcx.unit_graph, ws.gctx())?;
160 return Compilation::new(&bcx);
161 }
162 crate::core::gc::auto_gc(bcx.gctx);
163 let build_runner = BuildRunner::new(&bcx)?;
164 if options.build_config.dry_run {
165 build_runner.dry_run()
166 } else {
167 build_runner.compile(exec)
168 }
169}
170
171pub fn print<'a>(
175 ws: &Workspace<'a>,
176 options: &CompileOptions,
177 print_opt_value: &str,
178) -> CargoResult<()> {
179 let CompileOptions {
180 ref build_config,
181 ref target_rustc_args,
182 ..
183 } = *options;
184 let gctx = ws.gctx();
185 let rustc = gctx.load_global_rustc(Some(ws))?;
186 for (index, kind) in build_config.requested_kinds.iter().enumerate() {
187 if index != 0 {
188 drop_println!(gctx);
189 }
190 let target_info = TargetInfo::new(gctx, &build_config.requested_kinds, &rustc, *kind)?;
191 let mut process = rustc.process();
192 apply_env_config(gctx, &mut process)?;
193 process.args(&target_info.rustflags);
194 if let Some(args) = target_rustc_args {
195 process.args(args);
196 }
197 if let CompileKind::Target(t) = kind {
198 process.arg("--target").arg(t.rustc_target());
199 }
200 process.arg("--print").arg(print_opt_value);
201 process.exec()?;
202 }
203 Ok(())
204}
205
206#[tracing::instrument(skip_all)]
211pub fn create_bcx<'a, 'gctx>(
212 ws: &'a Workspace<'gctx>,
213 options: &'a CompileOptions,
214 interner: &'a UnitInterner,
215) -> CargoResult<BuildContext<'a, 'gctx>> {
216 let CompileOptions {
217 ref build_config,
218 ref spec,
219 ref cli_features,
220 ref filter,
221 ref target_rustdoc_args,
222 ref target_rustc_args,
223 ref target_rustc_crate_types,
224 rustdoc_document_private_items,
225 honor_rust_version,
226 } = *options;
227 let gctx = ws.gctx();
228
229 match build_config.intent {
231 UserIntent::Test | UserIntent::Build | UserIntent::Check { .. } | UserIntent::Bench => {
232 if ws.gctx().get_env("RUST_FLAGS").is_ok() {
233 gctx.shell().warn(
234 "Cargo does not read `RUST_FLAGS` environment variable. Did you mean `RUSTFLAGS`?",
235 )?;
236 }
237 }
238 UserIntent::Doc { .. } | UserIntent::Doctest => {
239 if ws.gctx().get_env("RUSTDOC_FLAGS").is_ok() {
240 gctx.shell().warn(
241 "Cargo does not read `RUSTDOC_FLAGS` environment variable. Did you mean `RUSTDOCFLAGS`?"
242 )?;
243 }
244 }
245 }
246 gctx.validate_term_config()?;
247
248 let mut target_data = RustcTargetData::new(ws, &build_config.requested_kinds)?;
249
250 let specs = spec.to_package_id_specs(ws)?;
251 let has_dev_units = {
252 let any_pkg_has_scrape_enabled = ws
256 .members_with_features(&specs, cli_features)?
257 .iter()
258 .any(|(pkg, _)| {
259 pkg.targets()
260 .iter()
261 .any(|target| target.is_example() && target.doc_scrape_examples().is_enabled())
262 });
263
264 if filter.need_dev_deps(build_config.intent)
265 || (build_config.intent.is_doc() && any_pkg_has_scrape_enabled)
266 {
267 HasDevUnits::Yes
268 } else {
269 HasDevUnits::No
270 }
271 };
272 let dry_run = false;
273 let resolve = ops::resolve_ws_with_opts(
274 ws,
275 &mut target_data,
276 &build_config.requested_kinds,
277 cli_features,
278 &specs,
279 has_dev_units,
280 crate::core::resolver::features::ForceAllTargets::No,
281 dry_run,
282 )?;
283 let WorkspaceResolve {
284 mut pkg_set,
285 workspace_resolve,
286 targeted_resolve: resolve,
287 resolved_features,
288 } = resolve;
289
290 let std_resolve_features = if let Some(crates) = &gctx.cli_unstable().build_std {
291 let (std_package_set, std_resolve, std_features) = standard_lib::resolve_std(
292 ws,
293 &mut target_data,
294 &build_config,
295 crates,
296 &build_config.requested_kinds,
297 )?;
298 pkg_set.add_set(std_package_set);
299 Some((std_resolve, std_features))
300 } else {
301 None
302 };
303
304 let to_build_ids = resolve.specs_to_ids(&specs)?;
308 let mut to_builds = pkg_set.get_many(to_build_ids)?;
312
313 to_builds.sort_by_key(|p| p.package_id());
317
318 for pkg in to_builds.iter() {
319 pkg.manifest().print_teapot(gctx);
320
321 if build_config.intent.is_any_test()
322 && !ws.is_member(pkg)
323 && pkg.dependencies().iter().any(|dep| !dep.is_transitive())
324 {
325 anyhow::bail!(
326 "package `{}` cannot be tested because it requires dev-dependencies \
327 and is not a member of the workspace",
328 pkg.name()
329 );
330 }
331 }
332
333 let (extra_args, extra_args_name) = match (target_rustc_args, target_rustdoc_args) {
334 (Some(args), _) => (Some(args.clone()), "rustc"),
335 (_, Some(args)) => (Some(args.clone()), "rustdoc"),
336 _ => (None, ""),
337 };
338
339 if extra_args.is_some() && to_builds.len() != 1 {
340 panic!(
341 "`{}` should not accept multiple `-p` flags",
342 extra_args_name
343 );
344 }
345
346 let profiles = Profiles::new(ws, build_config.requested_profile)?;
347 profiles.validate_packages(
348 ws.profiles(),
349 &mut gctx.shell(),
350 workspace_resolve.as_ref().unwrap_or(&resolve),
351 )?;
352
353 let explicit_host_kind = CompileKind::Target(CompileTarget::new(&target_data.rustc.host)?);
357 let explicit_host_kinds: Vec<_> = build_config
358 .requested_kinds
359 .iter()
360 .map(|kind| match kind {
361 CompileKind::Host => explicit_host_kind,
362 CompileKind::Target(t) => CompileKind::Target(*t),
363 })
364 .collect();
365
366 let generator = UnitGenerator {
372 ws,
373 packages: &to_builds,
374 spec,
375 target_data: &target_data,
376 filter,
377 requested_kinds: &build_config.requested_kinds,
378 explicit_host_kind,
379 intent: build_config.intent,
380 resolve: &resolve,
381 workspace_resolve: &workspace_resolve,
382 resolved_features: &resolved_features,
383 package_set: &pkg_set,
384 profiles: &profiles,
385 interner,
386 has_dev_units,
387 };
388 let mut units = generator.generate_root_units()?;
389
390 if let Some(args) = target_rustc_crate_types {
391 override_rustc_crate_types(&mut units, args, interner)?;
392 }
393
394 let should_scrape = build_config.intent.is_doc() && gctx.cli_unstable().rustdoc_scrape_examples;
395 let mut scrape_units = if should_scrape {
396 generator.generate_scrape_units(&units)?
397 } else {
398 Vec::new()
399 };
400
401 let std_roots = if let Some(crates) = gctx.cli_unstable().build_std.as_ref() {
402 let (std_resolve, std_features) = std_resolve_features.as_ref().unwrap();
403 standard_lib::generate_std_roots(
404 &crates,
405 &units,
406 std_resolve,
407 std_features,
408 &explicit_host_kinds,
409 &pkg_set,
410 interner,
411 &profiles,
412 &target_data,
413 )?
414 } else {
415 Default::default()
416 };
417
418 let mut unit_graph = build_unit_dependencies(
419 ws,
420 &pkg_set,
421 &resolve,
422 &resolved_features,
423 std_resolve_features.as_ref(),
424 &units,
425 &scrape_units,
426 &std_roots,
427 build_config.intent,
428 &target_data,
429 &profiles,
430 interner,
431 )?;
432
433 if build_config.intent.wants_deps_docs() {
436 remove_duplicate_doc(build_config, &units, &mut unit_graph);
437 }
438
439 let host_kind_requested = build_config
440 .requested_kinds
441 .iter()
442 .any(CompileKind::is_host);
443 (units, scrape_units, unit_graph) = rebuild_unit_graph_shared(
447 interner,
448 unit_graph,
449 &units,
450 &scrape_units,
451 host_kind_requested.then_some(explicit_host_kind),
452 build_config.compile_time_deps_only,
453 );
454
455 let mut extra_compiler_args = HashMap::new();
456 if let Some(args) = extra_args {
457 if units.len() != 1 {
458 anyhow::bail!(
459 "extra arguments to `{}` can only be passed to one \
460 target, consider filtering\nthe package by passing, \
461 e.g., `--lib` or `--bin NAME` to specify a single target",
462 extra_args_name
463 );
464 }
465 extra_compiler_args.insert(units[0].clone(), args);
466 }
467
468 for unit in units
469 .iter()
470 .filter(|unit| unit.mode.is_doc() || unit.mode.is_doc_test())
471 .filter(|unit| rustdoc_document_private_items || unit.target.is_bin())
472 {
473 let mut args = vec!["--document-private-items".into()];
477 if unit.target.is_bin() {
478 args.push("-Arustdoc::private-intra-doc-links".into());
482 }
483 extra_compiler_args
484 .entry(unit.clone())
485 .or_default()
486 .extend(args);
487 }
488
489 if honor_rust_version.unwrap_or(true) {
490 let rustc_version = target_data.rustc.version.clone().into();
491
492 let mut incompatible = Vec::new();
493 let mut local_incompatible = false;
494 for unit in unit_graph.keys() {
495 let Some(pkg_msrv) = unit.pkg.rust_version() else {
496 continue;
497 };
498
499 if pkg_msrv.is_compatible_with(&rustc_version) {
500 continue;
501 }
502
503 local_incompatible |= unit.is_local();
504 incompatible.push((unit, pkg_msrv));
505 }
506 if !incompatible.is_empty() {
507 use std::fmt::Write as _;
508
509 let plural = if incompatible.len() == 1 { "" } else { "s" };
510 let mut message = format!(
511 "rustc {rustc_version} is not supported by the following package{plural}:\n"
512 );
513 incompatible.sort_by_key(|(unit, _)| (unit.pkg.name(), unit.pkg.version()));
514 for (unit, msrv) in incompatible {
515 let name = &unit.pkg.name();
516 let version = &unit.pkg.version();
517 writeln!(&mut message, " {name}@{version} requires rustc {msrv}").unwrap();
518 }
519 if ws.is_ephemeral() {
520 if ws.ignore_lock() {
521 writeln!(
522 &mut message,
523 "Try re-running `cargo install` with `--locked`"
524 )
525 .unwrap();
526 }
527 } else if !local_incompatible {
528 writeln!(
529 &mut message,
530 "Either upgrade rustc or select compatible dependency versions with
531`cargo update <name>@<current-ver> --precise <compatible-ver>`
532where `<compatible-ver>` is the latest version supporting rustc {rustc_version}",
533 )
534 .unwrap();
535 }
536 return Err(anyhow::Error::msg(message));
537 }
538 }
539
540 let bcx = BuildContext::new(
541 ws,
542 pkg_set,
543 build_config,
544 profiles,
545 extra_compiler_args,
546 target_data,
547 units,
548 unit_graph,
549 scrape_units,
550 )?;
551
552 Ok(bcx)
553}
554
555fn rebuild_unit_graph_shared(
590 interner: &UnitInterner,
591 unit_graph: UnitGraph,
592 roots: &[Unit],
593 scrape_units: &[Unit],
594 to_host: Option<CompileKind>,
595 compile_time_deps_only: bool,
596) -> (Vec<Unit>, Vec<Unit>, UnitGraph) {
597 let mut result = UnitGraph::new();
598 let mut memo = HashMap::new();
601 let new_roots = roots
602 .iter()
603 .map(|root| {
604 traverse_and_share(
605 interner,
606 &mut memo,
607 &mut result,
608 &unit_graph,
609 root,
610 true,
611 false,
612 to_host,
613 compile_time_deps_only,
614 )
615 })
616 .collect();
617 let new_scrape_units = scrape_units
621 .iter()
622 .map(|unit| memo.get(unit).unwrap().clone())
623 .collect();
624 (new_roots, new_scrape_units, result)
625}
626
627fn traverse_and_share(
633 interner: &UnitInterner,
634 memo: &mut HashMap<Unit, Unit>,
635 new_graph: &mut UnitGraph,
636 unit_graph: &UnitGraph,
637 unit: &Unit,
638 unit_is_root: bool,
639 unit_is_for_host: bool,
640 to_host: Option<CompileKind>,
641 compile_time_deps_only: bool,
642) -> Unit {
643 if let Some(new_unit) = memo.get(unit) {
644 return new_unit.clone();
646 }
647 let mut dep_hash = StableHasher::new();
648 let skip_non_compile_time_deps = compile_time_deps_only
649 && (!unit.target.is_compile_time_dependency() ||
650 unit_is_root);
653 let new_deps: Vec<_> = unit_graph[unit]
654 .iter()
655 .map(|dep| {
656 let new_dep_unit = traverse_and_share(
657 interner,
658 memo,
659 new_graph,
660 unit_graph,
661 &dep.unit,
662 false,
663 dep.unit_for.is_for_host(),
664 to_host,
665 skip_non_compile_time_deps,
669 );
670 new_dep_unit.hash(&mut dep_hash);
671 UnitDep {
672 unit: new_dep_unit,
673 ..dep.clone()
674 }
675 })
676 .collect();
677 let new_dep_hash = Hasher::finish(&dep_hash);
680
681 let canonical_kind = match to_host {
688 Some(to_host) if to_host == unit.kind => CompileKind::Host,
689 _ => unit.kind,
690 };
691
692 let mut profile = unit.profile.clone();
693 if profile.strip.is_deferred() {
694 if !profile.debuginfo.is_turned_on()
698 && new_deps
699 .iter()
700 .all(|dep| !dep.unit.profile.debuginfo.is_turned_on())
701 {
702 profile.strip = profile.strip.strip_debuginfo();
703 }
704 }
705
706 if unit_is_for_host
710 && to_host.is_some()
711 && profile.debuginfo.is_deferred()
712 && !unit.artifact.is_true()
713 {
714 let canonical_debuginfo = profile.debuginfo.finalize();
718 let mut canonical_profile = profile.clone();
719 canonical_profile.debuginfo = canonical_debuginfo;
720 let unit_probe = interner.intern(
721 &unit.pkg,
722 &unit.target,
723 canonical_profile,
724 to_host.unwrap(),
725 unit.mode,
726 unit.features.clone(),
727 unit.rustflags.clone(),
728 unit.rustdocflags.clone(),
729 unit.links_overrides.clone(),
730 unit.is_std,
731 unit.dep_hash,
732 unit.artifact,
733 unit.artifact_target_for_features,
734 unit.skip_non_compile_time_dep,
735 );
736
737 profile.debuginfo = if unit_graph.contains_key(&unit_probe) {
739 canonical_debuginfo
742 } else {
743 canonical_debuginfo.weaken()
746 }
747 }
748
749 let new_unit = interner.intern(
750 &unit.pkg,
751 &unit.target,
752 profile,
753 canonical_kind,
754 unit.mode,
755 unit.features.clone(),
756 unit.rustflags.clone(),
757 unit.rustdocflags.clone(),
758 unit.links_overrides.clone(),
759 unit.is_std,
760 new_dep_hash,
761 unit.artifact,
762 None,
765 skip_non_compile_time_deps,
766 );
767 if !unit_is_root || !compile_time_deps_only {
768 assert!(memo.insert(unit.clone(), new_unit.clone()).is_none());
769 }
770 new_graph.entry(new_unit.clone()).or_insert(new_deps);
771 new_unit
772}
773
774fn remove_duplicate_doc(
790 build_config: &BuildConfig,
791 root_units: &[Unit],
792 unit_graph: &mut UnitGraph,
793) {
794 let mut all_docs: HashMap<String, Vec<Unit>> = HashMap::new();
797 for unit in unit_graph.keys() {
798 if unit.mode.is_doc() {
799 all_docs
800 .entry(unit.target.crate_name())
801 .or_default()
802 .push(unit.clone());
803 }
804 }
805 let mut removed_units: HashSet<Unit> = HashSet::new();
808 let mut remove = |units: Vec<Unit>, reason: &str, cb: &dyn Fn(&Unit) -> bool| -> Vec<Unit> {
809 let (to_remove, remaining_units): (Vec<Unit>, Vec<Unit>) = units
810 .into_iter()
811 .partition(|unit| cb(unit) && !root_units.contains(unit));
812 for unit in to_remove {
813 tracing::debug!(
814 "removing duplicate doc due to {} for package {} target `{}`",
815 reason,
816 unit.pkg,
817 unit.target.name()
818 );
819 unit_graph.remove(&unit);
820 removed_units.insert(unit);
821 }
822 remaining_units
823 };
824 for (_crate_name, mut units) in all_docs {
826 if units.len() == 1 {
827 continue;
828 }
829 if build_config
831 .requested_kinds
832 .iter()
833 .all(CompileKind::is_host)
834 {
835 units = remove(units, "host/target merger", &|unit| unit.kind.is_host());
840 if units.len() == 1 {
841 continue;
842 }
843 }
844 let mut source_map: HashMap<(InternedString, SourceId, CompileKind), Vec<Unit>> =
846 HashMap::new();
847 for unit in units {
848 let pkg_id = unit.pkg.package_id();
849 source_map
851 .entry((pkg_id.name(), pkg_id.source_id(), unit.kind))
852 .or_default()
853 .push(unit);
854 }
855 let mut remaining_units = Vec::new();
856 for (_key, mut units) in source_map {
857 if units.len() > 1 {
858 units.sort_by(|a, b| a.pkg.version().partial_cmp(b.pkg.version()).unwrap());
859 let newest_version = units.last().unwrap().pkg.version().clone();
861 let keep_units = remove(units, "older version", &|unit| {
862 unit.pkg.version() < &newest_version
863 });
864 remaining_units.extend(keep_units);
865 } else {
866 remaining_units.extend(units);
867 }
868 }
869 if remaining_units.len() == 1 {
870 continue;
871 }
872 }
875 for unit_deps in unit_graph.values_mut() {
877 unit_deps.retain(|unit_dep| !removed_units.contains(&unit_dep.unit));
878 }
879 let mut visited = HashSet::new();
881 fn visit(unit: &Unit, graph: &UnitGraph, visited: &mut HashSet<Unit>) {
882 if !visited.insert(unit.clone()) {
883 return;
884 }
885 for dep in &graph[unit] {
886 visit(&dep.unit, graph, visited);
887 }
888 }
889 for unit in root_units {
890 visit(unit, unit_graph, &mut visited);
891 }
892 unit_graph.retain(|unit, _| visited.contains(unit));
893}
894
895fn override_rustc_crate_types(
899 units: &mut [Unit],
900 args: &[String],
901 interner: &UnitInterner,
902) -> CargoResult<()> {
903 if units.len() != 1 {
904 anyhow::bail!(
905 "crate types to rustc can only be passed to one \
906 target, consider filtering\nthe package by passing, \
907 e.g., `--lib` or `--example` to specify a single target"
908 );
909 }
910
911 let unit = &units[0];
912 let override_unit = |f: fn(Vec<CrateType>) -> TargetKind| {
913 let crate_types = args.iter().map(|s| s.into()).collect();
914 let mut target = unit.target.clone();
915 target.set_kind(f(crate_types));
916 interner.intern(
917 &unit.pkg,
918 &target,
919 unit.profile.clone(),
920 unit.kind,
921 unit.mode,
922 unit.features.clone(),
923 unit.rustflags.clone(),
924 unit.rustdocflags.clone(),
925 unit.links_overrides.clone(),
926 unit.is_std,
927 unit.dep_hash,
928 unit.artifact,
929 unit.artifact_target_for_features,
930 unit.skip_non_compile_time_dep,
931 )
932 };
933 units[0] = match unit.target.kind() {
934 TargetKind::Lib(_) => override_unit(TargetKind::Lib),
935 TargetKind::ExampleLib(_) => override_unit(TargetKind::ExampleLib),
936 _ => {
937 anyhow::bail!(
938 "crate types can only be specified for libraries and example libraries.\n\
939 Binaries, tests, and benchmarks are always the `bin` crate type"
940 );
941 }
942 };
943
944 Ok(())
945}
946
947pub fn resolve_all_features(
953 resolve_with_overrides: &Resolve,
954 resolved_features: &features::ResolvedFeatures,
955 package_set: &PackageSet<'_>,
956 package_id: PackageId,
957) -> HashSet<String> {
958 let mut features: HashSet<String> = resolved_features
959 .activated_features(package_id, FeaturesFor::NormalOrDev)
960 .iter()
961 .map(|s| s.to_string())
962 .collect();
963
964 for (dep_id, deps) in resolve_with_overrides.deps(package_id) {
967 let is_proc_macro = package_set
968 .get_one(dep_id)
969 .expect("packages downloaded")
970 .proc_macro();
971 for dep in deps {
972 let features_for = FeaturesFor::from_for_host(is_proc_macro || dep.is_build());
973 for feature in resolved_features
974 .activated_features_unverified(dep_id, features_for)
975 .unwrap_or_default()
976 {
977 features.insert(format!("{}/{}", dep.name_in_toml(), feature));
978 }
979 }
980 }
981
982 features
983}