forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Auto merge of rust-lang#127328 - Oneirical:yield-to-petestrians, r=ji…
…eyouxu Migrate `pass-linker-flags-flavor`, `pass-linker-flags-from-dep` and `pass-linker-flags` `run-make` tests to rmake Part of rust-lang#121876 and the associated [Google Summer of Code project](https://blog.rust-lang.org/2024/05/01/gsoc-2024-selected-projects.html). Please test on i686-msvc. Expected to fail. try-job: aarch64-apple
- Loading branch information
Showing
7 changed files
with
155 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
// Setting the linker flavor as a C compiler should cause the output of the -l flags to be | ||
// prefixed by -Wl, except when a flag is requested to be verbatim. A bare linker (ld) should | ||
// never cause prefixes to appear in the output. This test checks this ruleset twice, once with | ||
// explicit flags and then with those flags passed inside the rust source code. | ||
// See https://github.com/rust-lang/rust/pull/118202 | ||
|
||
//@ only-linux | ||
// Reason: the `gnu-cc` linker is only available on linux | ||
|
||
use run_make_support::{regex, rustc}; | ||
|
||
fn main() { | ||
let out_gnu = rustc() | ||
.input("empty.rs") | ||
.linker_flavor("gnu-cc") | ||
.arg("-Zunstable-options") | ||
.arg("-lstatic=l1") | ||
.arg("-llink-arg=a1") | ||
.arg("-lstatic=l2") | ||
.arg("-llink-arg=a2") | ||
.arg("-ldylib=d1") | ||
.arg("-llink-arg=a3") | ||
.print("link-args") | ||
.run_unchecked() | ||
.stdout_utf8(); | ||
let out_gnu_verbatim = rustc() | ||
.input("empty.rs") | ||
.linker_flavor("gnu-cc") | ||
.arg("-Zunstable-options") | ||
.arg("-lstatic=l1") | ||
.arg("-llink-arg:+verbatim=a1") | ||
.arg("-lstatic=l2") | ||
.arg("-llink-arg=a2") | ||
.arg("-ldylib=d1") | ||
.arg("-llink-arg=a3") | ||
.print("link-args") | ||
.run_unchecked() | ||
.stdout_utf8(); | ||
let out_ld = rustc() | ||
.input("empty.rs") | ||
.linker_flavor("ld") | ||
.arg("-Zunstable-options") | ||
.arg("-lstatic=l1") | ||
.arg("-llink-arg=a1") | ||
.arg("-lstatic=l2") | ||
.arg("-llink-arg=a2") | ||
.arg("-ldylib=d1") | ||
.arg("-llink-arg=a3") | ||
.print("link-args") | ||
.run_unchecked() | ||
.stdout_utf8(); | ||
let out_att_gnu = rustc() | ||
.arg("-Zunstable-options") | ||
.linker_flavor("gnu-cc") | ||
.input("attribute.rs") | ||
.print("link-args") | ||
.run_unchecked() | ||
.stdout_utf8(); | ||
let out_att_gnu_verbatim = rustc() | ||
.cfg(r#"feature="verbatim""#) | ||
.arg("-Zunstable-options") | ||
.linker_flavor("gnu-cc") | ||
.input("attribute.rs") | ||
.print("link-args") | ||
.run_unchecked() | ||
.stdout_utf8(); | ||
let out_att_ld = rustc() | ||
.linker_flavor("ld") | ||
.input("attribute.rs") | ||
.print("link-args") | ||
.run_unchecked() | ||
.stdout_utf8(); | ||
|
||
let no_verbatim = regex::Regex::new("l1.*-Wl,a1.*l2.*-Wl,a2.*d1.*-Wl,a3").unwrap(); | ||
let one_verbatim = regex::Regex::new(r#"l1.*"a1".*l2.*-Wl,a2.*d1.*-Wl,a3"#).unwrap(); | ||
let ld = regex::Regex::new(r#"l1.*"a1".*l2.*"a2".*d1.*"a3""#).unwrap(); | ||
|
||
assert!(no_verbatim.is_match(&out_gnu)); | ||
assert!(no_verbatim.is_match(&out_att_gnu)); | ||
assert!(one_verbatim.is_match(&out_gnu_verbatim)); | ||
assert!(one_verbatim.is_match(&out_att_gnu_verbatim)); | ||
assert!(ld.is_match(&out_ld)); | ||
assert!(ld.is_match(&out_att_ld)); | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
// A similar test to pass-linker-flags, testing that the `-l link-arg` flag | ||
// respects the order relative to other `-l` flags, but this time, the flags | ||
// are passed on the compilation of a dependency. This test checks that the | ||
// downstream compiled binary contains the linker arguments of the dependency, | ||
// and in the correct order. | ||
// See https://github.com/rust-lang/rust/issues/99427 | ||
|
||
use run_make_support::{regex, rust_lib_name, rustc}; | ||
|
||
fn main() { | ||
// Build dependencies | ||
rustc().input("native_dep_1.rs").crate_type("staticlib").run(); | ||
rustc().input("native_dep_2.rs").crate_type("staticlib").run(); | ||
rustc() | ||
.input("rust_dep_flag.rs") | ||
.arg("-lstatic:-bundle=native_dep_1") | ||
.arg("-llink-arg=some_flag") | ||
.arg("-lstatic:-bundle=native_dep_2") | ||
.crate_type("lib") | ||
.arg("-Zunstable-options") | ||
.run(); | ||
rustc().input("rust_dep_attr.rs").crate_type("lib").run(); | ||
|
||
// Check sequence of linker arguments | ||
let out_flag = rustc() | ||
.input("main.rs") | ||
.extern_("lib", rust_lib_name("rust_dep_flag")) | ||
.crate_type("bin") | ||
.print("link-args") | ||
.run_unchecked() | ||
.stdout_utf8(); | ||
let out_attr = rustc() | ||
.input("main.rs") | ||
.extern_("lib", rust_lib_name("rust_dep_attr")) | ||
.crate_type("bin") | ||
.print("link-args") | ||
.run_unchecked() | ||
.stdout_utf8(); | ||
|
||
let re = regex::Regex::new("native_dep_1.*some_flag.*native_dep_2").unwrap(); | ||
assert!(re.is_match(&out_flag)); | ||
assert!(re.is_match(&out_attr)); | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
// This test checks the proper function of `-l link-arg=NAME`, which, unlike | ||
// -C link-arg, is supposed to guarantee that the order relative to other -l | ||
// options will be respected. In this test, compilation fails (because none of the | ||
// link arguments like `a1` exist), but it is still checked if the output contains the | ||
// link arguments in the exact order they were passed in. `attribute.rs` is a variant | ||
// of the test where the flags are defined in the rust file itself. | ||
// See https://github.com/rust-lang/rust/issues/99427 | ||
|
||
use run_make_support::{regex, rustc}; | ||
|
||
fn main() { | ||
let out = rustc() | ||
.input("empty.rs") | ||
.arg("-Zunstable-options") | ||
.arg("-lstatic=l1") | ||
.arg("-llink-arg=a1") | ||
.arg("-lstatic=l2") | ||
.arg("-llink-arg=a2") | ||
.arg("-ldylib=d1") | ||
.arg("-llink-arg=a3") | ||
.print("link-args") | ||
.run_unchecked() | ||
.stdout_utf8(); | ||
let out2 = rustc().input("attribute.rs").print("link-args").run_unchecked().stdout_utf8(); | ||
let re = regex::Regex::new("l1.*a1.*l2.*a2.*d1.*a3").unwrap(); | ||
assert!(re.is_match(&out)); | ||
assert!(re.is_match(&out2)); | ||
} |