From d2268902f7db32c03520f160f2d0e750d4d8d0b1 Mon Sep 17 00:00:00 2001 From: Oneirical Date: Tue, 11 Jun 2024 11:37:51 -0400 Subject: [PATCH 01/17] rewrite and rename issue-10971-temps-dir to rmake format --- .../tidy/src/allowed_run_make_makefiles.txt | 1 - tests/run-make/issue-10971-temps-dir/Makefile | 10 --------- .../parallel-rustc-no-overwrite/rmake.rs | 22 +++++++++++++++++++ 3 files changed, 22 insertions(+), 11 deletions(-) delete mode 100644 tests/run-make/issue-10971-temps-dir/Makefile create mode 100644 tests/run-make/parallel-rustc-no-overwrite/rmake.rs diff --git a/src/tools/tidy/src/allowed_run_make_makefiles.txt b/src/tools/tidy/src/allowed_run_make_makefiles.txt index ac89a30f3534..59c836862c5d 100644 --- a/src/tools/tidy/src/allowed_run_make_makefiles.txt +++ b/src/tools/tidy/src/allowed_run_make_makefiles.txt @@ -79,7 +79,6 @@ run-make/invalid-library/Makefile run-make/invalid-so/Makefile run-make/invalid-staticlib/Makefile run-make/issue-107094/Makefile -run-make/issue-10971-temps-dir/Makefile run-make/issue-109934-lto-debuginfo/Makefile run-make/issue-14698/Makefile run-make/issue-15460/Makefile diff --git a/tests/run-make/issue-10971-temps-dir/Makefile b/tests/run-make/issue-10971-temps-dir/Makefile deleted file mode 100644 index 6e1649a58d23..000000000000 --- a/tests/run-make/issue-10971-temps-dir/Makefile +++ /dev/null @@ -1,10 +0,0 @@ -include ../tools.mk - -# Regression test for issue #10971 -# Running two invocations in parallel would overwrite each other's temp files. - -all: - touch $(TMPDIR)/lib.rs - - $(RUSTC) --crate-type=lib -Z temps-dir=$(TMPDIR)/temp1 $(TMPDIR)/lib.rs & \ - $(RUSTC) --crate-type=staticlib -Z temps-dir=$(TMPDIR)/temp2 $(TMPDIR)/lib.rs diff --git a/tests/run-make/parallel-rustc-no-overwrite/rmake.rs b/tests/run-make/parallel-rustc-no-overwrite/rmake.rs new file mode 100644 index 000000000000..d45eb4f29116 --- /dev/null +++ b/tests/run-make/parallel-rustc-no-overwrite/rmake.rs @@ -0,0 +1,22 @@ +// When two instances of rustc are invoked in parallel, they +// can conflict on their temporary files and overwrite each others', +// leading to unsuccessful compilation. The -Z temps-dir flag adds +// separate designated directories for each rustc invocation, preventing +// conflicts. This test uses this flag and checks for successful compilation. +// See https://github.com/rust-lang/rust/pull/83846 + +use run_make_support::{fs_wrapper, rustc}; +use std::thread; + +fn main() { + fs_wrapper::create_file("lib.rs"); + let handle1 = thread::spawn(move || { + rustc().crate_type("lib").arg("-Ztemps-dir=temp1").input("lib.rs"); + }); + + let handle2 = thread::spawn(move || { + rustc().crate_type("staticlib").arg("-Ztemps-dir=temp2").input("lib.rs"); + }); + handle1.join().expect("lib thread panicked"); + handle2.join().expect("staticlib thread panicked"); +} From 03982dae0173f7358dd779aa2a92dd0a2ab0fe59 Mon Sep 17 00:00:00 2001 From: Oneirical Date: Tue, 11 Jun 2024 11:57:07 -0400 Subject: [PATCH 02/17] rewrite inaccessible-temp-dir to rmake format --- .../tidy/src/allowed_run_make_makefiles.txt | 1 - tests/run-make/inaccessible-temp-dir/Makefile | 32 -------------- tests/run-make/inaccessible-temp-dir/rmake.rs | 44 +++++++++++++++++++ 3 files changed, 44 insertions(+), 33 deletions(-) delete mode 100644 tests/run-make/inaccessible-temp-dir/Makefile create mode 100644 tests/run-make/inaccessible-temp-dir/rmake.rs diff --git a/src/tools/tidy/src/allowed_run_make_makefiles.txt b/src/tools/tidy/src/allowed_run_make_makefiles.txt index 59c836862c5d..dd6e64057b44 100644 --- a/src/tools/tidy/src/allowed_run_make_makefiles.txt +++ b/src/tools/tidy/src/allowed_run_make_makefiles.txt @@ -66,7 +66,6 @@ run-make/foreign-double-unwind/Makefile run-make/foreign-exceptions/Makefile run-make/foreign-rust-exceptions/Makefile run-make/glibc-staticlib-args/Makefile -run-make/inaccessible-temp-dir/Makefile run-make/include_bytes_deps/Makefile run-make/incr-add-rust-src-component/Makefile run-make/incr-foreign-head-span/Makefile diff --git a/tests/run-make/inaccessible-temp-dir/Makefile b/tests/run-make/inaccessible-temp-dir/Makefile deleted file mode 100644 index abdba4eb8614..000000000000 --- a/tests/run-make/inaccessible-temp-dir/Makefile +++ /dev/null @@ -1,32 +0,0 @@ -# only-linux -# ignore-arm - linker error on `armhf-gnu` - -include ../tools.mk - -# Issue #66530: We would ICE if someone compiled with `-o /dev/null`, -# because we would try to generate auxiliary files in `/dev/` (which -# at least the OS X file system rejects). -# -# An attempt to `-Ztemps-dir` into a directory we cannot write into should -# indeed be an error; but not an ICE. -# -# However, some folks run tests as root, which can write `/dev/` and end -# up clobbering `/dev/null`. Instead we'll use an inaccessible path, which -# also used to ICE, but even root can't magically write there. -# -# Note that `-Ztemps-dir` uses `create_dir_all` so it is not sufficient to -# use a directory with non-existing parent like `/does-not-exist/output`. - -all: - # Create an inaccessible directory - mkdir $(TMPDIR)/inaccessible - chmod 000 $(TMPDIR)/inaccessible - - # Run rustc with `-Ztemps-dir` set to a directory - # *inside* the inaccessible one, so that it can't create it - $(RUSTC) program.rs -Ztemps-dir=$(TMPDIR)/inaccessible/tmp 2>&1 \ - | $(CGREP) 'failed to find or create the directory specified by `--temps-dir`' - - # Make the inaccessible directory accessible, - # so that compiletest can delete the temp dir - chmod +rw $(TMPDIR)/inaccessible diff --git a/tests/run-make/inaccessible-temp-dir/rmake.rs b/tests/run-make/inaccessible-temp-dir/rmake.rs new file mode 100644 index 000000000000..25c9d363820d --- /dev/null +++ b/tests/run-make/inaccessible-temp-dir/rmake.rs @@ -0,0 +1,44 @@ +// Issue #66530: We would ICE if someone compiled with `-o /dev/null`, +// because we would try to generate auxiliary files in `/dev/` (which +// at least the OS X file system rejects). +// +// An attempt to `-Ztemps-dir` into a directory we cannot write into should +// indeed be an error; but not an ICE. +// +// However, some folks run tests as root, which can write `/dev/` and end +// up clobbering `/dev/null`. Instead we'll use an inaccessible path, which +// also used to ICE, but even root can't magically write there. +// +// Note that `-Ztemps-dir` uses `create_dir_all` so it is not sufficient to +// use a directory with non-existing parent like `/does-not-exist/output`. +// See https://github.com/rust-lang/rust/issues/66530 + +//@ only-linux +// Reason: set_mode is only available on Unix + +//@ ignore-arm +// Reason: linker error on `armhf-gnu` + +use run_make_support::{fs_wrapper, rustc}; + +fn main() { + // Create an inaccessible directory. + fs_wrapper::create_dir("inaccessible"); + let meta = fs_wrapper::metadata("inaccessible"); + let mut perms = meta.permissions(); + perms.set_mode(0o000); // Lock down the directory. + fs_wrapper::set_permissions("inaccessible", perms); + + // Run rustc with `-Z temps-dir` set to a directory *inside* the inaccessible one, + // so that it can't create `tmp`. + rustc() + .input("program.rs") + .arg("-Ztemps-dir=inaccessible/tmp") + .run_fail() + .assert_stderr_contains( + "failed to find or create the directory specified by `--temps-dir`", + ); + + perms.set_mode(0o666); // Unlock the directory, so that compiletest can delete it. + fs_wrapper::set_permissions("inaccessible", perms); +} From 7c2b3b5615cf5e8545c13f7635257cc3fb0eb7bf Mon Sep 17 00:00:00 2001 From: Oneirical Date: Tue, 11 Jun 2024 12:53:33 -0400 Subject: [PATCH 03/17] rewrite output-with-hyphens to rmake format --- .../tidy/src/allowed_run_make_makefiles.txt | 1 - tests/run-make/output-with-hyphens/Makefile | 8 ------- tests/run-make/output-with-hyphens/rmake.rs | 17 ++++++++++++++ .../parallel-rustc-no-overwrite/rmake.rs | 22 ++++++++++--------- 4 files changed, 29 insertions(+), 19 deletions(-) delete mode 100644 tests/run-make/output-with-hyphens/Makefile create mode 100644 tests/run-make/output-with-hyphens/rmake.rs diff --git a/src/tools/tidy/src/allowed_run_make_makefiles.txt b/src/tools/tidy/src/allowed_run_make_makefiles.txt index dd6e64057b44..0d7951bcfffc 100644 --- a/src/tools/tidy/src/allowed_run_make_makefiles.txt +++ b/src/tools/tidy/src/allowed_run_make_makefiles.txt @@ -156,7 +156,6 @@ run-make/optimization-remarks-dir/Makefile run-make/output-filename-conflicts-with-directory/Makefile run-make/output-filename-overwrites-input/Makefile run-make/output-type-permutations/Makefile -run-make/output-with-hyphens/Makefile run-make/override-aliased-flags/Makefile run-make/overwrite-input/Makefile run-make/panic-abort-eh_frame/Makefile diff --git a/tests/run-make/output-with-hyphens/Makefile b/tests/run-make/output-with-hyphens/Makefile deleted file mode 100644 index 846c9a66a89a..000000000000 --- a/tests/run-make/output-with-hyphens/Makefile +++ /dev/null @@ -1,8 +0,0 @@ -# ignore-cross-compile -include ../tools.mk - -all: - $(RUSTC) foo-bar.rs --crate-type bin - [ -f $(TMPDIR)/$(call BIN,foo-bar) ] - $(RUSTC) foo-bar.rs --crate-type lib - [ -f $(TMPDIR)/libfoo_bar.rlib ] diff --git a/tests/run-make/output-with-hyphens/rmake.rs b/tests/run-make/output-with-hyphens/rmake.rs new file mode 100644 index 000000000000..21c003c628b9 --- /dev/null +++ b/tests/run-make/output-with-hyphens/rmake.rs @@ -0,0 +1,17 @@ +// Rust files with hyphens in their filename should +// not result in compiled libraries keeping that hyphen - +// it should become an underscore. Only bin executables +// should keep the hyphen. This test ensures that this rule +// remains enforced. +// See https://github.com/rust-lang/rust/pull/23786 + +//@ ignore-cross-compile + +use run_make_support::{path, rustc}; + +fn main() { + rustc().input("foo-bar.rs").crate_type("bin").run(); + assert!(path(bin_name("foo-bar")).exists()); + rustc().input("foo-bar.rs").crate_type("lib").run(); + assert!(path(bin_name("libfoo_bar.rlib")).exists()); +} diff --git a/tests/run-make/parallel-rustc-no-overwrite/rmake.rs b/tests/run-make/parallel-rustc-no-overwrite/rmake.rs index d45eb4f29116..40c6ab7ed5eb 100644 --- a/tests/run-make/parallel-rustc-no-overwrite/rmake.rs +++ b/tests/run-make/parallel-rustc-no-overwrite/rmake.rs @@ -6,17 +6,19 @@ // See https://github.com/rust-lang/rust/pull/83846 use run_make_support::{fs_wrapper, rustc}; +use std::sync::{Arc, Barrier}; use std::thread; fn main() { - fs_wrapper::create_file("lib.rs"); - let handle1 = thread::spawn(move || { - rustc().crate_type("lib").arg("-Ztemps-dir=temp1").input("lib.rs"); - }); - - let handle2 = thread::spawn(move || { - rustc().crate_type("staticlib").arg("-Ztemps-dir=temp2").input("lib.rs"); - }); - handle1.join().expect("lib thread panicked"); - handle2.join().expect("staticlib thread panicked"); + let barrier = Arc::new(Barrier::new(2)); + let handle = { + let barrier = Arc::clone(&barrier); + thread::spawn(move || { + barrier.wait(); + rustc().crate_type("lib").arg("-Ztemps-dir=temp1").input("lib.rs"); + }) + }; + barrier.wait(); + rustc().crate_type("staticlib").arg("-Ztemps-dir=temp2").input("lib.rs"); + handle.join().expect("lib thread panicked"); } From ff82e43ca3dfc91e85c15070f836ca9cd692a476 Mon Sep 17 00:00:00 2001 From: Oneirical Date: Thu, 13 Jun 2024 16:10:49 -0400 Subject: [PATCH 04/17] rewrite and rename issue-64153 to rmake.rs --- src/tools/run-make-support/src/lib.rs | 3 +- src/tools/run-make-support/src/llvm.rs | 30 +++++++++++++ .../run-make-support/src/llvm_readobj.rs | 45 ------------------- tests/run-make/issue-64153/Makefile | 26 ----------- .../downstream.rs | 0 .../lto-avoid-object-duplication/rmake.rs | 37 +++++++++++++++ .../upstream.rs | 0 7 files changed, 69 insertions(+), 72 deletions(-) delete mode 100644 src/tools/run-make-support/src/llvm_readobj.rs delete mode 100644 tests/run-make/issue-64153/Makefile rename tests/run-make/{issue-64153 => lto-avoid-object-duplication}/downstream.rs (100%) create mode 100644 tests/run-make/lto-avoid-object-duplication/rmake.rs rename tests/run-make/{issue-64153 => lto-avoid-object-duplication}/upstream.rs (100%) diff --git a/src/tools/run-make-support/src/lib.rs b/src/tools/run-make-support/src/lib.rs index ba4524c150c4..2397fa767d8e 100644 --- a/src/tools/run-make-support/src/lib.rs +++ b/src/tools/run-make-support/src/lib.rs @@ -30,7 +30,8 @@ pub use cc::{cc, extra_c_flags, extra_cxx_flags, Cc}; pub use clang::{clang, Clang}; pub use diff::{diff, Diff}; pub use llvm::{ - llvm_filecheck, llvm_profdata, llvm_readobj, LlvmFilecheck, LlvmProfdata, LlvmReadobj, + llvm_filecheck, llvm_objdump, llvm_profdata, llvm_readobj, LlvmFilecheck, LlvmObjdump, + LlvmProfdata, LlvmReadobj, }; pub use run::{cmd, run, run_fail, run_with_args}; pub use rustc::{aux_build, rustc, Rustc}; diff --git a/src/tools/run-make-support/src/llvm.rs b/src/tools/run-make-support/src/llvm.rs index 414251abda29..d9eb25eec84a 100644 --- a/src/tools/run-make-support/src/llvm.rs +++ b/src/tools/run-make-support/src/llvm.rs @@ -20,6 +20,12 @@ pub fn llvm_filecheck() -> LlvmFilecheck { LlvmFilecheck::new() } +/// Construct a new `llvm-objdump` invocation. This assumes that `llvm-objdump` is available +/// at `$LLVM_BIN_DIR/llvm-objdump`. +pub fn llvm_objdump() -> LlvmObjdump { + LlvmObjdump::new() +} + /// A `llvm-readobj` invocation builder. #[derive(Debug)] #[must_use] @@ -41,9 +47,17 @@ pub struct LlvmFilecheck { cmd: Command, } +/// A `llvm-objdump` invocation builder. +#[derive(Debug)] +#[must_use] +pub struct LlvmObjdump { + cmd: Command, +} + crate::impl_common_helpers!(LlvmReadobj); crate::impl_common_helpers!(LlvmProfdata); crate::impl_common_helpers!(LlvmFilecheck); +crate::impl_common_helpers!(LlvmObjdump); /// Generate the path to the bin directory of LLVM. #[must_use] @@ -125,3 +139,19 @@ impl LlvmFilecheck { self } } + +impl LlvmObjdump { + /// Construct a new `llvm-objdump` invocation. This assumes that `llvm-objdump` is available + /// at `$LLVM_BIN_DIR/llvm-objdump`. + pub fn new() -> Self { + let llvm_objdump = llvm_bin_dir().join("llvm-objdump"); + let cmd = Command::new(llvm_objdump); + Self { cmd } + } + + /// Provide an input file. + pub fn input>(&mut self, path: P) -> &mut Self { + self.cmd.arg(path.as_ref()); + self + } +} diff --git a/src/tools/run-make-support/src/llvm_readobj.rs b/src/tools/run-make-support/src/llvm_readobj.rs deleted file mode 100644 index 3c719356e8f3..000000000000 --- a/src/tools/run-make-support/src/llvm_readobj.rs +++ /dev/null @@ -1,45 +0,0 @@ -use std::path::{Path, PathBuf}; - -use crate::command::Command; -use crate::env_var; - -/// Construct a new `llvm-readobj` invocation. This assumes that `llvm-readobj` is available -/// at `$LLVM_BIN_DIR/llvm-readobj`. -#[track_caller] -pub fn llvm_readobj() -> LlvmReadobj { - LlvmReadobj::new() -} - -/// A `llvm-readobj` invocation builder. -#[derive(Debug)] -#[must_use] -pub struct LlvmReadobj { - cmd: Command, -} - -crate::impl_common_helpers!(LlvmReadobj); - -impl LlvmReadobj { - /// Construct a new `llvm-readobj` invocation. This assumes that `llvm-readobj` is available - /// at `$LLVM_BIN_DIR/llvm-readobj`. - #[track_caller] - pub fn new() -> Self { - let llvm_bin_dir = env_var("LLVM_BIN_DIR"); - let llvm_bin_dir = PathBuf::from(llvm_bin_dir); - let llvm_readobj = llvm_bin_dir.join("llvm-readobj"); - let cmd = Command::new(llvm_readobj); - Self { cmd } - } - - /// Provide an input file. - pub fn input>(&mut self, path: P) -> &mut Self { - self.cmd.arg(path.as_ref()); - self - } - - /// Pass `--file-header` to display file headers. - pub fn file_header(&mut self) -> &mut Self { - self.cmd.arg("--file-header"); - self - } -} diff --git a/tests/run-make/issue-64153/Makefile b/tests/run-make/issue-64153/Makefile deleted file mode 100644 index f42ea620fb9d..000000000000 --- a/tests/run-make/issue-64153/Makefile +++ /dev/null @@ -1,26 +0,0 @@ -include ../tools.mk - -# `llvm-objdump`'s output looks different on windows than on other platforms. -# It should be enough to check on Unix platforms, so: -# ignore-windows - -# 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 -# working properly if the upstream crate was compiled with an explicit filename -# (via `-o`). -# -# This test makes sure that functions defined in the upstream crates do not -# appear twice in the final staticlib when listing all the symbols from it. - -all: - $(RUSTC) --crate-type rlib upstream.rs -o $(TMPDIR)/libupstream.rlib -Ccodegen-units=1 - $(RUSTC) --crate-type staticlib downstream.rs -Clto -Ccodegen-units=1 -o $(TMPDIR)/libdownstream.a - # Dump all the symbols from the staticlib into `syms` - "$(LLVM_BIN_DIR)"/llvm-objdump -t $(TMPDIR)/libdownstream.a > $(TMPDIR)/syms - # Count the global instances of `issue64153_test_function`. There'll be 2 - # if the `upstream` object file got erroneously included twice. - # The line we are testing for with the regex looks something like: - # 0000000000000000 g F .text.issue64153_test_function 00000023 issue64153_test_function - grep -c -e "[[:space:]]g[[:space:]]*F[[:space:]].*issue64153_test_function" $(TMPDIR)/syms > $(TMPDIR)/count - [ "$$(cat $(TMPDIR)/count)" -eq "1" ] diff --git a/tests/run-make/issue-64153/downstream.rs b/tests/run-make/lto-avoid-object-duplication/downstream.rs similarity index 100% rename from tests/run-make/issue-64153/downstream.rs rename to tests/run-make/lto-avoid-object-duplication/downstream.rs diff --git a/tests/run-make/lto-avoid-object-duplication/rmake.rs b/tests/run-make/lto-avoid-object-duplication/rmake.rs new file mode 100644 index 000000000000..018e6a25b925 --- /dev/null +++ b/tests/run-make/lto-avoid-object-duplication/rmake.rs @@ -0,0 +1,37 @@ +// 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 +// working properly if the upstream crate was compiled with an explicit filename +// (via `-o`). + +// This test makes sure that functions defined in the upstream crates do not +// appear twice in the final staticlib when listing all the symbols from it. + +//@ ignore-windows +// Reason: `llvm-objdump`'s output looks different on windows than on other platforms. +// Only checking on Unix platforms should suffice. + +use run_make_support::{llvm_objdump, regex, rust_lib_name, rustc, static_lib_name}; + +fn main() { + rustc() + .crate_type("rlib") + .input("upstream.rs") + .output(rust_lib_name("upstream")) + .codegen_units(1) + .run(); + rustc() + .crate_type("staticlib") + .input("downstream.rs") + .arg("-Clto") + .output(static_lib_name("downstream")) + .codegen_units(1) + .run(); + let syms = llvm_objdump().arg("-t").input(static_lib_name("downstream")).run().stdout_utf8(); + let re = regex::Regex::new(r#"(?m)\s*g\s*F\s.*issue64153_test_function"#).unwrap(); + // Count the global instances of `issue64153_test_function`. There'll be 2 + // if the `upstream` object file got erroneously included twice. + // The line we are testing for with the regex looks something like: + // 0000000000000000 g F .text.issue64153_test_function 00000023 issue64153_test_function + assert_eq!(re.find_iter(syms.as_str()).count(), 1); +} diff --git a/tests/run-make/issue-64153/upstream.rs b/tests/run-make/lto-avoid-object-duplication/upstream.rs similarity index 100% rename from tests/run-make/issue-64153/upstream.rs rename to tests/run-make/lto-avoid-object-duplication/upstream.rs From cabc9822537a7ded20a64092917bf81d3f994c71 Mon Sep 17 00:00:00 2001 From: Oneirical Date: Thu, 13 Jun 2024 16:19:59 -0400 Subject: [PATCH 05/17] rewrite invalid-staticlib to rmake --- .../tidy/src/allowed_run_make_makefiles.txt | 2 -- tests/run-make/invalid-staticlib/Makefile | 5 ----- tests/run-make/invalid-staticlib/rmake.rs | 17 +++++++++++++++++ 3 files changed, 17 insertions(+), 7 deletions(-) delete mode 100644 tests/run-make/invalid-staticlib/Makefile create mode 100644 tests/run-make/invalid-staticlib/rmake.rs diff --git a/src/tools/tidy/src/allowed_run_make_makefiles.txt b/src/tools/tidy/src/allowed_run_make_makefiles.txt index be9df226d64e..a4ca3151baa5 100644 --- a/src/tools/tidy/src/allowed_run_make_makefiles.txt +++ b/src/tools/tidy/src/allowed_run_make_makefiles.txt @@ -75,7 +75,6 @@ run-make/interdependent-c-libraries/Makefile run-make/intrinsic-unreachable/Makefile run-make/invalid-library/Makefile run-make/invalid-so/Makefile -run-make/invalid-staticlib/Makefile run-make/issue-107094/Makefile run-make/issue-10971-temps-dir/Makefile run-make/issue-109934-lto-debuginfo/Makefile @@ -96,7 +95,6 @@ run-make/issue-40535/Makefile run-make/issue-47384/Makefile run-make/issue-47551/Makefile run-make/issue-51671/Makefile -run-make/issue-64153/Makefile run-make/issue-68794-textrel-on-minimal-lib/Makefile run-make/issue-69368/Makefile run-make/issue-83045/Makefile diff --git a/tests/run-make/invalid-staticlib/Makefile b/tests/run-make/invalid-staticlib/Makefile deleted file mode 100644 index 3f0f74ce3cb0..000000000000 --- a/tests/run-make/invalid-staticlib/Makefile +++ /dev/null @@ -1,5 +0,0 @@ -include ../tools.mk - -all: - touch $(TMPDIR)/libfoo.a - echo | $(RUSTC) - --crate-type=rlib -lstatic=foo 2>&1 | $(CGREP) "failed to add native library" diff --git a/tests/run-make/invalid-staticlib/rmake.rs b/tests/run-make/invalid-staticlib/rmake.rs new file mode 100644 index 000000000000..451292932477 --- /dev/null +++ b/tests/run-make/invalid-staticlib/rmake.rs @@ -0,0 +1,17 @@ +// If the static library provided is not valid (in this test, +// created as an empty file), +// rustc should print a normal error message and not throw +// an internal compiler error (ICE). +// See https://github.com/rust-lang/rust/pull/28673 + +use run_make_support::{fs_wrapper, rustc, static_lib_name}; + +fn main() { + fs_wrapper::create_file(static_lib_name("foo")); + rustc() + .arg("-") + .crate_type("rlib") + .arg("-lstatic=foo") + .run_fail() + .assert_stderr_contains("failed to add native library"); +} From a3b7c2993ed969e4abb3ad196c7abe3e05d88a93 Mon Sep 17 00:00:00 2001 From: Oneirical Date: Fri, 14 Jun 2024 13:42:42 -0400 Subject: [PATCH 06/17] rewrite extern-flag-fun to rmake --- .../tidy/src/allowed_run_make_makefiles.txt | 1 - tests/run-make/extern-flag-fun/Makefile | 20 ----------- tests/run-make/extern-flag-fun/rmake.rs | 36 +++++++++++++++++++ 3 files changed, 36 insertions(+), 21 deletions(-) delete mode 100644 tests/run-make/extern-flag-fun/Makefile create mode 100644 tests/run-make/extern-flag-fun/rmake.rs diff --git a/src/tools/tidy/src/allowed_run_make_makefiles.txt b/src/tools/tidy/src/allowed_run_make_makefiles.txt index be9df226d64e..ec184c2c2146 100644 --- a/src/tools/tidy/src/allowed_run_make_makefiles.txt +++ b/src/tools/tidy/src/allowed_run_make_makefiles.txt @@ -43,7 +43,6 @@ run-make/error-writing-dependencies/Makefile run-make/export-executable-symbols/Makefile run-make/extern-diff-internal-name/Makefile run-make/extern-flag-disambiguates/Makefile -run-make/extern-flag-fun/Makefile run-make/extern-flag-pathless/Makefile run-make/extern-flag-rename-transitive/Makefile run-make/extern-fn-explicit-align/Makefile diff --git a/tests/run-make/extern-flag-fun/Makefile b/tests/run-make/extern-flag-fun/Makefile deleted file mode 100644 index 687cdfd76755..000000000000 --- a/tests/run-make/extern-flag-fun/Makefile +++ /dev/null @@ -1,20 +0,0 @@ -# ignore-cross-compile -include ../tools.mk - -all: - $(RUSTC) bar.rs --crate-type=rlib - $(RUSTC) bar.rs --crate-type=rlib -C extra-filename=-a - $(RUSTC) bar-alt.rs --crate-type=rlib - $(RUSTC) foo.rs --extern bar=no-exist && exit 1 || exit 0 - $(RUSTC) foo.rs --extern bar=foo.rs && exit 1 || exit 0 - $(RUSTC) foo.rs \ - --extern bar=$(TMPDIR)/libbar.rlib \ - --extern bar=$(TMPDIR)/libbar-alt.rlib \ - && exit 1 || exit 0 - $(RUSTC) foo.rs \ - --extern bar=$(TMPDIR)/libbar.rlib \ - --extern bar=$(TMPDIR)/libbar-a.rlib - $(RUSTC) foo.rs --extern bar=$(TMPDIR)/libbar.rlib - # Try to be sneaky and load a private crate from with a non-private name. - $(RUSTC) rustc.rs -Zforce-unstable-if-unmarked --crate-type=rlib - $(RUSTC) gated_unstable.rs --extern alloc=$(TMPDIR)/librustc.rlib 2>&1 | $(CGREP) 'rustc_private' diff --git a/tests/run-make/extern-flag-fun/rmake.rs b/tests/run-make/extern-flag-fun/rmake.rs new file mode 100644 index 000000000000..10fec6e30b42 --- /dev/null +++ b/tests/run-make/extern-flag-fun/rmake.rs @@ -0,0 +1,36 @@ +// The --extern flag can override the default crate search of +// the compiler and directly fetch a given path. There are a few rules +// to follow: for example, there can't be more than one rlib, the crates must +// be valid ("no-exist" in this test), and private crates can't be loaded +// as non-private. This test checks that these rules are enforced. +// See https://github.com/rust-lang/rust/pull/15319 + +//@ ignore-cross-compile + +use run_make_support::{rust_lib_name, rustc}; + +fn main() { + rustc().input("bar.rs").crate_type("rlib").run(); + rustc().input("bar.rs").crate_type("rlib").extra_filename("-a").run(); + rustc().input("bar-alt.rs").crate_type("rlib").run(); + rustc().input("foo.rs").extern_("bar", "no-exist").run_fail(); + rustc().input("foo.rs").extern_("bar", "foo.rs").run_fail(); + rustc() + .input("foo.rs") + .extern_("bar", rust_lib_name("bar")) + .extern_("bar", rust_lib_name("bar-alt")) + .run_fail(); + rustc() + .input("foo.rs") + .extern_("bar", rust_lib_name("bar")) + .extern_("bar", rust_lib_name("bar-a")) + .run(); + rustc().input("foo.rs").extern_("bar", rust_lib_name("bar")).run(); + // Try to be sneaky and load a private crate from with a non-private name. + rustc().input("rustc.rs").arg("-Zforce-unstable-if-unmarked").crate_type("rlib").run(); + rustc() + .input("gated_unstable.rs") + .extern_("alloc", rust_lib_name("rustc")) + .run_fail() + .assert_stderr_contains("rustc_private"); +} From ab715107042fc547501713e0601268fd1f953ce1 Mon Sep 17 00:00:00 2001 From: Oneirical Date: Fri, 14 Jun 2024 15:10:34 -0400 Subject: [PATCH 07/17] rewrite incremental-debugger-visualiser to rmake --- src/tools/run-make-support/src/lib.rs | 22 +++++++ .../tidy/src/allowed_run_make_makefiles.txt | 1 - .../incremental-debugger-visualizer/Makefile | 49 --------------- .../incremental-debugger-visualizer/rmake.rs | 61 +++++++++++++++++++ 4 files changed, 83 insertions(+), 50 deletions(-) delete mode 100644 tests/run-make/incremental-debugger-visualizer/Makefile create mode 100644 tests/run-make/incremental-debugger-visualizer/rmake.rs diff --git a/src/tools/run-make-support/src/lib.rs b/src/tools/run-make-support/src/lib.rs index ba4524c150c4..784bbe572ab3 100644 --- a/src/tools/run-make-support/src/lib.rs +++ b/src/tools/run-make-support/src/lib.rs @@ -271,6 +271,28 @@ pub fn set_host_rpath(cmd: &mut Command) { }); } +/// Read the contents of a file that cannot simply be read by +/// read_to_string, due to invalid utf8 data, then assert that it contains `expected`. +#[track_caller] +pub fn invalid_utf8_contains_str>(path: P, expected: &str) { + use std::io::Read; + let mut file = std::fs::File::open(path).unwrap(); + let mut buffer = Vec::new(); + file.read_to_end(&mut buffer).unwrap(); + assert!(String::from_utf8_lossy(&buffer).contains(expected)); +} + +/// Read the contents of a file that cannot simply be read by +/// read_to_string, due to invalid utf8 data, then assert that it does not contain `expected`. +#[track_caller] +pub fn invalid_utf8_not_contains_str>(path: P, expected: &str) { + use std::io::Read; + let mut file = std::fs::File::open(path).unwrap(); + let mut buffer = Vec::new(); + file.read_to_end(&mut buffer).unwrap(); + assert!(!String::from_utf8_lossy(&buffer).contains(expected)); +} + /// Copy a directory into another. pub fn copy_dir_all(src: impl AsRef, dst: impl AsRef) { fn copy_dir_all_inner(src: impl AsRef, dst: impl AsRef) -> io::Result<()> { diff --git a/src/tools/tidy/src/allowed_run_make_makefiles.txt b/src/tools/tidy/src/allowed_run_make_makefiles.txt index ec184c2c2146..7a08a9ab1a26 100644 --- a/src/tools/tidy/src/allowed_run_make_makefiles.txt +++ b/src/tools/tidy/src/allowed_run_make_makefiles.txt @@ -67,7 +67,6 @@ run-make/inaccessible-temp-dir/Makefile run-make/include_bytes_deps/Makefile run-make/incr-add-rust-src-component/Makefile run-make/incr-foreign-head-span/Makefile -run-make/incremental-debugger-visualizer/Makefile run-make/incremental-session-fail/Makefile run-make/inline-always-many-cgu/Makefile run-make/interdependent-c-libraries/Makefile diff --git a/tests/run-make/incremental-debugger-visualizer/Makefile b/tests/run-make/incremental-debugger-visualizer/Makefile deleted file mode 100644 index 8cfe41597adf..000000000000 --- a/tests/run-make/incremental-debugger-visualizer/Makefile +++ /dev/null @@ -1,49 +0,0 @@ -include ../tools.mk - -# This test makes sure that changes to files referenced via #[debugger_visualizer] -# are picked up when compiling incrementally. - -# We have to copy the source to $(TMPDIR) because Github CI mounts the source -# directory as readonly. We need to apply modifications to some of the source -# file. -SRC_DIR := $(TMPDIR)/src -INCR_CACHE_DIR := $(TMPDIR)/incremental - -all: - rm -rf $(TMPDIR)/* - mkdir $(SRC_DIR) - cp ./foo.rs $(SRC_DIR) - echo "GDB script v1" > $(SRC_DIR)/foo.py - echo "Natvis v1" > $(SRC_DIR)/foo.natvis - $(RUSTC) $(SRC_DIR)/foo.rs \ - --crate-type=rlib \ - --emit metadata \ - -C incremental=$(INCR_CACHE_DIR) \ - -Z incremental-verify-ich - $(CGREP) "GDB script v1" < $(TMPDIR)/libfoo.rmeta - $(CGREP) "Natvis v1" < $(TMPDIR)/libfoo.rmeta - - # Change only the GDB script and check that the change has been picked up - echo "GDB script v2" > $(SRC_DIR)/foo.py - $(RUSTC) $(SRC_DIR)/foo.rs \ - --crate-type=rlib \ - --emit metadata \ - -C incremental=$(INCR_CACHE_DIR) \ - -Z incremental-verify-ich - - $(CGREP) "GDB script v2" < $(TMPDIR)/libfoo.rmeta - $(CGREP) -v "GDB script v1" < $(TMPDIR)/libfoo.rmeta - $(CGREP) "Natvis v1" < $(TMPDIR)/libfoo.rmeta - - # Now change the Natvis version and check that the change has been picked up - echo "Natvis v2" > $(SRC_DIR)/foo.natvis - $(RUSTC) $(SRC_DIR)/foo.rs \ - --crate-type=rlib \ - --emit metadata \ - -C incremental=$(INCR_CACHE_DIR) \ - -Z incremental-verify-ich - - $(CGREP) "GDB script v2" < $(TMPDIR)/libfoo.rmeta - $(CGREP) -v "GDB script v1" < $(TMPDIR)/libfoo.rmeta - $(CGREP) "Natvis v2" < $(TMPDIR)/libfoo.rmeta - $(CGREP) -v "Natvis v1" < $(TMPDIR)/libfoo.rmeta diff --git a/tests/run-make/incremental-debugger-visualizer/rmake.rs b/tests/run-make/incremental-debugger-visualizer/rmake.rs new file mode 100644 index 000000000000..74de4e9909b3 --- /dev/null +++ b/tests/run-make/incremental-debugger-visualizer/rmake.rs @@ -0,0 +1,61 @@ +// This test makes sure that changes to files referenced via //[debugger_visualizer] +// are picked up when compiling incrementally. + +// We have to copy the source to $(TMPDIR) because Github CI mounts the source +// directory as readonly. We need to apply modifications to some of the source +// file. + +use run_make_support::{ + fs_wrapper, invalid_utf8_contains_str, invalid_utf8_not_contains_str, rustc, +}; +use std::io::Read; + +fn main() { + fs_wrapper::create_file("foo.py"); + fs_wrapper::write("foo.py", "GDB script v1"); + fs_wrapper::create_file("foo.natvis"); + fs_wrapper::write("foo.py", "Natvis v1"); + rustc() + .input("foo.rs") + .crate_type("rlib") + .emit("metadata") + .incremental("incremental") + .arg("-Zincremental-verify-ich") + .run(); + + invalid_utf8_contains_str("libfoo.rmeta", "GDB script v1"); + invalid_utf8_contains_str("libfoo.rmeta", "Natvis v1"); + + // Change only the GDB script and check that the change has been picked up + fs_wrapper::remove_file("foo.py"); + fs_wrapper::create_file("foo.py"); + fs_wrapper::write("foo.py", "GDB script v2"); + rustc() + .input("foo.rs") + .crate_type("rlib") + .emit("metadata") + .incremental("incremental") + .arg("-Zincremental-verify-ich") + .run(); + + invalid_utf8_contains_str("libfoo.rmeta", "GDB script v2"); + invalid_utf8_not_contains_str("libfoo.rmeta", "GDB script v1"); + invalid_utf8_contains_str("libfoo.rmeta", "Natvis v1"); + + // Now change the Natvis version and check that the change has been picked up + fs_wrapper::remove_file("foo.natvis"); + fs_wrapper::create_file("foo.natvis"); + fs_wrapper::write("foo.py", "Natvis v2"); + rustc() + .input("foo.rs") + .crate_type("rlib") + .emit("metadata") + .incremental("incremental") + .arg("-Zincremental-verify-ich") + .run(); + + invalid_utf8_contains_str("libfoo.rmeta", "GDB script v2"); + invalid_utf8_not_contains_str("libfoo.rmeta", "GDB script v1"); + invalid_utf8_not_contains_str("libfoo.rmeta", "Natvis v1"); + invalid_utf8_contains_str("libfoo.rmeta", "Natvis v2"); +} From e9ff47ff406dd6fd029333391bb5ed0be4c9464a Mon Sep 17 00:00:00 2001 From: Oneirical Date: Fri, 14 Jun 2024 15:50:33 -0400 Subject: [PATCH 08/17] rewrite error-found-staticlib-instead-crate to rmake --- src/tools/tidy/src/allowed_run_make_makefiles.txt | 1 - .../error-found-staticlib-instead-crate/Makefile | 5 ----- .../error-found-staticlib-instead-crate/rmake.rs | 11 +++++++++++ 3 files changed, 11 insertions(+), 6 deletions(-) delete mode 100644 tests/run-make/error-found-staticlib-instead-crate/Makefile create mode 100644 tests/run-make/error-found-staticlib-instead-crate/rmake.rs diff --git a/src/tools/tidy/src/allowed_run_make_makefiles.txt b/src/tools/tidy/src/allowed_run_make_makefiles.txt index be9df226d64e..5b2ccbf98d40 100644 --- a/src/tools/tidy/src/allowed_run_make_makefiles.txt +++ b/src/tools/tidy/src/allowed_run_make_makefiles.txt @@ -38,7 +38,6 @@ run-make/emit-shared-files/Makefile run-make/emit-stack-sizes/Makefile run-make/emit-to-stdout/Makefile run-make/env-dep-info/Makefile -run-make/error-found-staticlib-instead-crate/Makefile run-make/error-writing-dependencies/Makefile run-make/export-executable-symbols/Makefile run-make/extern-diff-internal-name/Makefile diff --git a/tests/run-make/error-found-staticlib-instead-crate/Makefile b/tests/run-make/error-found-staticlib-instead-crate/Makefile deleted file mode 100644 index 0eae41d720cc..000000000000 --- a/tests/run-make/error-found-staticlib-instead-crate/Makefile +++ /dev/null @@ -1,5 +0,0 @@ -include ../tools.mk - -all: - $(RUSTC) foo.rs --crate-type staticlib - $(RUSTC) bar.rs 2>&1 | $(CGREP) "found staticlib" diff --git a/tests/run-make/error-found-staticlib-instead-crate/rmake.rs b/tests/run-make/error-found-staticlib-instead-crate/rmake.rs new file mode 100644 index 000000000000..8c707092b7e4 --- /dev/null +++ b/tests/run-make/error-found-staticlib-instead-crate/rmake.rs @@ -0,0 +1,11 @@ +// When rustc is looking for a crate but is given a staticlib instead, +// the error message should be helpful and indicate precisely the cause +// of the compilation failure. +// See https://github.com/rust-lang/rust/pull/21978 + +use run_make_support::rustc; + +fn main() { + rustc().input("foo.rs").crate_type("staticlib").run(); + rustc().input("bar.rs").run_fail().assert_stderr_contains("found staticlib"); +} From e088edd149475f3e11267dd7061db3f3e6962772 Mon Sep 17 00:00:00 2001 From: Oneirical Date: Fri, 14 Jun 2024 16:01:24 -0400 Subject: [PATCH 09/17] rewrite output-filename-conflicts-with-directory to rmake --- src/tools/tidy/src/allowed_run_make_makefiles.txt | 1 - .../output-filename-conflicts-with-directory/Makefile | 7 ------- .../output-filename-conflicts-with-directory/rmake.rs | 11 +++++++++++ 3 files changed, 11 insertions(+), 8 deletions(-) delete mode 100644 tests/run-make/output-filename-conflicts-with-directory/Makefile create mode 100644 tests/run-make/output-filename-conflicts-with-directory/rmake.rs diff --git a/src/tools/tidy/src/allowed_run_make_makefiles.txt b/src/tools/tidy/src/allowed_run_make_makefiles.txt index 5b2ccbf98d40..58e17d24948e 100644 --- a/src/tools/tidy/src/allowed_run_make_makefiles.txt +++ b/src/tools/tidy/src/allowed_run_make_makefiles.txt @@ -152,7 +152,6 @@ run-make/no-duplicate-libs/Makefile run-make/obey-crate-type-flag/Makefile run-make/optimization-remarks-dir-pgo/Makefile run-make/optimization-remarks-dir/Makefile -run-make/output-filename-conflicts-with-directory/Makefile run-make/output-filename-overwrites-input/Makefile run-make/output-type-permutations/Makefile run-make/output-with-hyphens/Makefile diff --git a/tests/run-make/output-filename-conflicts-with-directory/Makefile b/tests/run-make/output-filename-conflicts-with-directory/Makefile deleted file mode 100644 index 45221356cd97..000000000000 --- a/tests/run-make/output-filename-conflicts-with-directory/Makefile +++ /dev/null @@ -1,7 +0,0 @@ -include ../tools.mk - -all: - cp foo.rs $(TMPDIR)/foo.rs - mkdir $(TMPDIR)/foo - $(RUSTC) $(TMPDIR)/foo.rs -o $(TMPDIR)/foo 2>&1 \ - | $(CGREP) -e "the generated executable for the input file \".*foo\.rs\" conflicts with the existing directory \".*foo\"" diff --git a/tests/run-make/output-filename-conflicts-with-directory/rmake.rs b/tests/run-make/output-filename-conflicts-with-directory/rmake.rs new file mode 100644 index 000000000000..245bc395f14a --- /dev/null +++ b/tests/run-make/output-filename-conflicts-with-directory/rmake.rs @@ -0,0 +1,11 @@ +// When the compiled executable would conflict with a directory, a +// rustc error should be displayed instead of a verbose and +// potentially-confusing linker error. +// See https://github.com/rust-lang/rust/pull/47203 + +use run_make_support::{fs_wrapper, rustc}; + +fn main() { + fs_wrapper::create_dir("foo"); + rustc().input("foo.rs").output("foo").run_fail().assert_stderr_contains(r#"the generated executable for the input file "foo.rs" conflicts with the existing directory "foo""#); +} From 8ece5ce31958bd1acadfc2ac7fccc7ce25176b8d Mon Sep 17 00:00:00 2001 From: Oneirical Date: Fri, 14 Jun 2024 16:21:55 -0400 Subject: [PATCH 10/17] rewrite output-filename-overwrites-input to rmake --- .../tidy/src/allowed_run_make_makefiles.txt | 1 - .../output-filename-overwrites-input/Makefile | 14 ------------- .../output-filename-overwrites-input/rmake.rs | 21 +++++++++++++++++++ 3 files changed, 21 insertions(+), 15 deletions(-) delete mode 100644 tests/run-make/output-filename-overwrites-input/Makefile create mode 100644 tests/run-make/output-filename-overwrites-input/rmake.rs diff --git a/src/tools/tidy/src/allowed_run_make_makefiles.txt b/src/tools/tidy/src/allowed_run_make_makefiles.txt index 58e17d24948e..fb6ea1f3c7a7 100644 --- a/src/tools/tidy/src/allowed_run_make_makefiles.txt +++ b/src/tools/tidy/src/allowed_run_make_makefiles.txt @@ -152,7 +152,6 @@ run-make/no-duplicate-libs/Makefile run-make/obey-crate-type-flag/Makefile run-make/optimization-remarks-dir-pgo/Makefile run-make/optimization-remarks-dir/Makefile -run-make/output-filename-overwrites-input/Makefile run-make/output-type-permutations/Makefile run-make/output-with-hyphens/Makefile run-make/override-aliased-flags/Makefile diff --git a/tests/run-make/output-filename-overwrites-input/Makefile b/tests/run-make/output-filename-overwrites-input/Makefile deleted file mode 100644 index fe5d231382dc..000000000000 --- a/tests/run-make/output-filename-overwrites-input/Makefile +++ /dev/null @@ -1,14 +0,0 @@ -# ignore-cross-compile -include ../tools.mk - -all: - cp foo.rs $(TMPDIR)/foo - $(RUSTC) $(TMPDIR)/foo -o $(TMPDIR)/foo 2>&1 \ - | $(CGREP) -e "the input file \".*foo\" would be overwritten by the generated executable" - cp bar.rs $(TMPDIR)/bar.rlib - $(RUSTC) $(TMPDIR)/bar.rlib -o $(TMPDIR)/bar.rlib 2>&1 \ - | $(CGREP) -e "the input file \".*bar.rlib\" would be overwritten by the generated executable" - $(RUSTC) foo.rs 2>&1 && $(RUSTC) -Z ls=root $(TMPDIR)/foo 2>&1 - cp foo.rs $(TMPDIR)/foo.rs - $(RUSTC) $(TMPDIR)/foo.rs -o $(TMPDIR)/foo.rs 2>&1 \ - | $(CGREP) -e "the input file \".*foo.rs\" would be overwritten by the generated executable" diff --git a/tests/run-make/output-filename-overwrites-input/rmake.rs b/tests/run-make/output-filename-overwrites-input/rmake.rs new file mode 100644 index 000000000000..c6055e818a17 --- /dev/null +++ b/tests/run-make/output-filename-overwrites-input/rmake.rs @@ -0,0 +1,21 @@ +// If rustc is invoked on a file that would be overwritten by the +// compilation, the compilation should fail, to avoid accidental loss. +// See https://github.com/rust-lang/rust/pull/46814 + +//@ ignore-cross-compile + +use run_make_support::{fs_wrapper, rustc}; + +fn main() { + fs_wrapper::copy("foo.rs", "foo"); + rustc().input("foo").output("foo").run_fail().assert_stderr_contains( + r#"the input file "foo" would be overwritten by the generated executable"#, + ); + fs_wrapper::copy("bar.rs", "bar.rlib"); + rustc().input("bar.rlib").output("bar.rlib").run_fail().assert_stderr_contains( + r#"the input file "bar.rlib" would be overwritten by the generated executable"#, + ); + rustc().input("foo.rs").output("foo.rs").run_fail().assert_stderr_contains( + r#"the input file "foo.rs" would be overwritten by the generated executable"#, + ); +} From 5f2b47fcb6aa06985686dc8dc23e33d96e430a12 Mon Sep 17 00:00:00 2001 From: Oneirical Date: Fri, 14 Jun 2024 16:45:52 -0400 Subject: [PATCH 11/17] rewrite native-link-modifier-verbatim-rustc to rmake --- .../tidy/src/allowed_run_make_makefiles.txt | 1 - .../Makefile | 12 ----- .../rmake.rs | 44 +++++++++++++++++++ 3 files changed, 44 insertions(+), 13 deletions(-) delete mode 100644 tests/run-make/native-link-modifier-verbatim-rustc/Makefile create mode 100644 tests/run-make/native-link-modifier-verbatim-rustc/rmake.rs diff --git a/src/tools/tidy/src/allowed_run_make_makefiles.txt b/src/tools/tidy/src/allowed_run_make_makefiles.txt index fb6ea1f3c7a7..9689f2b355fe 100644 --- a/src/tools/tidy/src/allowed_run_make_makefiles.txt +++ b/src/tools/tidy/src/allowed_run_make_makefiles.txt @@ -143,7 +143,6 @@ run-make/mixing-libs/Makefile run-make/msvc-opt-minsize/Makefile run-make/native-link-modifier-bundle/Makefile run-make/native-link-modifier-verbatim-linker/Makefile -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 diff --git a/tests/run-make/native-link-modifier-verbatim-rustc/Makefile b/tests/run-make/native-link-modifier-verbatim-rustc/Makefile deleted file mode 100644 index dfd6ec50fc00..000000000000 --- a/tests/run-make/native-link-modifier-verbatim-rustc/Makefile +++ /dev/null @@ -1,12 +0,0 @@ -include ../tools.mk - -all: - # Verbatim allows specify precise name. - $(RUSTC) upstream_native_dep.rs --crate-type=staticlib -o $(TMPDIR)/upstream_some_strange_name.ext - $(RUSTC) rust_dep.rs -l static:+verbatim=upstream_some_strange_name.ext --crate-type rlib - - # With verbatim any other name cannot be used (upstream). - $(RUSTC) upstream_native_dep.rs --crate-type=staticlib -o $(TMPDIR)/libupstream_native_dep.a - $(RUSTC) upstream_native_dep.rs --crate-type=staticlib -o $(TMPDIR)/upstream_native_dep.a - $(RUSTC) upstream_native_dep.rs --crate-type=staticlib -o $(TMPDIR)/upstream_native_dep.lib - $(RUSTC) rust_dep.rs -l static:+verbatim=upstream_native_dep --crate-type rlib 2>&1 | $(CGREP) "upstream_native_dep" diff --git a/tests/run-make/native-link-modifier-verbatim-rustc/rmake.rs b/tests/run-make/native-link-modifier-verbatim-rustc/rmake.rs new file mode 100644 index 000000000000..58c7fef232c7 --- /dev/null +++ b/tests/run-make/native-link-modifier-verbatim-rustc/rmake.rs @@ -0,0 +1,44 @@ +// `verbatim` is a native link modifier that forces rustc to only accept libraries with +// a specified name. This test checks that this modifier works as intended. +// See https://github.com/rust-lang/rust/issues/99425 + +use run_make_support::rustc; + +fn main() { + // Verbatim allows for the specification of a precise name - in this case, the unconventional ".ext" extension. + rustc() + .input("upstream_native_dep.rs") + .crate_type("staticlib") + .output("upstream_some_strange_name.ext") + .run(); + rustc() + .input("rust_dep.rs") + .crate_type("rlib") + .arg("-lstatic:+verbatim=upstream_some_strange_name.ext") + .run(); + + // This section voluntarily avoids using static_lib_name helpers to be verbatim. + // With verbatim, even these common library names are refused - it wants upstream_native_dep without + // any file extensions. + rustc() + .input("upstream_native_dep.rs") + .crate_type("staticlib") + .output("libupstream_native_dep.a") + .run(); + rustc() + .input("upstream_native_dep.rs") + .crate_type("staticlib") + .output("upstream_native_dep.a") + .run(); + rustc() + .input("upstream_native_dep.rs") + .crate_type("staticlib") + .output("upstream_native_dep.lib") + .run(); + rustc() + .input("rust_dep.rs") + .crate_type("rlib") + .arg("-lstatic:+verbatim=upstream_native_dep") + .run_fail() + .assert_stderr_contains("upstream_native_dep"); +} From c349d08088b344e0ff1a5ba20d9d0410e3cb6728 Mon Sep 17 00:00:00 2001 From: Jerry Wang Date: Sat, 15 Jun 2024 22:04:55 -0400 Subject: [PATCH 12/17] Add `readelf` support to `run-make-support` --- src/tools/run-make-support/src/llvm.rs | 28 +++++++++++++++++++++----- 1 file changed, 23 insertions(+), 5 deletions(-) diff --git a/src/tools/run-make-support/src/llvm.rs b/src/tools/run-make-support/src/llvm.rs index 664093e072d7..643e2576e3da 100644 --- a/src/tools/run-make-support/src/llvm.rs +++ b/src/tools/run-make-support/src/llvm.rs @@ -2,8 +2,8 @@ use std::path::{Path, PathBuf}; use crate::{env_var, Command}; -/// Construct a new `llvm-readobj` invocation. This assumes that `llvm-readobj` is available -/// at `$LLVM_BIN_DIR/llvm-readobj`. +/// Construct a new `llvm-readobj` invocation with the `GNU` output style. +/// This assumes that `llvm-readobj` is available at `$LLVM_BIN_DIR/llvm-readobj`. #[track_caller] pub fn llvm_readobj() -> LlvmReadobj { LlvmReadobj::new() @@ -56,13 +56,24 @@ pub fn llvm_bin_dir() -> PathBuf { } impl LlvmReadobj { - /// Construct a new `llvm-readobj` invocation. This assumes that `llvm-readobj` is available - /// at `$LLVM_BIN_DIR/llvm-readobj`. + /// Construct a new `llvm-readobj` invocation with the `GNU` output style. + /// This assumes that `llvm-readobj` is available at `$LLVM_BIN_DIR/llvm-readobj`. #[track_caller] pub fn new() -> Self { let llvm_readobj = llvm_bin_dir().join("llvm-readobj"); let cmd = Command::new(llvm_readobj); - Self { cmd } + let mut readobj = Self { cmd }; + readobj.elf_output_style("GNU"); + readobj + } + + /// Specify the format of the ELF information. + /// + /// Valid options are `LLVM` (default), `GNU`, and `JSON`. + pub fn elf_output_style(&mut self, style: &str) -> &mut Self { + self.cmd.arg("--elf-output-style"); + self.cmd.arg(style); + self } /// Provide an input file. @@ -76,6 +87,13 @@ impl LlvmReadobj { self.cmd.arg("--file-header"); self } + + /// Specify the section to display. + pub fn section(&mut self, section: &str) -> &mut Self { + self.cmd.arg("--string-dump"); + self.cmd.arg(section); + self + } } impl LlvmProfdata { From e601c8daa2e100c7211a12cb1da17a5d4dba7ffb Mon Sep 17 00:00:00 2001 From: Jerry Wang Date: Sat, 15 Jun 2024 21:47:27 -0400 Subject: [PATCH 13/17] Migrate `run-make/comment-section` to `rmake.rs` --- .../tidy/src/allowed_run_make_makefiles.txt | 1 - tests/run-make/comment-section/Makefile | 18 -------- tests/run-make/comment-section/rmake.rs | 45 +++++++++++++++++++ 3 files changed, 45 insertions(+), 19 deletions(-) delete mode 100644 tests/run-make/comment-section/Makefile create mode 100644 tests/run-make/comment-section/rmake.rs diff --git a/src/tools/tidy/src/allowed_run_make_makefiles.txt b/src/tools/tidy/src/allowed_run_make_makefiles.txt index fdd0be79a4de..86f9e2663a95 100644 --- a/src/tools/tidy/src/allowed_run_make_makefiles.txt +++ b/src/tools/tidy/src/allowed_run_make_makefiles.txt @@ -11,7 +11,6 @@ run-make/c-unwind-abi-catch-panic/Makefile run-make/cat-and-grep-sanity-check/Makefile run-make/cdylib-dylib-linkage/Makefile run-make/cdylib-fewer-symbols/Makefile -run-make/comment-section/Makefile run-make/compiler-lookup-paths-2/Makefile run-make/compiler-lookup-paths/Makefile run-make/compiler-rt-works-on-mingw/Makefile diff --git a/tests/run-make/comment-section/Makefile b/tests/run-make/comment-section/Makefile deleted file mode 100644 index d0b98176ffed..000000000000 --- a/tests/run-make/comment-section/Makefile +++ /dev/null @@ -1,18 +0,0 @@ -# Both GCC and Clang write by default a `.comment` section with compiler information. Rustc received a similar .comment section, so this tests checks that this section properly appears. -# See https://github.com/rust-lang/rust/commit/74b8d324eb77a8f337b35dc68ac91b0c2c06debc - -include ../tools.mk - -# only-linux - -all: - echo 'fn main(){}' | $(RUSTC) - --emit=link,obj -Csave-temps --target=$(TARGET) - - # Check linked output has a `.comment` section with the expected content. - readelf -p '.comment' $(TMPDIR)/rust_out | $(CGREP) -F 'rustc version 1.' - - # Check all object files (including temporary outputs) have a `.comment` - # section with the expected content. - set -e; for f in $(TMPDIR)/*.o; do \ - readelf -p '.comment' $$f | $(CGREP) -F 'rustc version 1.'; \ - done diff --git a/tests/run-make/comment-section/rmake.rs b/tests/run-make/comment-section/rmake.rs new file mode 100644 index 000000000000..ad37c24c4724 --- /dev/null +++ b/tests/run-make/comment-section/rmake.rs @@ -0,0 +1,45 @@ +// Both GCC and Clang write by default a `.comment` section with compiler information. +// Rustc received a similar .comment section, so this tests checks that this section +// properly appears. +// See https://github.com/rust-lang/rust/commit/74b8d324eb77a8f337b35dc68ac91b0c2c06debc + +//@ only-linux + +use std::path::PathBuf; + +use run_make_support::llvm_readobj; +use run_make_support::rustc; +use run_make_support::{cwd, env_var, read_dir, run_in_tmpdir}; + +fn main() { + let target = env_var("TARGET"); + + rustc() + .arg("-") + .stdin("fn main() {}") + .emit("link,obj") + .arg("-Csave-temps") + .target(&target) + .run(); + + // Check linked output has a `.comment` section with the expected content. + llvm_readobj() + .section(".comment") + .input("rust_out") + .run() + .assert_stdout_contains("rustc version 1."); + + // Check all object files (including temporary outputs) have a `.comment` + // section with the expected content. + read_dir(cwd(), |f| { + if !f.extension().is_some_and(|ext| ext == "o") { + return; + } + + llvm_readobj() + .section(".comment") + .input(&f) + .run() + .assert_stdout_contains("rustc version 1."); + }); +} From cdfcc9442e08f863a96e9099c7dfb79cd5dfb52b Mon Sep 17 00:00:00 2001 From: Oneirical Date: Fri, 14 Jun 2024 15:28:15 -0400 Subject: [PATCH 14/17] rewrite incremental-session-fail to rmake --- src/tools/run-make-support/src/lib.rs | 30 +++++++++------- .../tidy/src/allowed_run_make_makefiles.txt | 1 - tests/run-make/extern-flag-fun/rmake.rs | 6 ++-- .../incremental-debugger-visualizer/rmake.rs | 35 ++++++++----------- .../incremental-session-fail/Makefile | 14 -------- .../incremental-session-fail/rmake.rs | 15 ++++++++ 6 files changed, 52 insertions(+), 49 deletions(-) delete mode 100644 tests/run-make/incremental-session-fail/Makefile create mode 100644 tests/run-make/incremental-session-fail/rmake.rs diff --git a/src/tools/run-make-support/src/lib.rs b/src/tools/run-make-support/src/lib.rs index 784bbe572ab3..8d9976e27a58 100644 --- a/src/tools/run-make-support/src/lib.rs +++ b/src/tools/run-make-support/src/lib.rs @@ -274,23 +274,29 @@ pub fn set_host_rpath(cmd: &mut Command) { /// Read the contents of a file that cannot simply be read by /// read_to_string, due to invalid utf8 data, then assert that it contains `expected`. #[track_caller] -pub fn invalid_utf8_contains_str>(path: P, expected: &str) { - use std::io::Read; - let mut file = std::fs::File::open(path).unwrap(); - let mut buffer = Vec::new(); - file.read_to_end(&mut buffer).unwrap(); - assert!(String::from_utf8_lossy(&buffer).contains(expected)); +pub fn invalid_utf8_contains>(path: P, expected: &str) { + let buffer = fs_wrapper::read(path.as_ref()); + if !String::from_utf8_lossy(&buffer).contains(expected) { + eprintln!("=== FILE CONTENTS (LOSSY) ==="); + eprintln!("{}", String::from_utf8_lossy(&buffer)); + eprintln!("=== SPECIFIED TEXT ==="); + eprintln!("{}", expected); + panic!("specified text was not found in file"); + } } /// Read the contents of a file that cannot simply be read by /// read_to_string, due to invalid utf8 data, then assert that it does not contain `expected`. #[track_caller] -pub fn invalid_utf8_not_contains_str>(path: P, expected: &str) { - use std::io::Read; - let mut file = std::fs::File::open(path).unwrap(); - let mut buffer = Vec::new(); - file.read_to_end(&mut buffer).unwrap(); - assert!(!String::from_utf8_lossy(&buffer).contains(expected)); +pub fn invalid_utf8_not_contains>(path: P, expected: &str) { + let buffer = fs_wrapper::read(path.as_ref()); + if String::from_utf8_lossy(&buffer).contains(expected) { + eprintln!("=== FILE CONTENTS (LOSSY) ==="); + eprintln!("{}", String::from_utf8_lossy(&buffer)); + eprintln!("=== SPECIFIED TEXT ==="); + eprintln!("{}", expected); + panic!("specified text was unexpectedly found in file"); + } } /// Copy a directory into another. diff --git a/src/tools/tidy/src/allowed_run_make_makefiles.txt b/src/tools/tidy/src/allowed_run_make_makefiles.txt index 7a08a9ab1a26..1bc196419d02 100644 --- a/src/tools/tidy/src/allowed_run_make_makefiles.txt +++ b/src/tools/tidy/src/allowed_run_make_makefiles.txt @@ -67,7 +67,6 @@ run-make/inaccessible-temp-dir/Makefile run-make/include_bytes_deps/Makefile run-make/incr-add-rust-src-component/Makefile run-make/incr-foreign-head-span/Makefile -run-make/incremental-session-fail/Makefile run-make/inline-always-many-cgu/Makefile run-make/interdependent-c-libraries/Makefile run-make/intrinsic-unreachable/Makefile diff --git a/tests/run-make/extern-flag-fun/rmake.rs b/tests/run-make/extern-flag-fun/rmake.rs index 10fec6e30b42..c1825f6bbb88 100644 --- a/tests/run-make/extern-flag-fun/rmake.rs +++ b/tests/run-make/extern-flag-fun/rmake.rs @@ -5,21 +5,23 @@ // as non-private. This test checks that these rules are enforced. // See https://github.com/rust-lang/rust/pull/15319 -//@ ignore-cross-compile - use run_make_support::{rust_lib_name, rustc}; fn main() { rustc().input("bar.rs").crate_type("rlib").run(); + // Exactly the same rlib as the first line, only the filename changes. rustc().input("bar.rs").crate_type("rlib").extra_filename("-a").run(); rustc().input("bar-alt.rs").crate_type("rlib").run(); + // The crate must be valid. rustc().input("foo.rs").extern_("bar", "no-exist").run_fail(); rustc().input("foo.rs").extern_("bar", "foo.rs").run_fail(); + // Compilation fails with two different rlibs. rustc() .input("foo.rs") .extern_("bar", rust_lib_name("bar")) .extern_("bar", rust_lib_name("bar-alt")) .run_fail(); + // Even though this one has seemingly two rlibs, they are one and the same. rustc() .input("foo.rs") .extern_("bar", rust_lib_name("bar")) diff --git a/tests/run-make/incremental-debugger-visualizer/rmake.rs b/tests/run-make/incremental-debugger-visualizer/rmake.rs index 74de4e9909b3..1ef3af873530 100644 --- a/tests/run-make/incremental-debugger-visualizer/rmake.rs +++ b/tests/run-make/incremental-debugger-visualizer/rmake.rs @@ -1,20 +1,15 @@ -// This test makes sure that changes to files referenced via //[debugger_visualizer] -// are picked up when compiling incrementally. +// This test ensures that changes to files referenced via #[debugger_visualizer] +// (in this case, foo.py and foo.natvis) are picked up when compiling incrementally. +// See https://github.com/rust-lang/rust/pull/111641 -// We have to copy the source to $(TMPDIR) because Github CI mounts the source -// directory as readonly. We need to apply modifications to some of the source -// file. - -use run_make_support::{ - fs_wrapper, invalid_utf8_contains_str, invalid_utf8_not_contains_str, rustc, -}; +use run_make_support::{fs_wrapper, invalid_utf8_contains, invalid_utf8_not_contains, rustc}; use std::io::Read; fn main() { fs_wrapper::create_file("foo.py"); fs_wrapper::write("foo.py", "GDB script v1"); fs_wrapper::create_file("foo.natvis"); - fs_wrapper::write("foo.py", "Natvis v1"); + fs_wrapper::write("foo.natvis", "Natvis v1"); rustc() .input("foo.rs") .crate_type("rlib") @@ -23,8 +18,8 @@ fn main() { .arg("-Zincremental-verify-ich") .run(); - invalid_utf8_contains_str("libfoo.rmeta", "GDB script v1"); - invalid_utf8_contains_str("libfoo.rmeta", "Natvis v1"); + invalid_utf8_contains("libfoo.rmeta", "GDB script v1"); + invalid_utf8_contains("libfoo.rmeta", "Natvis v1"); // Change only the GDB script and check that the change has been picked up fs_wrapper::remove_file("foo.py"); @@ -38,14 +33,14 @@ fn main() { .arg("-Zincremental-verify-ich") .run(); - invalid_utf8_contains_str("libfoo.rmeta", "GDB script v2"); - invalid_utf8_not_contains_str("libfoo.rmeta", "GDB script v1"); - invalid_utf8_contains_str("libfoo.rmeta", "Natvis v1"); + invalid_utf8_contains("libfoo.rmeta", "GDB script v2"); + invalid_utf8_not_contains("libfoo.rmeta", "GDB script v1"); + invalid_utf8_contains("libfoo.rmeta", "Natvis v1"); // Now change the Natvis version and check that the change has been picked up fs_wrapper::remove_file("foo.natvis"); fs_wrapper::create_file("foo.natvis"); - fs_wrapper::write("foo.py", "Natvis v2"); + fs_wrapper::write("foo.natvis", "Natvis v2"); rustc() .input("foo.rs") .crate_type("rlib") @@ -54,8 +49,8 @@ fn main() { .arg("-Zincremental-verify-ich") .run(); - invalid_utf8_contains_str("libfoo.rmeta", "GDB script v2"); - invalid_utf8_not_contains_str("libfoo.rmeta", "GDB script v1"); - invalid_utf8_not_contains_str("libfoo.rmeta", "Natvis v1"); - invalid_utf8_contains_str("libfoo.rmeta", "Natvis v2"); + invalid_utf8_contains("libfoo.rmeta", "GDB script v2"); + invalid_utf8_not_contains("libfoo.rmeta", "GDB script v1"); + invalid_utf8_not_contains("libfoo.rmeta", "Natvis v1"); + invalid_utf8_contains("libfoo.rmeta", "Natvis v2"); } diff --git a/tests/run-make/incremental-session-fail/Makefile b/tests/run-make/incremental-session-fail/Makefile deleted file mode 100644 index f43eece2eb70..000000000000 --- a/tests/run-make/incremental-session-fail/Makefile +++ /dev/null @@ -1,14 +0,0 @@ -include ../tools.mk - -SESSION_DIR := $(TMPDIR)/session -OUTPUT_FILE := $(TMPDIR)/build-output - -all: - echo $(TMPDIR) - # Make it so that rustc will fail to create a session directory. - touch $(SESSION_DIR) - # Check exit code is 1 for an error, and not 101 for ICE. - $(RUSTC) foo.rs --crate-type=rlib -C incremental=$(SESSION_DIR) > $(OUTPUT_FILE) 2>&1; [ $$? -eq 1 ] - $(CGREP) "could not create incremental compilation crate directory" < $(OUTPUT_FILE) - # -v tests are fragile, hopefully this text won't change - $(CGREP) -v "internal compiler error" < $(OUTPUT_FILE) diff --git a/tests/run-make/incremental-session-fail/rmake.rs b/tests/run-make/incremental-session-fail/rmake.rs new file mode 100644 index 000000000000..0283709f2cf8 --- /dev/null +++ b/tests/run-make/incremental-session-fail/rmake.rs @@ -0,0 +1,15 @@ +// Failing to create the directory where output incremental +// files would be stored used to cause an ICE (Internal Compiler +// Error). This was patched in #85698, and this test checks that +// the ensuing compilation failure is not an ICE. +// See https://github.com/rust-lang/rust/pull/85698 + +use run_make_support::{fs_wrapper, rustc}; + +fn main() { + fs_wrapper::create_file("session"); + // rustc should fail to create the session directory here. + let out = rustc().input("foo.rs").crate_type("rlib").incremental("session").run_fail(); + out.assert_stderr_contains("could not create incremental compilation crate directory"); + out.assert_stderr_not_contains("internal compiler error"); +} From 03f19d632ad896be77a0dabfe1298f164c78067c Mon Sep 17 00:00:00 2001 From: Oneirical Date: Tue, 11 Jun 2024 16:12:36 -0400 Subject: [PATCH 15/17] Add new test_while_readonly helper function to run-make-support --- src/tools/run-make-support/src/lib.rs | 32 +++++++++++++++++ tests/run-make/inaccessible-temp-dir/rmake.rs | 36 ++++++++----------- tests/run-make/output-with-hyphens/rmake.rs | 4 +-- .../parallel-rustc-no-overwrite/rmake.rs | 5 +-- 4 files changed, 52 insertions(+), 25 deletions(-) diff --git a/src/tools/run-make-support/src/lib.rs b/src/tools/run-make-support/src/lib.rs index b920f9a07db8..6a89a75d7159 100644 --- a/src/tools/run-make-support/src/lib.rs +++ b/src/tools/run-make-support/src/lib.rs @@ -169,6 +169,38 @@ pub fn cwd() -> PathBuf { env::current_dir().unwrap() } +// FIXME(Oneirical): This will no longer be required after compiletest receives the ability +// to manipulate read-only files. See https://github.com/rust-lang/rust/issues/126334 +/// Ensure that the path P is read-only while the test runs, and restore original permissions +/// at the end so compiletest can clean up. +/// This will panic on Windows if the path is a directory (as it would otherwise do nothing) +#[track_caller] +pub fn test_while_readonly, F: FnOnce() + std::panic::UnwindSafe>( + path: P, + closure: F, +) { + let path = path.as_ref(); + if is_windows() && path.is_dir() { + eprintln!("This helper function cannot be used on Windows to make directories readonly."); + eprintln!( + "See the official documentation: + https://doc.rust-lang.org/std/fs/struct.Permissions.html#method.set_readonly" + ); + panic!("`test_while_readonly` on directory detected while on Windows."); + } + let metadata = fs_wrapper::metadata(&path); + let original_perms = metadata.permissions(); + + let mut new_perms = original_perms.clone(); + new_perms.set_readonly(true); + fs_wrapper::set_permissions(&path, new_perms); + + let success = std::panic::catch_unwind(closure); + + fs_wrapper::set_permissions(&path, original_perms); + success.unwrap(); +} + /// Use `cygpath -w` on a path to get a Windows path string back. This assumes that `cygpath` is /// available on the platform! #[track_caller] diff --git a/tests/run-make/inaccessible-temp-dir/rmake.rs b/tests/run-make/inaccessible-temp-dir/rmake.rs index 25c9d363820d..be24e47b6dec 100644 --- a/tests/run-make/inaccessible-temp-dir/rmake.rs +++ b/tests/run-make/inaccessible-temp-dir/rmake.rs @@ -13,32 +13,26 @@ // use a directory with non-existing parent like `/does-not-exist/output`. // See https://github.com/rust-lang/rust/issues/66530 -//@ only-linux -// Reason: set_mode is only available on Unix - //@ ignore-arm // Reason: linker error on `armhf-gnu` +//@ ignore-windows +// Reason: `set_readonly` has no effect on directories +// and does not prevent modification. -use run_make_support::{fs_wrapper, rustc}; +use run_make_support::{fs_wrapper, rustc, test_while_readonly}; fn main() { // Create an inaccessible directory. fs_wrapper::create_dir("inaccessible"); - let meta = fs_wrapper::metadata("inaccessible"); - let mut perms = meta.permissions(); - perms.set_mode(0o000); // Lock down the directory. - fs_wrapper::set_permissions("inaccessible", perms); - - // Run rustc with `-Z temps-dir` set to a directory *inside* the inaccessible one, - // so that it can't create `tmp`. - rustc() - .input("program.rs") - .arg("-Ztemps-dir=inaccessible/tmp") - .run_fail() - .assert_stderr_contains( - "failed to find or create the directory specified by `--temps-dir`", - ); - - perms.set_mode(0o666); // Unlock the directory, so that compiletest can delete it. - fs_wrapper::set_permissions("inaccessible", perms); + test_while_readonly("inaccessible", || { + // Run rustc with `-Z temps-dir` set to a directory *inside* the inaccessible one, + // so that it can't create `tmp`. + rustc() + .input("program.rs") + .arg("-Ztemps-dir=inaccessible/tmp") + .run_fail() + .assert_stderr_contains( + "failed to find or create the directory specified by `--temps-dir`", + ); + }); } diff --git a/tests/run-make/output-with-hyphens/rmake.rs b/tests/run-make/output-with-hyphens/rmake.rs index 21c003c628b9..79deb772bc5d 100644 --- a/tests/run-make/output-with-hyphens/rmake.rs +++ b/tests/run-make/output-with-hyphens/rmake.rs @@ -7,11 +7,11 @@ //@ ignore-cross-compile -use run_make_support::{path, rustc}; +use run_make_support::{bin_name, path, rust_lib_name, rustc}; fn main() { rustc().input("foo-bar.rs").crate_type("bin").run(); assert!(path(bin_name("foo-bar")).exists()); rustc().input("foo-bar.rs").crate_type("lib").run(); - assert!(path(bin_name("libfoo_bar.rlib")).exists()); + assert!(path(rust_lib_name("foo_bar")).exists()); } diff --git a/tests/run-make/parallel-rustc-no-overwrite/rmake.rs b/tests/run-make/parallel-rustc-no-overwrite/rmake.rs index 40c6ab7ed5eb..3f032cf3762a 100644 --- a/tests/run-make/parallel-rustc-no-overwrite/rmake.rs +++ b/tests/run-make/parallel-rustc-no-overwrite/rmake.rs @@ -10,15 +10,16 @@ use std::sync::{Arc, Barrier}; use std::thread; fn main() { + fs_wrapper::create_file("lib.rs"); let barrier = Arc::new(Barrier::new(2)); let handle = { let barrier = Arc::clone(&barrier); thread::spawn(move || { barrier.wait(); - rustc().crate_type("lib").arg("-Ztemps-dir=temp1").input("lib.rs"); + rustc().crate_type("lib").arg("-Ztemps-dir=temp1").input("lib.rs").run(); }) }; barrier.wait(); - rustc().crate_type("staticlib").arg("-Ztemps-dir=temp2").input("lib.rs"); + rustc().crate_type("staticlib").arg("-Ztemps-dir=temp2").input("lib.rs").run(); handle.join().expect("lib thread panicked"); } From 6fffe848e3575292ac67d550298a6f169528fd6c Mon Sep 17 00:00:00 2001 From: Oneirical Date: Fri, 14 Jun 2024 16:54:08 -0400 Subject: [PATCH 16/17] rewrite native-link-modifier-linker to rmake --- .../tidy/src/allowed_run_make_makefiles.txt | 1 - .../Makefile | 15 ------- .../rmake.rs | 41 +++++++++++++++++++ .../rmake.rs | 7 +++- .../rmake.rs | 5 ++- 5 files changed, 50 insertions(+), 19 deletions(-) delete mode 100644 tests/run-make/native-link-modifier-verbatim-linker/Makefile create mode 100644 tests/run-make/native-link-modifier-verbatim-linker/rmake.rs diff --git a/src/tools/tidy/src/allowed_run_make_makefiles.txt b/src/tools/tidy/src/allowed_run_make_makefiles.txt index 9689f2b355fe..2e266cd1a641 100644 --- a/src/tools/tidy/src/allowed_run_make_makefiles.txt +++ b/src/tools/tidy/src/allowed_run_make_makefiles.txt @@ -142,7 +142,6 @@ run-make/missing-crate-dependency/Makefile run-make/mixing-libs/Makefile run-make/msvc-opt-minsize/Makefile run-make/native-link-modifier-bundle/Makefile -run-make/native-link-modifier-verbatim-linker/Makefile run-make/native-link-modifier-whole-archive/Makefile run-make/no-alloc-shim/Makefile run-make/no-builtins-attribute/Makefile diff --git a/tests/run-make/native-link-modifier-verbatim-linker/Makefile b/tests/run-make/native-link-modifier-verbatim-linker/Makefile deleted file mode 100644 index 47ed2a142918..000000000000 --- a/tests/run-make/native-link-modifier-verbatim-linker/Makefile +++ /dev/null @@ -1,15 +0,0 @@ -# ignore-cross-compile -# ignore-apple - -include ../tools.mk - -all: - # Verbatim allows specify precise name. - $(RUSTC) local_native_dep.rs --crate-type=staticlib -o $(TMPDIR)/local_some_strange_name.ext - $(RUSTC) main.rs -l static:+verbatim=local_some_strange_name.ext - - # With verbatim any other name cannot be used (local). - $(RUSTC) local_native_dep.rs --crate-type=staticlib -o $(TMPDIR)/liblocal_native_dep.a - $(RUSTC) local_native_dep.rs --crate-type=staticlib -o $(TMPDIR)/local_native_dep.a - $(RUSTC) local_native_dep.rs --crate-type=staticlib -o $(TMPDIR)/local_native_dep.lib - $(RUSTC) main.rs -l static:+verbatim=local_native_dep 2>&1 | $(CGREP) "local_native_dep" diff --git a/tests/run-make/native-link-modifier-verbatim-linker/rmake.rs b/tests/run-make/native-link-modifier-verbatim-linker/rmake.rs new file mode 100644 index 000000000000..6868cb368ccc --- /dev/null +++ b/tests/run-make/native-link-modifier-verbatim-linker/rmake.rs @@ -0,0 +1,41 @@ +// `verbatim` is a native link modifier that forces rustc to only accept libraries with +// a specified name. This test checks that this modifier works as intended. +// This test is the same as native-link-modifier-rustc, but without rlibs. +// See https://github.com/rust-lang/rust/issues/99425 + +//@ ignore-apple +// Reason: linking fails due to the unusual ".ext" staticlib name. + +use run_make_support::rustc; + +fn main() { + // Verbatim allows for the specification of a precise name + // - in this case, the unconventional ".ext" extension. + rustc() + .input("local_native_dep.rs") + .crate_type("staticlib") + .output("local_some_strange_name.ext") + .run(); + rustc().input("main.rs").arg("-lstatic:+verbatim=local_some_strange_name.ext").run(); + + // This section voluntarily avoids using static_lib_name helpers to be verbatim. + // With verbatim, even these common library names are refused + // - it wants local_native_dep without + // any file extensions. + rustc() + .input("local_native_dep.rs") + .crate_type("staticlib") + .output("liblocal_native_dep.a") + .run(); + rustc().input("local_native_dep.rs").crate_type("staticlib").output("local_native_dep.a").run(); + rustc() + .input("local_native_dep.rs") + .crate_type("staticlib") + .output("local_native_dep.lib") + .run(); + rustc() + .input("main.rs") + .arg("-lstatic:+verbatim=local_native_dep") + .run_fail() + .assert_stderr_contains("local_native_dep"); +} diff --git a/tests/run-make/native-link-modifier-verbatim-rustc/rmake.rs b/tests/run-make/native-link-modifier-verbatim-rustc/rmake.rs index 58c7fef232c7..703b8a80ef3e 100644 --- a/tests/run-make/native-link-modifier-verbatim-rustc/rmake.rs +++ b/tests/run-make/native-link-modifier-verbatim-rustc/rmake.rs @@ -1,11 +1,13 @@ // `verbatim` is a native link modifier that forces rustc to only accept libraries with // a specified name. This test checks that this modifier works as intended. +// This test is the same as native-link-modifier-linker, but with rlibs. // See https://github.com/rust-lang/rust/issues/99425 use run_make_support::rustc; fn main() { - // Verbatim allows for the specification of a precise name - in this case, the unconventional ".ext" extension. + // Verbatim allows for the specification of a precise name + // - in this case, the unconventional ".ext" extension. rustc() .input("upstream_native_dep.rs") .crate_type("staticlib") @@ -18,7 +20,8 @@ fn main() { .run(); // This section voluntarily avoids using static_lib_name helpers to be verbatim. - // With verbatim, even these common library names are refused - it wants upstream_native_dep without + // With verbatim, even these common library names are refused + // - it wants upstream_native_dep without // any file extensions. rustc() .input("upstream_native_dep.rs") diff --git a/tests/run-make/output-filename-conflicts-with-directory/rmake.rs b/tests/run-make/output-filename-conflicts-with-directory/rmake.rs index 245bc395f14a..4b5c9e8d1187 100644 --- a/tests/run-make/output-filename-conflicts-with-directory/rmake.rs +++ b/tests/run-make/output-filename-conflicts-with-directory/rmake.rs @@ -1,3 +1,4 @@ +// ignore-tidy-linelength // When the compiled executable would conflict with a directory, a // rustc error should be displayed instead of a verbose and // potentially-confusing linker error. @@ -7,5 +8,7 @@ use run_make_support::{fs_wrapper, rustc}; fn main() { fs_wrapper::create_dir("foo"); - rustc().input("foo.rs").output("foo").run_fail().assert_stderr_contains(r#"the generated executable for the input file "foo.rs" conflicts with the existing directory "foo""#); + rustc().input("foo.rs").output("foo").run_fail().assert_stderr_contains( + r#"the generated executable for the input file "foo.rs" conflicts with the existing directory "foo""#, + ); } From df6d873ae852dfdefafeb9251f5f38ed20e9a2ff Mon Sep 17 00:00:00 2001 From: Oneirical Date: Thu, 13 Jun 2024 16:36:35 -0400 Subject: [PATCH 17/17] rewrite no-builtins-lto to rmake --- .../tidy/src/allowed_run_make_makefiles.txt | 1 - .../lto-avoid-object-duplication/rmake.rs | 5 ++++- tests/run-make/no-builtins-lto/Makefile | 9 --------- tests/run-make/no-builtins-lto/rmake.rs | 20 +++++++++++++++++++ 4 files changed, 24 insertions(+), 11 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/tidy/src/allowed_run_make_makefiles.txt b/src/tools/tidy/src/allowed_run_make_makefiles.txt index a4ca3151baa5..8b91c7d83089 100644 --- a/src/tools/tidy/src/allowed_run_make_makefiles.txt +++ b/src/tools/tidy/src/allowed_run_make_makefiles.txt @@ -146,7 +146,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 018e6a25b925..b0e7494cb513 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 @@ -10,6 +11,8 @@ //@ ignore-windows // Reason: `llvm-objdump`'s output looks different on windows than on other platforms. // Only checking on Unix platforms should suffice. +//FIXME(Oneirical): This could be adapted to work on Windows by checking how +// that output differs. use run_make_support::{llvm_objdump, regex, rust_lib_name, rustc, static_lib_name}; @@ -28,7 +31,7 @@ fn main() { .codegen_units(1) .run(); let syms = llvm_objdump().arg("-t").input(static_lib_name("downstream")).run().stdout_utf8(); - let re = regex::Regex::new(r#"(?m)\s*g\s*F\s.*issue64153_test_function"#).unwrap(); + let re = regex::Regex::new(r#"\s*g\s*F\s.*issue64153_test_function"#).unwrap(); // Count the global instances of `issue64153_test_function`. There'll be 2 // if the `upstream` object file got erroneously included twice. // The line we are testing for with the regex looks something like: diff --git a/tests/run-make/no-builtins-lto/Makefile b/tests/run-make/no-builtins-lto/Makefile deleted file mode 100644 index c8f05d9918b9..000000000000 --- 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 000000000000..8e0c3a636490 --- /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 this file 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")); +}