From 7128267173e64c2a1e2bc7ed0cc79d1c0c1f1de0 Mon Sep 17 00:00:00 2001 From: Oneirical Date: Thu, 13 Jun 2024 16:36:35 -0400 Subject: [PATCH] rewrite no-builtins-lto to rmake --- src/tools/run-make-support/src/command.rs | 14 +++++++++++++ .../tidy/src/allowed_run_make_makefiles.txt | 1 - .../lto-avoid-object-duplication/rmake.rs | 1 + tests/run-make/no-builtins-lto/Makefile | 9 --------- tests/run-make/no-builtins-lto/rmake.rs | 20 +++++++++++++++++++ 5 files changed, 35 insertions(+), 10 deletions(-) delete mode 100644 tests/run-make/no-builtins-lto/Makefile create mode 100644 tests/run-make/no-builtins-lto/rmake.rs diff --git a/src/tools/run-make-support/src/command.rs b/src/tools/run-make-support/src/command.rs index 7cbc61bdf33e8..e6b84f38f5640 100644 --- a/src/tools/run-make-support/src/command.rs +++ b/src/tools/run-make-support/src/command.rs @@ -176,6 +176,20 @@ impl CompletedProcess { self } + pub fn assert_stdout_contains>(&self, expected: S) -> &Self { + let stdout = self.stdout_utf8(); + let stdout_trimmed = stdout.trim(); + let expected_trimmed = expected.as_ref().trim(); + if !self.stdout_utf8().contains(expected.as_ref()) { + eprintln!("=== STDOUT (ACTUAL) TRIMMED ==="); + eprintln!("{}", stdout_trimmed); + eprintln!("=== EXPECTED TRIMMED ==="); + eprintln!("{}", expected_trimmed); + panic!("trimmed stdout does not contain trimmed expected"); + } + self + } + /// Checks that trimmed `stderr` matches trimmed `content`. #[track_caller] pub fn assert_stderr_equals>(&self, content: S) -> &Self { diff --git a/src/tools/tidy/src/allowed_run_make_makefiles.txt b/src/tools/tidy/src/allowed_run_make_makefiles.txt index 3cb775d1c87c0..ff43cf2262c1e 100644 --- a/src/tools/tidy/src/allowed_run_make_makefiles.txt +++ b/src/tools/tidy/src/allowed_run_make_makefiles.txt @@ -148,7 +148,6 @@ run-make/native-link-modifier-verbatim-rustc/Makefile run-make/native-link-modifier-whole-archive/Makefile run-make/no-alloc-shim/Makefile run-make/no-builtins-attribute/Makefile -run-make/no-builtins-lto/Makefile run-make/no-duplicate-libs/Makefile run-make/obey-crate-type-flag/Makefile run-make/optimization-remarks-dir-pgo/Makefile diff --git a/tests/run-make/lto-avoid-object-duplication/rmake.rs b/tests/run-make/lto-avoid-object-duplication/rmake.rs index 018e6a25b9254..31704fd0b28be 100644 --- a/tests/run-make/lto-avoid-object-duplication/rmake.rs +++ b/tests/run-make/lto-avoid-object-duplication/rmake.rs @@ -1,3 +1,4 @@ +// ignore-tidy-tab // Staticlibs don't include Rust object files from upstream crates if the same // code was already pulled into the lib via LTO. However, the bug described in // https://github.com/rust-lang/rust/issues/64153 lead to this exclusion not diff --git a/tests/run-make/no-builtins-lto/Makefile b/tests/run-make/no-builtins-lto/Makefile deleted file mode 100644 index c8f05d9918b91..0000000000000 --- a/tests/run-make/no-builtins-lto/Makefile +++ /dev/null @@ -1,9 +0,0 @@ -include ../tools.mk - -all: - # Compile a `#![no_builtins]` rlib crate - $(RUSTC) no_builtins.rs - # Build an executable that depends on that crate using LTO. The no_builtins crate doesn't - # participate in LTO, so its rlib must be explicitly linked into the final binary. Verify this by - # grepping the linker arguments. - $(RUSTC) main.rs -C lto --print link-args | $(CGREP) 'libno_builtins.rlib' diff --git a/tests/run-make/no-builtins-lto/rmake.rs b/tests/run-make/no-builtins-lto/rmake.rs new file mode 100644 index 0000000000000..325233fc826f1 --- /dev/null +++ b/tests/run-make/no-builtins-lto/rmake.rs @@ -0,0 +1,20 @@ +// The rlib produced by a no_builtins crate should be explicitely linked +// during compilation, and as a result be present in the linker arguments. +// See the comments inside the test for more details. +// See https://github.com/rust-lang/rust/pull/35637 + +use run_make_support::{rust_lib_name, rustc}; + +fn main() { + // Compile a `#![no_builtins]` rlib crate + rustc().input("no_builtins.rs").run(); + // Build an executable that depends on that crate using LTO. The no_builtins crate doesn't + // participate in LTO, so its rlib must be explicitly + // linked into the final binary. Verify this by grepping the linker arguments. + rustc() + .input("main.rs") + .arg("-Clto") + .print("link-args") + .run() + .assert_stdout_contains(rust_lib_name("no_builtins")); +}