Skip to content

Commit c314879

Browse files
author
Carolyn Zech
committed
only use env!(CARGO) for development run
1 parent 1ed90a4 commit c314879

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed

kani-driver/src/call_cargo.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@
44
use crate::args::VerificationArgs;
55
use crate::call_single_file::{LibConfig, to_rustc_arg};
66
use crate::project::Artifact;
7-
use crate::session::{KaniSession, lib_folder, lib_no_core_folder, setup_cargo_command};
7+
use crate::session::{
8+
KaniSession, get_cargo_path, lib_folder, lib_no_core_folder, setup_cargo_command,
9+
};
810
use crate::util;
911
use anyhow::{Context, Result, bail};
1012
use cargo_metadata::diagnostic::{Diagnostic, DiagnosticLevel};
@@ -248,7 +250,8 @@ crate-type = ["lib"]
248250
let mut cmd = MetadataCommand::new();
249251

250252
// Use Kani's toolchain when running `cargo metadata`
251-
cmd.cargo_path(env!("CARGO"));
253+
let cargo_path = get_cargo_path().unwrap();
254+
cmd.cargo_path(cargo_path);
252255

253256
// restrict metadata command to host platform. References:
254257
// https://github.com/rust-lang/rust-analyzer/issues/6908

kani-driver/src/session.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -439,3 +439,17 @@ pub fn setup_cargo_command() -> Result<Command> {
439439

440440
Ok(cmd)
441441
}
442+
443+
// Get the cargo path corresponding to the toolchain version in rust-toolchain.toml.
444+
// If kani is being run in developer mode, then we use the compile-time toolchain, i.e. the one used during cargo build-dev.
445+
// For release versions of Kani, we use a version of cargo that's in the toolchain that's been symlinked during `cargo-kani` setup.
446+
pub fn get_cargo_path() -> Result<PathBuf> {
447+
let install_type = InstallType::new()?;
448+
449+
let cargo_path = match install_type {
450+
InstallType::DevRepo(_) => env!("CARGO").into(),
451+
InstallType::Release(kani_dir) => kani_dir.join("toolchain").join("bin").join("cargo"),
452+
};
453+
454+
Ok(cargo_path)
455+
}

0 commit comments

Comments
 (0)