forked from model-checking/kani
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
We want to run the proofs in the target crate and don't need to build (or run) the proofs in any of the host crates. This avoids a need to make available the `kani` crate to any such host crates. Resolves model-checking#3101, model-checking#3238
- Loading branch information
1 parent
0bb1325
commit a5038a7
Showing
8 changed files
with
110 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 10 additions & 0 deletions
10
tests/cargo-kani/build-rs-plus-host-with-kani-proofs/README.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
This repo contains contains a minimal example that breaks compilation when using [kani](https://github.com/model-checking/kani), where I would expect compilation to work. | ||
|
||
Deleting the `binary/build.rs` script makes the compilation work suddenly, despite it being skipped anyways: | ||
|
||
``` | ||
binary$ cargo kani -v | ||
Kani Rust Verifier 0.48.0 (cargo plugin) | ||
Skipped the following unsupported targets: 'build-script-build'. | ||
... | ||
``` |
12 changes: 12 additions & 0 deletions
12
tests/cargo-kani/build-rs-plus-host-with-kani-proofs/binary/Cargo.toml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
[package] | ||
name = "binary" | ||
version = "0.1.0" | ||
edition = "2021" | ||
|
||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html | ||
|
||
[dependencies] | ||
constants = { path = "../constants" } | ||
|
||
[build-dependencies] | ||
constants = { path = "../constants" } |
19 changes: 19 additions & 0 deletions
19
tests/cargo-kani/build-rs-plus-host-with-kani-proofs/binary/build.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
// Copyright Kani Contributors | ||
// SPDX-License-Identifier: Apache-2.0 OR MIT | ||
|
||
// From https://github.com/model-checking/kani/issues/3101 | ||
|
||
use constants::SOME_CONSTANT; | ||
|
||
// Having a build script that depends on the constants package | ||
// breaks kani compilation of that package, when compiling the build script. | ||
// I assume it's because the build compile does not set cfg(kani) on the constants package dependency. | ||
|
||
fn main() { | ||
// build.rs changes should trigger rebuild | ||
println!("cargo:rerun-if-changed=build.rs"); | ||
|
||
// Here we have an assertion that gives us additional compile-time checks. | ||
// In reality, here I read a linker script and assert certain properties in relation to constants defined in the constants package. | ||
assert_eq!(SOME_CONSTANT, 42); | ||
} |
31 changes: 31 additions & 0 deletions
31
tests/cargo-kani/build-rs-plus-host-with-kani-proofs/binary/src/main.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
// Copyright Kani Contributors | ||
// SPDX-License-Identifier: Apache-2.0 OR MIT | ||
|
||
// From https://github.com/model-checking/kani/issues/3101 | ||
|
||
use constants::SomeStruct; | ||
|
||
fn function_that_does_something(b: bool) -> SomeStruct { | ||
SomeStruct { some_field: if b { 42 } else { 24 } } | ||
} | ||
|
||
fn main() { | ||
println!("The constant is {}", constants::SOME_CONSTANT); | ||
|
||
let some_struct = function_that_does_something(true); | ||
|
||
println!("some_field is {:?}", some_struct.some_field); | ||
} | ||
|
||
#[cfg(kani)] | ||
mod verification { | ||
use super::*; | ||
|
||
#[kani::proof] | ||
fn function_never_returns_zero_struct() { | ||
let input: bool = kani::any(); | ||
let output = function_that_does_something(input); | ||
|
||
assert!(output.some_field != 0); | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
tests/cargo-kani/build-rs-plus-host-with-kani-proofs/constants/Cargo.toml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
[package] | ||
name = "constants" | ||
version = "0.1.0" | ||
edition = "2021" | ||
|
||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html | ||
|
||
[dependencies] |
27 changes: 27 additions & 0 deletions
27
tests/cargo-kani/build-rs-plus-host-with-kani-proofs/constants/src/lib.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
// Copyright Kani Contributors | ||
// SPDX-License-Identifier: Apache-2.0 OR MIT | ||
|
||
// From https://github.com/model-checking/kani/issues/3101 | ||
|
||
pub const SOME_CONSTANT: u32 = 42; | ||
|
||
pub struct SomeStruct { | ||
pub some_field: u32, | ||
} | ||
|
||
#[cfg(kani)] | ||
impl kani::Arbitrary for SomeStruct { | ||
fn any() -> Self { | ||
SomeStruct { some_field: kani::any() } | ||
} | ||
} | ||
|
||
#[cfg(kani)] | ||
mod verification { | ||
use super::*; | ||
|
||
#[kani::proof] | ||
fn zero() { | ||
assert_ne!(SOME_CONSTANT, 0); | ||
} | ||
} |