Rewrite link-args-order to rmake

This commit is contained in:
Oneirical 2024-06-06 11:55:24 -04:00
parent 8814b926f4
commit fa2b612213
6 changed files with 65 additions and 13 deletions

@ -1 +1 @@
Subproject commit 45c1a6d69edfd1fc91fb7504cb73958dbd09441e
Subproject commit 5228bfac8267ad24659a81b92ec5417976b5edbc

@ -1 +1 @@
Subproject commit a1f47ec3f7cd076986f1bfcd7061f2e8cb1a726e
Subproject commit 4dcbca118ab7f9ffac4728004c983754bc6a04ff

View File

@ -230,6 +230,24 @@ impl Rustc {
self
}
/// Add multiple extra arguments to the linker invocation, via `-Clink-args`.
pub fn link_args(&mut self, link_args: &str) -> &mut Self {
self.cmd.arg(format!("-Clink-args={link_args}"));
self
}
/// Add an extra argument to prepend the linker invocation, via `-Zpre-link-arg`.
pub fn pre_link_arg(&mut self, link_arg: &str) -> &mut Self {
self.cmd.arg(format!("-Zpre-link-arg={link_arg}"));
self
}
/// Add multiple extra arguments to the linker invocation, via `-Zpre-link-args`.
pub fn pre_link_args(&mut self, link_args: &str) -> &mut Self {
self.cmd.arg(format!("-Zpre-link-args={link_args}"));
self
}
/// Specify a stdin input
pub fn stdin<I: AsRef<[u8]>>(&mut self, input: I) -> &mut Self {
self.cmd.set_stdin(input.as_ref().to_vec().into_boxed_slice());
@ -248,4 +266,10 @@ impl Rustc {
self.cmd.arg(format!("-Clinker={linker}"));
self
}
/// Specify the linker flavor
pub fn linker_flavor(&mut self, linker_flavor: &str) -> &mut Self {
self.cmd.arg(format!("-Clinker-flavor={linker_flavor}"));
self
}
}

View File

@ -100,7 +100,6 @@ run-make/libtest-json/Makefile
run-make/libtest-junit/Makefile
run-make/libtest-padding/Makefile
run-make/libtest-thread-limit/Makefile
run-make/link-args-order/Makefile
run-make/link-cfg/Makefile
run-make/link-framework/Makefile
run-make/link-path-order/Makefile

View File

@ -1,10 +0,0 @@
# ignore-msvc
include ../tools.mk
RUSTC_FLAGS = -C linker-flavor=ld -C link-arg=a -C link-args="b c" -C link-args="d e" -C link-arg=f
RUSTC_FLAGS_PRE = -C linker-flavor=ld -Z pre-link-arg=a -Z pre-link-args="b c" -Z pre-link-args="d e" -Z pre-link-arg=f
all:
$(RUSTC) $(RUSTC_FLAGS) empty.rs 2>&1 | $(CGREP) '"a" "b" "c" "d" "e" "f"'
$(RUSTC) $(RUSTC_FLAGS_PRE) empty.rs 2>&1 | $(CGREP) '"a" "b" "c" "d" "e" "f"'

View File

@ -0,0 +1,39 @@
// Passing linker arguments to the compiler used to be lost or reordered in a messy way
// as they were passed further to the linker. This was fixed in #70665, and this test
// checks that linker arguments remain intact and in the order they were originally passed in.
// See https://github.com/rust-lang/rust/pull/70665
use run_make_support::rustc;
fn main() {
assert!(
String::from_utf8(
rustc()
.input("empty.rs")
.linker_flavor("ld")
.link_arg("a")
.link_args("\"b c\"")
.link_args("\"d e\"")
.link_arg("f")
.run_fail()
.stderr
)
.unwrap()
.contains("\"a\" \"b\" \"c\" \"d\" \"e\" \"f\"")
);
assert!(
String::from_utf8(
rustc()
.input("empty.rs")
.linker_flavor("ld")
.pre_link_arg("a")
.pre_link_args("\"b c\"")
.pre_link_args("\"d e\"")
.pre_link_arg("f")
.run_fail()
.stderr
)
.unwrap()
.contains("\"a\" \"b\" \"c\" \"d\" \"e\" \"f\"")
);
}