Skip to content

Commit fa2b612

Browse files
committed
Rewrite link-args-order to rmake
1 parent 8814b92 commit fa2b612

File tree

6 files changed

+65
-13
lines changed

6 files changed

+65
-13
lines changed

src/tools/cargo

Submodule cargo updated 74 files

src/tools/run-make-support/src/rustc.rs

+24
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,24 @@ impl Rustc {
230230
self
231231
}
232232

233+
/// Add multiple extra arguments to the linker invocation, via `-Clink-args`.
234+
pub fn link_args(&mut self, link_args: &str) -> &mut Self {
235+
self.cmd.arg(format!("-Clink-args={link_args}"));
236+
self
237+
}
238+
239+
/// Add an extra argument to prepend the linker invocation, via `-Zpre-link-arg`.
240+
pub fn pre_link_arg(&mut self, link_arg: &str) -> &mut Self {
241+
self.cmd.arg(format!("-Zpre-link-arg={link_arg}"));
242+
self
243+
}
244+
245+
/// Add multiple extra arguments to the linker invocation, via `-Zpre-link-args`.
246+
pub fn pre_link_args(&mut self, link_args: &str) -> &mut Self {
247+
self.cmd.arg(format!("-Zpre-link-args={link_args}"));
248+
self
249+
}
250+
233251
/// Specify a stdin input
234252
pub fn stdin<I: AsRef<[u8]>>(&mut self, input: I) -> &mut Self {
235253
self.cmd.set_stdin(input.as_ref().to_vec().into_boxed_slice());
@@ -248,4 +266,10 @@ impl Rustc {
248266
self.cmd.arg(format!("-Clinker={linker}"));
249267
self
250268
}
269+
270+
/// Specify the linker flavor
271+
pub fn linker_flavor(&mut self, linker_flavor: &str) -> &mut Self {
272+
self.cmd.arg(format!("-Clinker-flavor={linker_flavor}"));
273+
self
274+
}
251275
}

src/tools/tidy/src/allowed_run_make_makefiles.txt

-1
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,6 @@ run-make/libtest-json/Makefile
100100
run-make/libtest-junit/Makefile
101101
run-make/libtest-padding/Makefile
102102
run-make/libtest-thread-limit/Makefile
103-
run-make/link-args-order/Makefile
104103
run-make/link-cfg/Makefile
105104
run-make/link-framework/Makefile
106105
run-make/link-path-order/Makefile

tests/run-make/link-args-order/Makefile

-10
This file was deleted.
+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
// Passing linker arguments to the compiler used to be lost or reordered in a messy way
2+
// as they were passed further to the linker. This was fixed in #70665, and this test
3+
// checks that linker arguments remain intact and in the order they were originally passed in.
4+
// See https://github.com/rust-lang/rust/pull/70665
5+
6+
use run_make_support::rustc;
7+
8+
fn main() {
9+
assert!(
10+
String::from_utf8(
11+
rustc()
12+
.input("empty.rs")
13+
.linker_flavor("ld")
14+
.link_arg("a")
15+
.link_args("\"b c\"")
16+
.link_args("\"d e\"")
17+
.link_arg("f")
18+
.run_fail()
19+
.stderr
20+
)
21+
.unwrap()
22+
.contains("\"a\" \"b\" \"c\" \"d\" \"e\" \"f\"")
23+
);
24+
assert!(
25+
String::from_utf8(
26+
rustc()
27+
.input("empty.rs")
28+
.linker_flavor("ld")
29+
.pre_link_arg("a")
30+
.pre_link_args("\"b c\"")
31+
.pre_link_args("\"d e\"")
32+
.pre_link_arg("f")
33+
.run_fail()
34+
.stderr
35+
)
36+
.unwrap()
37+
.contains("\"a\" \"b\" \"c\" \"d\" \"e\" \"f\"")
38+
);
39+
}

0 commit comments

Comments
 (0)