Skip to content

Commit 7a10070

Browse files
committed
Auto merge of #127328 - Oneirical:yield-to-petestrians, r=<try>
Migrate `pass-linker-flags-flavor`, `pass-linker-flags-from-dep` and `pass-linker-flags` `run-make` tests to rmake Part of #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: i686-msvc
2 parents 8a9cccb + 85aaaee commit 7a10070

File tree

7 files changed

+154
-31
lines changed

7 files changed

+154
-31
lines changed

src/tools/tidy/src/allowed_run_make_makefiles.txt

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -106,9 +106,6 @@ run-make/optimization-remarks-dir-pgo/Makefile
106106
run-make/optimization-remarks-dir/Makefile
107107
run-make/output-type-permutations/Makefile
108108
run-make/panic-abort-eh_frame/Makefile
109-
run-make/pass-linker-flags-flavor/Makefile
110-
run-make/pass-linker-flags-from-dep/Makefile
111-
run-make/pass-linker-flags/Makefile
112109
run-make/pass-non-c-like-enum-to-c/Makefile
113110
run-make/pdb-buildinfo-cl-cmd/Makefile
114111
run-make/pgo-gen-lto/Makefile

tests/run-make/pass-linker-flags-flavor/Makefile

Lines changed: 0 additions & 11 deletions
This file was deleted.
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
// Setting the linker flavor as a C compiler should cause the output of the -l flags to be
2+
// prefixed by -Wl, except when a flag is requested to be verbatim. A bare linker (ld) should
3+
// never cause prefixes to appear in the output. This test checks this ruleset twice, once with
4+
// explicit flags and then with those flags passed inside the rust source code.
5+
// See https://github.com/rust-lang/rust/pull/118202
6+
7+
//FIXME(Oneirical): only-linux
8+
9+
use run_make_support::{regex, rustc};
10+
11+
fn main() {
12+
let out_gnu = rustc()
13+
.input("empty.rs")
14+
.linker_flavor("gnu-cc")
15+
.arg("-Zunstable-options")
16+
.arg("-lstatic=l1")
17+
.arg("-llink-arg=a1")
18+
.arg("-lstatic=l2")
19+
.arg("-llink-arg=a2")
20+
.arg("-ldylib=d1")
21+
.arg("-llink-arg=a3")
22+
.print("link-args")
23+
.run_unchecked()
24+
.stdout_utf8();
25+
let out_gnu_verbatim = rustc()
26+
.input("empty.rs")
27+
.linker_flavor("gnu-cc")
28+
.arg("-Zunstable-options")
29+
.arg("-lstatic=l1")
30+
.arg("-llink-arg:+verbatim=a1")
31+
.arg("-lstatic=l2")
32+
.arg("-llink-arg=a2")
33+
.arg("-ldylib=d1")
34+
.arg("-llink-arg=a3")
35+
.print("link-args")
36+
.run_unchecked()
37+
.stdout_utf8();
38+
let out_ld = rustc()
39+
.input("empty.rs")
40+
.linker_flavor("ld")
41+
.arg("-Zunstable-options")
42+
.arg("-lstatic=l1")
43+
.arg("-llink-arg=a1")
44+
.arg("-lstatic=l2")
45+
.arg("-llink-arg=a2")
46+
.arg("-ldylib=d1")
47+
.arg("-llink-arg=a3")
48+
.print("link-args")
49+
.run_unchecked()
50+
.stdout_utf8();
51+
let out_att_gnu = rustc()
52+
.arg("-Zunstable-options")
53+
.linker_flavor("gnu-cc")
54+
.input("attribute.rs")
55+
.print("link-args")
56+
.run_unchecked()
57+
.stdout_utf8();
58+
let out_att_gnu_verbatim = rustc()
59+
.cfg(r#"feature="verbatim""#)
60+
.arg("-Zunstable-options")
61+
.linker_flavor("gnu-cc")
62+
.input("attribute.rs")
63+
.print("link-args")
64+
.run_unchecked()
65+
.stdout_utf8();
66+
let out_att_ld = rustc()
67+
.linker_flavor("ld")
68+
.input("attribute.rs")
69+
.print("link-args")
70+
.run_unchecked()
71+
.stdout_utf8();
72+
73+
let no_verbatim = regex::Regex::new("l1.*-Wl,a1.*l2.*-Wl,a2.*d1.*-Wl,a3").unwrap();
74+
let one_verbatim = regex::Regex::new(r#"l1.*"a1".*l2.*-Wl,a2.*d1.*-Wl,a3"#).unwrap();
75+
let ld = regex::Regex::new(r#"l1.*"a1".*l2.*"a2".*d1.*"a3""#).unwrap();
76+
77+
assert!(no_verbatim.is_match(&out_gnu));
78+
assert!(no_verbatim.is_match(&out_att_gnu));
79+
assert!(one_verbatim.is_match(&out_gnu_verbatim));
80+
assert!(one_verbatim.is_match(&out_att_gnu_verbatim));
81+
assert!(ld.is_match(&out_ld));
82+
assert!(ld.is_match(&out_att_ld));
83+
}

tests/run-make/pass-linker-flags-from-dep/Makefile

Lines changed: 0 additions & 12 deletions
This file was deleted.
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
// A similar test to pass-linker-flags, testing that the `-l link-arg` flag
2+
// respects the order relative to other `-l` flags, but this time, the flags
3+
// are passed on the compilation of a dependency. This test checks that the
4+
// downstream compiled binary contains the linker arguments of the dependency,
5+
// and in the correct order.
6+
// See https://github.com/rust-lang/rust/issues/99427
7+
8+
use run_make_support::{regex, rust_lib_name, rustc};
9+
10+
fn main() {
11+
// Build dependencies
12+
rustc().input("native_dep_1.rs").crate_type("staticlib").run();
13+
rustc().input("native_dep_2.rs").crate_type("staticlib").run();
14+
rustc()
15+
.input("rust_dep_flag.rs")
16+
.arg("-lstatic:-bundle=native_dep_1")
17+
.arg("-llink-arg=some_flag")
18+
.arg("-lstatic:-bundle=native_dep_2")
19+
.crate_type("lib")
20+
.arg("-Zunstable-options")
21+
.run();
22+
rustc().input("rust_dep_attr.rs").crate_type("lib").run();
23+
24+
// Check sequence of linker arguments
25+
let out_flag = rustc()
26+
.input("main.rs")
27+
.extern_("lib", rust_lib_name("rust_dep_flag"))
28+
.crate_type("bin")
29+
.print("link-args")
30+
.run_unchecked()
31+
.stdout_utf8();
32+
let out_attr = rustc()
33+
.input("main.rs")
34+
.extern_("lib", rust_lib_name("rust_dep_attr"))
35+
.crate_type("bin")
36+
.print("link-args")
37+
.run_unchecked()
38+
.stdout_utf8();
39+
40+
let re = regex::Regex::new("native_dep_1.*some_flag.*native_dep_2").unwrap();
41+
assert!(re.is_match(&out_flag));
42+
assert!(re.is_match(&out_attr));
43+
}

tests/run-make/pass-linker-flags/Makefile

Lines changed: 0 additions & 5 deletions
This file was deleted.
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// This test checks the proper function of `-l link-arg=NAME`, which, unlike
2+
// -C link-arg, is supposed to guarantee that the order relative to other -l
3+
// options will be respected. In this test, compilation fails (because none of the
4+
// link arguments like `a1` exist), but it is still checked if the output contains the
5+
// link arguments in the exact order they were passed in. `attribute.rs` is a variant
6+
// of the test where the flags are defined in the rust file itself.
7+
// See https://github.com/rust-lang/rust/issues/99427
8+
9+
use run_make_support::{regex, rustc};
10+
11+
fn main() {
12+
let out = rustc()
13+
.input("empty.rs")
14+
.arg("-Zunstable-options")
15+
.arg("-lstatic=l1")
16+
.arg("-llink-arg=a1")
17+
.arg("-lstatic=l2")
18+
.arg("-llink-arg=a2")
19+
.arg("-ldylib=d1")
20+
.arg("-llink-arg=a3")
21+
.print("link-args")
22+
.run_unchecked()
23+
.stdout_utf8();
24+
let out2 = rustc().input("attribute.rs").print("link-args").run_unchecked().stdout_utf8();
25+
let re = regex::Regex::new("l1.*a1.*l2.*a2.*d1.*a3").unwrap();
26+
assert!(re.is_match(&out));
27+
assert!(re.is_match(&out2));
28+
}

0 commit comments

Comments
 (0)