Skip to content

fix(build-std): include artifact dependency targets#17074

Open
npmccallum wants to merge 2 commits into
rust-lang:masterfrom
npmccallum:issue-10444-15365-bindeps-build-std
Open

fix(build-std): include artifact dependency targets#17074
npmccallum wants to merge 2 commits into
rust-lang:masterfrom
npmccallum:issue-10444-15365-bindeps-build-std

Conversation

@npmccallum

Copy link
Copy Markdown
Contributor

Artifact dependencies can introduce target kinds that were not requested on the command line. When -Zbuild-std is active, generate std roots for those discovered targets as well so unit construction does not panic when attaching std dependencies.

The regression covers a bindeps artifact built for an alternate target while the root package is checked for the host target.

Closes #10444.

Refs #15365.

@rustbot rustbot added A-cfg-expr Area: Platform cfg expressions Command-fetch S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jun 4, 2026
@rustbot

rustbot commented Jun 4, 2026

Copy link
Copy Markdown
Collaborator

r? @weihanglo

rustbot has assigned @weihanglo.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

Why was this reviewer chosen?

The reviewer was selected based on:

  • Owners of files modified in this PR: @ehuss, @epage, @weihanglo
  • @ehuss, @epage, @weihanglo expanded to ehuss, epage, weihanglo
  • Random selection from ehuss, epage, weihanglo

}

#[cargo_test(build_std_mock)]
fn artifact_dep_target_builds_std_for_unrequested_target() {

@epage epage Jun 4, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Please see https://epage.github.io/dev/pr-style/#c-test (note our contrib guide says this as policy but that goes into more detail)

View changes since the review

@epage

epage commented Jun 4, 2026

Copy link
Copy Markdown
Contributor

@davidtwco or @adamgemmell would either of you be up for doing a first pass on this?

Note the issue is in the triage state. If we are not ready yet for this, including design discussions, we can shift the focus to the issue by moving this to a draft or closing it. See also https://doc.crates.io/contrib/issues.html#issue-status-labels

@adamgemmell adamgemmell left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Thanks for this, and sorry for the slow response.

I'm relieved this fix took so little code! Does this fix also work for other situations with multiple targets in the resolve such as when using per-pkg-target?

View changes since this review

Comment thread src/cargo/ops/cargo_compile/mod.rs Outdated
.any(CompileKind::is_host);
let mut std_kinds = build_config.requested_kinds.clone();
std_kinds.extend(target_data.target_kinds().filter(|kind| {
!(host_kind_requested && target_data.rustc.host == target_data.short_name(kind))

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

There's probably a simpler way to express the logic in this block. Is there actually a case where a compilekind is in target_kinds() but not requested_kinds?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

That case is covered now by per_package_target_builds_std_for_manifest_target.

Comment thread src/cargo/ops/cargo_fetch.rs Outdated
let mut std_kinds = build_config.requested_kinds.clone();
std_kinds.extend(
data.target_kinds()
.filter(|kind| !(host_kind_requested && data.rustc.host == data.short_name(kind))),

@adamgemmell adamgemmell Jun 24, 2026

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

In addition to the above, this is quite complex and weird in general, and is now duplicated. Could you put it in a helper function with a comment explaining why the filter is necessary?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Addressed by moving this into standard_lib::resolve_std_kinds with a comment explaining the host-target filter.

@npmccallum npmccallum force-pushed the issue-10444-15365-bindeps-build-std branch from e04e305 to cebeb7b Compare June 24, 2026 14:42
@rustbot

rustbot commented Jun 24, 2026

Copy link
Copy Markdown
Collaborator

This PR was rebased onto a different master commit. Here's a range-diff highlighting what actually changed.

Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers.

@adamgemmell adamgemmell left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Thanks for revisiting this for per-pkg-target, I think that should be all we need to support mixed-target builds for rust-lang/rust#155363. I'm happy with the functionality and code at a low-level, a cargo team member will need to check for higher-level concerns 🙂

View changes since this review

.target_host()
.with_stderr_data(str![[r#"
...
[RUNNING] `[..]rustc --crate-name std [..]--target [ALT_TARGET][..]`

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Could you add an extra check that the host std is also built?

.iter()
.copied()
.chain(ws.members().flat_map(|p| {
let mut manifest_target_kinds = ws

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

It's a bit unfortunate that the real target of a package is only figured out during unit generation. As is, this leads to std being resolved with more targets than required if a package has both default and forced targets set.

Right now it would be feasible to do the main resolve, generate its units, then resolve std for the right targets and attach those units. But with #16675, unit generation happens in one step and so will require both resolves ahead of time.

I think that's fine for now as std doesn't actually get built more times than required. per-pkg-target is unstable (as is build-std), and I'd prefer if #16675 is merged before looking for improvements here

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-cfg-expr Area: Platform cfg expressions Command-fetch S-waiting-on-review Status: Awaiting review from the assignee but also interested parties.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Panic when combining -Zbuild-std with artifact dependencies

5 participants