Skip to content

Commit 326b35e

Browse files
authored
Include Kissat in the Kani bundle (rust-lang#2087)
1 parent c90f447 commit 326b35e

File tree

11 files changed

+128
-0
lines changed

11 files changed

+128
-0
lines changed

.github/actions/setup/action.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@ runs:
2525
run: ./scripts/setup/${{ inputs.os }}/install_viewer.sh
2626
shell: bash
2727

28+
- name: Install Kissat
29+
run: ./scripts/setup/install_kissat.sh
30+
shell: bash
31+
2832
- name: Install Rust toolchain
2933
run: ./scripts/setup/install_rustup.sh
3034
shell: bash

.github/workflows/kani.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,7 @@ jobs:
156156
docker run -w /tmp/kani/tests/cargo-kani/simple-lib $tag cargo kani
157157
docker run -w /tmp/kani/tests/cargo-kani/simple-visualize $tag cargo kani
158158
docker run -w /tmp/kani/tests/cargo-kani/build-rs-works $tag cargo kani
159+
docker run -w /tmp/kani/tests/cargo-kani/simple-kissat $tag cargo kani
159160
docker run $tag cargo-kani setup --use-local-bundle ./${{ matrix.artifact }}
160161
done
161162
# While the above test OS issues, now try testing with nightly as default:

docs/src/build-from-source.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ In general, the following dependencies are required to build Kani from source.
1313
1. Cargo installed via [rustup](https://rustup.rs/)
1414
2. [CBMC](https://github.com/diffblue/cbmc) (latest release)
1515
3. [CBMC Viewer](https://github.com/awslabs/aws-viewer-for-cbmc) (latest release)
16+
4. [Kissat](https://github.com/arminbiere/kissat) (Release 3.0.0)
1617

1718
Kani has been tested in [Ubuntu](#install-dependencies-on-ubuntu) and [macOS](##install-dependencies-on-macos) platforms.
1819

@@ -30,6 +31,7 @@ git submodule update --init
3031
./scripts/setup/ubuntu/install_deps.sh
3132
./scripts/setup/ubuntu/install_cbmc.sh
3233
./scripts/setup/ubuntu/install_viewer.sh
34+
./scripts/setup/install_kissat.sh
3335
# If you haven't already (or from https://rustup.rs/):
3436
./scripts/setup/install_rustup.sh
3537
source $HOME/.cargo/env
@@ -47,6 +49,7 @@ git submodule update --init
4749
./scripts/setup/macos/install_deps.sh
4850
./scripts/setup/macos/install_cbmc.sh
4951
./scripts/setup/macos/install_viewer.sh
52+
./scripts/setup/install_kissat.sh
5053
# If you haven't already (or from https://rustup.rs/):
5154
./scripts/setup/install_rustup.sh
5255
source $HOME/.cargo/env

kani-dependencies

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
CBMC_VERSION="5.75.0"
22
# If you update this version number, remember to bump it in `src/setup.rs` too
33
CBMC_VIEWER_VERSION="3.8"
4+
KISSAT_VERSION="3.0.0"

scripts/check_kissat_version.sh

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#!/usr/bin/env bash
2+
# Copyright Kani Contributors
3+
# SPDX-License-Identifier: Apache-2.0 OR MIT
4+
5+
# Check if kissat has the minimum required version specified in the
6+
# `kani_dependencies` file under kani's root folder
7+
8+
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
9+
KANI_DIR=$SCRIPT_DIR/..
10+
source "${KANI_DIR}/kani-dependencies"
11+
12+
if [ -z "${KISSAT_VERSION:-}" ]; then
13+
echo "$0: ERROR: KISSAT_VERSION is not set"
14+
return 1
15+
fi
16+
cmd="kissat --version"
17+
if kissat_version=$($cmd); then
18+
# Perform a lexicographic comparison of the version
19+
if [[ $kissat_version < $KISSAT_VERSION ]]; then
20+
echo "ERROR: Kissat version is $kissat_version. Expected at least $KISSAT_VERSION."
21+
return 1
22+
fi
23+
else
24+
echo "ERROR: Couldn't run command '$cmd'"
25+
return 1
26+
fi

scripts/kani-regression.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ export KANI_FAIL_ON_UNEXPECTED_DESCRIPTION="true"
2424
# Required dependencies
2525
check-cbmc-version.py --major 5 --minor 75
2626
check-cbmc-viewer-version.py --major 3 --minor 5
27+
check_kissat_version.sh
2728

2829
# Formatting check
2930
${SCRIPT_DIR}/kani-fmt.sh --check

scripts/setup/install_kissat.sh

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
#!/bin/bash
2+
# Copyright Kani Contributors
3+
# SPDX-License-Identifier: Apache-2.0 OR MIT
4+
5+
set -eu
6+
7+
# Source kani-dependencies to get KISSAT_VERSION
8+
source kani-dependencies
9+
10+
if [ -z "${KISSAT_VERSION:-}" ]; then
11+
echo "$0: Error: KISSAT_VERSION is not specified"
12+
exit 1
13+
fi
14+
15+
# Check if the correct Kissat version is already installed
16+
if command -v kissat > /dev/null; then
17+
if kissat_version=$(kissat --version); then
18+
if [[ $kissat_version == $KISSAT_VERSION ]]; then
19+
# Already installed
20+
exit 0
21+
else
22+
echo "Warning: Overriding Kissat version ${kissat_version} with ${KISSAT_VERSION}"
23+
fi
24+
fi
25+
fi
26+
27+
# Kissat release
28+
FILE="rel-${KISSAT_VERSION}.tar.gz"
29+
URL="https://github.com/arminbiere/kissat/archive/refs/tags/$FILE"
30+
31+
set -x
32+
33+
wget -O "$FILE" "$URL"
34+
tar -xvzf $FILE
35+
DIR_NAME="kissat-rel-${KISSAT_VERSION}"
36+
cd $DIR_NAME
37+
./configure && make kissat && sudo install build/kissat /usr/local/bin
38+
cd -
39+
40+
# Clean up on success
41+
rm $FILE
42+
rm -rf $DIR_NAME
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# Copyright Kani Contributors
2+
# SPDX-License-Identifier: Apache-2.0 OR MIT
3+
[package]
4+
name = "simple-kissat"
5+
version = "0.1.0"
6+
edition = "2021"
7+
description = "Tests that Kani can be invoked with Kissat"
8+
9+
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
10+
11+
[dependencies]
12+
13+
[kani.flags]
14+
enable-unstable = true
15+
cbmc-args = ["--external-sat-solver", "kissat" ]
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Solving with External SAT solver
2+
VERIFICATION:- SUCCESSFUL
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// Copyright Kani Contributors
2+
// SPDX-License-Identifier: Apache-2.0 OR MIT
3+
4+
//! This test checks that concatenating two nondet arrays into a vector
5+
//! preserves the values
6+
7+
#[kani::proof]
8+
fn check_concat() {
9+
let arr1: [i32; 2] = kani::any();
10+
let arr2: [i32; 3] = kani::any();
11+
let mut v = Vec::new();
12+
v.extend_from_slice(&arr1);
13+
v.extend_from_slice(&arr2);
14+
assert_eq!(v[0], arr1[0]);
15+
assert_eq!(v[1], arr1[1]);
16+
assert_eq!(v[2], arr2[0]);
17+
assert_eq!(v[3], arr2[1]);
18+
assert_eq!(v[4], arr2[2]);
19+
}
20+
21+
fn main() {}

tools/build-kani/src/main.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ fn main() -> Result<()> {
4040

4141
bundle_kani(dir)?;
4242
bundle_cbmc(dir)?;
43+
bundle_kissat(dir)?;
4344
// cbmc-viewer isn't bundled, it's pip install'd on first-time setup
4445

4546
create_release_bundle(dir, &bundle_name)?;
@@ -140,6 +141,17 @@ fn bundle_cbmc(dir: &Path) -> Result<()> {
140141
Ok(())
141142
}
142143

144+
/// Copy Kissat binary into `dir`
145+
fn bundle_kissat(dir: &Path) -> Result<()> {
146+
// Assumes `kissat` exists in PATH (similar to `bundle_cbmc`)
147+
let bin = dir.join("bin");
148+
149+
// We use these directly
150+
cp(&which::which("kissat")?, &bin)?;
151+
152+
Ok(())
153+
}
154+
143155
/// Create the release tarball from `./dir` named `bundle`.
144156
/// This should include all files as `dir/<path>` in the tarball.
145157
/// e.g. `kani-1.0/bin/kani-compiler` not just `bin/kani-compiler`.

0 commit comments

Comments
 (0)