From fa2b6122135ad18640e2e9b47450f50fa873c54a Mon Sep 17 00:00:00 2001 From: Oneirical Date: Thu, 6 Jun 2024 11:55:24 -0400 Subject: [PATCH] Rewrite link-args-order to rmake --- src/doc/book | 2 +- src/tools/cargo | 2 +- src/tools/run-make-support/src/rustc.rs | 24 ++++++++++++ .../tidy/src/allowed_run_make_makefiles.txt | 1 - tests/run-make/link-args-order/Makefile | 10 ----- tests/run-make/link-args-order/rmake.rs | 39 +++++++++++++++++++ 6 files changed, 65 insertions(+), 13 deletions(-) delete mode 100644 tests/run-make/link-args-order/Makefile create mode 100644 tests/run-make/link-args-order/rmake.rs diff --git a/src/doc/book b/src/doc/book index 45c1a6d69ed..5228bfac826 160000 --- a/src/doc/book +++ b/src/doc/book @@ -1 +1 @@ -Subproject commit 45c1a6d69edfd1fc91fb7504cb73958dbd09441e +Subproject commit 5228bfac8267ad24659a81b92ec5417976b5edbc diff --git a/src/tools/cargo b/src/tools/cargo index a1f47ec3f7c..4dcbca118ab 160000 --- a/src/tools/cargo +++ b/src/tools/cargo @@ -1 +1 @@ -Subproject commit a1f47ec3f7cd076986f1bfcd7061f2e8cb1a726e +Subproject commit 4dcbca118ab7f9ffac4728004c983754bc6a04ff diff --git a/src/tools/run-make-support/src/rustc.rs b/src/tools/run-make-support/src/rustc.rs index 331e1a5ab8b..7e5a637e20e 100644 --- a/src/tools/run-make-support/src/rustc.rs +++ b/src/tools/run-make-support/src/rustc.rs @@ -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>(&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 + } } diff --git a/src/tools/tidy/src/allowed_run_make_makefiles.txt b/src/tools/tidy/src/allowed_run_make_makefiles.txt index 1596257747f..feb31e25e5f 100644 --- a/src/tools/tidy/src/allowed_run_make_makefiles.txt +++ b/src/tools/tidy/src/allowed_run_make_makefiles.txt @@ -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 diff --git a/tests/run-make/link-args-order/Makefile b/tests/run-make/link-args-order/Makefile deleted file mode 100644 index c562cc1b396..00000000000 --- a/tests/run-make/link-args-order/Makefile +++ /dev/null @@ -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"' diff --git a/tests/run-make/link-args-order/rmake.rs b/tests/run-make/link-args-order/rmake.rs new file mode 100644 index 00000000000..cd921a03129 --- /dev/null +++ b/tests/run-make/link-args-order/rmake.rs @@ -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\"") + ); +}