Skip to content

Commit d720ee4

Browse files
committed
Rejoin kani-verifer into the overall workspace (rust-lang#1058)
* Rejoin kani-verifer into the overall workspace * Instead of copying binaries, let's cargo install the package into the container.
1 parent 59d474d commit d720ee4

File tree

10 files changed

+47
-33
lines changed

10 files changed

+47
-33
lines changed

Diff for: .dockerignore

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
.git
22
firecracker
3-
target
3+
target/debug
4+
target/release
45
build

Diff for: .github/workflows/kani.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ jobs:
8484
- name: Build release bundle
8585
run: |
8686
cargo run -p make-kani-release -- latest
87-
rm -rf target
87+
cargo package -p kani-verifier
8888
8989
- name: Build container test
9090
run: |

Diff for: .gitignore

-1
Original file line numberDiff line numberDiff line change
@@ -86,4 +86,3 @@ tests/kani-multicrate/type-mismatch/mismatch/target
8686
/docs/book
8787
/docs/mdbook*
8888
/kani-*.tar.gz
89-
/src/kani-verifier/target

Diff for: Cargo.lock

+8
Original file line numberDiff line numberDiff line change
@@ -449,6 +449,14 @@ dependencies = [
449449
"toml",
450450
]
451451

452+
[[package]]
453+
name = "kani-verifier"
454+
version = "0.1.0"
455+
dependencies = [
456+
"anyhow",
457+
"home",
458+
]
459+
452460
[[package]]
453461
name = "kani_macros"
454462
version = "0.1.0"

Diff for: Cargo.toml

+1-2
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ members = [
88
"tools/bookrunner",
99
"tools/compiletest",
1010
"tools/make-kani-release",
11+
"src/kani-verifier",
1112
"src/kani-driver",
1213
"src/kani-compiler",
1314
"src/kani_metadata",
@@ -16,8 +17,6 @@ members = [
1617
]
1718

1819
exclude = [
19-
# temporarily exclude `kani-verifier` until we don't have colliding binary names (cargo-kani)
20-
"src/kani-verifier",
2120
"build",
2221
"target",
2322
# dependency tests have their own workspace

Diff for: scripts/ci/Dockerfile.release-bundle-test

+3-2
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ ENV PATH="/root/.cargo/bin:${PATH}"
1414
WORKDIR /tmp/kani
1515
COPY ./tests ./tests
1616
COPY ./kani-latest-x86_64-unknown-linux-gnu.tar.gz ./
17-
COPY ./src/kani-verifier/target/release/kani /root/.cargo/bin/
18-
COPY ./src/kani-verifier/target/release/cargo-kani /root/.cargo/bin/
17+
# Very awkward glob (not regex!) to get `kani-verifier-*` and not `kani-verifier-*.crate`
18+
COPY ./target/package/kani-verifier-*[^e] ./kani-verifier
19+
RUN cargo install --path ./kani-verifier
1920
RUN cargo-kani setup --use-local-bundle ./kani-latest-x86_64-unknown-linux-gnu.tar.gz

Diff for: src/kani-verifier/src/lib.rs

+20
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ pub fn proxy(bin: &str) -> Result<()> {
5858
setup(None)
5959
}
6060
} else {
61+
fail_if_in_dev_environment()?;
6162
if !appears_setup() {
6263
setup(None)?;
6364
}
@@ -70,6 +71,25 @@ fn appears_setup() -> bool {
7071
kani_dir().exists()
7172
}
7273

74+
/// In dev environments, this proxy shouldn't be used.
75+
/// But accidentally using it (with the test suite) can fire off
76+
/// hundreds of HTTP requests trying to download a non-existent release bundle.
77+
/// So if we positively detect a dev environment, raise an error early.
78+
fn fail_if_in_dev_environment() -> Result<()> {
79+
if let Ok(exe) = std::env::current_exe() {
80+
if let Some(path) = exe.parent() {
81+
if path.ends_with("target/debug") || path.ends_with("target/release") {
82+
bail!(
83+
"Running a release-only executable, {}, from a development environment. This is usually caused by PATH including 'target/release' erroneously.",
84+
exe.file_name().unwrap().to_string_lossy()
85+
)
86+
}
87+
}
88+
}
89+
90+
Ok(())
91+
}
92+
7393
/// Sets up Kani by unpacking/installing to `~/.kani/kani-VERSION`
7494
fn setup(use_local_bundle: Option<OsString>) -> Result<()> {
7595
let kani_dir = kani_dir();

Diff for: tools/compiletest/src/main.rs

+12
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,21 @@ fn main() {
4040
let config = parse_config(env::args().collect());
4141

4242
log_config(&config);
43+
add_kani_to_path();
4344
run_tests(config);
4445
}
4546

47+
/// Adds Kani to the current `PATH` environment variable.
48+
fn add_kani_to_path() {
49+
let cwd = env::current_dir().unwrap();
50+
let kani_bin = cwd.join("target").join("debug");
51+
let kani_scripts = cwd.join("scripts");
52+
env::set_var(
53+
"PATH",
54+
format!("{}:{}:{}", kani_scripts.display(), kani_bin.display(), env::var("PATH").unwrap()),
55+
);
56+
}
57+
4658
pub fn parse_config(args: Vec<String>) -> Config {
4759
let mut opts = Options::new();
4860
opts.optopt("", "compile-lib-path", "path to host shared libraries", "PATH")

Diff for: tools/compiletest/src/runtest.rs

-19
Original file line numberDiff line numberDiff line change
@@ -163,21 +163,6 @@ impl<'test> TestCx<'test> {
163163
proc_res.fatal(None, || ());
164164
}
165165

166-
/// Adds kani scripts directory to the `PATH` environment variable.
167-
fn add_kani_dir_to_path(&self, command: &mut Command) {
168-
// If the PATH environment variable is already defined,
169-
if let Some((key, val)) = env::vars().find(|(key, _)| key == "PATH") {
170-
// Add the Kani scripts directory to the PATH.
171-
command.env(key, format!("{}:{}", self.config.kani_dir_path.to_str().unwrap(), val));
172-
} else {
173-
// Otherwise, insert PATH as a new environment variable and set its value to the Kani scripts directory.
174-
command.env(
175-
String::from("PATH"),
176-
String::from(self.config.kani_dir_path.to_str().unwrap()),
177-
);
178-
}
179-
}
180-
181166
/// Runs `kani-compiler` on the test file specified by `self.testpaths.file`. An
182167
/// error message is printed to stdout if the check result is not expected.
183168
fn check(&self) {
@@ -187,7 +172,6 @@ impl<'test> TestCx<'test> {
187172
.args(self.props.compile_flags.clone())
188173
.args(["-Z", "no-codegen"])
189174
.arg(&self.testpaths.file);
190-
self.add_kani_dir_to_path(&mut rustc);
191175
let proc_res = self.compose_and_run(rustc);
192176
if self.props.kani_panic_step == Some(KaniFailStep::Check) {
193177
if proc_res.status.success() {
@@ -211,7 +195,6 @@ impl<'test> TestCx<'test> {
211195
.args(["--out-dir"])
212196
.arg(self.output_base_dir())
213197
.arg(&self.testpaths.file);
214-
self.add_kani_dir_to_path(&mut rustc);
215198
let proc_res = self.compose_and_run(rustc);
216199
if self.props.kani_panic_step == Some(KaniFailStep::Codegen) {
217200
if proc_res.status.success() {
@@ -325,7 +308,6 @@ impl<'test> TestCx<'test> {
325308
if "expected" != self.testpaths.file.file_name().unwrap() {
326309
cargo.args(["--harness", function_name]);
327310
}
328-
self.add_kani_dir_to_path(&mut cargo);
329311
let proc_res = self.compose_and_run(cargo);
330312
let expected = fs::read_to_string(self.testpaths.file.clone()).unwrap();
331313
self.verify_output(&proc_res, &expected);
@@ -352,7 +334,6 @@ impl<'test> TestCx<'test> {
352334
kani.arg("--enable-unstable").arg("--cbmc-args").args(&self.props.cbmc_flags);
353335
}
354336

355-
self.add_kani_dir_to_path(&mut kani);
356337
self.compose_and_run(kani)
357338
}
358339

Diff for: tools/make-kani-release/src/main.rs

-7
Original file line numberDiff line numberDiff line change
@@ -64,13 +64,6 @@ fn prebundle(dir: &Path) -> Result<()> {
6464
// Before we begin, ensure Kani is built successfully in release mode.
6565
Command::new("cargo").args(&["build", "--release"]).run()?;
6666

67-
// TODO: temporarily, until cargo-kani is renamed kani-driver, we need to build this thing not in our workspace.
68-
// This isn't actually used by this script, but by the Dockerfile that tests this script
69-
Command::new("cargo")
70-
.args(&["build", "--release"])
71-
.current_dir(Path::new("src/kani-verifier"))
72-
.run()?;
73-
7467
Ok(())
7568
}
7669

0 commit comments

Comments
 (0)