Skip to content

Conversation

@ranger-ross
Copy link
Member

@ranger-ross ranger-ross commented Jan 9, 2026

What does this PR try to resolve?

This PR fixes a regression found in rust-lang/rust#150739 that was introduced in #16436.

For -Zbuild-std std dependencies, we would panic due to the dependency not being present in Cargo.toml.
This PR adds handling fallback to the unit.pkg.name() if the unit both not present in Cargo.toml and is_std. (see #16489 (comment))

This PR ensures that metadata propagation is only allowed between std->std crates and non-std->non-std crates.

How to test and review this PR?

cargo new foo
cd foo
cargo add cortex-m
cargo -Zbuild-std build

Previously we panic with

thread 'main' (4072127) panicked at src/cargo/core/compiler/custom_build.rs:472:21:
Dependency `compiler_builtins` not found in `foo`s dependencies
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

with this change we not compile successfully

r? @weihanglo

@rustbot rustbot added A-build-scripts Area: build.rs scripts S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jan 9, 2026
Comment on lines 479 to 481
// If the depenency is a build-std dependency, it might not be in
// Cargo.toml. If its not present, we simply use the package name as we
// know its not renamed.
Copy link
Member

Choose a reason for hiding this comment

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

See rust-lang/rust#150739 (comment)

Though they are not using any dep link metadata at this moment.

(I am a bit paranoid, sorry 😬)

Copy link
Member Author

Choose a reason for hiding this comment

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

I guess we can go the .filter() route mentioned in rust-lang/rust#150739 (comment) for now just to be safe?

Copy link
Member

Choose a reason for hiding this comment

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

That disables dep metadata propagation for the entire std graph, no?

Copy link
Member

Choose a reason for hiding this comment

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

Probably this filter(|dep| dep.unit.is_std == unit.is_std)?

Copy link
Member Author

@ranger-ross ranger-ross Jan 9, 2026

Choose a reason for hiding this comment

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

ahh so allow propagation for std crate -> std crate but not std crate -> user crate?

I wonder if any std crates use the build std magic not include the dependencies in their Cargo.toml?
Hopefully not?

Copy link
Member

@weihanglo weihanglo Jan 9, 2026

Choose a reason for hiding this comment

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

I wonder if any std crates use the build std magic not include the dependencies in Cargo.toml?

I guess not. std bootstrap doesn't use -Zbuild-std. It would be awkward if someone forked std and relied on -Zbuild-std attaching std root units to std units itself.

Copy link
Member Author

@ranger-ross ranger-ross Jan 9, 2026

Choose a reason for hiding this comment

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

Updated the impl to add the std/nonstd boundary, as well as the PR tilte+description.

@ranger-ross ranger-ross changed the title fix: Added handling for build-std when preparing build-script metadata Isolate build script metadata progation between std and non-std crates Jan 9, 2026
Copy link
Member

@weihanglo weihanglo left a comment

Choose a reason for hiding this comment

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

@weihanglo weihanglo enabled auto-merge January 9, 2026 03:30
@weihanglo weihanglo added this pull request to the merge queue Jan 9, 2026
Merged via the queue into rust-lang:master with commit 8c133af Jan 9, 2026
29 checks passed
@rustbot rustbot removed the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Jan 9, 2026
rust-bors bot added a commit to rust-lang/rust that referenced this pull request Jan 9, 2026
Update cargo submodule

27 commits in 94c368ad2b9db0f0da5bdd8421cea13786ce4412..8c133afcd5e0d69932fe11f5907683723f8d361d
2025-12-26 19:39:15 +0000 to 2026-01-09 03:50:15 +0000
- Isolate build script metadata progation between std and non-std crates (rust-lang/cargo#16489)
- Add Clippy like lint groups (rust-lang/cargo#16464)
- feat: in-memory only `Manifest` (rust-lang/cargo#16409)
- Fixed incorrect version comparision during build script dependency selection (rust-lang/cargo#16486)
- refactor: new type for unit index (rust-lang/cargo#16485)
- feat(test): Make CARGO_BIN_EXE_ available at runtime  (rust-lang/cargo#16421)
- fix(package): detect dirty files when run from workspace member (rust-lang/cargo#16479)
- fix(timing)!: remove `--timings=<FMT>` optional format values (rust-lang/cargo#16420)
- docs(unstable): expand docs for `-Zbuild-analysis` (rust-lang/cargo#16476)
- test: add `-Zunstable-options` with custom targets (rust-lang/cargo#16467)
- feat(report): add cargo report rebuilds  (rust-lang/cargo#16456)
- feat(test-support): Use test name for dir when running tests (rust-lang/cargo#16121)
- refactor: Migrate some cases to expect/reason (rust-lang/cargo#16461)
- docs(build-script): clarify OUT_DIR is not cleaned between builds (rust-lang/cargo#16437)
- chore: Update dependencies (rust-lang/cargo#16460)
- Update handlebars to 6.4.0 (rust-lang/cargo#16457)
- chore(deps): update alpine docker tag to v3.23 (rust-lang/cargo#16454)
- Any build scripts can now use cargo::metadata=KEY=VALUE (rust-lang/cargo#16436)
- fix(log): add `dependencies` field to `UnitRegistered` (rust-lang/cargo#16448)
- Implement fine grain locking for `build-dir` (rust-lang/cargo#16155)
- feat(resolver): List features when no close match (rust-lang/cargo#16445)
- feat(report): new command `cargo report sessions` (rust-lang/cargo#16428)
- feat (patch): Display where the patch was defined in patch-related error messages (rust-lang/cargo#16407)
- test(build-rs): Reduce from 'build' to 'check' where possible (rust-lang/cargo#16444)
- feat(toml): TOML 1.1 parse support (rust-lang/cargo#16415)
- feat(report): support --manifest-path in `cargo report timings` (rust-lang/cargo#16441)
- fix(vendor): recursively filter git files in subdirectories (rust-lang/cargo#16439)
@rustbot rustbot added this to the 1.94.0 milestone Jan 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-build-scripts Area: build.rs scripts

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants