From 2c6338b856230e7230129d3c689176aa1136680d Mon Sep 17 00:00:00 2001 From: Eric Huss Date: Sun, 26 Jan 2025 12:43:34 -0800 Subject: [PATCH 1/2] Update test message for E0433 The text of the message was changed in https://github.com/rust-lang/rust/pull/133154 --- tests/testsuite/standard_lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/testsuite/standard_lib.rs b/tests/testsuite/standard_lib.rs index d072a196454..47079ee8b0f 100644 --- a/tests/testsuite/standard_lib.rs +++ b/tests/testsuite/standard_lib.rs @@ -699,7 +699,7 @@ fn no_implicit_alloc() { .target_host() .with_stderr_data(str![[r#" ... -error[E0433]: failed to resolve: use of undeclared crate or module `alloc` +error[E0433]: failed to resolve[..]`alloc` ... "#]]) .with_status(101) From c35cb56d326c646fe1d6f2c2ff275d9aaf5d6d8c Mon Sep 17 00:00:00 2001 From: Eric Huss Date: Sun, 26 Jan 2025 13:25:17 -0800 Subject: [PATCH 2/2] Update tests to deal with linker warnings Nightly recently introduced the `linker-messages` lint which prints any messages from linkers. These tests were triggering that lint because they were passing missing directories to the linker. This fixes it by creating empty directories to pass to the linker. Note that this lint will be downgraded soon via https://github.com/rust-lang/rust/pull/136098, but it seemed worthwhile to fix the underlying problem. This also fixes a problem where build_script_needed_for_host_and_target was not testing for the correct command-line flags. These got lost in https://github.com/rust-lang/cargo/pull/14132. --- tests/testsuite/build_script.rs | 39 +++++++++++++++++++++----------- tests/testsuite/cross_compile.rs | 12 ++++++---- 2 files changed, 34 insertions(+), 17 deletions(-) diff --git a/tests/testsuite/build_script.rs b/tests/testsuite/build_script.rs index ef2ef093cf8..a072d567f2d 100644 --- a/tests/testsuite/build_script.rs +++ b/tests/testsuite/build_script.rs @@ -878,20 +878,26 @@ fn custom_build_script_rustc_flags() { "foo/build.rs", r#" fn main() { - println!("cargo::rustc-flags=-l nonexistinglib -L /dummy/path1 -L /dummy/path2"); + let root = std::env::current_dir().unwrap(); + let root = root.parent().unwrap(); + println!("cargo::rustc-flags=-l nonexistinglib \ + -L {R}/dummy-path1 -L {R}/dummy-path2", R=root.display()); } "#, ) .build(); + p.root().join("dummy-path1").mkdir_p(); + p.root().join("dummy-path2").mkdir_p(); - p.cargo("build --verbose").with_stderr_data(str![[r#" + p.cargo("build --verbose") + .with_stderr_data(str![[r#" [LOCKING] 1 package to latest compatible version [COMPILING] foo v0.5.0 ([ROOT]/foo/foo) [RUNNING] `rustc --crate-name build_script_build --edition=2015 foo/build.rs [..]` [RUNNING] `[ROOT]/foo/target/debug/build/foo-[HASH]/build-script-build` -[RUNNING] `rustc --crate-name foo --edition=2015 foo/src/lib.rs [..]-L dependency=[ROOT]/foo/target/debug/deps -L /dummy/path1 -L /dummy/path2 -l nonexistinglib` +[RUNNING] `rustc --crate-name foo --edition=2015 foo/src/lib.rs [..]-L dependency=[ROOT]/foo/target/debug/deps -L [ROOT]/foo/dummy-path1 -L [ROOT]/foo/dummy-path2 -l nonexistinglib` [COMPILING] bar v0.5.0 ([ROOT]/foo) -[RUNNING] `rustc --crate-name bar --edition=2015 src/main.rs [..]-L dependency=[ROOT]/foo/target/debug/deps --extern foo=[ROOT]/foo/target/debug/deps/libfoo-[HASH].rlib -L /dummy/path1 -L /dummy/path2` +[RUNNING] `rustc --crate-name bar --edition=2015 src/main.rs [..]-L dependency=[ROOT]/foo/target/debug/deps --extern foo=[ROOT]/foo/target/debug/deps/libfoo-[HASH].rlib -L [ROOT]/foo/dummy-path1 -L [ROOT]/foo/dummy-path2` [FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s "#]]).run(); @@ -932,20 +938,25 @@ fn custom_build_script_rustc_flags_no_space() { "foo/build.rs", r#" fn main() { - println!("cargo::rustc-flags=-lnonexistinglib -L/dummy/path1 -L/dummy/path2"); + let root = std::env::current_dir().unwrap(); + let root = root.parent().unwrap(); + println!("cargo::rustc-flags=-lnonexistinglib \ + -L {R}/dummy-path1 -L {R}/dummy-path2", R=root.display()); } "#, ) .build(); + p.root().join("dummy-path1").mkdir_p(); + p.root().join("dummy-path2").mkdir_p(); p.cargo("build --verbose").with_stderr_data(str![[r#" [LOCKING] 1 package to latest compatible version [COMPILING] foo v0.5.0 ([ROOT]/foo/foo) [RUNNING] `rustc --crate-name build_script_build --edition=2015 foo/build.rs [..]` [RUNNING] `[ROOT]/foo/target/debug/build/foo-[HASH]/build-script-build` -[RUNNING] `rustc --crate-name foo --edition=2015 foo/src/lib.rs [..]-L dependency=[ROOT]/foo/target/debug/deps -L /dummy/path1 -L /dummy/path2 -l nonexistinglib` +[RUNNING] `rustc --crate-name foo --edition=2015 foo/src/lib.rs [..]-L dependency=[ROOT]/foo/target/debug/deps -L [ROOT]/foo/dummy-path1 -L [ROOT]/foo/dummy-path2 -l nonexistinglib` [COMPILING] bar v0.5.0 ([ROOT]/foo) -[RUNNING] `rustc --crate-name bar --edition=2015 src/main.rs [..]-L dependency=[ROOT]/foo/target/debug/deps --extern foo=[ROOT]/foo/target/debug/deps/libfoo-[HASH].rlib -L /dummy/path1 -L /dummy/path2` +[RUNNING] `rustc --crate-name bar --edition=2015 src/main.rs [..]-L dependency=[ROOT]/foo/target/debug/deps --extern foo=[ROOT]/foo/target/debug/deps/libfoo-[HASH].rlib -L [ROOT]/foo/dummy-path1 -L [ROOT]/foo/dummy-path2` [FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s "#]]).run(); @@ -2975,11 +2986,13 @@ fn flags_go_into_tests() { "a/build.rs", r#" fn main() { - println!("cargo::rustc-link-search=test"); + let path = std::env::current_dir().unwrap().parent().unwrap().join("link-dir"); + println!("cargo::rustc-link-search={}", path.display()); } "#, ) .build(); + p.root().join("link-dir").mkdir_p(); p.cargo("test -v --test=foo") .with_stderr_data(str![[r#" @@ -2987,12 +3000,12 @@ fn flags_go_into_tests() { [COMPILING] a v0.5.0 ([ROOT]/foo/a) [RUNNING] `rustc [..] a/build.rs [..]` [RUNNING] `[ROOT]/foo/target/debug/build/a-[HASH]/build-script-build` -[RUNNING] `rustc [..] a/src/lib.rs [..] -L test` +[RUNNING] `rustc [..] a/src/lib.rs [..] -L [ROOT]/foo/link-dir` [COMPILING] b v0.5.0 ([ROOT]/foo/b) -[RUNNING] `rustc [..] b/src/lib.rs [..] -L test` +[RUNNING] `rustc [..] b/src/lib.rs [..] -L [ROOT]/foo/link-dir` [COMPILING] foo v0.5.0 ([ROOT]/foo) -[RUNNING] `rustc [..] src/lib.rs [..] -L test` -[RUNNING] `rustc [..] tests/foo.rs [..] -L test` +[RUNNING] `rustc [..] src/lib.rs [..] -L [ROOT]/foo/link-dir` +[RUNNING] `rustc [..] tests/foo.rs [..] -L [ROOT]/foo/link-dir` [FINISHED] `test` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s [RUNNING] `[ROOT]/foo/target/debug/deps/foo-[HASH][EXE]` @@ -3011,7 +3024,7 @@ test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; fini .with_stderr_data(str![[r#" [FRESH] a v0.5.0 ([ROOT]/foo/a) [COMPILING] b v0.5.0 ([ROOT]/foo/b) -[RUNNING] `rustc --crate-name b [..] -L test` +[RUNNING] `rustc --crate-name b [..] -L [ROOT]/foo/link-dir` [FINISHED] `test` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s [RUNNING] `[ROOT]/foo/target/debug/deps/b-[HASH][EXE]` diff --git a/tests/testsuite/cross_compile.rs b/tests/testsuite/cross_compile.rs index 54901c35dca..f84efeab1a7 100644 --- a/tests/testsuite/cross_compile.rs +++ b/tests/testsuite/cross_compile.rs @@ -731,7 +731,9 @@ fn build_script_needed_for_host_and_target() { use std::env; fn main() { let target = env::var("TARGET").unwrap(); - println!("cargo::rustc-flags=-L /path/to/{}", target); + let root = std::env::current_dir().unwrap(); + let root = root.parent().unwrap().join(format!("link-{target}")); + println!("cargo::rustc-flags=-L {}", root.display()); } "#, ) @@ -757,6 +759,8 @@ fn build_script_needed_for_host_and_target() { ", ) .build(); + p.root().join(format!("link-{target}")).mkdir_p(); + p.root().join(format!("link-{}", rustc_host())).mkdir_p(); p.cargo("build -v --target") .arg(&target) @@ -769,11 +773,11 @@ fn build_script_needed_for_host_and_target() { [RUNNING] `rustc [..] d1/src/lib.rs [..] --out-dir [ROOT]/foo/target/debug/deps [..] [RUNNING] `rustc [..] d1/src/lib.rs [..] --out-dir [ROOT]/foo/target/[ALT_TARGET]/debug/deps [..] [COMPILING] d2 v0.0.0 ([ROOT]/foo/d2) -[RUNNING] `rustc [..] d2/src/lib.rs [..] --out-dir [ROOT]/foo/target/debug/deps [..] +[RUNNING] `rustc [..] d2/src/lib.rs [..] --out-dir [ROOT]/foo/target/debug/deps [..]-L [ROOT]/foo/link-[HOST_TARGET]` [COMPILING] foo v0.0.0 ([ROOT]/foo) -[RUNNING] `rustc [..] build.rs [..] --out-dir [ROOT]/foo/target/debug/build/foo-[HASH] [..] +[RUNNING] `rustc [..] build.rs [..] --out-dir [ROOT]/foo/target/debug/build/foo-[HASH] [..]-L [ROOT]/foo/link-[HOST_TARGET]` [RUNNING] `[ROOT]/foo/target/debug/build/foo-[HASH]/build-script-build` -[RUNNING] `rustc [..] src/main.rs [..] --out-dir [ROOT]/foo/target/[ALT_TARGET]/debug/deps --target [ALT_TARGET] [..] +[RUNNING] `rustc [..] src/main.rs [..] --out-dir [ROOT]/foo/target/[ALT_TARGET]/debug/deps --target [ALT_TARGET] [..]-L [ROOT]/foo/link-[ALT_TARGET]` [FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s "#]].unordered())