forked from rust-lang/rust
-
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.
Use cfg=kani_host for host crates (rust-lang#3244)
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 rust-lang#3101, rust-lang#3238
- Loading branch information
1 parent
e7d1624
commit d4a3f7b
Showing
11 changed files
with
114 additions
and
8 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
2 changes: 2 additions & 0 deletions
2
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,2 @@ | ||
This repo contains contains a minimal example that used to break compilation | ||
when using Kani. See https://github.com/model-checking/kani/issues/3101. |
14 changes: 14 additions & 0 deletions
14
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,14 @@ | ||
# Copyright Kani Contributors | ||
# SPDX-License-Identifier: Apache-2.0 OR MIT | ||
[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" } |
16 changes: 16 additions & 0 deletions
16
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,16 @@ | ||
// Copyright Kani Contributors | ||
// SPDX-License-Identifier: Apache-2.0 OR MIT | ||
|
||
// From https://github.com/model-checking/kani/issues/3101 | ||
|
||
use constants::SOME_CONSTANT; | ||
|
||
fn main() { | ||
// build.rs changes should trigger rebuild | ||
println!("cargo:rerun-if-changed=build.rs"); | ||
|
||
#[cfg(not(kani_host))] | ||
assert_eq!(constants::SOME_CONSTANT, 0); | ||
#[cfg(kani_host)] | ||
assert_eq!(constants::SOME_CONSTANT, 2); | ||
} |
32 changes: 32 additions & 0 deletions
32
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,32 @@ | ||
// Copyright Kani Contributors | ||
// SPDX-License-Identifier: Apache-2.0 OR MIT | ||
|
||
// From https://github.com/model-checking/kani/issues/3101 | ||
// This file demonstrates that Kani is working on the `binary` crate itself. | ||
|
||
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); | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
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,9 @@ | ||
# Copyright Kani Contributors | ||
# SPDX-License-Identifier: Apache-2.0 OR MIT | ||
[package] | ||
name = "constants" | ||
version = "0.1.0" | ||
edition = "2021" | ||
|
||
|
||
[dependencies] |
32 changes: 32 additions & 0 deletions
32
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,32 @@ | ||
// Copyright Kani Contributors | ||
// SPDX-License-Identifier: Apache-2.0 OR MIT | ||
|
||
// From https://github.com/model-checking/kani/issues/3101 | ||
|
||
#[cfg(not(any(kani, kani_host)))] | ||
pub const SOME_CONSTANT: u32 = 0; | ||
#[cfg(kani)] | ||
pub const SOME_CONSTANT: u32 = 1; | ||
#[cfg(kani_host)] | ||
pub const SOME_CONSTANT: u32 = 2; | ||
|
||
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 one() { | ||
assert_eq!(constants::SOME_CONSTANT, 1); | ||
} | ||
} |
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 |
---|---|---|
@@ -1,2 +1,2 @@ | ||
Skipped the following unsupported targets: 'lib'. | ||
Skipped verification of the following unsupported targets: 'lib'. | ||
error: No supported targets were found. |
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