Skip to content

Commit 4a930ce

Browse files
authored
fix(build-std): std link metadata propagate to user (#16496)
### What does this PR try to resolve? This reverts #16489 though currently only compiler_builtins has link metadata `-Zany-build-script-metadata` is not supported yet for build-std ### How to test and review this PR? Test passes.
2 parents 2e5dd34 + 0ec8a97 commit 4a930ce

4 files changed

Lines changed: 28 additions & 5 deletions

File tree

src/cargo/core/compiler/custom_build.rs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -460,11 +460,6 @@ 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)
468463
.filter_map(|dep| {
469464
if dep.unit.mode.is_run_custom_build() {
470465
let dep_metadata = build_runner.get_run_build_script_metadata(&dep.unit);

tests/testsuite/mock-std/library/compiler_builtins/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@ name = "compiler_builtins"
33
version = "0.1.0"
44
authors = ["Alex Crichton <[email protected]>"]
55
edition = "2018"
6+
links = "compiler-rt"
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
fn main() {
2+
println!("cargo::metadata=compiler-rt=foo");
3+
}

tests/testsuite/standard_lib.rs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -419,6 +419,8 @@ fn build_std_with_no_arg_for_core_only_target() {
419419
[COMPILING] compiler_builtins v0.1.0 ([..]/library/compiler_builtins)
420420
[COMPILING] core v0.1.0 ([..]/library/core)
421421
[COMPILING] foo v0.0.1 ([ROOT]/foo)
422+
[RUNNING] `[..] rustc --crate-name build_script_build [..]/compiler_builtins/build.rs [..]`
423+
[RUNNING] `[ROOT]/foo/target/debug/build/compiler_builtins-[HASH]/build-script-build`
422424
[RUNNING] `[..] rustc --crate-name compiler_builtins [..]--target aarch64-unknown-none[..]`
423425
[RUNNING] `[..] rustc --crate-name core [..]--target aarch64-unknown-none[..]`
424426
[RUNNING] `[..] rustc --crate-name foo [..]--target aarch64-unknown-none[..]`
@@ -456,6 +458,9 @@ fn build_std_with_no_arg_for_core_only_target() {
456458
[COMPILING] rustc-std-workspace-alloc v1.9.0 ([..]/library/rustc-std-workspace-alloc)
457459
[COMPILING] registry-dep-using-alloc v1.0.0
458460
[COMPILING] std v0.1.0 ([..]/library/std)
461+
[RUNNING] `[..] rustc --crate-name build_script_build [..]/compiler_builtins/build.rs [..]`
462+
[RUNNING] `[ROOT]/foo/target/debug/build/compiler_builtins-[HASH]/build-script-build`
463+
[RUNNING] `[ROOT]/foo/target/debug/build/compiler_builtins-[HASH]/build-script-build`
459464
[RUNNING] `[..]rustc --crate-name compiler_builtins [..]--target aarch64-unknown-none[..]`
460465
[RUNNING] `[..]rustc --crate-name core [..]--target aarch64-unknown-none[..]`
461466
[RUNNING] `[..]rustc --crate-name foo [..]--target aarch64-unknown-none[..]`
@@ -866,3 +871,22 @@ fn fetch() {
866871
.with_stderr_does_not_contain("[DOWNLOADED] [..]")
867872
.run();
868873
}
874+
875+
#[cargo_test(build_std_mock)]
876+
fn std_build_script_metadata_propagate_to_user() {
877+
let setup = setup();
878+
879+
let p = project()
880+
.file("src/lib.rs", "")
881+
.file(
882+
"build.rs",
883+
r#"
884+
fn main() {
885+
assert_eq!(std::env::var("DEP_COMPILER_RT_COMPILER_RT").unwrap(), "foo");
886+
}
887+
"#,
888+
)
889+
.build();
890+
891+
p.cargo("check").build_std(&setup).target_host().run();
892+
}

0 commit comments

Comments
 (0)