about summary refs log tree commit diff
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2024-08-14 19:24:19 +0000
committerbors <bors@rust-lang.org>2024-08-14 19:24:19 +0000
commit13a52890dde8cfeb95069d77c223ac37c0cf3a46 (patch)
tree0f05aaf7620f18c0b348d9a47bcbe276ca470aec
parent355a307a874077eff12bd99c6fd3eb6bfda79993 (diff)
parentb85bedcb24e31636e47c724e0a1cbedf09d03158 (diff)
downloadrust-13a52890dde8cfeb95069d77c223ac37c0cf3a46.tar.gz
rust-13a52890dde8cfeb95069d77c223ac37c0cf3a46.zip
Auto merge of #128407 - Oneirical:feline-dotestication, r=jieyouxu
Migrate `min-global-align` and `no-alloc-shim` `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: aarch64-apple
try-job: test-various
try-job: armhf-gnu
try-job: aarch64-gnu
try-job: aarch64-gnu
-rw-r--r--src/tools/run-make-support/src/assertion_helpers.rs14
-rw-r--r--src/tools/run-make-support/src/lib.rs2
-rw-r--r--src/tools/tidy/src/allowed_run_make_makefiles.txt2
-rw-r--r--tests/run-make/min-global-align/Makefile22
-rw-r--r--tests/run-make/min-global-align/rmake.rs27
-rw-r--r--tests/run-make/no-alloc-shim/Makefile24
-rw-r--r--tests/run-make/no-alloc-shim/rmake.rs55
7 files changed, 97 insertions, 49 deletions
diff --git a/src/tools/run-make-support/src/assertion_helpers.rs b/src/tools/run-make-support/src/assertion_helpers.rs
index 6d256fc594d..b4da65aff4a 100644
--- a/src/tools/run-make-support/src/assertion_helpers.rs
+++ b/src/tools/run-make-support/src/assertion_helpers.rs
@@ -77,6 +77,20 @@ pub fn assert_not_contains_regex<H: AsRef<str>, N: AsRef<str>>(haystack: H, need
     }
 }
 
+/// Assert that `haystack` contains `needle` a `count` number of times.
+#[track_caller]
+pub fn assert_count_is<H: AsRef<str>, N: AsRef<str>>(count: usize, haystack: H, needle: N) {
+    let haystack = haystack.as_ref();
+    let needle = needle.as_ref();
+    if count != haystack.matches(needle).count() {
+        eprintln!("=== HAYSTACK ===");
+        eprintln!("{}", haystack);
+        eprintln!("=== NEEDLE ===");
+        eprintln!("{}", needle);
+        panic!("needle did not appear {count} times in haystack");
+    }
+}
+
 /// Assert that all files in `dir1` exist and have the same content in `dir2`
 pub fn assert_dirs_are_equal(dir1: impl AsRef<Path>, dir2: impl AsRef<Path>) {
     let dir2 = dir2.as_ref();
diff --git a/src/tools/run-make-support/src/lib.rs b/src/tools/run-make-support/src/lib.rs
index 4d0c1b0930c..4bef4f05007 100644
--- a/src/tools/run-make-support/src/lib.rs
+++ b/src/tools/run-make-support/src/lib.rs
@@ -87,7 +87,7 @@ pub use path_helpers::{
 pub use scoped_run::{run_in_tmpdir, test_while_readonly};
 
 pub use assertion_helpers::{
-    assert_contains, assert_contains_regex, assert_dirs_are_equal, assert_equals,
+    assert_contains, assert_contains_regex, assert_count_is, assert_dirs_are_equal, assert_equals,
     assert_not_contains, assert_not_contains_regex,
 };
 
diff --git a/src/tools/tidy/src/allowed_run_make_makefiles.txt b/src/tools/tidy/src/allowed_run_make_makefiles.txt
index 25fa8c5e1af..bc446555773 100644
--- a/src/tools/tidy/src/allowed_run_make_makefiles.txt
+++ b/src/tools/tidy/src/allowed_run_make_makefiles.txt
@@ -13,9 +13,7 @@ run-make/libtest-json/Makefile
 run-make/libtest-junit/Makefile
 run-make/libtest-thread-limit/Makefile
 run-make/macos-deployment-target/Makefile
-run-make/min-global-align/Makefile
 run-make/native-link-modifier-bundle/Makefile
-run-make/no-alloc-shim/Makefile
 run-make/reproducible-build/Makefile
 run-make/rlib-format-packed-bundled-libs/Makefile
 run-make/split-debuginfo/Makefile
diff --git a/tests/run-make/min-global-align/Makefile b/tests/run-make/min-global-align/Makefile
deleted file mode 100644
index 82f38749e00..00000000000
--- a/tests/run-make/min-global-align/Makefile
+++ /dev/null
@@ -1,22 +0,0 @@
-include ../tools.mk
-
-# only-linux
-
-# This tests ensure that global variables respect the target minimum alignment.
-# The three bools `STATIC_BOOL`, `STATIC_MUT_BOOL`, and `CONST_BOOL` all have
-# type-alignment of 1, but some targets require greater global alignment.
-
-SRC = min_global_align.rs
-LL = $(TMPDIR)/min_global_align.ll
-
-all:
-# Most targets are happy with default alignment -- take i686 for example.
-ifeq ($(filter x86,$(LLVM_COMPONENTS)),x86)
-	$(RUSTC) --target=i686-unknown-linux-gnu --emit=llvm-ir $(SRC)
-	[ "$$(grep -c 'align 1' "$(LL)")" -eq "3" ]
-endif
-# SystemZ requires even alignment for PC-relative addressing.
-ifeq ($(filter systemz,$(LLVM_COMPONENTS)),systemz)
-	$(RUSTC) --target=s390x-unknown-linux-gnu --emit=llvm-ir $(SRC)
-	[ "$$(grep -c 'align 2' "$(LL)")" -eq "3" ]
-endif
diff --git a/tests/run-make/min-global-align/rmake.rs b/tests/run-make/min-global-align/rmake.rs
new file mode 100644
index 00000000000..2adaaf172f4
--- /dev/null
+++ b/tests/run-make/min-global-align/rmake.rs
@@ -0,0 +1,27 @@
+// This test checks that global variables respect the target minimum alignment.
+// The three bools `STATIC_BOOL`, `STATIC_MUT_BOOL`, and `CONST_BOOL` all have
+// type-alignment of 1, but some targets require greater global alignment.
+// See https://github.com/rust-lang/rust/pull/44440
+
+//@ only-linux
+// Reason: this test is specific to linux, considering compilation is targeted
+// towards linux architectures only.
+
+use run_make_support::{assert_count_is, llvm_components_contain, rfs, rustc};
+
+fn main() {
+    // Most targets are happy with default alignment -- take i686 for example.
+    if llvm_components_contain("x86") {
+        rustc().target("i686-unknown-linux-gnu").emit("llvm-ir").input("min_global_align.rs").run();
+        assert_count_is(3, rfs::read_to_string("min_global_align.ll"), "align 1");
+    }
+    // SystemZ requires even alignment for PC-relative addressing.
+    if llvm_components_contain("systemz") {
+        rustc()
+            .target("s390x-unknown-linux-gnu")
+            .emit("llvm-ir")
+            .input("min_global_align.rs")
+            .run();
+        assert_count_is(3, rfs::read_to_string("min_global_align.ll"), "align 2");
+    }
+}
diff --git a/tests/run-make/no-alloc-shim/Makefile b/tests/run-make/no-alloc-shim/Makefile
deleted file mode 100644
index 568e3f9ba1d..00000000000
--- a/tests/run-make/no-alloc-shim/Makefile
+++ /dev/null
@@ -1,24 +0,0 @@
-include ../tools.mk
-
-# ignore-cross-compile
-# ignore-msvc FIXME(bjorn3) can't figure out how to link with the MSVC toolchain
-
-TARGET_LIBDIR = $$($(RUSTC) --print target-libdir)
-
-all:
-	$(RUSTC) foo.rs --crate-type bin --emit obj -Cpanic=abort
-ifdef IS_MSVC
-	$(CC) $(CFLAGS) $(TMPDIR)/foo.o $(call OUT_EXE,foo) /link $(TARGET_LIBDIR)/liballoc-*.rlib $(TARGET_LIBDIR)/libcore-*.rlib $(TARGET_LIBDIR)/libcompiler_builtins-*.rlib
-	$(call OUT_EXE,foo)
-else
-	$(CC) $(CFLAGS) $(TMPDIR)/foo.o $(TARGET_LIBDIR)/liballoc-*.rlib $(TARGET_LIBDIR)/libcore-*.rlib $(TARGET_LIBDIR)/libcompiler_builtins-*.rlib -o $(call RUN_BINFILE,foo)
-	$(call RUN_BINFILE,foo)
-endif
-
-	# Check that linking without __rust_no_alloc_shim_is_unstable defined fails
-	$(RUSTC) foo.rs --crate-type bin --emit obj -Cpanic=abort --cfg check_feature_gate
-ifdef IS_MSVC
-	$(CC) $(CFLAGS) $(TMPDIR)/foo.o $(call OUT_EXE,foo) /link $(TARGET_LIBDIR)/liballoc-*.rlib $(TARGET_LIBDIR)/libcore-*.rlib $(TARGET_LIBDIR)/libcompiler_builtins-*.rlib || exit 0 && exit 1
-else
-	$(CC) $(CFLAGS) $(TMPDIR)/foo.o $(TARGET_LIBDIR)/liballoc-*.rlib $(TARGET_LIBDIR)/libcore-*.rlib $(TARGET_LIBDIR)/libcompiler_builtins-*.rlib -o $(call RUN_BINFILE,foo) || exit 0 && exit 1
-endif
diff --git a/tests/run-make/no-alloc-shim/rmake.rs b/tests/run-make/no-alloc-shim/rmake.rs
new file mode 100644
index 00000000000..c398a3177df
--- /dev/null
+++ b/tests/run-make/no-alloc-shim/rmake.rs
@@ -0,0 +1,55 @@
+// This test checks the compatibility of the interaction between `--emit obj` and
+// `#[global_allocator]`, as it is now possible to invoke the latter without the
+// allocator shim since #86844. As this feature is unstable, it should fail if
+// --cfg check_feature_gate is passed.
+// See https://github.com/rust-lang/rust/pull/86844
+
+//@ ignore-cross-compile
+// Reason: the compiled binary is executed
+
+//@ ignore-msvc
+//FIXME(Oneirical): Getting this to work on MSVC requires passing libcmt.lib to CC,
+// which is not trivial to do.
+// Tracking issue: https://github.com/rust-lang/rust/issues/128602
+// Discussion: https://github.com/rust-lang/rust/pull/128407#discussion_r1702439172
+
+use run_make_support::{cc, cwd, has_extension, has_prefix, run, rustc, shallow_find_files};
+
+fn main() {
+    rustc().input("foo.rs").crate_type("bin").emit("obj").panic("abort").run();
+    let libdir = rustc().print("target-libdir").run().stdout_utf8();
+    let libdir = libdir.trim();
+
+    let alloc_libs = shallow_find_files(&libdir, |path| {
+        has_prefix(path, "liballoc-") && has_extension(path, "rlib")
+    });
+    let core_libs = shallow_find_files(&libdir, |path| {
+        has_prefix(path, "libcore-") && has_extension(path, "rlib")
+    });
+    let compiler_builtins_libs = shallow_find_files(libdir, |path| {
+        has_prefix(path, "libcompiler_builtins") && has_extension(path, "rlib")
+    });
+
+    cc().input("foo.o")
+        .out_exe("foo")
+        .args(&alloc_libs)
+        .args(&core_libs)
+        .args(&compiler_builtins_libs)
+        .run();
+    run("foo");
+
+    // Check that linking without __rust_no_alloc_shim_is_unstable defined fails
+    rustc()
+        .input("foo.rs")
+        .crate_type("bin")
+        .emit("obj")
+        .panic("abort")
+        .cfg("check_feature_gate")
+        .run();
+    cc().input("foo.o")
+        .out_exe("foo")
+        .args(&alloc_libs)
+        .args(&core_libs)
+        .args(&compiler_builtins_libs)
+        .run_fail();
+}