Skip to content

Commit 1a2928b

Browse files
committed
Auto merge of rust-lang#128075 - Oneirical:try-your-damnetest, r=<try>
Migrate `rlib-format-packed-bundled-libs-2`, `native-link-modifier-whole-archive` and `no-builtins-attribute` `run-make` tests to rmake Part of rust-lang#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
2 parents d111ccd + 3347dfb commit 1a2928b

File tree

9 files changed

+155
-92
lines changed

9 files changed

+155
-92
lines changed

Diff for: src/tools/run-make-support/src/external_deps/cc.rs

+23
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,13 @@ pub fn cc() -> Cc {
1515
Cc::new()
1616
}
1717

18+
/// Construct a new platform-specific CXX compiler invocation.
19+
/// CXX_DEFAULT_FLAGS is passed from compiletest.
20+
#[track_caller]
21+
pub fn cxx() -> Cc {
22+
Cc::new_cxx()
23+
}
24+
1825
/// A platform-specific C compiler invocation builder. The specific C compiler used is
1926
/// passed down from compiletest.
2027
#[derive(Debug)]
@@ -44,6 +51,22 @@ impl Cc {
4451
Self { cmd }
4552
}
4653

54+
/// Construct a new platform-specific CXX compiler invocation.
55+
/// CXX_DEFAULT_FLAGS is passed from compiletest.
56+
#[track_caller]
57+
pub fn new_cxx() -> Self {
58+
let compiler = env_var("CXX");
59+
60+
let mut cmd = Command::new(compiler);
61+
62+
let default_cflags = env_var("CXX_DEFAULT_FLAGS");
63+
for flag in default_cflags.split(char::is_whitespace) {
64+
cmd.arg(flag);
65+
}
66+
67+
Self { cmd }
68+
}
69+
4770
/// Specify path of the input file.
4871
pub fn input<P: AsRef<Path>>(&mut self, path: P) -> &mut Self {
4972
self.cmd.arg(path.as_ref());

Diff for: src/tools/run-make-support/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ pub use external_deps::{c_build, cc, clang, htmldocck, llvm, python, rustc, rust
4444

4545
// These rely on external dependencies.
4646
pub use c_build::build_native_static_lib;
47-
pub use cc::{cc, extra_c_flags, extra_cxx_flags, Cc};
47+
pub use cc::{cc, cxx, extra_c_flags, extra_cxx_flags, Cc};
4848
pub use clang::{clang, Clang};
4949
pub use htmldocck::htmldocck;
5050
pub use llvm::{

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

-3
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,7 @@ run-make/lto-linkage-used-attr/Makefile
4747
run-make/macos-deployment-target/Makefile
4848
run-make/min-global-align/Makefile
4949
run-make/native-link-modifier-bundle/Makefile
50-
run-make/native-link-modifier-whole-archive/Makefile
5150
run-make/no-alloc-shim/Makefile
52-
run-make/no-builtins-attribute/Makefile
5351
run-make/no-duplicate-libs/Makefile
5452
run-make/panic-abort-eh_frame/Makefile
5553
run-make/pdb-buildinfo-cl-cmd/Makefile
@@ -68,7 +66,6 @@ run-make/redundant-libs/Makefile
6866
run-make/remap-path-prefix-dwarf/Makefile
6967
run-make/reproducible-build-2/Makefile
7068
run-make/reproducible-build/Makefile
71-
run-make/rlib-format-packed-bundled-libs-2/Makefile
7269
run-make/rlib-format-packed-bundled-libs/Makefile
7370
run-make/sanitizer-cdylib-link/Makefile
7471
run-make/sanitizer-dylib-link/Makefile

Diff for: tests/run-make/native-link-modifier-whole-archive/Makefile

-52
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
// This test case makes sure that native libraries are linked with appropriate semantics
2+
// when the `[+-]bundle,[+-]whole-archive` modifiers are applied to them.
3+
// The test works by checking that the resulting executables produce the expected output,
4+
// part of which is emitted by otherwise unreferenced C code. If +whole-archive didn't work
5+
// that code would never make it into the final executable and we'd thus be missing some
6+
// of the output.
7+
// See https://github.com/rust-lang/rust/issues/88085
8+
9+
//@ ignore-cross-compile
10+
// Reason: compiling C++ code does not work well when cross-compiling
11+
// plus, the compiled binary is executed
12+
13+
use run_make_support::{cxx, is_msvc, llvm_ar, run, run_with_args, rustc, static_lib_name};
14+
15+
fn main() {
16+
let mut cxx = cxx();
17+
if is_msvc() {
18+
cxx.arg("-EHs");
19+
}
20+
cxx.input("c_static_lib_with_constructor.cpp")
21+
.arg("-c")
22+
.out_exe("libc_static_lib_with_constructor")
23+
.run();
24+
25+
let mut llvm_ar = llvm_ar();
26+
llvm_ar.obj_to_ar();
27+
if is_msvc() {
28+
llvm_ar
29+
.output_input(
30+
static_lib_name("c_static_lib_with_constructor"),
31+
"libc_static_lib_with_constructor.obj",
32+
)
33+
.run();
34+
} else {
35+
llvm_ar
36+
.output_input(
37+
static_lib_name("c_static_lib_with_constructor"),
38+
"libc_static_lib_with_constructor",
39+
)
40+
.run();
41+
}
42+
43+
// Native lib linked directly into executable
44+
rustc()
45+
.input("directly_linked.rs")
46+
.arg("-lstatic:+whole-archive=c_static_lib_with_constructor")
47+
.run();
48+
49+
// Native lib linked into test executable, +whole-archive
50+
rustc()
51+
.input("directly_linked_test_plus_whole_archive.rs")
52+
.arg("--test")
53+
.arg("-lstatic:+whole-archive=c_static_lib_with_constructor")
54+
.run();
55+
56+
// Native lib linked into test executable, -whole-archive
57+
rustc()
58+
.input("directly_linked_test_minus_whole_archive.rs")
59+
.arg("--test")
60+
.arg("-lstatic:-whole-archive=c_static_lib_with_constructor")
61+
.run();
62+
63+
// Native lib linked into rlib with via commandline
64+
rustc()
65+
.input("rlib_with_cmdline_native_lib.rs")
66+
.crate_type("rlib")
67+
.arg("-lstatic:-bundle,+whole-archive=c_static_lib_with_constructor")
68+
.run();
69+
// Native lib linked into RLIB via `-l static:-bundle,+whole-archive`
70+
// RLIB linked into executable
71+
rustc().input("indirectly_linked.rs").run();
72+
73+
// Native lib linked into rlib via `#[link()]` attribute on extern block.
74+
rustc().input("native_lib_in_src.rs").crate_type("rlib").run();
75+
// Native lib linked into RLIB via #[link] attribute, RLIB linked into executable
76+
rustc().input("indirectly_linked_via_attr.rs").run();
77+
78+
run("directly_linked").assert_stdout_contains("static-initializer.directly_linked.");
79+
run_with_args("directly_linked_test_plus_whole_archive", &["--nocapture"])
80+
.assert_stdout_contains("static-initializer.");
81+
run_with_args("directly_linked_test_minus_whole_archive", &["--nocapture"])
82+
.assert_stdout_not_contains("static-initializer.");
83+
run("indirectly_linked").assert_stdout_contains("static-initializer.indirectly_linked.");
84+
run("indirectly_linked_via_attr")
85+
.assert_stdout_contains("static-initializer.native_lib_in_src.");
86+
}

Diff for: tests/run-make/no-builtins-attribute/Makefile

-9
This file was deleted.

Diff for: tests/run-make/no-builtins-attribute/rmake.rs

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// `no_builtins` is an attribute related to LLVM's optimizations. In order to ensure that it has an
2+
// effect on link-time optimizations (LTO), it should be added to function declarations in a crate.
3+
// This test uses the `llvm-filecheck` tool to determine that this attribute is successfully
4+
// being added to these function declarations.
5+
// See https://github.com/rust-lang/rust/pull/113716
6+
7+
use run_make_support::{llvm_filecheck, rfs, rustc};
8+
9+
fn main() {
10+
rustc().input("no_builtins.rs").emit("link").run();
11+
rustc().input("main.rs").emit("llvm-ir").run();
12+
llvm_filecheck().patterns("filecheck.main.txt").stdin(rfs::read("main.ll")).run();
13+
}

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

-27
This file was deleted.
+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
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+
// This test simply checks that this flag can be passed alongside verbatim syntax
4+
// in rustc flags without a compilation failure or the removal of expected symbols.
5+
// See https://github.com/rust-lang/rust/pull/100101
6+
7+
//FIXME(Oneirical): try it on test-various
8+
9+
use run_make_support::{llvm_ar, llvm_readobj, regex, rfs, rust_lib_name, rustc};
10+
11+
fn main() {
12+
// Build a strangely named dependency.
13+
rustc().input("native_dep.rs").crate_type("staticlib").output("native_dep.ext").run();
14+
15+
rustc().input("rust_dep.rs").crate_type("rlib").arg("-Zpacked_bundled_libs").run();
16+
let symbols = llvm_readobj().symbols().input(rust_lib_name("rust_dep")).run().stdout_utf8();
17+
let re = regex::Regex::new("U.*native_f1").unwrap();
18+
assert!(re.is_match(&symbols));
19+
llvm_ar()
20+
.arg("t")
21+
.arg(rust_lib_name("rust_dep"))
22+
.run()
23+
.assert_stdout_contains("native_dep.ext");
24+
25+
// Ensure the compiler does not use files it should not be aware of.
26+
rfs::remove_file("native_dep.ext");
27+
rustc()
28+
.input("main.rs")
29+
.extern_("rust_dep", rust_lib_name("rust_dep"))
30+
.arg("-Zpacked_bundled_libs")
31+
.run();
32+
}

0 commit comments

Comments
 (0)