Skip to content

Commit fe94c51

Browse files
committed
rewrite native-link-modifier-bundle to rmake
1 parent 2b8e93d commit fe94c51

File tree

3 files changed

+85
-39
lines changed

3 files changed

+85
-39
lines changed

src/tools/tidy/src/allowed_run_make_makefiles.txt

-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ 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

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

-38
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
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+
// FIXME(Oneirical): cross compile and MSVC
20+
21+
use run_make_support::{
22+
build_native_static_lib, dynamic_lib_name, llvm_nm, rust_lib_name, rustc, static_lib_name,
23+
};
24+
25+
fn main() {
26+
build_native_static_lib("native-staticlib");
27+
// Build a staticlib and a rlib, the `native_func` symbol will be bundled into them
28+
rustc().input("bundled.rs").crate_type("staticlib").crate_type("rlib").run();
29+
llvm_nm()
30+
.input(static_lib_name("bundled"))
31+
.run()
32+
.assert_stdout_contains_regex("T _*native_func");
33+
llvm_nm()
34+
.input(static_lib_name("bundled"))
35+
.run()
36+
.assert_stdout_contains_regex("U _*native_func");
37+
llvm_nm().input(rust_lib_name("bundled")).run().assert_stdout_contains_regex("T _*native_func");
38+
llvm_nm().input(rust_lib_name("bundled")).run().assert_stdout_contains_regex("U _*native_func");
39+
40+
// Build a staticlib and a rlib, the `native_func` symbol will not be bundled into it
41+
build_native_static_lib("native-staticlib");
42+
rustc().input("non-bundled.rs").crate_type("staticlib").crate_type("rlib").run();
43+
llvm_nm()
44+
.input(static_lib_name("non_bundled"))
45+
.run()
46+
.assert_stdout_not_contains_regex("T _*native_func");
47+
llvm_nm()
48+
.input(static_lib_name("non_bundled"))
49+
.run()
50+
.assert_stdout_contains_regex("U _*native_func");
51+
llvm_nm()
52+
.input(rust_lib_name("non_bundled"))
53+
.run()
54+
.assert_stdout_not_contains_regex("T _*native_func");
55+
llvm_nm()
56+
.input(rust_lib_name("non_bundled"))
57+
.run()
58+
.assert_stdout_contains_regex("U _*native_func");
59+
60+
// Build a cdylib, `native-staticlib` will not appear on the linker line because it was bundled
61+
// previously. The cdylib will contain the `native_func` symbol in the end.
62+
rustc()
63+
.input("cdylib-bundled.rs")
64+
.crate_type("cdylib")
65+
.print("link-args")
66+
.run()
67+
.assert_stdout_not_contains(r#"-l[" ]*native-staticlib"#);
68+
llvm_nm()
69+
.input(dynamic_lib_name("cdylib_bundled"))
70+
.run()
71+
.assert_stdout_contains_regex("[Tt] _*native_func");
72+
73+
// Build a cdylib, `native-staticlib` will appear on the linker line because it was not bundled
74+
// previously. The cdylib will contain the `native_func` symbol in the end
75+
rustc()
76+
.input("cdylib-non-bundled.rs")
77+
.crate_type("cdylib")
78+
.print("link-args")
79+
.run()
80+
.assert_stdout_contains_regex(r#"-l[" ]*native-staticlib"#);
81+
llvm_nm()
82+
.input(dynamic_lib_name("cdylib_non_bundled"))
83+
.run()
84+
.assert_stdout_contains_regex("[Tt] _*native_func");
85+
}

0 commit comments

Comments
 (0)