Skip to content

Commit 0583aa4

Browse files
committed
Auto merge of #9046 - Ekleog:store-kinds-list-in-bcx, r=alexcrichton
Small refactor, adding a list of all kinds to BuildContext Involved in #9030 cc `@alexcrichton`
2 parents 2f218d0 + 2f14f98 commit 0583aa4

File tree

3 files changed

+21
-12
lines changed

3 files changed

+21
-12
lines changed

src/cargo/core/compiler/build_context/mod.rs

+18-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use crate::util::config::Config;
77
use crate::util::errors::CargoResult;
88
use crate::util::interning::InternedString;
99
use crate::util::Rustc;
10-
use std::collections::HashMap;
10+
use std::collections::{HashMap, HashSet};
1111
use std::path::PathBuf;
1212

1313
mod target_info;
@@ -22,22 +22,31 @@ pub use self::target_info::{FileFlavor, FileType, RustcTargetData, TargetInfo};
2222
pub struct BuildContext<'a, 'cfg> {
2323
/// The workspace the build is for.
2424
pub ws: &'a Workspace<'cfg>,
25+
2526
/// The cargo configuration.
2627
pub config: &'cfg Config,
2728
pub profiles: Profiles,
2829
pub build_config: &'a BuildConfig,
30+
2931
/// Extra compiler args for either `rustc` or `rustdoc`.
3032
pub extra_compiler_args: HashMap<Unit, Vec<String>>,
33+
3134
/// Package downloader.
3235
///
3336
/// This holds ownership of the `Package` objects.
3437
pub packages: PackageSet<'cfg>,
38+
3539
/// Information about rustc and the target platform.
3640
pub target_data: RustcTargetData,
41+
3742
/// The root units of `unit_graph` (units requested on the command-line).
3843
pub roots: Vec<Unit>,
44+
3945
/// The dependency graph of units to compile.
4046
pub unit_graph: UnitGraph,
47+
48+
/// The list of all kinds that are involved in this build
49+
pub all_kinds: HashSet<CompileKind>,
4150
}
4251

4352
impl<'a, 'cfg> BuildContext<'a, 'cfg> {
@@ -51,6 +60,13 @@ impl<'a, 'cfg> BuildContext<'a, 'cfg> {
5160
roots: Vec<Unit>,
5261
unit_graph: UnitGraph,
5362
) -> CargoResult<BuildContext<'a, 'cfg>> {
63+
let all_kinds = unit_graph
64+
.keys()
65+
.map(|u| u.kind)
66+
.chain(build_config.requested_kinds.iter().copied())
67+
.chain(std::iter::once(CompileKind::Host))
68+
.collect();
69+
5470
Ok(BuildContext {
5571
ws,
5672
config: ws.config(),
@@ -61,6 +77,7 @@ impl<'a, 'cfg> BuildContext<'a, 'cfg> {
6177
target_data,
6278
roots,
6379
unit_graph,
80+
all_kinds,
6481
})
6582
}
6683

src/cargo/core/compiler/compilation.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -113,10 +113,8 @@ impl<'cfg> Compilation<'cfg> {
113113
.sysroot_host_libdir
114114
.clone(),
115115
sysroot_target_libdir: bcx
116-
.build_config
117-
.requested_kinds
116+
.all_kinds
118117
.iter()
119-
.chain(Some(&CompileKind::Host))
120118
.map(|kind| {
121119
(
122120
*kind,

src/cargo/core/compiler/context/mod.rs

+2-8
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,7 @@ impl<'a, 'cfg> Context<'a, 'cfg> {
287287
let dest = self.bcx.profiles.get_dir_name();
288288
let host_layout = Layout::new(self.bcx.ws, None, &dest)?;
289289
let mut targets = HashMap::new();
290-
for kind in self.bcx.build_config.requested_kinds.iter() {
290+
for kind in self.bcx.all_kinds.iter() {
291291
if let CompileKind::Target(target) = *kind {
292292
let layout = Layout::new(self.bcx.ws, Some(target), &dest)?;
293293
targets.insert(target, layout);
@@ -319,13 +319,7 @@ impl<'a, 'cfg> Context<'a, 'cfg> {
319319
}
320320

321321
let files = self.files.as_ref().unwrap();
322-
for &kind in self
323-
.bcx
324-
.build_config
325-
.requested_kinds
326-
.iter()
327-
.chain(Some(&CompileKind::Host))
328-
{
322+
for &kind in self.bcx.all_kinds.iter() {
329323
let layout = files.layout(kind);
330324
self.compilation
331325
.root_output

0 commit comments

Comments
 (0)