From 831b85da86ed46d06bc2e96fcd76ca1b6710005a Mon Sep 17 00:00:00 2001 From: Julian Frimmel Date: Wed, 18 Sep 2024 20:35:36 +0200 Subject: [PATCH 1/5] Format the code to comply with `rustfmt` standards This was accidentally introduced with #77. --- src/driver.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/driver.rs b/src/driver.rs index 377f0df..1248357 100644 --- a/src/driver.rs +++ b/src/driver.rs @@ -20,7 +20,10 @@ pub fn driver() -> io::Result { let cargo = env::var_os("CARGO").expect("CARGO environment variable is not set"); /* get the output of `cargo version -v` */ - let rustc_info = Command::new(&cargo).args(&["version", "-v"]).output()?.stdout; + let rustc_info = Command::new(&cargo) + .args(&["version", "-v"]) + .output()? + .stdout; /* get the host information (all after the "host: ..." line) */ let host = rustc_info From 6578dcdb7e1b20a8773093f09785ff58eabab4de Mon Sep 17 00:00:00 2001 From: Julian Frimmel Date: Wed, 18 Sep 2024 20:37:09 +0200 Subject: [PATCH 2/5] Keep the code compiling with the current MSRV The previous code was cleaner, but is not yet supported on Rust 1.51. This was accidentally introduced with #77. --- src/driver.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/driver.rs b/src/driver.rs index 1248357..d87b86d 100644 --- a/src/driver.rs +++ b/src/driver.rs @@ -39,7 +39,7 @@ pub fn driver() -> io::Result { .collect(); /* convert to runner env variable */ - let host = host.replace(&['-', '.'], "_").to_uppercase(); + let host = host.replace('-', "_").replace('.', "_").to_uppercase(); let runner = format!("CARGO_TARGET_{}_RUNNER", host); /* cargo run with a custom runner */ From 39975e3e38bfe4592f7167bfd8d28fe108c1197b Mon Sep 17 00:00:00 2001 From: Julian Frimmel Date: Wed, 18 Sep 2024 20:47:48 +0200 Subject: [PATCH 3/5] Support older `cargo` versions (up to MSRV) While it makes sense to be able to build this project with old versions of Rust, it also needs to be able to run the tool successfully. There- fore this commit introduces a fallback for older Rust versions, where `cargo` does not include the `host:`-field in the output (the 1.51 cargo outputs): cargo 1.51.0 (43b129a20 2021-03-16) release: 1.51.0 commit-hash: 43b129a20fbf1ede0df411396ccf0c024bf34134 commit-date: 2021-03-16 --- src/driver.rs | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/driver.rs b/src/driver.rs index d87b86d..e42e74e 100644 --- a/src/driver.rs +++ b/src/driver.rs @@ -3,6 +3,7 @@ use std::env; use std::ffi::OsString; use std::io; +use std::path::Path; use std::process::Command; /// The prefix line for the target host output. @@ -18,19 +19,23 @@ const HOST_PREFIX: &[u8] = b"host: "; /// executed. pub fn driver() -> io::Result { let cargo = env::var_os("CARGO").expect("CARGO environment variable is not set"); + let rustc = Path::new(&cargo).with_file_name("rustc"); /* get the output of `cargo version -v` */ - let rustc_info = Command::new(&cargo) + let cargo_info = Command::new(&cargo) .args(&["version", "-v"]) .output()? .stdout; + /* old cargo versions don't include the host-field, so fall back to rustc */ + let rustc_info = Command::new(rustc).arg("-vV").output()?.stdout; + let info = [cargo_info, rustc_info].concat(); /* get the host information (all after the "host: ..." line) */ - let host = rustc_info + let host = info .windows(HOST_PREFIX.len()) .position(|window| window == HOST_PREFIX) - .expect("Host information not present in `cargo version -v`"); - let host: String = rustc_info + .expect("Host information not present in `cargo version -v` or `rustc -vV"); + let host: String = info .into_iter() .skip(host) .skip(HOST_PREFIX.len()) From 517d24796e9edcd348bfdcd14fc5e26ae4551f17 Mon Sep 17 00:00:00 2001 From: Julian Frimmel Date: Wed, 18 Sep 2024 20:50:28 +0200 Subject: [PATCH 4/5] Make test runnable on Rust 1.51 --- tests/corpus/issue-74.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/corpus/issue-74.rs b/tests/corpus/issue-74.rs index 93d38e5..2b31425 100644 --- a/tests/corpus/issue-74.rs +++ b/tests/corpus/issue-74.rs @@ -29,9 +29,9 @@ fn ex4() { let (a, b) = split_at_mut(r, 4); - println!("a={a:?} (should be [1, 2, 3, 4]"); + println!("a={:?} (should be [1, 2, 3, 4]", a); drop(a); - println!("b={b:?} (should be [5, 6])"); + println!("b={:?} (should be [5, 6])", b); // assert_eq!(a, &mut[1, 2, 3, 4]); // assert_eq!(b, &mut[5, 6]); } From fcf3d78d834109e63d81a843b228639d0e2ef160 Mon Sep 17 00:00:00 2001 From: Julian Frimmel Date: Wed, 18 Sep 2024 20:51:52 +0200 Subject: [PATCH 5/5] Rust tests also with MSRV (in the `msrv.yaml` job) --- .github/workflows/msrv.yaml | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/.github/workflows/msrv.yaml b/.github/workflows/msrv.yaml index c638b29..58b4247 100644 --- a/.github/workflows/msrv.yaml +++ b/.github/workflows/msrv.yaml @@ -5,10 +5,13 @@ env: CARGO_TERM_COLOR: always MSRV: "1.51" jobs: - # build but don't test the crate with the Minimum Supported Rust Version + # Build and test the tool with the Minimum Supported Rust Version msrv: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 + - name: Install valgrind + run: sudo apt install valgrind - run: rustup update $MSRV && rustup default $MSRV - - run: cargo check + - name: Run tests + run: cargo test