about summary refs log tree commit diff
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2024-07-20 19:49:49 +0000
committerbors <bors@rust-lang.org>2024-07-20 19:49:49 +0000
commit5069856495870486134dd2ca0b0e2516308c5c2a (patch)
treefccda32f14f8186cbb4f9ee3c205b49bef7bc762
parent2e6fc425411280c658d852813de01c5157255088 (diff)
parentfdc8d62c962c401a096a9e4beb63a3b421570471 (diff)
downloadrust-5069856495870486134dd2ca0b0e2516308c5c2a.tar.gz
rust-5069856495870486134dd2ca0b0e2516308c5c2a.zip
Auto merge of #127663 - Oneirical:fuzzy-testure, r=jieyouxu
Migrate 9 more very similar FFI `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).

For the tracking issue:

- return-non-c-like-enum-from-c
- pass-non-c-like-enum-to-c
- c-static-dylib
- c-static-rlib
- extern-fn-generic
- extern-fn-with-union
- lto-no-link-whole-rlib
- linkage-attr-on-static
- issue-28595
-rw-r--r--src/tools/tidy/src/allowed_run_make_makefiles.txt9
-rw-r--r--tests/run-make/c-static-dylib/Makefile13
-rw-r--r--tests/run-make/c-static-dylib/rmake.rs20
-rw-r--r--tests/run-make/c-static-rlib/Makefile12
-rw-r--r--tests/run-make/c-static-rlib/rmake.rs17
-rw-r--r--tests/run-make/extern-fn-generic/Makefile7
-rw-r--r--tests/run-make/extern-fn-generic/rmake.rs16
-rw-r--r--tests/run-make/extern-fn-with-union/Makefile7
-rw-r--r--tests/run-make/extern-fn-with-union/rmake.rs16
-rw-r--r--tests/run-make/issue-28595/Makefile7
-rw-r--r--tests/run-make/linkage-attr-on-static/Makefile6
-rw-r--r--tests/run-make/linkage-attr-on-static/rmake.rs15
-rw-r--r--tests/run-make/lto-no-link-whole-rlib/Makefile9
-rw-r--r--tests/run-make/lto-no-link-whole-rlib/rmake.rs18
-rw-r--r--tests/run-make/native-lib-load-order/a.c (renamed from tests/run-make/issue-28595/a.c)0
-rw-r--r--tests/run-make/native-lib-load-order/a.rs (renamed from tests/run-make/issue-28595/a.rs)0
-rw-r--r--tests/run-make/native-lib-load-order/b.c (renamed from tests/run-make/issue-28595/b.c)0
-rw-r--r--tests/run-make/native-lib-load-order/b.rs (renamed from tests/run-make/issue-28595/b.rs)0
-rw-r--r--tests/run-make/native-lib-load-order/rmake.rs16
-rw-r--r--tests/run-make/pass-non-c-like-enum-to-c/Makefile6
-rw-r--r--tests/run-make/pass-non-c-like-enum-to-c/rmake.rs19
-rw-r--r--tests/run-make/return-non-c-like-enum-from-c/Makefile6
-rw-r--r--tests/run-make/return-non-c-like-enum-from-c/rmake.rs17
23 files changed, 154 insertions, 82 deletions
diff --git a/src/tools/tidy/src/allowed_run_make_makefiles.txt b/src/tools/tidy/src/allowed_run_make_makefiles.txt
index 4b50bcb38fd..1cb52ea91f9 100644
--- a/src/tools/tidy/src/allowed_run_make_makefiles.txt
+++ b/src/tools/tidy/src/allowed_run_make_makefiles.txt
@@ -1,8 +1,6 @@
 run-make/branch-protection-check-IBT/Makefile
 run-make/c-dynamic-dylib/Makefile
 run-make/c-dynamic-rlib/Makefile
-run-make/c-static-dylib/Makefile
-run-make/c-static-rlib/Makefile
 run-make/c-unwind-abi-catch-lib-panic/Makefile
 run-make/c-unwind-abi-catch-panic/Makefile
 run-make/cat-and-grep-sanity-check/Makefile
@@ -21,9 +19,7 @@ run-make/emit-to-stdout/Makefile
 run-make/export-executable-symbols/Makefile
 run-make/extern-diff-internal-name/Makefile
 run-make/extern-flag-disambiguates/Makefile
-run-make/extern-fn-generic/Makefile
 run-make/extern-fn-reachable/Makefile
-run-make/extern-fn-with-union/Makefile
 run-make/extern-multiple-copies/Makefile
 run-make/extern-multiple-copies2/Makefile
 run-make/fmt-write-bloat/Makefile
@@ -36,7 +32,6 @@ run-make/interdependent-c-libraries/Makefile
 run-make/issue-107094/Makefile
 run-make/issue-14698/Makefile
 run-make/issue-15460/Makefile
-run-make/issue-28595/Makefile
 run-make/issue-33329/Makefile
 run-make/issue-35164/Makefile
 run-make/issue-36710/Makefile
@@ -52,11 +47,9 @@ run-make/libtest-junit/Makefile
 run-make/libtest-thread-limit/Makefile
 run-make/link-cfg/Makefile
 run-make/link-framework/Makefile
-run-make/linkage-attr-on-static/Makefile
 run-make/long-linker-command-lines-cmd-exe/Makefile
 run-make/long-linker-command-lines/Makefile
 run-make/lto-linkage-used-attr/Makefile
-run-make/lto-no-link-whole-rlib/Makefile
 run-make/macos-deployment-target/Makefile
 run-make/min-global-align/Makefile
 run-make/native-link-modifier-bundle/Makefile
@@ -65,7 +58,6 @@ run-make/no-alloc-shim/Makefile
 run-make/no-builtins-attribute/Makefile
 run-make/no-duplicate-libs/Makefile
 run-make/panic-abort-eh_frame/Makefile
-run-make/pass-non-c-like-enum-to-c/Makefile
 run-make/pdb-buildinfo-cl-cmd/Makefile
 run-make/pgo-gen-lto/Makefile
 run-make/pgo-gen-no-imp-symbols/Makefile
@@ -82,7 +74,6 @@ run-make/redundant-libs/Makefile
 run-make/remap-path-prefix-dwarf/Makefile
 run-make/reproducible-build-2/Makefile
 run-make/reproducible-build/Makefile
-run-make/return-non-c-like-enum-from-c/Makefile
 run-make/rlib-format-packed-bundled-libs-2/Makefile
 run-make/rlib-format-packed-bundled-libs-3/Makefile
 run-make/rlib-format-packed-bundled-libs/Makefile
diff --git a/tests/run-make/c-static-dylib/Makefile b/tests/run-make/c-static-dylib/Makefile
deleted file mode 100644
index 05da1743c83..00000000000
--- a/tests/run-make/c-static-dylib/Makefile
+++ /dev/null
@@ -1,13 +0,0 @@
-# This test checks that static Rust linking with C does not encounter any errors, with dynamic dependencies given preference over static.
-# See https://github.com/rust-lang/rust/issues/10434
-
-# ignore-cross-compile
-include ../tools.mk
-
-all: $(call NATIVE_STATICLIB,cfoo)
-	$(RUSTC) foo.rs -C prefer-dynamic
-	$(RUSTC) bar.rs
-	rm $(call NATIVE_STATICLIB,cfoo)
-	$(call RUN,bar)
-	$(call REMOVE_DYLIBS,foo)
-	$(call FAIL,bar)
diff --git a/tests/run-make/c-static-dylib/rmake.rs b/tests/run-make/c-static-dylib/rmake.rs
new file mode 100644
index 00000000000..12ec06c8199
--- /dev/null
+++ b/tests/run-make/c-static-dylib/rmake.rs
@@ -0,0 +1,20 @@
+// This test checks that static Rust linking with C does not encounter any errors,
+// with dynamic dependencies given preference over static.
+// See https://github.com/rust-lang/rust/issues/10434
+
+//@ ignore-cross-compile
+// Reason: the compiled binary is executed
+
+use run_make_support::{
+    build_native_static_lib, dynamic_lib_name, rfs, run, run_fail, rustc, static_lib_name,
+};
+
+fn main() {
+    build_native_static_lib("cfoo");
+    rustc().input("foo.rs").arg("-Cprefer-dynamic").run();
+    rustc().input("bar.rs").run();
+    rfs::remove_file(static_lib_name("cfoo"));
+    run("bar");
+    rfs::remove_file(dynamic_lib_name("foo"));
+    run_fail("bar");
+}
diff --git a/tests/run-make/c-static-rlib/Makefile b/tests/run-make/c-static-rlib/Makefile
deleted file mode 100644
index 298e432cdb8..00000000000
--- a/tests/run-make/c-static-rlib/Makefile
+++ /dev/null
@@ -1,12 +0,0 @@
-# This test checks that static Rust linking with C does not encounter any errors, with static dependencies given preference over dynamic. (This is the default behaviour.)
-# See https://github.com/rust-lang/rust/issues/10434
-
-# ignore-cross-compile
-include ../tools.mk
-
-all: $(call NATIVE_STATICLIB,cfoo)
-	$(RUSTC) foo.rs
-	$(RUSTC) bar.rs
-	$(call REMOVE_RLIBS,foo)
-	rm $(call NATIVE_STATICLIB,cfoo)
-	$(call RUN,bar)
diff --git a/tests/run-make/c-static-rlib/rmake.rs b/tests/run-make/c-static-rlib/rmake.rs
new file mode 100644
index 00000000000..447e29a14f6
--- /dev/null
+++ b/tests/run-make/c-static-rlib/rmake.rs
@@ -0,0 +1,17 @@
+// This test checks that static Rust linking with C does not encounter any errors,
+// with static dependencies given preference over dynamic. (This is the default behaviour.)
+// See https://github.com/rust-lang/rust/issues/10434
+
+//@ ignore-cross-compile
+// Reason: the compiled binary is executed
+
+use run_make_support::{build_native_static_lib, rfs, run, rust_lib_name, rustc, static_lib_name};
+
+fn main() {
+    build_native_static_lib("cfoo");
+    rustc().input("foo.rs").run();
+    rustc().input("bar.rs").run();
+    rfs::remove_file(rust_lib_name("foo"));
+    rfs::remove_file(static_lib_name("cfoo"));
+    run("bar");
+}
diff --git a/tests/run-make/extern-fn-generic/Makefile b/tests/run-make/extern-fn-generic/Makefile
deleted file mode 100644
index 7dceea6cb88..00000000000
--- a/tests/run-make/extern-fn-generic/Makefile
+++ /dev/null
@@ -1,7 +0,0 @@
-# ignore-cross-compile
-include ../tools.mk
-
-all: $(call NATIVE_STATICLIB,test)
-	$(RUSTC) testcrate.rs
-	$(RUSTC) test.rs
-	$(call RUN,test) || exit 1
diff --git a/tests/run-make/extern-fn-generic/rmake.rs b/tests/run-make/extern-fn-generic/rmake.rs
new file mode 100644
index 00000000000..05de839a1b0
--- /dev/null
+++ b/tests/run-make/extern-fn-generic/rmake.rs
@@ -0,0 +1,16 @@
+// Generic types in foreign-function interfaces were introduced in #15831 - this
+// test simply runs a Rust program containing generics that is also reliant on
+// a C library, and checks that compilation and execution are successful.
+// See https://github.com/rust-lang/rust/pull/15831
+
+//@ 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("test");
+    rustc().input("testcrate.rs").run();
+    rustc().input("test.rs").run();
+    run("test");
+}
diff --git a/tests/run-make/extern-fn-with-union/Makefile b/tests/run-make/extern-fn-with-union/Makefile
deleted file mode 100644
index e6c8c993679..00000000000
--- a/tests/run-make/extern-fn-with-union/Makefile
+++ /dev/null
@@ -1,7 +0,0 @@
-# ignore-cross-compile
-include ../tools.mk
-
-all: $(call NATIVE_STATICLIB,ctest)
-	$(RUSTC) testcrate.rs
-	$(RUSTC) test.rs
-	$(call RUN,test) || exit 1
diff --git a/tests/run-make/extern-fn-with-union/rmake.rs b/tests/run-make/extern-fn-with-union/rmake.rs
new file mode 100644
index 00000000000..200602eabeb
--- /dev/null
+++ b/tests/run-make/extern-fn-with-union/rmake.rs
@@ -0,0 +1,16 @@
+// If an external function from foreign-function interface was called upon,
+// its attributes would only be passed to LLVM if and only if it was called in the same crate.
+// This caused passing around unions to be incorrect.
+// See https://github.com/rust-lang/rust/pull/14191
+
+//@ 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("ctest");
+    rustc().input("testcrate.rs").run();
+    rustc().input("test.rs").run();
+    run("test");
+}
diff --git a/tests/run-make/issue-28595/Makefile b/tests/run-make/issue-28595/Makefile
deleted file mode 100644
index 258f9788aaf..00000000000
--- a/tests/run-make/issue-28595/Makefile
+++ /dev/null
@@ -1,7 +0,0 @@
-# ignore-cross-compile
-include ../tools.mk
-
-all: $(call NATIVE_STATICLIB,a) $(call NATIVE_STATICLIB,b)
-	$(RUSTC) a.rs
-	$(RUSTC) b.rs
-	$(call RUN,b)
diff --git a/tests/run-make/linkage-attr-on-static/Makefile b/tests/run-make/linkage-attr-on-static/Makefile
deleted file mode 100644
index ef50a7ef9f1..00000000000
--- a/tests/run-make/linkage-attr-on-static/Makefile
+++ /dev/null
@@ -1,6 +0,0 @@
-# ignore-cross-compile
-include ../tools.mk
-
-all: $(call NATIVE_STATICLIB,foo)
-	$(RUSTC) bar.rs
-	$(call RUN,bar) || exit 1
diff --git a/tests/run-make/linkage-attr-on-static/rmake.rs b/tests/run-make/linkage-attr-on-static/rmake.rs
new file mode 100644
index 00000000000..cd85542e958
--- /dev/null
+++ b/tests/run-make/linkage-attr-on-static/rmake.rs
@@ -0,0 +1,15 @@
+// #[linkage] is a useful attribute which can be applied to statics to allow
+// external linkage, something which was not possible before #18890. This test
+// checks that using this new feature results in successful compilation and execution.
+// See https://github.com/rust-lang/rust/pull/18890
+
+//@ 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("foo");
+    rustc().input("bar.rs").run();
+    run("bar");
+}
diff --git a/tests/run-make/lto-no-link-whole-rlib/Makefile b/tests/run-make/lto-no-link-whole-rlib/Makefile
deleted file mode 100644
index 3e82322e72d..00000000000
--- a/tests/run-make/lto-no-link-whole-rlib/Makefile
+++ /dev/null
@@ -1,9 +0,0 @@
-# ignore-cross-compile
-include ../tools.mk
-
-all: $(call NATIVE_STATICLIB,foo) $(call NATIVE_STATICLIB,bar)
-	$(RUSTC) lib1.rs
-	$(RUSTC) lib2.rs
-	$(RUSTC) main.rs -Clto
-	$(call RUN,main)
-
diff --git a/tests/run-make/lto-no-link-whole-rlib/rmake.rs b/tests/run-make/lto-no-link-whole-rlib/rmake.rs
new file mode 100644
index 00000000000..8cd653d5f08
--- /dev/null
+++ b/tests/run-make/lto-no-link-whole-rlib/rmake.rs
@@ -0,0 +1,18 @@
+// In order to improve linking performance, entire rlibs will only be linked if a dylib is being
+// created. Otherwise, an executable will only link one rlib as usual. Linking will fail in this
+// test should this optimization be reverted.
+// See https://github.com/rust-lang/rust/pull/31460
+
+//@ 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("foo");
+    build_native_static_lib("bar");
+    rustc().input("lib1.rs").run();
+    rustc().input("lib2.rs").run();
+    rustc().input("main.rs").arg("-Clto").run();
+    run("main");
+}
diff --git a/tests/run-make/issue-28595/a.c b/tests/run-make/native-lib-load-order/a.c
index 7bfd83cca21..7bfd83cca21 100644
--- a/tests/run-make/issue-28595/a.c
+++ b/tests/run-make/native-lib-load-order/a.c
diff --git a/tests/run-make/issue-28595/a.rs b/tests/run-make/native-lib-load-order/a.rs
index 07863cf64d6..07863cf64d6 100644
--- a/tests/run-make/issue-28595/a.rs
+++ b/tests/run-make/native-lib-load-order/a.rs
diff --git a/tests/run-make/issue-28595/b.c b/tests/run-make/native-lib-load-order/b.c
index 6aecb5f9e04..6aecb5f9e04 100644
--- a/tests/run-make/issue-28595/b.c
+++ b/tests/run-make/native-lib-load-order/b.c
diff --git a/tests/run-make/issue-28595/b.rs b/tests/run-make/native-lib-load-order/b.rs
index 1f389859fad..1f389859fad 100644
--- a/tests/run-make/issue-28595/b.rs
+++ b/tests/run-make/native-lib-load-order/b.rs
diff --git a/tests/run-make/native-lib-load-order/rmake.rs b/tests/run-make/native-lib-load-order/rmake.rs
new file mode 100644
index 00000000000..ffe20a64168
--- /dev/null
+++ b/tests/run-make/native-lib-load-order/rmake.rs
@@ -0,0 +1,16 @@
+// An old compiler bug from 2015 caused native libraries to be loaded in the
+// wrong order, causing `b` to be loaded before `a` in this test. If the compilation
+// is successful, the libraries were loaded in the correct order.
+
+//@ 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("a");
+    build_native_static_lib("b");
+    rustc().input("a.rs").run();
+    rustc().input("b.rs").run();
+    run("b");
+}
diff --git a/tests/run-make/pass-non-c-like-enum-to-c/Makefile b/tests/run-make/pass-non-c-like-enum-to-c/Makefile
deleted file mode 100644
index bd441d321bf..00000000000
--- a/tests/run-make/pass-non-c-like-enum-to-c/Makefile
+++ /dev/null
@@ -1,6 +0,0 @@
-# ignore-cross-compile
-include ../tools.mk
-
-all: $(call NATIVE_STATICLIB,test)
-	$(RUSTC) nonclike.rs -L$(TMPDIR) -ltest
-	$(call RUN,nonclike)
diff --git a/tests/run-make/pass-non-c-like-enum-to-c/rmake.rs b/tests/run-make/pass-non-c-like-enum-to-c/rmake.rs
new file mode 100644
index 00000000000..c706e82f4a0
--- /dev/null
+++ b/tests/run-make/pass-non-c-like-enum-to-c/rmake.rs
@@ -0,0 +1,19 @@
+// Similar to the `return-non-c-like-enum-from-c` test, where
+// the C code is the library, and the Rust code compiles
+// into the executable. Once again, enum variants should be treated
+// like an union of structs, which should prevent segfaults or
+// unexpected results. The only difference with the aforementioned
+// test is that the structs are passed into C directly through the
+// `tt_add` and `t_add` function calls.
+// See https://github.com/rust-lang/rust/issues/68190
+
+//@ 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("test");
+    rustc().input("nonclike.rs").arg("-ltest").run();
+    run("nonclike");
+}
diff --git a/tests/run-make/return-non-c-like-enum-from-c/Makefile b/tests/run-make/return-non-c-like-enum-from-c/Makefile
deleted file mode 100644
index bd441d321bf..00000000000
--- a/tests/run-make/return-non-c-like-enum-from-c/Makefile
+++ /dev/null
@@ -1,6 +0,0 @@
-# ignore-cross-compile
-include ../tools.mk
-
-all: $(call NATIVE_STATICLIB,test)
-	$(RUSTC) nonclike.rs -L$(TMPDIR) -ltest
-	$(call RUN,nonclike)
diff --git a/tests/run-make/return-non-c-like-enum-from-c/rmake.rs b/tests/run-make/return-non-c-like-enum-from-c/rmake.rs
new file mode 100644
index 00000000000..f24bd6d5fc7
--- /dev/null
+++ b/tests/run-make/return-non-c-like-enum-from-c/rmake.rs
@@ -0,0 +1,17 @@
+// A reversed version of the `return-non-c-like-enum` test, though
+// this time, the C code is the library, and the Rust code compiles
+// into the executable. Once again, enum variants should be treated
+// like an union of structs, which should prevent segfaults or
+// unexpected results.
+// See https://github.com/rust-lang/rust/issues/68190
+
+//@ 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("test");
+    rustc().input("nonclike.rs").arg("-ltest").run();
+    run("nonclike");
+}