about summary refs log tree commit diff
diff options
context:
space:
mode:
authorOneirical <manchot@videotron.ca>2024-07-22 15:08:26 -0400
committerOneirical <manchot@videotron.ca>2024-07-26 12:07:17 -0400
commitc8f049cd802fd7e5a111218d65822a80bb796ac4 (patch)
treeef54bed7713b37e5743f91e824019721ccf79592
parent4f7f60b927e4c7f951664e75e7ed385aee080d83 (diff)
downloadrust-c8f049cd802fd7e5a111218d65822a80bb796ac4.tar.gz
rust-c8f049cd802fd7e5a111218d65822a80bb796ac4.zip
rewrite native-link-modifier-whole-archive to rmake
-rw-r--r--src/tools/tidy/src/allowed_run_make_makefiles.txt1
-rw-r--r--tests/run-make/native-link-modifier-whole-archive/Makefile52
-rw-r--r--tests/run-make/native-link-modifier-whole-archive/rmake.rs85
3 files changed, 85 insertions, 53 deletions
diff --git a/src/tools/tidy/src/allowed_run_make_makefiles.txt b/src/tools/tidy/src/allowed_run_make_makefiles.txt
index 86add3a75b1..3ee3bf65cfa 100644
--- a/src/tools/tidy/src/allowed_run_make_makefiles.txt
+++ b/src/tools/tidy/src/allowed_run_make_makefiles.txt
@@ -34,7 +34,6 @@ run-make/long-linker-command-lines/Makefile
 run-make/macos-deployment-target/Makefile
 run-make/min-global-align/Makefile
 run-make/native-link-modifier-bundle/Makefile
-run-make/native-link-modifier-whole-archive/Makefile
 run-make/no-alloc-shim/Makefile
 run-make/no-builtins-attribute/Makefile
 run-make/pdb-buildinfo-cl-cmd/Makefile
diff --git a/tests/run-make/native-link-modifier-whole-archive/Makefile b/tests/run-make/native-link-modifier-whole-archive/Makefile
deleted file mode 100644
index 5eb7a416f91..00000000000
--- a/tests/run-make/native-link-modifier-whole-archive/Makefile
+++ /dev/null
@@ -1,52 +0,0 @@
-# ignore-cross-compile -- compiling C++ code does not work well when cross-compiling
-
-# This test case makes sure that native libraries are linked with appropriate semantics
-# when the `[+-]bundle,[+-]whole-archive` modifiers are applied to them.
-#
-# The test works by checking that the resulting executables produce the expected output,
-# part of which is emitted by otherwise unreferenced C code. If +whole-archive didn't work
-# that code would never make it into the final executable and we'd thus be missing some
-# of the output.
-
-include ../tools.mk
-
-all: $(TMPDIR)/$(call BIN,directly_linked) \
-     $(TMPDIR)/$(call BIN,directly_linked_test_plus_whole_archive) \
-     $(TMPDIR)/$(call BIN,directly_linked_test_minus_whole_archive) \
-     $(TMPDIR)/$(call BIN,indirectly_linked) \
-     $(TMPDIR)/$(call BIN,indirectly_linked_via_attr)
-	$(call RUN,directly_linked) | $(CGREP) 'static-initializer.directly_linked.'
-	$(call RUN,directly_linked_test_plus_whole_archive) --nocapture | $(CGREP) 'static-initializer.'
-	$(call RUN,directly_linked_test_minus_whole_archive) --nocapture | $(CGREP) -v 'static-initializer.'
-	$(call RUN,indirectly_linked) | $(CGREP) 'static-initializer.indirectly_linked.'
-	$(call RUN,indirectly_linked_via_attr) | $(CGREP) 'static-initializer.native_lib_in_src.'
-
-# Native lib linked directly into executable
-$(TMPDIR)/$(call BIN,directly_linked): $(call NATIVE_STATICLIB,c_static_lib_with_constructor)
-	$(RUSTC) directly_linked.rs -l static:+whole-archive=c_static_lib_with_constructor
-
-# Native lib linked into test executable, +whole-archive
-$(TMPDIR)/$(call BIN,directly_linked_test_plus_whole_archive): $(call NATIVE_STATICLIB,c_static_lib_with_constructor)
-	$(RUSTC) directly_linked_test_plus_whole_archive.rs --test -l static:+whole-archive=c_static_lib_with_constructor
-# Native lib linked into test executable, -whole-archive
-$(TMPDIR)/$(call BIN,directly_linked_test_minus_whole_archive): $(call NATIVE_STATICLIB,c_static_lib_with_constructor)
-	$(RUSTC) directly_linked_test_minus_whole_archive.rs --test -l static:-whole-archive=c_static_lib_with_constructor
-
-# Native lib linked into RLIB via `-l static:-bundle,+whole-archive`, RLIB linked into executable
-$(TMPDIR)/$(call BIN,indirectly_linked): $(TMPDIR)/librlib_with_cmdline_native_lib.rlib
-	$(RUSTC) indirectly_linked.rs
-
-# Native lib linked into RLIB via #[link] attribute, RLIB linked into executable
-$(TMPDIR)/$(call BIN,indirectly_linked_via_attr): $(TMPDIR)/libnative_lib_in_src.rlib
-	$(RUSTC) indirectly_linked_via_attr.rs
-
-# Native lib linked into rlib with via commandline
-$(TMPDIR)/librlib_with_cmdline_native_lib.rlib: $(call NATIVE_STATICLIB,c_static_lib_with_constructor)
-	$(RUSTC) rlib_with_cmdline_native_lib.rs --crate-type=rlib -l static:-bundle,+whole-archive=c_static_lib_with_constructor
-
-# Native lib linked into rlib via `#[link()]` attribute on extern block.
-$(TMPDIR)/libnative_lib_in_src.rlib: $(call NATIVE_STATICLIB,c_static_lib_with_constructor)
-	$(RUSTC) native_lib_in_src.rs --crate-type=rlib
-
-$(TMPDIR)/libc_static_lib_with_constructor.o: c_static_lib_with_constructor.cpp
-	$(call COMPILE_OBJ_CXX,$@,$<)
diff --git a/tests/run-make/native-link-modifier-whole-archive/rmake.rs b/tests/run-make/native-link-modifier-whole-archive/rmake.rs
new file mode 100644
index 00000000000..4e1f34d112e
--- /dev/null
+++ b/tests/run-make/native-link-modifier-whole-archive/rmake.rs
@@ -0,0 +1,85 @@
+// This test case makes sure that native libraries are linked with appropriate semantics
+// when the `[+-]bundle,[+-]whole-archive` modifiers are applied to them.
+// The test works by checking that the resulting executables produce the expected output,
+// part of which is emitted by otherwise unreferenced C code. If +whole-archive didn't work
+// that code would never make it into the final executable and we'd thus be missing some
+// of the output.
+// See https://github.com/rust-lang/rust/issues/88085
+
+//@ ignore-cross-compile
+// Reason: compiling C++ code does not work well when cross-compiling
+// plus, the compiled binary is executed
+
+use run_make_support::{cxx, is_msvc, llvm_ar, run, run_with_args, rustc, static_lib_name};
+
+fn main() {
+    let mut cxx = cxx();
+    if is_msvc() {
+        cxx.arg("-EHs");
+    }
+    cxx.input("c_static_lib_with_constructor.cpp")
+        .arg("-c")
+        .out_exe("libc_static_lib_with_constructor")
+        .run();
+
+    let mut llvm_ar = llvm_ar();
+    llvm_ar.obj_to_ar();
+    if is_msvc() {
+        llvm_ar
+            .output_input(
+                static_lib_name("c_static_lib_with_constructor"),
+                "libc_static_lib_with_constructor.obj",
+            )
+            .run();
+    } else {
+        llvm_ar
+            .output_input(
+                static_lib_name("c_static_lib_with_constructor"),
+                "libc_static_lib_with_constructor",
+            )
+            .run();
+    }
+
+    // Native lib linked directly into executable
+    rustc()
+        .input("directly_linked.rs")
+        .arg("-lstatic:+whole-archive=c_static_lib_with_constructor")
+        .run();
+
+    // Native lib linked into test executable, +whole-archive
+    rustc()
+        .input("directly_linked_test_plus_whole_archive.rs")
+        .arg("--test")
+        .arg("-lstatic:+whole-archive=c_static_lib_with_constructor")
+        .run();
+
+    // Native lib linked into test executable, -whole-archive
+    rustc()
+        .input("directly_linked_test_minus_whole_archive.rs")
+        .arg("--test")
+        .arg("-lstatic:-whole-archive=c_static_lib_with_constructor")
+        .run();
+
+    // Native lib linked into rlib with via commandline
+    rustc()
+        .input("rlib_with_cmdline_native_lib.rs")
+        .crate_type("rlib")
+        .arg("-lstatic:-bundle,+whole-archive=c_static_lib_with_constructor")
+        .run();
+    // Native lib linked into RLIB via `-l static:-bundle,+whole-archive`, RLIB linked into executable
+    rustc().input("indirectly_linked.rs").run();
+
+    // Native lib linked into rlib via `#[link()]` attribute on extern block.
+    rustc().input("native_lib_in_src.rs").crate_type("rlib").run();
+    // Native lib linked into RLIB via #[link] attribute, RLIB linked into executable
+    rustc().input("indirectly_linked_via_attr.rs").run();
+
+    run("directly_linked").assert_stdout_contains("static-initializer.directly_linked.");
+    run_with_args("directly_linked_test_plus_whole_archive", &["--nocapture"])
+        .assert_stdout_contains("static-initializer.");
+    run_with_args("directly_linked_test_minus_whole_archive", &["--nocapture"])
+        .assert_stdout_not_contains("static-initializer.");
+    run("indirectly_linked").assert_stdout_contains("static-initializer.indirectly_linked.");
+    run("indirectly_linked_via_attr")
+        .assert_stdout_contains("static-initializer.native_lib_in_src.");
+}