Skip to content

Commit 2402892

Browse files
authored
Build and include kani-cov in the bundle (#3641)
This PR adds another step to the `cargo bundle` command so that `kani-cov` is built in release mode and then included in the bundle. This will allow users to call `kani-cov` once Kani has been setup. I have manually tested it works by running: ``` cargo bundle tar -xzf kani-0.56.0-x86_64-unknown-linux-gnu.tar.gz ls kani-0.56.0/bin/ ``` This showed `kani-cov` along with other binaries like `cbmc` and `kissat`. By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 and MIT licenses.
1 parent ab2cb50 commit 2402892

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

tools/build-kani/src/main.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@
1010
mod parser;
1111
mod sysroot;
1212

13-
use crate::sysroot::{build_bin, build_lib, kani_no_core_lib, kani_playback_lib, kani_sysroot_lib};
13+
use crate::sysroot::{
14+
build_bin, build_lib, build_tools, kani_no_core_lib, kani_playback_lib, kani_sysroot_lib,
15+
};
1416
use anyhow::{Result, bail};
1517
use clap::Parser;
1618
use std::{ffi::OsString, path::Path, process::Command};
@@ -72,6 +74,8 @@ fn prebundle(dir: &Path) -> Result<()> {
7274
bail!("Couldn't find the 'cbmc' binary to include in the release bundle.");
7375
}
7476

77+
build_tools(&["--release"])?;
78+
7579
// Before we begin, ensure Kani is built successfully in release mode.
7680
// And that libraries have been built too.
7781
build_lib(&build_bin(&["--release"])?)
@@ -86,6 +90,7 @@ fn bundle_kani(dir: &Path) -> Result<()> {
8690
let release = Path::new("./target/release");
8791
cp(&release.join("kani-driver"), &bin)?;
8892
cp(&release.join("kani-compiler"), &bin)?;
93+
cp(&release.join("kani-cov"), &bin)?;
8994

9095
// 2. Kani scripts
9196
let scripts = dir.join("scripts");

tools/build-kani/src/sysroot.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -278,3 +278,17 @@ pub fn build_bin<T: AsRef<OsStr>>(extra_args: &[T]) -> Result<PathBuf> {
278278
.or(Err(format_err!("Failed to build binaries.")))?;
279279
Ok(out_dir)
280280
}
281+
282+
/// Build tool binaries with the extra arguments provided.
283+
/// At present, the only tool we build for the bundle is `kani-cov`, but this
284+
/// could include other tools in the future.
285+
pub fn build_tools<T: AsRef<OsStr>>(extra_args: &[T]) -> Result<()> {
286+
let args = ["-p", "kani-cov"];
287+
Command::new("cargo")
288+
.arg("build")
289+
.args(extra_args)
290+
.args(args)
291+
.run()
292+
.or(Err(format_err!("Failed to build tool binaries.")))?;
293+
Ok(())
294+
}

0 commit comments

Comments
 (0)