Skip to content

Commit

Permalink
Merge pull request #94 from jfrimmel/support-running-msrv
Browse files Browse the repository at this point in the history
Follow-up to #77: make sure, that everything works with current MSRV
  • Loading branch information
jfrimmel authored Sep 18, 2024
2 parents 3d1d6a9 + fcf3d78 commit 93069e5
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 9 deletions.
7 changes: 5 additions & 2 deletions .github/workflows/msrv.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
18 changes: 13 additions & 5 deletions src/driver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -18,16 +19,23 @@ const HOST_PREFIX: &[u8] = b"host: ";
/// executed.
pub fn driver() -> io::Result<bool> {
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).args(&["version", "-v"]).output()?.stdout;
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())
Expand All @@ -36,7 +44,7 @@ pub fn driver() -> io::Result<bool> {
.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 */
Expand Down
4 changes: 2 additions & 2 deletions tests/corpus/issue-74.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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]);
}
Expand Down

0 comments on commit 93069e5

Please sign in to comment.