Skip to content

Commit d424417

Browse files
committed
devenv: Add Kani formal verification tool
Kani is a bounded model checker for Rust that can verify safety properties and absence of undefined behavior. It requires rustup because it bundles a specific nightly toolchain version. Key changes: - Add rustup symlink at $CARGO_HOME/bin/rustup (required for rustup's self-update check which looks for itself there) - Add new 'kani' build stage that compiles kani-verifier and runs setup - Set KANI_HOME=/usr/local/kani for system-wide installation - Copy kani bundle (compiler, libraries, CBMC) to final image The kani version is renovate-managed via the kaniversion ARG. Assisted-by: OpenCode (Claude Sonnet 4) Signed-off-by: Colin Walters <walters@verbum.org>
1 parent 7910dde commit d424417

2 files changed

Lines changed: 68 additions & 8 deletions

File tree

devenv/Containerfile.c10s

Lines changed: 34 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,34 @@ export CARGO_HOME=/usr/local/cargo
9090
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y --default-toolchain stable --profile default
9191
# Move binaries to /usr/local/bin (system-managed, root-owned)
9292
mv /usr/local/cargo/bin/* /usr/local/bin/
93-
# Nothing really left here
94-
rm -vrf /usr/local/cargo/bin
93+
# Recreate bin directory with symlink to rustup - rustup's self-update check
94+
# looks for itself at $CARGO_HOME/bin/rustup
95+
mkdir -p /usr/local/cargo/bin
96+
ln -sf /usr/local/bin/rustup /usr/local/cargo/bin/rustup
97+
EORUN
98+
99+
# Kani formal verification tool - requires rustup for toolchain management
100+
FROM rust as kani
101+
# renovate: datasource=crate depName=kani-verifier
102+
ARG kaniversion=0.67.0
103+
RUN <<EORUN
104+
set -xeuo pipefail
105+
# Install build dependencies needed to compile kani-verifier
106+
dnf install -y gcc
107+
export RUSTUP_HOME=/usr/local/rustup
108+
export CARGO_HOME=/usr/local/cargo
109+
export PATH="/usr/local/bin:$PATH"
110+
# Install Kani to a system-wide location so all users can access it
111+
export KANI_HOME=/usr/local/kani
112+
113+
# Install kani-verifier
114+
/bin/time -f '%E %C' cargo install --locked kani-verifier --version $kaniversion
115+
116+
# Run kani setup - downloads bundle and installs required nightly toolchain
117+
/bin/time -f '%E %C' /usr/local/cargo/bin/cargo-kani setup
118+
119+
# Move kani binaries to /usr/local/bin, keep rustup symlink
120+
mv /usr/local/cargo/bin/cargo-kani /usr/local/cargo/bin/kani /usr/local/bin/
95121
EORUN
96122

97123
# This builds the image.
@@ -110,10 +136,14 @@ RUN grep -vEe '^#' npm.txt | /bin/time -f '%E %C' xargs npm i -g
110136

111137
# Copy in the binaries from our tools container image
112138
COPY --from=tools /usr/local/bin/* /usr/local/bin/
113-
COPY --from=rust /usr/local/bin/* /usr/local/bin/
114-
COPY --from=rust /usr/local/rustup /usr/local/rustup
139+
COPY --from=kani /usr/local/bin/* /usr/local/bin/
140+
COPY --from=kani /usr/local/rustup /usr/local/rustup
141+
# Kani bundle (compiler, libraries, CBMC) installed via KANI_HOME during setup
142+
COPY --from=kani /usr/local/kani /usr/local/kani
115143
# Point rustup at the system-wide installation, but let CARGO_HOME default to ~/.cargo
116144
ENV RUSTUP_HOME=/usr/local/rustup
145+
# Point Kani at the system-wide installation
146+
ENV KANI_HOME=/usr/local/kani
117147
# Setup for codespaces
118148
COPY devenv-init.sh /usr/local/bin/
119149

devenv/Containerfile.debian

Lines changed: 34 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,34 @@ export CARGO_HOME=/usr/local/cargo
8888
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y --default-toolchain stable --profile default
8989
# Move binaries to /usr/local/bin (system-managed, root-owned)
9090
mv /usr/local/cargo/bin/* /usr/local/bin/
91-
# Nothing really left here
92-
rm -vrf /usr/local/cargo/bin
91+
# Recreate bin directory with symlink to rustup - rustup's self-update check
92+
# looks for itself at $CARGO_HOME/bin/rustup
93+
mkdir -p /usr/local/cargo/bin
94+
ln -sf /usr/local/bin/rustup /usr/local/cargo/bin/rustup
95+
EORUN
96+
97+
# Kani formal verification tool - requires rustup for toolchain management
98+
FROM rust as kani
99+
# renovate: datasource=crate depName=kani-verifier
100+
ARG kaniversion=0.67.0
101+
RUN <<EORUN
102+
set -xeuo pipefail
103+
# Install build dependencies needed to compile kani-verifier
104+
apt-get update && apt-get install -y --no-install-recommends build-essential
105+
export RUSTUP_HOME=/usr/local/rustup
106+
export CARGO_HOME=/usr/local/cargo
107+
export PATH="/usr/local/bin:$PATH"
108+
# Install Kani to a system-wide location so all users can access it
109+
export KANI_HOME=/usr/local/kani
110+
111+
# Install kani-verifier
112+
/bin/time -f '%E %C' cargo install --locked kani-verifier --version $kaniversion
113+
114+
# Run kani setup - downloads bundle and installs required nightly toolchain
115+
/bin/time -f '%E %C' /usr/local/cargo/bin/cargo-kani setup
116+
117+
# Move kani binaries to /usr/local/bin, keep rustup symlink
118+
mv /usr/local/cargo/bin/cargo-kani /usr/local/cargo/bin/kani /usr/local/bin/
93119
EORUN
94120

95121
# This builds the image.
@@ -108,10 +134,14 @@ RUN grep -vEe '^#' npm.txt | /bin/time -f '%E %C' xargs npm i -g
108134

109135
# Copy in the binaries from our tools container image
110136
COPY --from=tools /usr/local/bin/* /usr/local/bin/
111-
COPY --from=rust /usr/local/bin/* /usr/local/bin/
112-
COPY --from=rust /usr/local/rustup /usr/local/rustup
137+
COPY --from=kani /usr/local/bin/* /usr/local/bin/
138+
COPY --from=kani /usr/local/rustup /usr/local/rustup
139+
# Kani bundle (compiler, libraries, CBMC) installed via KANI_HOME during setup
140+
COPY --from=kani /usr/local/kani /usr/local/kani
113141
# Point rustup at the system-wide installation, but let CARGO_HOME default to ~/.cargo
114142
ENV RUSTUP_HOME=/usr/local/rustup
143+
# Point Kani at the system-wide installation
144+
ENV KANI_HOME=/usr/local/kani
115145
# Setup for codespaces
116146
COPY devenv-init.sh /usr/local/bin/
117147

0 commit comments

Comments
 (0)