From 84146b372ab5b9bc3a6e21719750d7f2f66ceb8d Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Sun, 23 Jun 2024 15:11:57 +0200 Subject: [PATCH 1/3] Add `ar_command` in `run_make_support` --- src/tools/run-make-support/src/lib.rs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/tools/run-make-support/src/lib.rs b/src/tools/run-make-support/src/lib.rs index 487132683e920..14b4f14e8f0cd 100644 --- a/src/tools/run-make-support/src/lib.rs +++ b/src/tools/run-make-support/src/lib.rs @@ -61,6 +61,14 @@ pub fn target() -> String { env_var("TARGET") } +/// `AR` +#[track_caller] +#[must_use] +pub fn ar_command() -> Command { + let ar_path = env_var("AR"); + Command::new(ar_path) +} + /// Check if target is windows-like. #[must_use] pub fn is_windows() -> bool { From 449cde32ade77758359fcd83e0f6ac7a191b70f0 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Sun, 23 Jun 2024 15:12:17 +0200 Subject: [PATCH 2/3] Migrate `run-make/invalid-library` to `rmake.rs` --- src/tools/tidy/src/allowed_run_make_makefiles.txt | 1 - tests/run-make/invalid-library/Makefile | 6 ------ tests/run-make/invalid-library/rmake.rs | 8 ++++++++ 3 files changed, 8 insertions(+), 7 deletions(-) delete mode 100644 tests/run-make/invalid-library/Makefile create mode 100644 tests/run-make/invalid-library/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 cb68589d8a4c2..2bc3acc58cb22 100644 --- a/src/tools/tidy/src/allowed_run_make_makefiles.txt +++ b/src/tools/tidy/src/allowed_run_make_makefiles.txt @@ -54,7 +54,6 @@ run-make/incr-add-rust-src-component/Makefile run-make/incr-foreign-head-span/Makefile run-make/interdependent-c-libraries/Makefile run-make/intrinsic-unreachable/Makefile -run-make/invalid-library/Makefile run-make/issue-107094/Makefile run-make/issue-109934-lto-debuginfo/Makefile run-make/issue-14698/Makefile diff --git a/tests/run-make/invalid-library/Makefile b/tests/run-make/invalid-library/Makefile deleted file mode 100644 index 910d9af7b0564..0000000000000 --- a/tests/run-make/invalid-library/Makefile +++ /dev/null @@ -1,6 +0,0 @@ -include ../tools.mk - -all: - touch $(TMPDIR)/lib.rmeta - $(AR) crus $(TMPDIR)/libfoo-ffffffff-1.0.rlib $(TMPDIR)/lib.rmeta - $(RUSTC) foo.rs 2>&1 | $(CGREP) "found invalid metadata" diff --git a/tests/run-make/invalid-library/rmake.rs b/tests/run-make/invalid-library/rmake.rs new file mode 100644 index 0000000000000..e76b3f3b5d223 --- /dev/null +++ b/tests/run-make/invalid-library/rmake.rs @@ -0,0 +1,8 @@ +use run_make_support::fs_wrapper::create_file; +use run_make_support::{ar_command, rustc}; + +fn main() { + create_file("lib.rmeta"); + ar_command().arg("crus").arg("libfoo-ffffffff-1.0.rlib").arg("lib.rmeta").run(); + rustc().input("foo.rs").run_fail().assert_stderr_contains("found invalid metadata"); +} From 3394fe89d8a6b12ca86140724a09c2c9360a5684 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Mon, 24 Jun 2024 11:47:20 +0200 Subject: [PATCH 3/3] Add `ar` command in `run-make-support` --- Cargo.lock | 7 +++++++ src/tools/run-make-support/Cargo.toml | 1 + src/tools/run-make-support/src/lib.rs | 13 +++++++++---- tests/run-make/invalid-library/rmake.rs | 4 ++-- 4 files changed, 19 insertions(+), 6 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 6d0563839aedf..e977964b72c01 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -228,6 +228,12 @@ dependencies = [ "backtrace", ] +[[package]] +name = "ar" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d67af77d68a931ecd5cbd8a3b5987d63a1d1d1278f7f6a60ae33db485cdebb69" + [[package]] name = "ar_archive_writer" version = "0.2.0" @@ -3394,6 +3400,7 @@ dependencies = [ name = "run_make_support" version = "0.2.0" dependencies = [ + "ar", "gimli 0.28.1", "object 0.34.0", "regex", diff --git a/src/tools/run-make-support/Cargo.toml b/src/tools/run-make-support/Cargo.toml index 2f7f51442f164..e3837a2f8cc4e 100644 --- a/src/tools/run-make-support/Cargo.toml +++ b/src/tools/run-make-support/Cargo.toml @@ -9,3 +9,4 @@ similar = "2.5.0" wasmparser = "0.118.2" regex = "1.8" # 1.8 to avoid memchr 2.6.0, as 2.5.0 is pinned in the workspace gimli = "0.28.1" +ar = "0.9.0" diff --git a/src/tools/run-make-support/src/lib.rs b/src/tools/run-make-support/src/lib.rs index 14b4f14e8f0cd..771cda630af6a 100644 --- a/src/tools/run-make-support/src/lib.rs +++ b/src/tools/run-make-support/src/lib.rs @@ -63,10 +63,15 @@ pub fn target() -> String { /// `AR` #[track_caller] -#[must_use] -pub fn ar_command() -> Command { - let ar_path = env_var("AR"); - Command::new(ar_path) +pub fn ar(inputs: &[impl AsRef], output_path: impl AsRef) { + let output = fs::File::create(&output_path).expect(&format!( + "the file in path \"{}\" could not be created", + output_path.as_ref().display() + )); + let mut builder = ar::Builder::new(output); + for input in inputs { + builder.append_path(input).unwrap(); + } } /// Check if target is windows-like. diff --git a/tests/run-make/invalid-library/rmake.rs b/tests/run-make/invalid-library/rmake.rs index e76b3f3b5d223..750fcd05c8ac5 100644 --- a/tests/run-make/invalid-library/rmake.rs +++ b/tests/run-make/invalid-library/rmake.rs @@ -1,8 +1,8 @@ use run_make_support::fs_wrapper::create_file; -use run_make_support::{ar_command, rustc}; +use run_make_support::{ar, rustc}; fn main() { create_file("lib.rmeta"); - ar_command().arg("crus").arg("libfoo-ffffffff-1.0.rlib").arg("lib.rmeta").run(); + ar(&["lib.rmeta"], "libfoo-ffffffff-1.0.rlib"); rustc().input("foo.rs").run_fail().assert_stderr_contains("found invalid metadata"); }