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
4 changes: 3 additions & 1 deletion src/doc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,9 @@ fn generate_single_target_doc(

let verus_target_dir = verus::get_verus_target_dir();
let target_dir = verus::get_target_dir();
let mut cmd = Command::new("rustdoc");
let rustdoc = verus::get_rustdoc();

let mut cmd = Command::new(&rustdoc);

// Set VERUSDOC environment variable based on verus_conds flags
let verus_doc_value = if verus_conds || verus_conds_debug {
Expand Down
18 changes: 15 additions & 3 deletions src/executable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,25 @@ use crate::files;
use std::env;
use std::path::{Path, PathBuf};

#[cfg(target_os = "windows")]
const EXE_SUFFIX: &str = ".exe";
#[cfg(not(target_os = "windows"))]
const EXE_SUFFIX: &str = "";

fn bin_name(binary: &Path) -> PathBuf {
PathBuf::from(format!("{}{}", binary.display(), EXE_SUFFIX))
}

pub fn locate_from_path<P>(binary: &P) -> Option<PathBuf>
where
P: AsRef<Path> + ?Sized,
{
let binary = bin_name(binary.as_ref());
let path = env::var("PATH").ok()?;
let paths = env::split_paths(&path);
paths
.filter_map(|dir| {
let full = dir.join(binary);
let full = dir.join(&binary);
if full.is_file() {
Some(full)
} else {
Expand All @@ -26,10 +36,11 @@ where
P: AsRef<Path> + ?Sized,
D: AsRef<Path>,
{
let binary = bin_name(binary.as_ref());
hints
.iter()
.filter_map(|hint| {
let full = hint.as_ref().join(binary);
let full = hint.as_ref().join(&binary);
if full.is_file() {
Some(full)
} else {
Expand All @@ -43,11 +54,12 @@ pub fn locate_from_env<P>(binary: &P, env_var: &str) -> Option<PathBuf>
where
P: AsRef<Path> + ?Sized,
{
let binary = bin_name(binary.as_ref());
let env_path = env::var(env_var).ok()?;
let paths = env::split_paths(&env_path);
paths
.filter_map(|dir| {
let full = dir.join(binary);
let full = dir.join(&binary);
if full.is_file() {
Some(full)
} else {
Expand Down
68 changes: 1 addition & 67 deletions src/verus.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,66 +24,27 @@ pub type DynError = Box<dyn std::error::Error>;
/// It also provides a method to get the root directory of the project.
///

#[cfg(target_os = "windows")]
pub const VERUS_BIN: &str = "verus.exe";
#[cfg(not(target_os = "windows"))]
pub const VERUS_BIN: &str = "verus";

#[cfg(target_os = "windows")]
pub const CARGO_VERUS_BIN: &str = "cargo-verus.exe";
#[cfg(not(target_os = "windows"))]
pub const CARGO_VERUS_BIN: &str = "cargo-verus";
pub const CARGO_VERUS_ENV: &str = "CARGO_VERUS_PATH";

pub const VERUS_HINT_RELEASE: &str = "tools/verus/source/target-verus/release";
pub const VERUS_HINT: &str = "tools/verus/source/target-verus/debug";
pub const VERUS_EVN: &str = "VERUS_PATH";
pub const CARGO_VERUS_ENV: &str = "CARGO_VERUS_PATH";

#[cfg(target_os = "windows")]
pub const VERUSFMT_BIN: &str = "verusfmt.exe";
#[cfg(not(target_os = "windows"))]
pub const VERUSFMT_BIN: &str = "verusfmt";

#[cfg(target_os = "windows")]
pub const RUST_VERIFY: &str = "rust_verify.exe";
#[cfg(not(target_os = "windows"))]
pub const RUST_VERIFY: &str = "rust_verify";

#[cfg(target_os = "windows")]
pub const Z3_BIN: &str = "z3.exe";
#[cfg(not(target_os = "windows"))]
pub const Z3_BIN: &str = "z3";

#[cfg(target_os = "windows")]
pub const DYN_LIB: &str = ".dll";
#[cfg(target_os = "linux")]
pub const DYN_LIB: &str = ".so";
#[cfg(target_os = "macos")]
pub const DYN_LIB: &str = ".dylib";

pub const Z3_HINT: &str = "tools/verus/source";
pub const Z3_EVN: &str = "VERUS_Z3_PATH";

pub const RUSTDOC_BIN: &str = "rustdoc";

#[cfg(target_os = "windows")]
pub const VERUSDOC_BIN: &str = "verusdoc.exe";
#[cfg(not(target_os = "windows"))]
pub const VERUSDOC_BIN: &str = "verusdoc";
pub const VERUSDOC_HINT_RELEASE: &str = "tools/verus/source/target/release";
pub const VERUSDOC_HINT: &str = "tools/verus/source/target/debug";

#[memoize]
pub fn get_verus(release: bool) -> PathBuf {
executable::locate(
VERUS_BIN,
Some(VERUS_EVN),
if release { &[VERUS_HINT_RELEASE] } else {&[VERUS_HINT]},
).unwrap_or_else(|| {
error!("Cannot find the Verus binary, please set the VERUS_PATH environment variable or add it to your PATH");
})
}

#[memoize]
pub fn get_cargo_verus(release: bool) -> PathBuf {
executable::locate(
Expand All @@ -102,33 +63,6 @@ pub fn get_cargo_verus(release: bool) -> PathBuf {
})
}

#[memoize]
pub fn get_rust_verify(release: bool) -> PathBuf {
executable::locate(
RUST_VERIFY,
None,
if release {
&[VERUS_HINT_RELEASE]
} else {
&[VERUS_HINT]
},
)
.unwrap_or_else(|| {
error!("Cannot find the Verus `rust_verify` binary.");
})
}

#[memoize]
pub fn get_z3() -> PathBuf {
executable::locate(
Z3_BIN,
Some(Z3_EVN),
&[Z3_HINT],
).unwrap_or_else(|| {
error!("Cannot find the Z3 binary, please set the VERUS_Z3_PATH environment variable or add it to your PATH");
})
}

#[memoize]
pub fn get_rustdoc() -> PathBuf {
executable::locate(
Expand Down
Loading