rewrite pass-linker-flags-from-dep to rmake

This commit is contained in:
Oneirical 2024-07-04 13:46:26 -04:00
parent bc765929fb
commit 9f994b633a
4 changed files with 45 additions and 14 deletions

View File

@ -106,7 +106,6 @@ run-make/optimization-remarks-dir-pgo/Makefile
run-make/optimization-remarks-dir/Makefile
run-make/output-type-permutations/Makefile
run-make/panic-abort-eh_frame/Makefile
run-make/pass-linker-flags-from-dep/Makefile
run-make/pass-non-c-like-enum-to-c/Makefile
run-make/pdb-buildinfo-cl-cmd/Makefile
run-make/pgo-gen-lto/Makefile

View File

@ -4,7 +4,8 @@
// explicit flags and then with those flags passed inside the rust source code.
// See https://github.com/rust-lang/rust/pull/118202
//FIXME(Oneirical): only-linux
//@ only-linux
// Reason: the `gnu-cc` linker is only available on linux
use run_make_support::{regex, rustc};

View File

@ -1,12 +0,0 @@
include ../tools.mk
all:
# Build deps
$(RUSTC) native_dep_1.rs --crate-type=staticlib
$(RUSTC) native_dep_2.rs --crate-type=staticlib
$(RUSTC) rust_dep_flag.rs -l static:-bundle=native_dep_1 -l link-arg=some_flag -l static:-bundle=native_dep_2 --crate-type=lib -Z unstable-options
$(RUSTC) rust_dep_attr.rs --crate-type=lib
# Check sequence of linker args
$(RUSTC) main.rs --extern lib=$(TMPDIR)/librust_dep_flag.rlib --crate-type=bin --print link-args | $(CGREP) -e 'native_dep_1.*some_flag.*native_dep_2'
$(RUSTC) main.rs --extern lib=$(TMPDIR)/librust_dep_attr.rlib --crate-type=bin --print link-args | $(CGREP) -e 'native_dep_1.*some_flag.*native_dep_2'

View File

@ -0,0 +1,43 @@
// A similar test to pass-linker-flags, testing that the `-l link-arg` flag
// respects the order relative to other `-l` flags, but this time, the flags
// are passed on the compilation of a dependency. This test checks that the
// downstream compiled binary contains the linker arguments of the dependency,
// and in the correct order.
// See https://github.com/rust-lang/rust/issues/99427
use run_make_support::{regex, rust_lib_name, rustc};
fn main() {
// Build dependencies
rustc().input("native_dep_1.rs").crate_type("staticlib").run();
rustc().input("native_dep_2.rs").crate_type("staticlib").run();
rustc()
.input("rust_dep_flag.rs")
.arg("-lstatic:-bundle=native_dep_1")
.arg("-llink-arg=some_flag")
.arg("-lstatic:-bundle=native_dep_2")
.crate_type("lib")
.arg("-Zunstable-options")
.run();
rustc().input("rust_dep_attr.rs").crate_type("lib").run();
// Check sequence of linker arguments
let out_flag = rustc()
.input("main.rs")
.extern_("lib", rust_lib_name("rust_dep_flag"))
.crate_type("bin")
.print("link-args")
.run_unchecked()
.stdout_utf8();
let out_attr = rustc()
.input("main.rs")
.extern_("lib", rust_lib_name("rust_dep_attr"))
.crate_type("bin")
.print("link-args")
.run_unchecked()
.stdout_utf8();
let re = regex::Regex::new("native_dep_1.*some_flag.*native_dep_2").unwrap();
assert!(re.is_match(&out_flag));
assert!(re.is_match(&out_attr));
}