diff --git a/kani-driver/src/call_cargo.rs b/kani-driver/src/call_cargo.rs index 9097713a0016..05849b918316 100644 --- a/kani-driver/src/call_cargo.rs +++ b/kani-driver/src/call_cargo.rs @@ -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, bundled_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}; @@ -241,6 +243,9 @@ crate-type = ["lib"] pub fn cargo_metadata(&self, build_target: &str) -> Result { let mut cmd = MetadataCommand::new(); + if let Some(cargo_path) = bundled_cargo_path()? { + cmd.cargo_path(cargo_path); + } // restrict metadata command to host platform. References: // https://github.com/rust-lang/rust-analyzer/issues/6908 diff --git a/kani-driver/src/session.rs b/kani-driver/src/session.rs index 6645db06e45e..f57ada9521af 100644 --- a/kani-driver/src/session.rs +++ b/kani-driver/src/session.rs @@ -442,3 +442,11 @@ pub fn setup_cargo_command() -> Result { Ok(cmd) } + +pub fn bundled_cargo_path() -> Result> { + if let InstallType::Release(kani_dir) = InstallType::new()? { + Ok(Some(kani_dir.join("toolchain").join("bin").join("cargo"))) + } else { + Ok(None) + } +}