Skip to content

Commit

Permalink
test: improve rust version setup (#178)
Browse files Browse the repository at this point in the history
  • Loading branch information
camshaft authored Sep 23, 2023
1 parent a9349f6 commit 7e3fa73
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 17 deletions.
6 changes: 2 additions & 4 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -86,12 +86,10 @@ jobs:
# kani isn't compatible with sccache
wrapper: false

- name: Setup target rustc
if: matrix.rust != 'stable' && matrix.rust != 'nightly'
run: echo "TARGET_RUSTC=${{ matrix.rust }}" >> $GITHUB_ENV

- name: Run tests
run: cargo +stable run
env:
BOLERO_RUSTUP_TOOLCHAIN: "${{ matrix.rust }}"

kani:
runs-on: ubuntu-latest
Expand Down
2 changes: 1 addition & 1 deletion tests/src/bolero.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use xshell::{cmd, Shell};
pub fn test() -> Result {
let rust_version = env::rustc();

let supports_arbitrary = rust_version.major > 1 && rust_version.minor >= 63;
let supports_arbitrary = rust_version.map_or(true, |v| v.major > 1 && v.minor >= 63);

Test { supports_arbitrary }.run()?;

Expand Down
2 changes: 1 addition & 1 deletion tests/src/cargo_bolero.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use xshell::{cmd, Shell};
pub fn test() -> Result {
let rust_version = env::rustc();

let use_stable = rust_version.major <= 1 && rust_version.minor <= 65;
let use_stable = rust_version.map_or(false, |v| v.major > 1 && v.minor <= 65);

Test { use_stable }.run()?;

Expand Down
4 changes: 1 addition & 3 deletions tests/src/engines.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@ use crate::{env, Result};
use xshell::{cmd, Shell};

pub fn test() -> Result {
let rust_version = env::rustc();

let is_nightly = rust_version.build.as_str() == "nightly";
let is_nightly = env::rustc_build().map_or(false, |b| b == "nightly");

for engine in ["libfuzzer", "afl", "honggfuzz", "kani"] {
// TODO fix honggfuzz
Expand Down
23 changes: 15 additions & 8 deletions tests/src/env.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,25 @@ pub fn examples() -> &'static str {
concat!(env!("CARGO_MANIFEST_DIR"), "/../examples")
}

pub fn rustc() -> Rustc {
if let Ok(rustc) = std::env::var("TARGET_RUSTC") {
rustc_version::Version::parse(&rustc).unwrap()
pub fn rustc() -> Option<Rustc> {
if let Ok(rustc) = std::env::var("BOLERO_RUSTUP_TOOLCHAIN") {
rustc_version::Version::parse(&rustc).ok()
} else {
rustc_version::version().unwrap()
rustc_version::version().ok()
}
}

pub fn rustc_build() -> Option<String> {
if let Some(rustc) = rustc() {
Some(rustc.build.as_str().to_string())
} else {
std::env::var("BOLERO_RUSTUP_TOOLCHAIN").ok()
}
}

pub fn configure_toolchain(sh: &xshell::Shell) {
if let Ok(rustc) = std::env::var("TARGET_RUSTC") {
xshell::cmd!(sh, "rustup override set {rustc}")
.run()
.unwrap();
if let Ok(rustc) = std::env::var("BOLERO_RUSTUP_TOOLCHAIN") {
sh.set_var("RUSTUP_TOOLCHAIN", rustc);
}
let _ = xshell::cmd!(sh, "rustc -vV").run();
}

0 comments on commit 7e3fa73

Please sign in to comment.