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

fix: generate std roots based on all collected targets #14480

Closed
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
7 changes: 6 additions & 1 deletion src/cargo/core/compiler/build_context/target_info.rs
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for putting effort on a fix. This seems incomplete and lacks tests. Could you follow the atomic commit pattern that the first commit contains tests and passes. The second shows the actual fix and test change.

https://doc.crates.io/contrib/process/working-on-cargo.html#submitting-a-pull-request

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we are looking for something like ehuss suggesting: #10444 (comment), though I personally have no time working on a proper refactor 😞

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, this had originally fixed my issue but after some more testing it appears to also cause more issues in other places :/ It appears you are correct and a proper fix is somewhat more complex. Gonna close this for now

Original file line number Diff line number Diff line change
Expand Up @@ -915,7 +915,7 @@ impl<'gctx> RustcTargetData<'gctx> {
let mut res = RustcTargetData {
rustc,
gctx,
requested_kinds: requested_kinds.into(),
requested_kinds: Vec::new(),
host_config,
host_info,
target_config,
Expand Down Expand Up @@ -948,6 +948,7 @@ impl<'gctx> RustcTargetData<'gctx> {
}));
for kind in all_kinds {
res.merge_compile_kind(kind)?;
res.requested_kinds.push(kind);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This only collects target triples from workspace members. It doesn't walk through the entire dependency graph. I believe if there is a transitive artifact dependency requiring an extra target triple it will fail. We need a test case to verify it.

}

Ok(res)
Expand Down Expand Up @@ -1023,6 +1024,10 @@ impl<'gctx> RustcTargetData<'gctx> {
CompileKind::Target(s) => &self.target_config[&s],
}
}

pub fn requested_kinds(&self) -> &[CompileKind] {
&self.requested_kinds
}
}

/// Structure used to deal with Rustdoc fingerprinting
Expand Down
3 changes: 1 addition & 2 deletions src/cargo/core/compiler/standard_lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,6 @@ pub fn generate_std_roots(
crates: &[String],
std_resolve: &Resolve,
std_features: &ResolvedFeatures,
kinds: &[CompileKind],
package_set: &PackageSet<'_>,
interner: &UnitInterner,
profiles: &Profiles,
Expand All @@ -150,7 +149,7 @@ pub fn generate_std_roots(
// significant.
let mode = CompileMode::Build;
let features = std_features.activated_features(pkg.package_id(), FeaturesFor::NormalOrDev);
for kind in kinds {
for kind in target_data.requested_kinds() {
let list = ret.entry(*kind).or_insert_with(Vec::new);
let unit_for = UnitFor::new_normal(*kind);
let profile = profiles.get_profile(
Expand Down
9 changes: 0 additions & 9 deletions src/cargo/ops/cargo_compile/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -343,14 +343,6 @@ pub fn create_bcx<'a, 'gctx>(
// assuming `--target $HOST` was specified. See
// `rebuild_unit_graph_shared` for more on why this is done.
let explicit_host_kind = CompileKind::Target(CompileTarget::new(&target_data.rustc.host)?);
let explicit_host_kinds: Vec<_> = build_config
.requested_kinds
.iter()
.map(|kind| match kind {
CompileKind::Host => explicit_host_kind,
CompileKind::Target(t) => CompileKind::Target(*t),
})
.collect();

// Passing `build_config.requested_kinds` instead of
// `explicit_host_kinds` here so that `generate_root_units` can do
Expand Down Expand Up @@ -396,7 +388,6 @@ pub fn create_bcx<'a, 'gctx>(
&crates,
std_resolve,
std_features,
&explicit_host_kinds,
&pkg_set,
interner,
&profiles,
Expand Down