Skip to content

Commit 870e37b

Browse files
celinvaltedinski
authored andcommitted
Only compile as binary target if verifying main function (rust-lang#869)
* Only compile as binary target if verifying main function In order to verify a harness using `kani` command, user either have to have a `main` function defined in their crate or they have to set the env variable RUSTFLAGS to include --crate-type lib. With these changes, Kani will pick the crate type based on the --function argument. * Update call_single_file.rs
1 parent 8e5e3a6 commit 870e37b

File tree

3 files changed

+10
-3
lines changed

3 files changed

+10
-3
lines changed

src/cargo-kani/src/call_single_file.rs

+9
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,15 @@ impl KaniSession {
5454
if !args.contains(&t) {
5555
args.push(t);
5656
}
57+
} else {
58+
if self.args.function != "main" {
59+
// Unless entry function for proof harness is main, compile code as lib.
60+
// This ensures that rustc won't prune functions that are not reachable
61+
// from main as well as enable compilation of crates that don't have a main
62+
// function.
63+
args.push("--crate-type".into());
64+
args.push("lib".into());
65+
}
5766
}
5867

5968
let mut cmd = Command::new(&self.kani_rustc);
+1-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
UNREACHABLE
2-
** 1 of 5 failed (1 unreachable)
2+
** 1 of 3 failed (1 unreachable)

tests/expected/reach/unreachable/test.rs

-2
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,3 @@ fn foo(x: i32) {
1616
assert!(x <= 5);
1717
}
1818
}
19-
20-
fn main() {}

0 commit comments

Comments
 (0)