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
This commit is contained in:
bors 2024-07-20 19:49:49 +00:00
commit 5069856495
23 changed files with 154 additions and 82 deletions

View File

@ -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

View File

@ -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)

View File

@ -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");
}

View File

@ -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)

View File

@ -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");
}

View File

@ -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

View File

@ -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");
}

View File

@ -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

View File

@ -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");
}

View File

@ -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)

View File

@ -1,6 +0,0 @@
# ignore-cross-compile
include ../tools.mk
all: $(call NATIVE_STATICLIB,foo)
$(RUSTC) bar.rs
$(call RUN,bar) || exit 1

View File

@ -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");
}

View File

@ -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)

View File

@ -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");
}

View File

@ -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");
}

View File

@ -1,6 +0,0 @@
# ignore-cross-compile
include ../tools.mk
all: $(call NATIVE_STATICLIB,test)
$(RUSTC) nonclike.rs -L$(TMPDIR) -ltest
$(call RUN,nonclike)

View File

@ -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");
}

View File

@ -1,6 +0,0 @@
# ignore-cross-compile
include ../tools.mk
all: $(call NATIVE_STATICLIB,test)
$(RUSTC) nonclike.rs -L$(TMPDIR) -ltest
$(call RUN,nonclike)

View File

@ -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");
}