Skip to content

Commit

Permalink
refactor(build-std): extract support core only detection
Browse files Browse the repository at this point in the history
This is a preparation of reuse for subsequent fix.
  • Loading branch information
weihanglo committed Dec 17, 2024
1 parent b4d089b commit 2e26bfb
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
7 changes: 7 additions & 0 deletions src/cargo/core/compiler/build_context/target_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -619,6 +619,13 @@ impl TargetInfo {
.iter()
.any(|sup| sup.as_str() == split.as_str())
}

/// Checks if a target support core only.
///
/// If no explictly stated in target spec json, we treat it as "maybe support".
pub fn support_core_only(&self) -> bool {
matches!(self.supports_std, Some(false))
}
}

/// Takes rustc output (using specialized command line args), and calculates the file prefix and
Expand Down
6 changes: 3 additions & 3 deletions src/cargo/core/compiler/standard_lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,9 +115,9 @@ pub fn generate_std_roots(
) -> CargoResult<HashMap<CompileKind, Vec<Unit>>> {
// Generate a map of Units for each kind requested.
let mut ret = HashMap::new();
let (core_only, maybe_std): (Vec<&CompileKind>, Vec<_>) = kinds.iter().partition(|kind|
// Only include targets that explicitly don't support std
target_data.info(**kind).supports_std == Some(false));
let (core_only, maybe_std): (Vec<&CompileKind>, Vec<_>) = kinds
.iter()
.partition(|kind| target_data.info(**kind).support_core_only());
for (default_crate, kinds) in [("core", core_only), ("std", maybe_std)] {
if kinds.is_empty() {
continue;
Expand Down

0 comments on commit 2e26bfb

Please sign in to comment.