Skip to content

Commit 759f93f

Browse files
Rollup merge of #129018 - Oneirical:nmemonic-artifice, r=jieyouxu
Migrate `rlib-format-packed-bundled-libs` and `native-link-modifier-bundle` `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 (ATTEMPTED: IGNORE RESTORED) try-job: x86_64-msvc try-job: aarch64-apple try-job: aarch64-gnu try-job: x86_64-mingw try-job: i686-mingw
2 parents 5858329 + 51628fb commit 759f93f

File tree

6 files changed

+180
-79
lines changed

6 files changed

+180
-79
lines changed

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

+6
Original file line numberDiff line numberDiff line change
@@ -297,6 +297,12 @@ impl LlvmAr {
297297
self
298298
}
299299

300+
/// Print the table of contents.
301+
pub fn table_of_contents(&mut self) -> &mut Self {
302+
self.cmd.arg("t");
303+
self
304+
}
305+
300306
/// Provide an output, then an input file. Bundled in one function, as llvm-ar has
301307
/// no "--output"-style flag.
302308
pub fn output_input(&mut self, out: impl AsRef<Path>, input: impl AsRef<Path>) -> &mut Self {

src/tools/tidy/src/allowed_run_make_makefiles.txt

-2
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,7 @@ run-make/libtest-json/Makefile
1010
run-make/libtest-junit/Makefile
1111
run-make/libtest-thread-limit/Makefile
1212
run-make/macos-deployment-target/Makefile
13-
run-make/native-link-modifier-bundle/Makefile
1413
run-make/reproducible-build/Makefile
15-
run-make/rlib-format-packed-bundled-libs/Makefile
1614
run-make/split-debuginfo/Makefile
1715
run-make/symbol-mangling-hashed/Makefile
1816
run-make/translation/Makefile

tests/run-make/native-link-modifier-bundle/Makefile

-38
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
// This test exercises the `bundle` link argument, which can be turned on or off.
2+
3+
// When building a rlib or staticlib, +bundle means that all object files from the native static
4+
// library will be added to the rlib or staticlib archive, and then used from it during linking of
5+
// the final binary.
6+
7+
// When building a rlib -bundle means that the native static library is registered as a dependency
8+
// of that rlib "by name", and object files from it are included only during linking of the final
9+
// binary, the file search by that name is also performed during final linking.
10+
// When building a staticlib -bundle means that the native static library is simply not included
11+
// into the archive and some higher level build system will need to add it later during linking of
12+
// the final binary.
13+
14+
// This modifier has no effect when building other targets like executables or dynamic libraries.
15+
16+
// The default for this modifier is +bundle.
17+
// See https://github.com/rust-lang/rust/pull/95818
18+
19+
//@ ignore-cross-compile
20+
// Reason: cross-compilation fails to export native symbols
21+
22+
use run_make_support::{
23+
build_native_static_lib, dynamic_lib_name, is_msvc, llvm_nm, rust_lib_name, rustc,
24+
static_lib_name,
25+
};
26+
27+
fn main() {
28+
build_native_static_lib("native-staticlib");
29+
// Build a staticlib and a rlib, the `native_func` symbol will be bundled into them
30+
rustc().input("bundled.rs").crate_type("staticlib").crate_type("rlib").run();
31+
llvm_nm()
32+
.input(static_lib_name("bundled"))
33+
.run()
34+
.assert_stdout_contains_regex("T _*native_func");
35+
llvm_nm()
36+
.input(static_lib_name("bundled"))
37+
.run()
38+
.assert_stdout_contains_regex("U _*native_func");
39+
llvm_nm().input(rust_lib_name("bundled")).run().assert_stdout_contains_regex("T _*native_func");
40+
llvm_nm().input(rust_lib_name("bundled")).run().assert_stdout_contains_regex("U _*native_func");
41+
42+
// Build a staticlib and a rlib, the `native_func` symbol will not be bundled into it
43+
build_native_static_lib("native-staticlib");
44+
rustc().input("non-bundled.rs").crate_type("staticlib").crate_type("rlib").run();
45+
llvm_nm()
46+
.input(static_lib_name("non_bundled"))
47+
.run()
48+
.assert_stdout_not_contains_regex("T _*native_func");
49+
llvm_nm()
50+
.input(static_lib_name("non_bundled"))
51+
.run()
52+
.assert_stdout_contains_regex("U _*native_func");
53+
llvm_nm()
54+
.input(rust_lib_name("non_bundled"))
55+
.run()
56+
.assert_stdout_not_contains_regex("T _*native_func");
57+
llvm_nm()
58+
.input(rust_lib_name("non_bundled"))
59+
.run()
60+
.assert_stdout_contains_regex("U _*native_func");
61+
62+
// This part of the test does not function on Windows MSVC - no symbols are printed.
63+
if !is_msvc() {
64+
// Build a cdylib, `native-staticlib` will not appear on the linker line because it was
65+
// bundled previously. The cdylib will contain the `native_func` symbol in the end.
66+
rustc()
67+
.input("cdylib-bundled.rs")
68+
.crate_type("cdylib")
69+
.print("link-args")
70+
.run()
71+
.assert_stdout_not_contains(r#"-l[" ]*native-staticlib"#);
72+
llvm_nm()
73+
.input(dynamic_lib_name("cdylib_bundled"))
74+
.run()
75+
.assert_stdout_contains_regex("[Tt] _*native_func");
76+
77+
// Build a cdylib, `native-staticlib` will appear on the linker line because it was not
78+
// bundled previously. The cdylib will contain the `native_func` symbol in the end
79+
rustc()
80+
.input("cdylib-non-bundled.rs")
81+
.crate_type("cdylib")
82+
.print("link-args")
83+
.run()
84+
.assert_stdout_contains_regex(r#"-l[" ]*native-staticlib"#);
85+
llvm_nm()
86+
.input(dynamic_lib_name("cdylib_non_bundled"))
87+
.run()
88+
.assert_stdout_contains_regex("[Tt] _*native_func");
89+
}
90+
}

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

-39
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+
// Output files compiled with this flag should still contain all expected symbols -
4+
// that is what this test checks.
5+
// See https://github.com/rust-lang/rust/pull/100101
6+
7+
//@ ignore-cross-compile
8+
// Reason: cross-compilation fails to export native symbols
9+
10+
use run_make_support::{
11+
bin_name, build_native_static_lib, cwd, filename_contains, is_msvc, llvm_ar, llvm_nm, rfs,
12+
rust_lib_name, rustc, shallow_find_files,
13+
};
14+
15+
fn main() {
16+
build_native_static_lib("native_dep_1");
17+
build_native_static_lib("native_dep_2");
18+
build_native_static_lib("native_dep_3");
19+
rustc().input("rust_dep_up.rs").crate_type("rlib").arg("-Zpacked_bundled_libs").run();
20+
llvm_nm()
21+
.input(rust_lib_name("rust_dep_up"))
22+
.run()
23+
.assert_stdout_contains_regex("U.*native_f2");
24+
llvm_nm()
25+
.input(rust_lib_name("rust_dep_up"))
26+
.run()
27+
.assert_stdout_contains_regex("U.*native_f3");
28+
llvm_nm()
29+
.input(rust_lib_name("rust_dep_up"))
30+
.run()
31+
.assert_stdout_contains_regex("T.*rust_dep_up");
32+
llvm_ar()
33+
.table_of_contents()
34+
.arg(rust_lib_name("rust_dep_up"))
35+
.run()
36+
.assert_stdout_contains("native_dep_2");
37+
llvm_ar()
38+
.table_of_contents()
39+
.arg(rust_lib_name("rust_dep_up"))
40+
.run()
41+
.assert_stdout_contains("native_dep_3");
42+
rustc()
43+
.input("rust_dep_local.rs")
44+
.extern_("rlib", rust_lib_name("rust_dep_up"))
45+
.arg("-Zpacked_bundled_libs")
46+
.crate_type("rlib")
47+
.run();
48+
llvm_nm()
49+
.input(rust_lib_name("rust_dep_local"))
50+
.run()
51+
.assert_stdout_contains_regex("U.*native_f1");
52+
llvm_nm()
53+
.input(rust_lib_name("rust_dep_local"))
54+
.run()
55+
.assert_stdout_contains_regex("T.*rust_dep_local");
56+
llvm_ar()
57+
.table_of_contents()
58+
.arg(rust_lib_name("rust_dep_local"))
59+
.run()
60+
.assert_stdout_contains("native_dep_1");
61+
62+
// Ensure the compiler will not use files it should not know about.
63+
for file in shallow_find_files(cwd(), |path| filename_contains(path, "native_dep_")) {
64+
rfs::remove_file(file);
65+
}
66+
67+
rustc()
68+
.input("main.rs")
69+
.extern_("lib", rust_lib_name("rust_dep_local"))
70+
.output(bin_name("main"))
71+
.arg("-Zpacked_bundled_libs")
72+
.print("link-args")
73+
.run()
74+
.assert_stdout_contains_regex("native_dep_1.*native_dep_2.*native_dep_3");
75+
76+
// The binary "main" will not contain any symbols on MSVC.
77+
if !is_msvc() {
78+
llvm_nm().input(bin_name("main")).run().assert_stdout_contains_regex("T.*native_f1");
79+
llvm_nm().input(bin_name("main")).run().assert_stdout_contains_regex("T.*native_f2");
80+
llvm_nm().input(bin_name("main")).run().assert_stdout_contains_regex("T.*native_f3");
81+
llvm_nm().input(bin_name("main")).run().assert_stdout_contains_regex("T.*rust_dep_local");
82+
llvm_nm().input(bin_name("main")).run().assert_stdout_contains_regex("T.*rust_dep_up");
83+
}
84+
}

0 commit comments

Comments
 (0)