Skip to content

Commit 13a5289

Browse files
committed
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
2 parents 355a307 + b85bedc commit 13a5289

File tree

7 files changed

+97
-49
lines changed

7 files changed

+97
-49
lines changed

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

+14
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,20 @@ pub fn assert_not_contains_regex<H: AsRef<str>, N: AsRef<str>>(haystack: H, need
7777
}
7878
}
7979

80+
/// Assert that `haystack` contains `needle` a `count` number of times.
81+
#[track_caller]
82+
pub fn assert_count_is<H: AsRef<str>, N: AsRef<str>>(count: usize, haystack: H, needle: N) {
83+
let haystack = haystack.as_ref();
84+
let needle = needle.as_ref();
85+
if count != haystack.matches(needle).count() {
86+
eprintln!("=== HAYSTACK ===");
87+
eprintln!("{}", haystack);
88+
eprintln!("=== NEEDLE ===");
89+
eprintln!("{}", needle);
90+
panic!("needle did not appear {count} times in haystack");
91+
}
92+
}
93+
8094
/// Assert that all files in `dir1` exist and have the same content in `dir2`
8195
pub fn assert_dirs_are_equal(dir1: impl AsRef<Path>, dir2: impl AsRef<Path>) {
8296
let dir2 = dir2.as_ref();

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ pub use path_helpers::{
8787
pub use scoped_run::{run_in_tmpdir, test_while_readonly};
8888

8989
pub use assertion_helpers::{
90-
assert_contains, assert_contains_regex, assert_dirs_are_equal, assert_equals,
90+
assert_contains, assert_contains_regex, assert_count_is, assert_dirs_are_equal, assert_equals,
9191
assert_not_contains, assert_not_contains_regex,
9292
};
9393

src/tools/tidy/src/allowed_run_make_makefiles.txt

-2
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,7 @@ run-make/libtest-json/Makefile
1313
run-make/libtest-junit/Makefile
1414
run-make/libtest-thread-limit/Makefile
1515
run-make/macos-deployment-target/Makefile
16-
run-make/min-global-align/Makefile
1716
run-make/native-link-modifier-bundle/Makefile
18-
run-make/no-alloc-shim/Makefile
1917
run-make/reproducible-build/Makefile
2018
run-make/rlib-format-packed-bundled-libs/Makefile
2119
run-make/split-debuginfo/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 test checks 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 specific to linux, 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

+55
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
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+
//@ ignore-msvc
11+
//FIXME(Oneirical): Getting this to work on MSVC requires passing libcmt.lib to CC,
12+
// which is not trivial to do.
13+
// Tracking issue: https://github.com/rust-lang/rust/issues/128602
14+
// Discussion: https://github.com/rust-lang/rust/pull/128407#discussion_r1702439172
15+
16+
use run_make_support::{cc, cwd, has_extension, has_prefix, run, rustc, shallow_find_files};
17+
18+
fn main() {
19+
rustc().input("foo.rs").crate_type("bin").emit("obj").panic("abort").run();
20+
let libdir = rustc().print("target-libdir").run().stdout_utf8();
21+
let libdir = libdir.trim();
22+
23+
let alloc_libs = shallow_find_files(&libdir, |path| {
24+
has_prefix(path, "liballoc-") && has_extension(path, "rlib")
25+
});
26+
let core_libs = shallow_find_files(&libdir, |path| {
27+
has_prefix(path, "libcore-") && has_extension(path, "rlib")
28+
});
29+
let compiler_builtins_libs = shallow_find_files(libdir, |path| {
30+
has_prefix(path, "libcompiler_builtins") && has_extension(path, "rlib")
31+
});
32+
33+
cc().input("foo.o")
34+
.out_exe("foo")
35+
.args(&alloc_libs)
36+
.args(&core_libs)
37+
.args(&compiler_builtins_libs)
38+
.run();
39+
run("foo");
40+
41+
// Check that linking without __rust_no_alloc_shim_is_unstable defined fails
42+
rustc()
43+
.input("foo.rs")
44+
.crate_type("bin")
45+
.emit("obj")
46+
.panic("abort")
47+
.cfg("check_feature_gate")
48+
.run();
49+
cc().input("foo.o")
50+
.out_exe("foo")
51+
.args(&alloc_libs)
52+
.args(&core_libs)
53+
.args(&compiler_builtins_libs)
54+
.run_fail();
55+
}

0 commit comments

Comments
 (0)