Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit f34cae2

Browse files
committedAug 12, 2024
Auto merge of #129018 - Oneirical:nmemonic-artifice, r=<try>
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: x86_64-msvc // try-job: test-various (ATTEMPTED: IGNORE RESTORED)
2 parents e08b80c + 1d3de31 commit f34cae2

File tree

6 files changed

+178
-79
lines changed

6 files changed

+178
-79
lines changed
 

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

+6
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,12 @@ impl LlvmAr {
277277
self
278278
}
279279

280+
/// Print the table of contents.
281+
pub fn table_of_contents(&mut self) -> &mut Self {
282+
self.cmd.arg("t");
283+
self
284+
}
285+
280286
/// Provide an output, then an input file. Bundled in one function, as llvm-ar has
281287
/// no "--output"-style flag.
282288
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
@@ -14,11 +14,9 @@ run-make/libtest-junit/Makefile
1414
run-make/libtest-thread-limit/Makefile
1515
run-make/macos-deployment-target/Makefile
1616
run-make/min-global-align/Makefile
17-
run-make/native-link-modifier-bundle/Makefile
1817
run-make/no-alloc-shim/Makefile
1918
run-make/remap-path-prefix-dwarf/Makefile
2019
run-make/reproducible-build/Makefile
21-
run-make/rlib-format-packed-bundled-libs/Makefile
2220
run-make/split-debuginfo/Makefile
2321
run-make/symbol-mangling-hashed/Makefile
2422
run-make/sysroot-crates-are-unstable/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,88 @@
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+
// FIXME(Oneirical): MSVC
23+
24+
use run_make_support::{
25+
build_native_static_lib, dynamic_lib_name, llvm_nm, rust_lib_name, rustc, static_lib_name,
26+
};
27+
28+
fn main() {
29+
build_native_static_lib("native-staticlib");
30+
// Build a staticlib and a rlib, the `native_func` symbol will be bundled into them
31+
rustc().input("bundled.rs").crate_type("staticlib").crate_type("rlib").run();
32+
llvm_nm()
33+
.input(static_lib_name("bundled"))
34+
.run()
35+
.assert_stdout_contains_regex("T _*native_func");
36+
llvm_nm()
37+
.input(static_lib_name("bundled"))
38+
.run()
39+
.assert_stdout_contains_regex("U _*native_func");
40+
llvm_nm().input(rust_lib_name("bundled")).run().assert_stdout_contains_regex("T _*native_func");
41+
llvm_nm().input(rust_lib_name("bundled")).run().assert_stdout_contains_regex("U _*native_func");
42+
43+
// Build a staticlib and a rlib, the `native_func` symbol will not be bundled into it
44+
build_native_static_lib("native-staticlib");
45+
rustc().input("non-bundled.rs").crate_type("staticlib").crate_type("rlib").run();
46+
llvm_nm()
47+
.input(static_lib_name("non_bundled"))
48+
.run()
49+
.assert_stdout_not_contains_regex("T _*native_func");
50+
llvm_nm()
51+
.input(static_lib_name("non_bundled"))
52+
.run()
53+
.assert_stdout_contains_regex("U _*native_func");
54+
llvm_nm()
55+
.input(rust_lib_name("non_bundled"))
56+
.run()
57+
.assert_stdout_not_contains_regex("T _*native_func");
58+
llvm_nm()
59+
.input(rust_lib_name("non_bundled"))
60+
.run()
61+
.assert_stdout_contains_regex("U _*native_func");
62+
63+
// Build a cdylib, `native-staticlib` will not appear on the linker line because it was bundled
64+
// previously. The cdylib will contain the `native_func` symbol in the end.
65+
rustc()
66+
.input("cdylib-bundled.rs")
67+
.crate_type("cdylib")
68+
.print("link-args")
69+
.run()
70+
.assert_stdout_not_contains(r#"-l[" ]*native-staticlib"#);
71+
llvm_nm()
72+
.input(dynamic_lib_name("cdylib_bundled"))
73+
.run()
74+
.assert_stdout_contains_regex("[Tt] _*native_func");
75+
76+
// Build a cdylib, `native-staticlib` will appear on the linker line because it was not bundled
77+
// previously. The cdylib will contain the `native_func` symbol in the end
78+
rustc()
79+
.input("cdylib-non-bundled.rs")
80+
.crate_type("cdylib")
81+
.print("link-args")
82+
.run()
83+
.assert_stdout_contains_regex(r#"-l[" ]*native-staticlib"#);
84+
llvm_nm()
85+
.input(dynamic_lib_name("cdylib_non_bundled"))
86+
.run()
87+
.assert_stdout_contains_regex("[Tt] _*native_func");
88+
}

‎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+
// FIXME(Oneirical): MSVC
11+
12+
use run_make_support::{
13+
bin_name, build_native_static_lib, cwd, filename_contains, llvm_ar, llvm_nm, rfs,
14+
rust_lib_name, rustc, shallow_find_files,
15+
};
16+
17+
fn main() {
18+
build_native_static_lib("native_dep_1");
19+
build_native_static_lib("native_dep_2");
20+
build_native_static_lib("native_dep_3");
21+
rustc().input("rust_dep_up.rs").crate_type("rlib").arg("-Zpacked_bundled_libs").run();
22+
llvm_nm()
23+
.input(rust_lib_name("rust_dep_up"))
24+
.run()
25+
.assert_stdout_contains_regex("U.*native_f2");
26+
llvm_nm()
27+
.input(rust_lib_name("rust_dep_up"))
28+
.run()
29+
.assert_stdout_contains_regex("U.*native_f3");
30+
llvm_nm()
31+
.input(rust_lib_name("rust_dep_up"))
32+
.run()
33+
.assert_stdout_contains_regex("T.*rust_dep_up");
34+
llvm_ar()
35+
.table_of_contents()
36+
.arg(rust_lib_name("rust_dep_up"))
37+
.run()
38+
.assert_stdout_contains("native_dep_2");
39+
llvm_ar()
40+
.table_of_contents()
41+
.arg(rust_lib_name("rust_dep_up"))
42+
.run()
43+
.assert_stdout_contains("native_dep_3");
44+
rustc()
45+
.input("rust_dep_local.rs")
46+
.extern_("rlib", rust_lib_name("rust_dep_up"))
47+
.arg("-Zpacked_bundled_libs")
48+
.crate_type("rlib")
49+
.run();
50+
llvm_nm()
51+
.input(rust_lib_name("rust_dep_local"))
52+
.run()
53+
.assert_stdout_contains_regex("U.*native_f1");
54+
llvm_nm()
55+
.input(rust_lib_name("rust_dep_local"))
56+
.run()
57+
.assert_stdout_contains_regex("T.*rust_dep_local");
58+
llvm_ar()
59+
.table_of_contents()
60+
.arg(rust_lib_name("rust_dep_local"))
61+
.run()
62+
.assert_stdout_contains("native_dep_1");
63+
64+
// Ensure the compiler will not use files it should not know about.
65+
for file in shallow_find_files(cwd(), |path| filename_contains(path, "native_dep_")) {
66+
rfs::remove_file(file);
67+
}
68+
69+
rustc()
70+
.input("main.rs")
71+
.extern_("lib", rust_lib_name("rust_dep_local"))
72+
.output(bin_name("main"))
73+
.arg("-Zpacked_bundled_libs")
74+
.print("link-args")
75+
.run()
76+
.assert_stdout_contains_regex("native_dep_1.*native_dep_2.*native_dep_3");
77+
78+
//FIXME(Oneirical): This part will apparently fail on MSVC
79+
llvm_nm().input(bin_name("main")).run().assert_stdout_contains_regex("T.*native_f1");
80+
llvm_nm().input(bin_name("main")).run().assert_stdout_contains_regex("T.*native_f2");
81+
llvm_nm().input(bin_name("main")).run().assert_stdout_contains_regex("T.*native_f3");
82+
llvm_nm().input(bin_name("main")).run().assert_stdout_contains_regex("T.*rust_dep_local");
83+
llvm_nm().input(bin_name("main")).run().assert_stdout_contains_regex("T.*rust_dep_up");
84+
}

0 commit comments

Comments
 (0)
Failed to load comments.