Skip to content

Commit cbdbfe4

Browse files
committed
refactor(build-std): extract support core only detection
This is a preparation of reuse for subsequent fix.
1 parent ca59614 commit cbdbfe4

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -619,6 +619,16 @@ impl TargetInfo {
619619
.iter()
620620
.any(|sup| sup.as_str() == split.as_str())
621621
}
622+
623+
/// Checks if a target maybe support std.
624+
///
625+
/// If no explictly stated in target spec json, we treat it as "maybe support".
626+
///
627+
/// This is only useful for `-Zbuild-std` to determine the default set of
628+
/// crates it is going to build.
629+
pub fn maybe_support_std(&self) -> bool {
630+
matches!(self.supports_std, Some(true) | None)
631+
}
622632
}
623633

624634
/// Takes rustc output (using specialized command line args), and calculates the file prefix and

src/cargo/core/compiler/standard_lib.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -115,10 +115,10 @@ pub fn generate_std_roots(
115115
) -> CargoResult<HashMap<CompileKind, Vec<Unit>>> {
116116
// Generate a map of Units for each kind requested.
117117
let mut ret = HashMap::new();
118-
let (core_only, maybe_std): (Vec<&CompileKind>, Vec<_>) = kinds.iter().partition(|kind|
119-
// Only include targets that explicitly don't support std
120-
target_data.info(**kind).supports_std == Some(false));
121-
for (default_crate, kinds) in [("core", core_only), ("std", maybe_std)] {
118+
let (maybe_std, maybe_core): (Vec<&CompileKind>, Vec<_>) = kinds
119+
.iter()
120+
.partition(|kind| target_data.info(**kind).maybe_support_std());
121+
for (default_crate, kinds) in [("core", maybe_core), ("std", maybe_std)] {
122122
if kinds.is_empty() {
123123
continue;
124124
}

0 commit comments

Comments
 (0)