From 7c5aa54690cd1651656ff490d0f59e1998441e5a Mon Sep 17 00:00:00 2001 From: Yoshi Takashima Date: Tue, 16 Aug 2022 18:02:00 -0400 Subject: [PATCH 1/2] Added --all-features flag. --- kani-driver/src/args.rs | 3 +++ kani-driver/src/call_cargo.rs | 4 ++++ tests/cargo-kani/feature-flag/Cargo.toml | 18 ++++++++++++++++++ tests/cargo-kani/feature-flag/expected | 1 + tests/cargo-kani/feature-flag/src/lib.rs | 21 +++++++++++++++++++++ 5 files changed, 47 insertions(+) create mode 100644 tests/cargo-kani/feature-flag/Cargo.toml create mode 100644 tests/cargo-kani/feature-flag/expected create mode 100644 tests/cargo-kani/feature-flag/src/lib.rs diff --git a/kani-driver/src/args.rs b/kani-driver/src/args.rs index 1fe852b2a8d6..c425254f78ff 100644 --- a/kani-driver/src/args.rs +++ b/kani-driver/src/args.rs @@ -114,6 +114,9 @@ pub struct KaniArgs { /// Kani will only compile the crate. No verification will be performed #[structopt(long, hidden_short_help(true))] pub only_codegen: bool, + /// Compile all features with kani. + #[structopt(long)] + pub all_features: bool, /// Specify the value used for loop unwinding in CBMC #[structopt(long)] diff --git a/kani-driver/src/call_cargo.rs b/kani-driver/src/call_cargo.rs index f8624297f972..7e25f8c6d2fc 100644 --- a/kani-driver/src/call_cargo.rs +++ b/kani-driver/src/call_cargo.rs @@ -52,6 +52,10 @@ impl KaniSession { args.push("build".into()); } + if self.args.all_features { + args.push("--all-features".into()); + } + args.push("--target".into()); args.push(build_target.into()); diff --git a/tests/cargo-kani/feature-flag/Cargo.toml b/tests/cargo-kani/feature-flag/Cargo.toml new file mode 100644 index 000000000000..10eaf2a511be --- /dev/null +++ b/tests/cargo-kani/feature-flag/Cargo.toml @@ -0,0 +1,18 @@ +# Copyright Kani Contributors +# SPDX-License-Identifier: Apache-2.0 OR MIT + +[package] +name = "feature-flag" +version = "0.1.0" +edition = "2021" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[features] +A = [] +B = [] + +[dependencies] + +[package.metadata.kani.flags] +all-features = true diff --git a/tests/cargo-kani/feature-flag/expected b/tests/cargo-kani/feature-flag/expected new file mode 100644 index 000000000000..2288e57be799 --- /dev/null +++ b/tests/cargo-kani/feature-flag/expected @@ -0,0 +1 @@ +3 successfully verified harnesses diff --git a/tests/cargo-kani/feature-flag/src/lib.rs b/tests/cargo-kani/feature-flag/src/lib.rs new file mode 100644 index 000000000000..44e206b1141f --- /dev/null +++ b/tests/cargo-kani/feature-flag/src/lib.rs @@ -0,0 +1,21 @@ +// Copyright Kani Contributors +// SPDX-License-Identifier: Apache-2.0 OR MIT + +//! 3 proof harnesses, 2 of them are feature-gated. + +#[kani::proof] +fn check_proof() { + assert!(1 == 1); +} + +#[cfg(feature = "A")] +#[kani::proof] +fn check_proof_a() { + assert!(2 == 2); +} + +#[cfg(feature = "B")] +#[kani::proof] +fn check_proof_b() { + assert!(3 == 3); +} From 613160e1b55b08937351a19581ed56bbf6bb5874 Mon Sep 17 00:00:00 2001 From: Yoshi Takashima Date: Wed, 17 Aug 2022 09:43:58 -0400 Subject: [PATCH 2/2] Made the doc more detailed. --- kani-driver/src/args.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kani-driver/src/args.rs b/kani-driver/src/args.rs index c425254f78ff..2c6fde76475f 100644 --- a/kani-driver/src/args.rs +++ b/kani-driver/src/args.rs @@ -114,7 +114,7 @@ pub struct KaniArgs { /// Kani will only compile the crate. No verification will be performed #[structopt(long, hidden_short_help(true))] pub only_codegen: bool, - /// Compile all features with kani. + /// Compiles Kani harnesses in all features of all packages selected on the command-line. #[structopt(long)] pub all_features: bool,