Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion kani-driver/src/call_cargo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
use crate::args::VerificationArgs;
use crate::call_single_file::{LibConfig, to_rustc_arg};
use crate::project::Artifact;
use crate::session::{KaniSession, lib_folder, lib_no_core_folder, setup_cargo_command};
use crate::session::{
KaniSession, get_cargo_path, lib_folder, lib_no_core_folder, setup_cargo_command,
};
use crate::util;
use anyhow::{Context, Result, bail};
use cargo_metadata::diagnostic::{Diagnostic, DiagnosticLevel};
Expand Down Expand Up @@ -247,6 +249,10 @@ crate-type = ["lib"]
pub fn cargo_metadata(&self, build_target: &str) -> Result<Metadata> {
let mut cmd = MetadataCommand::new();

// Use Kani's toolchain when running `cargo metadata`
let cargo_path = get_cargo_path().unwrap();
cmd.cargo_path(cargo_path);

// restrict metadata command to host platform. References:
// https://github.com/rust-lang/rust-analyzer/issues/6908
// https://github.com/rust-lang/rust-analyzer/pull/6912
Expand Down
14 changes: 14 additions & 0 deletions kani-driver/src/session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -439,3 +439,17 @@ pub fn setup_cargo_command() -> Result<Command> {

Ok(cmd)
}

// Get the cargo path corresponding to the toolchain version in rust-toolchain.toml.
// If kani is being run in developer mode, then we use the compile-time toolchain, i.e. the one used during cargo build-dev.
// For release versions of Kani, we use a version of cargo that's in the toolchain that's been symlinked during `cargo-kani` setup.
pub fn get_cargo_path() -> Result<PathBuf> {
let install_type = InstallType::new()?;

let cargo_path = match install_type {
InstallType::DevRepo(_) => env!("CARGO").into(),
InstallType::Release(kani_dir) => kani_dir.join("toolchain").join("bin").join("cargo"),
};

Ok(cargo_path)
}
Loading