Skip to content

Commit 8ded134

Browse files
committed
Auto merge of rust-lang#127778 - Oneirical:artificial-intestlligence, r=jieyouxu
Migrate `staticlib-blank-lib`, `rlib-format-packed-bundled-libs-3` and `issue-97463-abi-param-passing` `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: aarch64-gnu try-job: armhf-gnu try-job: test-various try-job: x86_64-mingw try-job: x86_64-msvc try-job: x86_64-gnu-llvm-18
2 parents cefe1dc + 55dda5d commit 8ded134

File tree

10 files changed

+124
-59
lines changed

10 files changed

+124
-59
lines changed

src/tools/run-make-support/src/external_deps/llvm.rs

+2
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,8 @@ impl LlvmAr {
229229
Self { cmd }
230230
}
231231

232+
/// Automatically pass the commonly used arguments `rcus`, used for combining one or more
233+
/// input object files into one output static library file.
232234
pub fn obj_to_ar(&mut self) -> &mut Self {
233235
self.cmd.arg("rcus");
234236
self

src/tools/tidy/src/allowed_run_make_makefiles.txt

-3
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ run-make/issue-47551/Makefile
3434
run-make/issue-69368/Makefile
3535
run-make/issue-84395-lto-embed-bitcode/Makefile
3636
run-make/issue-88756-default-output/Makefile
37-
run-make/issue-97463-abi-param-passing/Makefile
3837
run-make/jobserver-error/Makefile
3938
run-make/libs-through-symlinks/Makefile
4039
run-make/libtest-json/Makefile
@@ -70,7 +69,6 @@ run-make/remap-path-prefix-dwarf/Makefile
7069
run-make/reproducible-build-2/Makefile
7170
run-make/reproducible-build/Makefile
7271
run-make/rlib-format-packed-bundled-libs-2/Makefile
73-
run-make/rlib-format-packed-bundled-libs-3/Makefile
7472
run-make/rlib-format-packed-bundled-libs/Makefile
7573
run-make/sanitizer-cdylib-link/Makefile
7674
run-make/sanitizer-dylib-link/Makefile
@@ -80,7 +78,6 @@ run-make/simd-ffi/Makefile
8078
run-make/split-debuginfo/Makefile
8179
run-make/stable-symbol-names/Makefile
8280
run-make/static-dylib-by-default/Makefile
83-
run-make/staticlib-blank-lib/Makefile
8481
run-make/staticlib-dylib-linkage/Makefile
8582
run-make/symbol-mangling-hashed/Makefile
8683
run-make/symbol-visibility/Makefile

tests/run-make/issue-97463-abi-param-passing/Makefile

-15
This file was deleted.

tests/run-make/rlib-format-packed-bundled-libs-3/Makefile

-35
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
// `-Z packed_bundled_libs` is an unstable rustc flag that makes the compiler
2+
// only require a native library and no supplementary object files to compile.
3+
// #105601 made it possible to have this behaviour without an unstable flag by
4+
// passing +bundle in modifiers, and this test checks that this feature successfully
5+
// compiles and includes only the static libraries, with no object files.
6+
// See https://github.com/rust-lang/rust/pull/105601
7+
8+
use run_make_support::{
9+
build_native_static_lib, is_msvc, llvm_ar, regex, rfs, rust_lib_name, rustc, static_lib_name,
10+
};
11+
12+
//@ ignore-cross-compile
13+
// Reason: Invalid library format (not ELF) causes compilation failure
14+
// in the final `rustc` call.
15+
16+
//@ only-linux
17+
// Reason: differences in the native lib compilation process causes differences
18+
// in the --print link-args output
19+
20+
fn main() {
21+
build_native_static_lib("native_dep_1");
22+
build_native_static_lib("native_dep_2");
23+
build_native_static_lib("native_dep_3");
24+
build_native_static_lib("native_dep_4");
25+
// Test cfg with packed bundle.
26+
rustc().input("rust_dep_cfg.rs").crate_type("rlib").run();
27+
rustc()
28+
.input("main.rs")
29+
.extern_("rust_dep", rust_lib_name("rust_dep_cfg"))
30+
.crate_type("staticlib")
31+
.cfg("should_add")
32+
.run();
33+
// Only static libraries should appear, no object files at all.
34+
llvm_ar()
35+
.arg("t")
36+
.arg(rust_lib_name("rust_dep_cfg"))
37+
.run()
38+
.assert_stdout_contains(static_lib_name("native_dep_1"));
39+
llvm_ar()
40+
.arg("t")
41+
.arg(rust_lib_name("rust_dep_cfg"))
42+
.run()
43+
.assert_stdout_contains(static_lib_name("native_dep_2"));
44+
llvm_ar().arg("t").arg(static_lib_name("main")).run().assert_stdout_contains("native_dep_1.o");
45+
llvm_ar()
46+
.arg("t")
47+
.arg(static_lib_name("main"))
48+
.run()
49+
.assert_stdout_not_contains("native_dep_2.o");
50+
51+
// Test bundle with whole archive.
52+
rustc().input("rust_dep.rs").crate_type("rlib").run();
53+
// Only deps with `+bundle` should appear.
54+
llvm_ar().arg("t").arg(rust_lib_name("rust_dep")).run().assert_stdout_contains("native_dep_1");
55+
llvm_ar().arg("t").arg(rust_lib_name("rust_dep")).run().assert_stdout_contains("native_dep_3");
56+
llvm_ar()
57+
.arg("t")
58+
.arg(rust_lib_name("rust_dep"))
59+
.run()
60+
.assert_stdout_not_contains("native_dep_2");
61+
llvm_ar()
62+
.arg("t")
63+
.arg(rust_lib_name("rust_dep"))
64+
.run()
65+
.assert_stdout_not_contains("native_dep_4");
66+
67+
// The compiler shouldn't use files which it doesn't know about.
68+
rfs::remove_file(static_lib_name("native_dep_1"));
69+
rfs::remove_file(static_lib_name("native_dep_3"));
70+
71+
let out = rustc()
72+
.input("main.rs")
73+
.extern_("rust_dep", rust_lib_name("rust_dep"))
74+
.print("link-args")
75+
.run()
76+
.assert_stdout_not_contains("native_dep_3")
77+
.stdout_utf8();
78+
79+
let re = regex::Regex::new(
80+
"--whole-archive.*native_dep_1.*--whole-archive.*lnative_dep_2.*no-whole-archive.*lnative_dep_4"
81+
).unwrap();
82+
83+
assert!(re.is_match(&out));
84+
}

tests/run-make/staticlib-blank-lib/Makefile

-6
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// In this test, the static library foo is made blank, which used to cause
2+
// a compilation error. As the compiler now returns Ok upon encountering a blank
3+
// staticlib as of #12379, this test checks that compilation is successful despite
4+
// the blank staticlib.
5+
// See https://github.com/rust-lang/rust/pull/12379
6+
7+
use run_make_support::{llvm_ar, rustc, static_lib_name};
8+
9+
fn main() {
10+
llvm_ar().obj_to_ar().output_input(static_lib_name("foo"), "foo.rs").run();
11+
llvm_ar().arg("d").output_input(static_lib_name("foo"), "foo.rs").run();
12+
rustc().input("foo.rs").run();
13+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// This test was created in response to an obscure miscompilation bug, only
2+
// visible with the -O3 flag passed to the cc compiler when trying to obtain
3+
// a native static library for the sake of foreign function interface. This
4+
// flag could cause certain integer types to fail to be zero-extended, resulting
5+
// in type casting errors. After the fix in #97800, this test attempts integer casting
6+
// while simultaneously interfacing with a C library and using the -O3 flag.
7+
// See https://github.com/rust-lang/rust/issues/97463
8+
9+
//@ ignore-msvc
10+
// Reason: the rustc compilation fails due to an unresolved external symbol
11+
12+
//@ ignore-cross-compile
13+
// Reason: The compiled binary is executed.
14+
15+
use run_make_support::{cc, is_msvc, llvm_ar, run, rustc, static_lib_name};
16+
17+
fn main() {
18+
// The issue exercised by this test specifically needs needs `-O`
19+
// flags (like `-O3`) to reproduce. Thus, we call `cc()` instead of
20+
// the nicer `build_native_static_lib`.
21+
cc().arg("-c").arg("-O3").out_exe("bad.o").input("bad.c").run();
22+
llvm_ar().obj_to_ar().output_input(static_lib_name("bad"), "bad.o").run();
23+
rustc().input("param_passing.rs").arg("-lbad").opt_level("3").run();
24+
run("param_passing");
25+
}

0 commit comments

Comments
 (0)