Skip to content

Commit f1747f4

Browse files
committed
rewrite rlib-format-packed-bundled-libs-3 to rmake
1 parent 7d3cbb3 commit f1747f4

File tree

3 files changed

+88
-36
lines changed

3 files changed

+88
-36
lines changed

Diff for: src/tools/tidy/src/allowed_run_make_makefiles.txt

-1
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,6 @@ run-make/reproducible-build-2/Makefile
9292
run-make/reproducible-build/Makefile
9393
run-make/return-non-c-like-enum-from-c/Makefile
9494
run-make/rlib-format-packed-bundled-libs-2/Makefile
95-
run-make/rlib-format-packed-bundled-libs-3/Makefile
9695
run-make/rlib-format-packed-bundled-libs/Makefile
9796
run-make/sanitizer-cdylib-link/Makefile
9897
run-make/sanitizer-dylib-link/Makefile

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

-35
This file was deleted.
+88
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
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, fs_wrapper, is_msvc, llvm_ar, regex, rust_lib_name, rustc,
10+
static_lib_name,
11+
};
12+
13+
// FIXME only-linux test-various
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+
build_native_static_lib("native_dep_4");
20+
// Test cfg with packed bundle.
21+
rustc().input("rust_dep_cfg.rs").crate_type("rlib").run();
22+
rustc()
23+
.input("main.rs")
24+
.extern_("rust_dep", rust_lib_name("rust_dep_cfg"))
25+
.crate_type("staticlib")
26+
.cfg("should_add")
27+
.run();
28+
// Only static libraries should appear, no object files at all.
29+
llvm_ar()
30+
.arg("t")
31+
.arg(rust_lib_name("rust_dep_cfg"))
32+
.run()
33+
.assert_stdout_contains(static_lib_name("native_dep_1"));
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_2"));
39+
llvm_ar()
40+
.arg("t")
41+
.arg(static_lib_name("main"))
42+
.run()
43+
.assert_stdout_contains(object_file_name("native_dep_1"));
44+
llvm_ar()
45+
.arg("t")
46+
.arg(static_lib_name("main"))
47+
.run()
48+
.assert_stdout_not_contains(object_file_name("native_dep_2"));
49+
50+
// Test bundle with whole archive.
51+
rustc().input("rust_dep.rs").crate_type("rlib").run();
52+
// Only deps with `+bundle` should appear.
53+
llvm_ar().arg("t").arg(rust_lib_name("rust_dep")).run().assert_stdout_contains("native_dep_1");
54+
llvm_ar().arg("t").arg(rust_lib_name("rust_dep")).run().assert_stdout_contains("native_dep_3");
55+
llvm_ar()
56+
.arg("t")
57+
.arg(rust_lib_name("rust_dep"))
58+
.run()
59+
.assert_stdout_not_contains("native_dep_2");
60+
llvm_ar()
61+
.arg("t")
62+
.arg(rust_lib_name("rust_dep"))
63+
.run()
64+
.assert_stdout_not_contains("native_dep_4");
65+
66+
// The compiler shouldn't use files which it doesn't know about.
67+
fs_wrapper::remove_file(static_lib_name("native_dep_1"));
68+
fs_wrapper::remove_file(static_lib_name("native_dep_3"));
69+
70+
let out = rustc()
71+
.input("main.rs")
72+
.extern_("rust_dep", rust_lib_name("rust_dep"))
73+
.print("link-args")
74+
.run()
75+
.assert_stdout_not_contains("native_dep_3")
76+
.stdout_utf8();
77+
78+
let re = regex::Regex::new(
79+
"--whole-archive.*native_dep_1.*--whole-archive.*lnative_dep_2.*no-whole-archive.*lnative_dep_4"
80+
).unwrap();
81+
82+
assert!(re.is_match(&out));
83+
}
84+
85+
//FIXME(Oneirical): potential helper fn if this works on msvc too
86+
fn object_file_name(name: &str) -> String {
87+
if is_msvc() { format!("{name}.obj") } else { format!("{name}.o") }
88+
}

0 commit comments

Comments
 (0)