Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Small refactor, adding a list of all kinds to BuildContext #9046

Merged
merged 1 commit into from
Jan 5, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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