From e1b35d50db5b65bdc68e09793742a48af951e628 Mon Sep 17 00:00:00 2001 From: jaisnan Date: Wed, 13 Mar 2024 21:03:46 +0000 Subject: [PATCH] Add CI test for --use-local-toolchain --- .github/workflows/check-setup.yml | 78 +++++++++++++++++++++++++++++++ src/setup.rs | 6 ++- 2 files changed, 83 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/check-setup.yml diff --git a/.github/workflows/check-setup.yml b/.github/workflows/check-setup.yml new file mode 100644 index 000000000000..ce25789aa6a8 --- /dev/null +++ b/.github/workflows/check-setup.yml @@ -0,0 +1,78 @@ +# Copyright Kani Contributors +# SPDX-License-Identifier: Apache-2.0 OR MIT +# +# Job to check if the setup flow and associated flags are working as expected +# +# This will run everytime there's a change to main +name: Check Setup +on: + pull_request: + push: + branches: + - 'main' + +jobs: + test-use-local-toolchain: + name: TestLocalToolchain + strategy: + matrix: + os: [macos-13, ubuntu-20.04, ubuntu-22.04] + include: + - os: macos-13 + rust_target: x86_64-apple-darwin + - os: ubuntu-20.04 + rust_target: x86_64-unknown-linux-gnu + - os: ubuntu-22.04 + rust_target: x86_64-unknown-linux-gnu + runs-on: ${{ matrix.os }} + steps: + - name: Checkout Kani + uses: actions/checkout@v4 + with: + fetch-depth: '0' + submodules: 'true' + + - name: Check download + run: | + ls -lh . + + - name: Install from bundle + run: | + cargo install --locked --path . + + - name: Extract nightly version date from rust-toolchain.toml + id: extract-date + run: | + DATE=$(grep 'channel' rust-toolchain.toml | cut -d '=' -f2 | tr -d ' "' | cut -d'-' -f2-) + echo "Nightly date: $DATE" + echo "DATE=$DATE" >> $GITHUB_ENV + + - name: Remove installed Rust toolchain + run: rustup toolchain remove nightly-$DATE + + - name: Create a custom toolchain directory + run: mkdir -p ${{ github.workspace }}/custom_toolchain + + - name: Fetch the nightly tarball + run: | + echo "Downloading Rust toolchain from rust server." + curl --proto '=https' --tlsv1.2 -O https://static.rust-lang.org/dist/$DATE/rust-nightly-${{ matrix.rust_target }}.tar.gz + tar -xzf rust-nightly-${{ matrix.rust_target }}.tar.gz + ./rust-nightly-${{ matrix.rust_target }}/install.sh --prefix=${{ github.workspace }}/custom_toolchain + + - name: Ensure installation is correct + run: | + cargo kani setup --use-local-toolchain ${{ github.workspace }}/custom_toolchain/ + + - name: Ensure that the rustup toolchain is not present + run: ls -la ~/.rustup/toolchains/ + + - name: Run tests + run: | + ls ./tests/cargo-ui/ + for dir in function multiple-harnesses verbose; do + >&2 echo "Running test $dir" + pushd ./tests/cargo-ui/$dir + cargo kani + popd + done diff --git a/src/setup.rs b/src/setup.rs index 050a8e166334..00e9481db172 100644 --- a/src/setup.rs +++ b/src/setup.rs @@ -145,7 +145,6 @@ pub(crate) fn get_rust_toolchain_version(kani_dir: &Path) -> Result { fn setup_rust_toolchain(kani_dir: &Path, use_local_toolchain: Option) -> Result { // Currently this means we require the bundle to have been unpacked first! let toolchain_version = get_rust_toolchain_version(kani_dir)?; - println!("[3/5] Installing rust toolchain version: {}", &toolchain_version); // Symlink to a local toolchain if the user explicitly requests if let Some(local_toolchain_path) = use_local_toolchain { @@ -153,10 +152,15 @@ fn setup_rust_toolchain(kani_dir: &Path, use_local_toolchain: Option) // TODO: match the version against which kani was built // Issue: https://github.com/model-checking/kani/issues/3060 symlink_rust_toolchain(toolchain_path, kani_dir)?; + println!( + "[3/5] Installing rust toolchain from path provided: {}", + &toolchain_path.to_string_lossy() + ); return Ok(toolchain_version); } // This is the default behaviour when no explicit path to a toolchain is mentioned + println!("[3/5] Installing rust toolchain version: {}", &toolchain_version); Command::new("rustup").args(["toolchain", "install", &toolchain_version]).run()?; let toolchain = home::rustup_home()?.join("toolchains").join(&toolchain_version); symlink_rust_toolchain(&toolchain, kani_dir)?;