Skip to content

Commit bc76592

Browse files
committed
rewrite pass-linker-flags-flavor to rmake
1 parent f11ab15 commit bc76592

File tree

4 files changed

+86
-14
lines changed

4 files changed

+86
-14
lines changed

src/tools/tidy/src/allowed_run_make_makefiles.txt

-1
Original file line numberDiff line numberDiff line change
@@ -106,7 +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
110109
run-make/pass-linker-flags-from-dep/Makefile
111110
run-make/pass-non-c-like-enum-to-c/Makefile
112111
run-make/pdb-buildinfo-cl-cmd/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,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/rmake.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ fn main() {
1212
let out = rustc()
1313
.input("empty.rs")
1414
.arg("-Zunstable-options")
15-
.args(&["-l", "static=l1"])
15+
.arg("-lstatic=l1")
1616
.arg("-llink-arg=a1")
1717
.arg("-lstatic=l2")
1818
.arg("-llink-arg=a2")
@@ -23,5 +23,6 @@ fn main() {
2323
.stdout_utf8();
2424
let out2 = rustc().input("attribute.rs").print("link-args").run_unchecked().stdout_utf8();
2525
let re = regex::Regex::new("l1.*a1.*l2.*a2.*d1.*a3").unwrap();
26-
assert!(re.is_match(&out) && re.is_match(&out2));
26+
assert!(re.is_match(&out));
27+
assert!(re.is_match(&out2));
2728
}

0 commit comments

Comments
 (0)