Skip to content

Commit 957bf04

Browse files
committed
Auto merge of #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 #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 47243b3 + 1a15d90 commit 957bf04

File tree

11 files changed

+224
-96
lines changed

11 files changed

+224
-96
lines changed

src/tools/run-make-support/src/assertion_helpers.rs

+31-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
use std::panic;
44
use std::path::Path;
55

6-
use crate::fs;
6+
use crate::{fs, regex};
77

88
/// Assert that `actual` is equal to `expected`.
99
#[track_caller]
@@ -47,6 +47,36 @@ pub fn assert_not_contains<H: AsRef<str>, N: AsRef<str>>(haystack: H, needle: N)
4747
}
4848
}
4949

50+
/// Assert that `haystack` contains the regex pattern `needle`.
51+
#[track_caller]
52+
pub fn assert_contains_regex<H: AsRef<str>, N: AsRef<str>>(haystack: H, needle: N) {
53+
let haystack = haystack.as_ref();
54+
let needle = needle.as_ref();
55+
let re = regex::Regex::new(needle).unwrap();
56+
if !re.is_match(haystack) {
57+
eprintln!("=== HAYSTACK ===");
58+
eprintln!("{}", haystack);
59+
eprintln!("=== NEEDLE ===");
60+
eprintln!("{}", needle);
61+
panic!("needle was not found in haystack");
62+
}
63+
}
64+
65+
/// Assert that `haystack` does not contain the regex pattern `needle`.
66+
#[track_caller]
67+
pub fn assert_not_contains_regex<H: AsRef<str>, N: AsRef<str>>(haystack: H, needle: N) {
68+
let haystack = haystack.as_ref();
69+
let needle = needle.as_ref();
70+
let re = regex::Regex::new(needle).unwrap();
71+
if re.is_match(haystack) {
72+
eprintln!("=== HAYSTACK ===");
73+
eprintln!("{}", haystack);
74+
eprintln!("=== NEEDLE ===");
75+
eprintln!("{}", needle);
76+
panic!("needle was unexpectedly found in haystack");
77+
}
78+
}
79+
5080
/// Assert that all files in `dir1` exist and have the same content in `dir2`
5181
pub fn assert_dirs_are_equal(dir1: impl AsRef<Path>, dir2: impl AsRef<Path>) {
5282
let dir2 = dir2.as_ref();

src/tools/run-make-support/src/command.rs

+32-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,10 @@ use std::path::Path;
66
use std::process::{Command as StdCommand, ExitStatus, Output, Stdio};
77

88
use crate::util::handle_failed_output;
9-
use crate::{assert_contains, assert_equals, assert_not_contains};
9+
use crate::{
10+
assert_contains, assert_contains_regex, assert_equals, assert_not_contains,
11+
assert_not_contains_regex,
12+
};
1013

1114
use build_helper::drop_bomb::DropBomb;
1215

@@ -192,13 +195,27 @@ impl CompletedProcess {
192195
self
193196
}
194197

198+
/// Checks that `stdout` does not contain the regex pattern `unexpected`.
199+
#[track_caller]
200+
pub fn assert_stdout_not_contains_regex<S: AsRef<str>>(&self, unexpected: S) -> &Self {
201+
assert_not_contains_regex(&self.stdout_utf8(), unexpected);
202+
self
203+
}
204+
195205
/// Checks that `stdout` contains `expected`.
196206
#[track_caller]
197207
pub fn assert_stdout_contains<S: AsRef<str>>(&self, expected: S) -> &Self {
198208
assert_contains(&self.stdout_utf8(), expected);
199209
self
200210
}
201211

212+
/// Checks that `stdout` contains the regex pattern `expected`.
213+
#[track_caller]
214+
pub fn assert_stdout_contains_regex<S: AsRef<str>>(&self, expected: S) -> &Self {
215+
assert_contains_regex(&self.stdout_utf8(), expected);
216+
self
217+
}
218+
202219
/// Checks that trimmed `stderr` matches trimmed `expected`.
203220
#[track_caller]
204221
pub fn assert_stderr_equals<S: AsRef<str>>(&self, expected: S) -> &Self {
@@ -213,13 +230,27 @@ impl CompletedProcess {
213230
self
214231
}
215232

233+
/// Checks that `stderr` contains the regex pattern `expected`.
234+
#[track_caller]
235+
pub fn assert_stderr_contains_regex<S: AsRef<str>>(&self, expected: S) -> &Self {
236+
assert_contains_regex(&self.stderr_utf8(), expected);
237+
self
238+
}
239+
216240
/// Checks that `stderr` does not contain `unexpected`.
217241
#[track_caller]
218242
pub fn assert_stderr_not_contains<S: AsRef<str>>(&self, unexpected: S) -> &Self {
219243
assert_not_contains(&self.stdout_utf8(), unexpected);
220244
self
221245
}
222246

247+
/// Checks that `stderr` does not contain the regex pattern `unexpected`.
248+
#[track_caller]
249+
pub fn assert_stderr_not_contains_regex<S: AsRef<str>>(&self, unexpected: S) -> &Self {
250+
assert_not_contains_regex(&self.stdout_utf8(), unexpected);
251+
self
252+
}
253+
223254
#[track_caller]
224255
pub fn assert_exit_code(&self, code: i32) -> &Self {
225256
assert!(self.output.status.code() == Some(code));

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

+30
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,12 @@ pub fn llvm_ar() -> LlvmAr {
3636
LlvmAr::new()
3737
}
3838

39+
/// Construct a new `llvm-nm` invocation. This assumes that `llvm-nm` is available
40+
/// at `$LLVM_BIN_DIR/llvm-nm`.
41+
pub fn llvm_nm() -> LlvmNm {
42+
LlvmNm::new()
43+
}
44+
3945
/// A `llvm-readobj` invocation builder.
4046
#[derive(Debug)]
4147
#[must_use]
@@ -71,11 +77,19 @@ pub struct LlvmAr {
7177
cmd: Command,
7278
}
7379

80+
/// A `llvm-nm` invocation builder.
81+
#[derive(Debug)]
82+
#[must_use]
83+
pub struct LlvmNm {
84+
cmd: Command,
85+
}
86+
7487
crate::macros::impl_common_helpers!(LlvmReadobj);
7588
crate::macros::impl_common_helpers!(LlvmProfdata);
7689
crate::macros::impl_common_helpers!(LlvmFilecheck);
7790
crate::macros::impl_common_helpers!(LlvmObjdump);
7891
crate::macros::impl_common_helpers!(LlvmAr);
92+
crate::macros::impl_common_helpers!(LlvmNm);
7993

8094
/// Generate the path to the bin directory of LLVM.
8195
#[must_use]
@@ -244,3 +258,19 @@ impl LlvmAr {
244258
self
245259
}
246260
}
261+
262+
impl LlvmNm {
263+
/// Construct a new `llvm-nm` invocation. This assumes that `llvm-nm` is available
264+
/// at `$LLVM_BIN_DIR/llvm-nm`.
265+
pub fn new() -> Self {
266+
let llvm_nm = llvm_bin_dir().join("llvm-nm");
267+
let cmd = Command::new(llvm_nm);
268+
Self { cmd }
269+
}
270+
271+
/// Provide an input file.
272+
pub fn input<P: AsRef<Path>>(&mut self, path: P) -> &mut Self {
273+
self.cmd.arg(path.as_ref());
274+
self
275+
}
276+
}

src/tools/run-make-support/src/lib.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,8 @@ 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::{
51-
llvm_ar, llvm_filecheck, llvm_objdump, llvm_profdata, llvm_readobj, LlvmAr, LlvmFilecheck,
52-
LlvmObjdump, LlvmProfdata, LlvmReadobj,
51+
llvm_ar, llvm_filecheck, llvm_nm, llvm_objdump, llvm_profdata, llvm_readobj, LlvmAr,
52+
LlvmFilecheck, LlvmNm, LlvmObjdump, LlvmProfdata, LlvmReadobj,
5353
};
5454
pub use python::python_command;
5555
pub use rustc::{aux_build, bare_rustc, rustc, Rustc};
@@ -84,7 +84,8 @@ pub use path_helpers::{
8484
pub use scoped_run::{run_in_tmpdir, test_while_readonly};
8585

8686
pub use assertion_helpers::{
87-
assert_contains, assert_dirs_are_equal, assert_equals, assert_not_contains,
87+
assert_contains, assert_contains_regex, assert_dirs_are_equal, assert_equals,
88+
assert_not_contains, assert_not_contains_regex,
8889
};
8990

9091
pub use string::{

src/tools/tidy/src/allowed_run_make_makefiles.txt

-3
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,7 @@ run-make/long-linker-command-lines/Makefile
3131
run-make/macos-deployment-target/Makefile
3232
run-make/min-global-align/Makefile
3333
run-make/native-link-modifier-bundle/Makefile
34-
run-make/native-link-modifier-whole-archive/Makefile
3534
run-make/no-alloc-shim/Makefile
36-
run-make/no-builtins-attribute/Makefile
3735
run-make/pdb-buildinfo-cl-cmd/Makefile
3836
run-make/pgo-gen-lto/Makefile
3937
run-make/pgo-indirect-call-promotion/Makefile
@@ -48,7 +46,6 @@ run-make/redundant-libs/Makefile
4846
run-make/remap-path-prefix-dwarf/Makefile
4947
run-make/reproducible-build-2/Makefile
5048
run-make/reproducible-build/Makefile
51-
run-make/rlib-format-packed-bundled-libs-2/Makefile
5249
run-make/rlib-format-packed-bundled-libs/Makefile
5350
run-make/sanitizer-cdylib-link/Makefile
5451
run-make/sanitizer-dylib-link/Makefile

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+
}

tests/run-make/no-builtins-attribute/Makefile

-9
This file was deleted.
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+
}

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

-27
This file was deleted.

0 commit comments

Comments
 (0)