Skip to content

Commit 8e53144

Browse files
committed
Auto merge of #128407 - Oneirical:feline-dotestication, r=<try>
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: x86_64-msvc
2 parents 006c8df + 4c26950 commit 8e53144

File tree

7 files changed

+78
-49
lines changed

7 files changed

+78
-49
lines changed

src/tools/run-make-support/src/assertion_helpers.rs

+14
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,20 @@ pub fn assert_not_contains<H: AsRef<str>, N: AsRef<str>>(haystack: H, needle: N)
4747
}
4848
}
4949

50+
/// Assert that `haystack` contains `needle` a `count` number of times.
51+
#[track_caller]
52+
pub fn assert_count_is<H: AsRef<str>, N: AsRef<str>>(count: usize, haystack: H, needle: N) {
53+
let haystack = haystack.as_ref();
54+
let needle = needle.as_ref();
55+
if count != haystack.matches(needle).count() {
56+
eprintln!("=== HAYSTACK ===");
57+
eprintln!("{}", haystack);
58+
eprintln!("=== NEEDLE ===");
59+
eprintln!("{}", needle);
60+
panic!("needle did not appear {count} times in haystack");
61+
}
62+
}
63+
5064
/// Assert that all files in `dir1` exist and have the same content in `dir2`
5165
pub fn assert_dirs_are_equal(dir1: impl AsRef<Path>, dir2: impl AsRef<Path>) {
5266
let dir2 = dir2.as_ref();

src/tools/run-make-support/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ pub use path_helpers::{
8484
pub use scoped_run::{run_in_tmpdir, test_while_readonly};
8585

8686
pub use assertion_helpers::{
87-
assert_contains, assert_dirs_are_equal, assert_equals, assert_not_contains,
87+
assert_contains, assert_count_is, assert_dirs_are_equal, assert_equals, assert_not_contains,
8888
};
8989

9090
pub use string::{

src/tools/tidy/src/allowed_run_make_makefiles.txt

-2
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,8 @@ run-make/link-cfg/Makefile
2929
run-make/long-linker-command-lines-cmd-exe/Makefile
3030
run-make/long-linker-command-lines/Makefile
3131
run-make/macos-deployment-target/Makefile
32-
run-make/min-global-align/Makefile
3332
run-make/native-link-modifier-bundle/Makefile
3433
run-make/native-link-modifier-whole-archive/Makefile
35-
run-make/no-alloc-shim/Makefile
3634
run-make/no-builtins-attribute/Makefile
3735
run-make/pdb-buildinfo-cl-cmd/Makefile
3836
run-make/pgo-gen-lto/Makefile

tests/run-make/min-global-align/Makefile

-22
This file was deleted.
+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// This tests ensure that global variables respect the target minimum alignment.
2+
// The three bools `STATIC_BOOL`, `STATIC_MUT_BOOL`, and `CONST_BOOL` all have
3+
// type-alignment of 1, but some targets require greater global alignment.
4+
// See https://github.com/rust-lang/rust/pull/44440
5+
6+
//@ only-linux
7+
// Reason: this test is target-independent, considering compilation is targeted
8+
// towards linux architectures only.
9+
10+
use run_make_support::{assert_count_is, llvm_components_contain, rfs, rustc};
11+
12+
fn main() {
13+
// Most targets are happy with default alignment -- take i686 for example.
14+
if llvm_components_contain("x86") {
15+
rustc().target("i686-unknown-linux-gnu").emit("llvm-ir").input("min_global_align.rs").run();
16+
assert_count_is(3, rfs::read_to_string("min_global_align.ll"), "align 1");
17+
}
18+
// SystemZ requires even alignment for PC-relative addressing.
19+
if llvm_components_contain("systemz") {
20+
rustc()
21+
.target("s390x-unknown-linux-gnu")
22+
.emit("llvm-ir")
23+
.input("min_global_align.rs")
24+
.run();
25+
assert_count_is(3, rfs::read_to_string("min_global_align.ll"), "align 2");
26+
}
27+
}

tests/run-make/no-alloc-shim/Makefile

-24
This file was deleted.

tests/run-make/no-alloc-shim/rmake.rs

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
// This test checks the compatibility of the interaction between `--emit obj` and
2+
// `#[global_allocator]`, as it is now possible to invoke the latter without the
3+
// allocator shim since #86844. As this feature is unstable, it should fail if
4+
// --cfg check_feature_gate is passed.
5+
// See https://github.com/rust-lang/rust/pull/86844
6+
7+
//@ ignore-cross-compile
8+
// Reason: the compiled binary is executed
9+
10+
//FIXME(Oneirical): ignore-msvc FIXME(bjorn3) can't figure out how to link with the MSVC toolchain
11+
12+
use run_make_support::{cc, cwd, has_extension, has_prefix, run, rustc, shallow_find_files};
13+
14+
fn main() {
15+
rustc().input("foo.rs").crate_type("bin").emit("obj").panic("abort").run();
16+
let libdir = rustc().print("target-libdir").run().stdout_utf8();
17+
let libdir = libdir.trim();
18+
let alloc_libs = shallow_find_files(&libdir, |path| {
19+
has_prefix(path, "liballoc-") && has_extension(path, "rlib")
20+
});
21+
let core_libs = shallow_find_files(libdir, |path| {
22+
has_prefix(path, "libcore-") && has_extension(path, "rlib")
23+
});
24+
cc().input("foo.o").out_exe("foo").args(&alloc_libs).args(&core_libs).run();
25+
run("foo");
26+
27+
// Check that linking without __rust_no_alloc_shim_is_unstable defined fails
28+
rustc()
29+
.input("foo.rs")
30+
.crate_type("bin")
31+
.emit("obj")
32+
.panic("abort")
33+
.cfg("check_feature_gate")
34+
.run();
35+
cc().input("foo.o").out_exe("foo").args(&alloc_libs).args(&core_libs).run_fail();
36+
}

0 commit comments

Comments
 (0)