diff --git a/src/cargo/core/compiler/build_context/mod.rs b/src/cargo/core/compiler/build_context/mod.rs index 47efdc77de8..303bf6a873c 100644 --- a/src/cargo/core/compiler/build_context/mod.rs +++ b/src/cargo/core/compiler/build_context/mod.rs @@ -7,7 +7,7 @@ use crate::util::config::Config; use crate::util::errors::CargoResult; use crate::util::interning::InternedString; use crate::util::Rustc; -use std::collections::HashMap; +use std::collections::{HashMap, HashSet}; use std::path::PathBuf; mod target_info; @@ -22,22 +22,31 @@ pub use self::target_info::{FileFlavor, FileType, RustcTargetData, TargetInfo}; pub struct BuildContext<'a, 'cfg> { /// The workspace the build is for. pub ws: &'a Workspace<'cfg>, + /// The cargo configuration. pub config: &'cfg Config, pub profiles: Profiles, pub build_config: &'a BuildConfig, + /// Extra compiler args for either `rustc` or `rustdoc`. pub extra_compiler_args: HashMap>, + /// Package downloader. /// /// This holds ownership of the `Package` objects. pub packages: PackageSet<'cfg>, + /// Information about rustc and the target platform. pub target_data: RustcTargetData, + /// The root units of `unit_graph` (units requested on the command-line). pub roots: Vec, + /// The dependency graph of units to compile. pub unit_graph: UnitGraph, + + /// The list of all kinds that are involved in this build + pub all_kinds: HashSet, } impl<'a, 'cfg> BuildContext<'a, 'cfg> { @@ -51,6 +60,13 @@ impl<'a, 'cfg> BuildContext<'a, 'cfg> { roots: Vec, unit_graph: UnitGraph, ) -> CargoResult> { + let all_kinds = unit_graph + .keys() + .map(|u| u.kind) + .chain(build_config.requested_kinds.iter().copied()) + .chain(std::iter::once(CompileKind::Host)) + .collect(); + Ok(BuildContext { ws, config: ws.config(), @@ -61,6 +77,7 @@ impl<'a, 'cfg> BuildContext<'a, 'cfg> { target_data, roots, unit_graph, + all_kinds, }) } diff --git a/src/cargo/core/compiler/compilation.rs b/src/cargo/core/compiler/compilation.rs index f45997aa411..461196f6076 100644 --- a/src/cargo/core/compiler/compilation.rs +++ b/src/cargo/core/compiler/compilation.rs @@ -113,10 +113,8 @@ impl<'cfg> Compilation<'cfg> { .sysroot_host_libdir .clone(), sysroot_target_libdir: bcx - .build_config - .requested_kinds + .all_kinds .iter() - .chain(Some(&CompileKind::Host)) .map(|kind| { ( *kind, diff --git a/src/cargo/core/compiler/context/mod.rs b/src/cargo/core/compiler/context/mod.rs index dc09f7df8f4..4e31fed0b12 100644 --- a/src/cargo/core/compiler/context/mod.rs +++ b/src/cargo/core/compiler/context/mod.rs @@ -287,7 +287,7 @@ impl<'a, 'cfg> Context<'a, 'cfg> { let dest = self.bcx.profiles.get_dir_name(); let host_layout = Layout::new(self.bcx.ws, None, &dest)?; let mut targets = HashMap::new(); - for kind in self.bcx.build_config.requested_kinds.iter() { + for kind in self.bcx.all_kinds.iter() { if let CompileKind::Target(target) = *kind { let layout = Layout::new(self.bcx.ws, Some(target), &dest)?; targets.insert(target, layout); @@ -319,13 +319,7 @@ impl<'a, 'cfg> Context<'a, 'cfg> { } let files = self.files.as_ref().unwrap(); - for &kind in self - .bcx - .build_config - .requested_kinds - .iter() - .chain(Some(&CompileKind::Host)) - { + for &kind in self.bcx.all_kinds.iter() { let layout = files.layout(kind); self.compilation .root_output