Skip to content

Commit 8c133af

Browse files
authored
Isolate build script metadata progation between std and non-std crates (#16489)
### 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
2 parents c9895a1 + d5c1597 commit 8c133af

1 file changed

Lines changed: 5 additions & 0 deletions

File tree

src/cargo/core/compiler/custom_build.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -460,6 +460,11 @@ fn build_work(build_runner: &mut BuildRunner<'_, '_>, unit: &Unit) -> CargoResul
460460
// sorts of variables need to be discovered at that time.
461461
let lib_deps = dependencies
462462
.iter()
463+
// We allow std dependencies to propagate metadata between other std dependencies but
464+
// not to non-std crates. Non-std crates can propagate metadata to other non-std crates.
465+
// We enforce a boundary between std and non-std crates. This may be lifted in the
466+
// future but for now we are being conservative.
467+
.filter(|dep| dep.unit.is_std == unit.is_std)
463468
.filter_map(|dep| {
464469
if dep.unit.mode.is_run_custom_build() {
465470
let dep_metadata = build_runner.get_run_build_script_metadata(&dep.unit);

0 commit comments

Comments
 (0)