Skip to content

Commit d4a6200

Browse files
committed
Auto merge of rust-lang#127328 - Oneirical:yield-to-petestrians, r=jieyouxu
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
2 parents 35b658f + 9f994b6 commit d4a6200

File tree

7 files changed

+155
-31
lines changed

7 files changed

+155
-31
lines changed

src/tools/tidy/src/allowed_run_make_makefiles.txt

-3
Original file line numberDiff line numberDiff line change
@@ -98,9 +98,6 @@ run-make/no-builtins-attribute/Makefile
9898
run-make/no-duplicate-libs/Makefile
9999
run-make/obey-crate-type-flag/Makefile
100100
run-make/panic-abort-eh_frame/Makefile
101-
run-make/pass-linker-flags-flavor/Makefile
102-
run-make/pass-linker-flags-from-dep/Makefile
103-
run-make/pass-linker-flags/Makefile
104101
run-make/pass-non-c-like-enum-to-c/Makefile
105102
run-make/pdb-buildinfo-cl-cmd/Makefile
106103
run-make/pgo-gen-lto/Makefile

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

-11
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
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+
//@ only-linux
8+
// Reason: the `gnu-cc` linker is only available on linux
9+
10+
use run_make_support::{regex, rustc};
11+
12+
fn main() {
13+
let out_gnu = rustc()
14+
.input("empty.rs")
15+
.linker_flavor("gnu-cc")
16+
.arg("-Zunstable-options")
17+
.arg("-lstatic=l1")
18+
.arg("-llink-arg=a1")
19+
.arg("-lstatic=l2")
20+
.arg("-llink-arg=a2")
21+
.arg("-ldylib=d1")
22+
.arg("-llink-arg=a3")
23+
.print("link-args")
24+
.run_unchecked()
25+
.stdout_utf8();
26+
let out_gnu_verbatim = rustc()
27+
.input("empty.rs")
28+
.linker_flavor("gnu-cc")
29+
.arg("-Zunstable-options")
30+
.arg("-lstatic=l1")
31+
.arg("-llink-arg:+verbatim=a1")
32+
.arg("-lstatic=l2")
33+
.arg("-llink-arg=a2")
34+
.arg("-ldylib=d1")
35+
.arg("-llink-arg=a3")
36+
.print("link-args")
37+
.run_unchecked()
38+
.stdout_utf8();
39+
let out_ld = rustc()
40+
.input("empty.rs")
41+
.linker_flavor("ld")
42+
.arg("-Zunstable-options")
43+
.arg("-lstatic=l1")
44+
.arg("-llink-arg=a1")
45+
.arg("-lstatic=l2")
46+
.arg("-llink-arg=a2")
47+
.arg("-ldylib=d1")
48+
.arg("-llink-arg=a3")
49+
.print("link-args")
50+
.run_unchecked()
51+
.stdout_utf8();
52+
let out_att_gnu = rustc()
53+
.arg("-Zunstable-options")
54+
.linker_flavor("gnu-cc")
55+
.input("attribute.rs")
56+
.print("link-args")
57+
.run_unchecked()
58+
.stdout_utf8();
59+
let out_att_gnu_verbatim = rustc()
60+
.cfg(r#"feature="verbatim""#)
61+
.arg("-Zunstable-options")
62+
.linker_flavor("gnu-cc")
63+
.input("attribute.rs")
64+
.print("link-args")
65+
.run_unchecked()
66+
.stdout_utf8();
67+
let out_att_ld = rustc()
68+
.linker_flavor("ld")
69+
.input("attribute.rs")
70+
.print("link-args")
71+
.run_unchecked()
72+
.stdout_utf8();
73+
74+
let no_verbatim = regex::Regex::new("l1.*-Wl,a1.*l2.*-Wl,a2.*d1.*-Wl,a3").unwrap();
75+
let one_verbatim = regex::Regex::new(r#"l1.*"a1".*l2.*-Wl,a2.*d1.*-Wl,a3"#).unwrap();
76+
let ld = regex::Regex::new(r#"l1.*"a1".*l2.*"a2".*d1.*"a3""#).unwrap();
77+
78+
assert!(no_verbatim.is_match(&out_gnu));
79+
assert!(no_verbatim.is_match(&out_att_gnu));
80+
assert!(one_verbatim.is_match(&out_gnu_verbatim));
81+
assert!(one_verbatim.is_match(&out_att_gnu_verbatim));
82+
assert!(ld.is_match(&out_ld));
83+
assert!(ld.is_match(&out_att_ld));
84+
}

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

-12
This file was deleted.
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

-5
This file was deleted.
+28
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)