about summary refs log tree commit diff
diff options
context:
space:
mode:
authorTrevor Gross <t.gross35@gmail.com>2024-07-19 03:27:47 -0500
committerGitHub <noreply@github.com>2024-07-19 03:27:47 -0500
commit39ccb8a7691f8398682fb681f94a93b49ef4d221 (patch)
tree6b0af5f181d1e8a4205566724829ebdd6dc85dc1
parent986d6bf9fb7aeb3032014183cdd7c30d90810360 (diff)
parent47c21012efc27b8a008ae11276ea95d9f818fcc9 (diff)
downloadrust-39ccb8a7691f8398682fb681f94a93b49ef4d221.tar.gz
rust-39ccb8a7691f8398682fb681f94a93b49ef4d221.zip
Rollup merge of #127825 - Oneirical:self-testeem, r=jieyouxu
Migrate `macos-fat-archive`, `manual-link` and `archive-duplicate-names` `run-make` tests to rmake

Part of #121876 and the associated [Google Summer of Code project](https://blog.rust-lang.org/2024/05/01/gsoc-2024-selected-projects.html).

Please try:

try-job: x86_64-msvc
try-job: aarch64-apple
-rw-r--r--src/tools/tidy/src/allowed_run_make_makefiles.txt3
-rw-r--r--tests/run-make/archive-duplicate-names/Makefile16
-rw-r--r--tests/run-make/archive-duplicate-names/rmake.rs37
-rw-r--r--tests/run-make/macos-fat-archive/Makefile10
-rw-r--r--tests/run-make/macos-fat-archive/rmake.rs20
-rw-r--r--tests/run-make/manual-link/Makefile7
-rw-r--r--tests/run-make/manual-link/rmake.rs16
7 files changed, 73 insertions, 36 deletions
diff --git a/src/tools/tidy/src/allowed_run_make_makefiles.txt b/src/tools/tidy/src/allowed_run_make_makefiles.txt
index 745f00c4f52..b980d77d158 100644
--- a/src/tools/tidy/src/allowed_run_make_makefiles.txt
+++ b/src/tools/tidy/src/allowed_run_make_makefiles.txt
@@ -1,4 +1,3 @@
-run-make/archive-duplicate-names/Makefile
 run-make/branch-protection-check-IBT/Makefile
 run-make/c-dynamic-dylib/Makefile
 run-make/c-dynamic-rlib/Makefile
@@ -64,8 +63,6 @@ run-make/lto-linkage-used-attr/Makefile
 run-make/lto-no-link-whole-rlib/Makefile
 run-make/lto-smoke-c/Makefile
 run-make/macos-deployment-target/Makefile
-run-make/macos-fat-archive/Makefile
-run-make/manual-link/Makefile
 run-make/min-global-align/Makefile
 run-make/native-link-modifier-bundle/Makefile
 run-make/native-link-modifier-whole-archive/Makefile
diff --git a/tests/run-make/archive-duplicate-names/Makefile b/tests/run-make/archive-duplicate-names/Makefile
deleted file mode 100644
index 207eee39299..00000000000
--- a/tests/run-make/archive-duplicate-names/Makefile
+++ /dev/null
@@ -1,16 +0,0 @@
-# When two object archives with the same filename are present, an iterator is supposed to inspect each object, recognize the duplication and extract each one to a different directory.
-# This test checks that this duplicate handling behaviour has not been broken.
-# See https://github.com/rust-lang/rust/pull/24439
-
-# ignore-cross-compile
-include ../tools.mk
-
-all:
-	mkdir $(TMPDIR)/a
-	mkdir $(TMPDIR)/b
-	$(call COMPILE_OBJ,$(TMPDIR)/a/foo.o,foo.c)
-	$(call COMPILE_OBJ,$(TMPDIR)/b/foo.o,bar.c)
-	$(AR) crus $(TMPDIR)/libfoo.a $(TMPDIR)/a/foo.o $(TMPDIR)/b/foo.o
-	$(RUSTC) foo.rs
-	$(RUSTC) bar.rs
-	$(call RUN,bar)
diff --git a/tests/run-make/archive-duplicate-names/rmake.rs b/tests/run-make/archive-duplicate-names/rmake.rs
new file mode 100644
index 00000000000..62a35566199
--- /dev/null
+++ b/tests/run-make/archive-duplicate-names/rmake.rs
@@ -0,0 +1,37 @@
+// When two object archives with the same filename are present, an iterator is supposed to
+// inspect each object, recognize the duplication and extract each one to a different directory.
+// This test checks that this duplicate handling behaviour has not been broken.
+// See https://github.com/rust-lang/rust/pull/24439
+
+//@ ignore-cross-compile
+// Reason: the compiled binary is executed
+
+use run_make_support::{cc, is_msvc, llvm_ar, rfs, run, rustc};
+
+fn main() {
+    rfs::create_dir("a");
+    rfs::create_dir("b");
+    compile_obj_force_foo("a", "foo");
+    compile_obj_force_foo("b", "bar");
+    let mut ar = llvm_ar();
+    ar.obj_to_ar().arg("libfoo.a");
+    if is_msvc() {
+        ar.arg("a/foo.obj").arg("b/foo.obj").run();
+    } else {
+        ar.arg("a/foo.o").arg("b/foo.o").run();
+    }
+    rustc().input("foo.rs").run();
+    rustc().input("bar.rs").run();
+    run("bar");
+}
+
+#[track_caller]
+pub fn compile_obj_force_foo(dir: &str, lib_name: &str) {
+    let obj_file = if is_msvc() { format!("{dir}/foo") } else { format!("{dir}/foo.o") };
+    let src = format!("{lib_name}.c");
+    if is_msvc() {
+        cc().arg("-c").out_exe(&obj_file).input(src).run();
+    } else {
+        cc().arg("-v").arg("-c").out_exe(&obj_file).input(src).run();
+    };
+}
diff --git a/tests/run-make/macos-fat-archive/Makefile b/tests/run-make/macos-fat-archive/Makefile
deleted file mode 100644
index 0feb39a23cb..00000000000
--- a/tests/run-make/macos-fat-archive/Makefile
+++ /dev/null
@@ -1,10 +0,0 @@
-# only-apple
-
-include ../tools.mk
-
-"$(TMPDIR)"/libnative-library.a: native-library.c
-	$(CC) -arch arm64 -arch x86_64 native-library.c -c -o "$(TMPDIR)"/native-library.o
-	$(AR) crs "$(TMPDIR)"/libnative-library.a "$(TMPDIR)"/native-library.o
-
-all: "$(TMPDIR)"/libnative-library.a
-	$(RUSTC) lib.rs --crate-type=lib -L "native=$(TMPDIR)" -l static=native-library
diff --git a/tests/run-make/macos-fat-archive/rmake.rs b/tests/run-make/macos-fat-archive/rmake.rs
new file mode 100644
index 00000000000..c9f0fa07693
--- /dev/null
+++ b/tests/run-make/macos-fat-archive/rmake.rs
@@ -0,0 +1,20 @@
+// macOS (and iOS) has a concept of universal (fat) binaries which contain code for multiple CPU
+// architectures in the same file. Apple is migrating from x86_64 to aarch64 CPUs,
+// so for the next few years it will be important for macOS developers to
+// build "fat" binaries (executables and cdylibs).
+
+// Rustc used to be unable to handle these special libraries, which was fixed in #98736. If
+// compilation in this test is successful, the native fat library was successfully linked to.
+// See https://github.com/rust-lang/rust/issues/55235
+
+//@ only-apple
+
+use run_make_support::{cc, llvm_ar, rustc};
+
+fn main() {
+    cc().args(&["-arch", "arm64", "-arch", "x86_64", "native-library.c", "-c"])
+        .out_exe("native-library.o")
+        .run();
+    llvm_ar().obj_to_ar().output_input("libnative-library.a", "native-library.o").run();
+    rustc().input("lib.rs").crate_type("lib").arg("-lstatic=native-library").run();
+}
diff --git a/tests/run-make/manual-link/Makefile b/tests/run-make/manual-link/Makefile
deleted file mode 100644
index 8dbf0460fff..00000000000
--- a/tests/run-make/manual-link/Makefile
+++ /dev/null
@@ -1,7 +0,0 @@
-# ignore-cross-compile
-include ../tools.mk
-
-all: $(TMPDIR)/libbar.a
-	$(RUSTC) foo.rs -lstatic=bar
-	$(RUSTC) main.rs
-	$(call RUN,main)
diff --git a/tests/run-make/manual-link/rmake.rs b/tests/run-make/manual-link/rmake.rs
new file mode 100644
index 00000000000..1d362172263
--- /dev/null
+++ b/tests/run-make/manual-link/rmake.rs
@@ -0,0 +1,16 @@
+// A smoke test for the `-l` command line rustc flag, which manually links to the selected
+// library. Useful for native libraries, this is roughly equivalent to `#[link]` in Rust code.
+// If compilation succeeds, the flag successfully linked the native library.
+// See https://github.com/rust-lang/rust/pull/18470
+
+//@ ignore-cross-compile
+// Reason: the compiled binary is executed
+
+use run_make_support::{build_native_static_lib, run, rustc};
+
+fn main() {
+    build_native_static_lib("bar");
+    rustc().input("foo.rs").arg("-lstatic=bar").run();
+    rustc().input("main.rs").run();
+    run("main");
+}