Skip to content

Commit

Permalink
Small refactor, adding a list of all kinds to BuildContext
Browse files Browse the repository at this point in the history
Involved in #9030
  • Loading branch information
Ekleog committed Jan 5, 2021
1 parent 0cf6d24 commit 2f14f98
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 12 deletions.
19 changes: 18 additions & 1 deletion src/cargo/core/compiler/build_context/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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<Unit, Vec<String>>,

/// 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<Unit>,

/// 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<CompileKind>,
}

impl<'a, 'cfg> BuildContext<'a, 'cfg> {
Expand All @@ -51,6 +60,13 @@ impl<'a, 'cfg> BuildContext<'a, 'cfg> {
roots: Vec<Unit>,
unit_graph: UnitGraph,
) -> CargoResult<BuildContext<'a, 'cfg>> {
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(),
Expand All @@ -61,6 +77,7 @@ impl<'a, 'cfg> BuildContext<'a, 'cfg> {
target_data,
roots,
unit_graph,
all_kinds,
})
}

Expand Down
4 changes: 1 addition & 3 deletions src/cargo/core/compiler/compilation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
10 changes: 2 additions & 8 deletions src/cargo/core/compiler/context/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 2f14f98

Please sign in to comment.