Skip to content

Commit 8f106b3

Browse files
committed
Auto merge of #127778 - Oneirical:artificial-intestlligence, r=<try>
Migrate `staticlib-blank-lib`, `rlib-format-packed-bundled-libs-3` and `issue-97463-abi-param-passing` `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: test-various try-job: x86-64-msvc
2 parents 11e5724 + c01e8cd commit 8f106b3

File tree

10 files changed

+128
-59
lines changed

10 files changed

+128
-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
@@ -47,7 +47,6 @@ run-make/issue-47551/Makefile
4747
run-make/issue-69368/Makefile
4848
run-make/issue-84395-lto-embed-bitcode/Makefile
4949
run-make/issue-88756-default-output/Makefile
50-
run-make/issue-97463-abi-param-passing/Makefile
5150
run-make/jobserver-error/Makefile
5251
run-make/libs-through-symlinks/Makefile
5352
run-make/libtest-json/Makefile
@@ -87,7 +86,6 @@ run-make/reproducible-build-2/Makefile
8786
run-make/reproducible-build/Makefile
8887
run-make/return-non-c-like-enum-from-c/Makefile
8988
run-make/rlib-format-packed-bundled-libs-2/Makefile
90-
run-make/rlib-format-packed-bundled-libs-3/Makefile
9189
run-make/rlib-format-packed-bundled-libs/Makefile
9290
run-make/sanitizer-cdylib-link/Makefile
9391
run-make/sanitizer-dylib-link/Makefile
@@ -97,7 +95,6 @@ run-make/simd-ffi/Makefile
9795
run-make/split-debuginfo/Makefile
9896
run-make/stable-symbol-names/Makefile
9997
run-make/static-dylib-by-default/Makefile
100-
run-make/staticlib-blank-lib/Makefile
10198
run-make/staticlib-dylib-linkage/Makefile
10299
run-make/symbol-mangling-hashed/Makefile
103100
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,87 @@
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+
// FIXME only-linux test-various
13+
14+
fn main() {
15+
build_native_static_lib("native_dep_1");
16+
build_native_static_lib("native_dep_2");
17+
build_native_static_lib("native_dep_3");
18+
build_native_static_lib("native_dep_4");
19+
// Test cfg with packed bundle.
20+
rustc().input("rust_dep_cfg.rs").crate_type("rlib").run();
21+
rustc()
22+
.input("main.rs")
23+
.extern_("rust_dep", rust_lib_name("rust_dep_cfg"))
24+
.crate_type("staticlib")
25+
.cfg("should_add")
26+
.run();
27+
// Only static libraries should appear, no object files at all.
28+
llvm_ar()
29+
.arg("t")
30+
.arg(rust_lib_name("rust_dep_cfg"))
31+
.run()
32+
.assert_stdout_contains(static_lib_name("native_dep_1"));
33+
llvm_ar()
34+
.arg("t")
35+
.arg(rust_lib_name("rust_dep_cfg"))
36+
.run()
37+
.assert_stdout_contains(static_lib_name("native_dep_2"));
38+
llvm_ar()
39+
.arg("t")
40+
.arg(static_lib_name("main"))
41+
.run()
42+
.assert_stdout_contains(object_file_name("native_dep_1"));
43+
llvm_ar()
44+
.arg("t")
45+
.arg(static_lib_name("main"))
46+
.run()
47+
.assert_stdout_not_contains(object_file_name("native_dep_2"));
48+
49+
// Test bundle with whole archive.
50+
rustc().input("rust_dep.rs").crate_type("rlib").run();
51+
// Only deps with `+bundle` should appear.
52+
llvm_ar().arg("t").arg(rust_lib_name("rust_dep")).run().assert_stdout_contains("native_dep_1");
53+
llvm_ar().arg("t").arg(rust_lib_name("rust_dep")).run().assert_stdout_contains("native_dep_3");
54+
llvm_ar()
55+
.arg("t")
56+
.arg(rust_lib_name("rust_dep"))
57+
.run()
58+
.assert_stdout_not_contains("native_dep_2");
59+
llvm_ar()
60+
.arg("t")
61+
.arg(rust_lib_name("rust_dep"))
62+
.run()
63+
.assert_stdout_not_contains("native_dep_4");
64+
65+
// The compiler shouldn't use files which it doesn't know about.
66+
rfs::remove_file(static_lib_name("native_dep_1"));
67+
rfs::remove_file(static_lib_name("native_dep_3"));
68+
69+
let out = rustc()
70+
.input("main.rs")
71+
.extern_("rust_dep", rust_lib_name("rust_dep"))
72+
.print("link-args")
73+
.run()
74+
.assert_stdout_not_contains("native_dep_3")
75+
.stdout_utf8();
76+
77+
let re = regex::Regex::new(
78+
"--whole-archive.*native_dep_1.*--whole-archive.*lnative_dep_2.*no-whole-archive.*lnative_dep_4"
79+
).unwrap();
80+
81+
assert!(re.is_match(&out));
82+
}
83+
84+
//FIXME(Oneirical): potential helper fn if this works on msvc too
85+
fn object_file_name(name: &str) -> String {
86+
if is_msvc() { format!("{name}.obj") } else { format!("{name}.o") }
87+
}

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,26 @@
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+
// FIXME(Oneirical): ignore-msvc
10+
11+
//@ ignore-cross-compile
12+
// Reason: The compiled binary is executed.
13+
14+
use run_make_support::{cc, is_msvc, llvm_ar, run, rustc, static_lib_name};
15+
16+
fn main() {
17+
// The issue exercised by this test specifically needs needs `-O`
18+
// flags (like `-O3`) to reproduce. Thus, we call `cc()` instead of
19+
// the nicer `build_native_static_lib`.
20+
let obj_file = if is_msvc() { "bad" } else { "bad.o" };
21+
cc().arg("-c").arg("-O3").out_exe(&obj_file).input("bad.c").run();
22+
let obj_file = if is_msvc() { "bad.obj" } else { "bad.o" };
23+
llvm_ar().obj_to_ar().output_input(static_lib_name("bad"), &obj_file).run();
24+
rustc().input("param_passing.rs").arg("-lbad").opt_level("3").run();
25+
run("param_passing");
26+
}

0 commit comments

Comments
 (0)