Skip to content

Commit

Permalink
Auto merge of rust-lang#128407 - Oneirical:feline-dotestication, r=<try>
Browse files Browse the repository at this point in the history
Migrate `min-global-align` and `no-alloc-shim` `run-make` tests to rmake

Part of rust-lang#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
  • Loading branch information
bors committed Jul 30, 2024
2 parents 006c8df + 4c26950 commit 8e53144
Show file tree
Hide file tree
Showing 7 changed files with 78 additions and 49 deletions.
14 changes: 14 additions & 0 deletions src/tools/run-make-support/src/assertion_helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,20 @@ pub fn assert_not_contains<H: AsRef<str>, N: AsRef<str>>(haystack: H, needle: N)
}
}

/// 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();
Expand Down
2 changes: 1 addition & 1 deletion src/tools/run-make-support/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ pub use path_helpers::{
pub use scoped_run::{run_in_tmpdir, test_while_readonly};

pub use assertion_helpers::{
assert_contains, assert_dirs_are_equal, assert_equals, assert_not_contains,
assert_contains, assert_count_is, assert_dirs_are_equal, assert_equals, assert_not_contains,
};

pub use string::{
Expand Down
2 changes: 0 additions & 2 deletions src/tools/tidy/src/allowed_run_make_makefiles.txt
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,8 @@ run-make/link-cfg/Makefile
run-make/long-linker-command-lines-cmd-exe/Makefile
run-make/long-linker-command-lines/Makefile
run-make/macos-deployment-target/Makefile
run-make/min-global-align/Makefile
run-make/native-link-modifier-bundle/Makefile
run-make/native-link-modifier-whole-archive/Makefile
run-make/no-alloc-shim/Makefile
run-make/no-builtins-attribute/Makefile
run-make/pdb-buildinfo-cl-cmd/Makefile
run-make/pgo-gen-lto/Makefile
Expand Down
22 changes: 0 additions & 22 deletions tests/run-make/min-global-align/Makefile

This file was deleted.

27 changes: 27 additions & 0 deletions tests/run-make/min-global-align/rmake.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// 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.
// See https://github.com/rust-lang/rust/pull/44440

//@ only-linux
// Reason: this test is target-independent, 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");
}
}
24 changes: 0 additions & 24 deletions tests/run-make/no-alloc-shim/Makefile

This file was deleted.

36 changes: 36 additions & 0 deletions tests/run-make/no-alloc-shim/rmake.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
// 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

//FIXME(Oneirical): ignore-msvc FIXME(bjorn3) can't figure out how to link with the MSVC toolchain

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")
});
cc().input("foo.o").out_exe("foo").args(&alloc_libs).args(&core_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).run_fail();
}

0 comments on commit 8e53144

Please sign in to comment.