Add 'kani verify-artifacts' subcommand - #4600
Conversation
Adds a fourth Project constructor that reads pre-built *.kani-metadata.json + *.symtab.out artifacts from directories on disk instead of running cargo or rustc. The recorded goto_file path is the build machine's OUT_DIR and is wrong after relocation (CI cache, archive, build-system store), so the constructor resolves each goto_file by basename against the directory the metadata file was found in. This relies on kani-compiler's existing emit layout (artifacts co-located with their metadata).
Adds a standalone subcommand that runs the verification pipeline against pre-built compiler artifacts without rebuilding. This is the inverse of '--only-codegen': build systems that own the compile phase (for caching, sharding, or per-crate incremental builds) can produce artifacts with kani-compiler and verify them separately. Mirrors 'kani verify-std' exactly: a standalone subcommand, gated behind -Z unstable-options, that constructs a Project differently and falls through to verify_project().
Round-trip test: build artifacts with 'cargo kani --only-codegen', then verify them with 'kani verify-artifacts'. Uses two harnesses (one passes, one fails) so the test proves the verdict is honest -- that the pipeline actually reached CBMC and propagated the result -- not merely that the command exited. The fixture crate is excluded from the kani workspace (workspace Cargo.toml exclude list, same as no_codegen and no_codegen_error).
There was a problem hiding this comment.
Pull request overview
This PR adds a new standalone driver path to verify previously-produced Kani compilation artifacts, enabling workflows that split compilation and verification (e.g., CI sharding, external build systems with their own caching) without re-running cargo/rustc. It does so by introducing a kani verify-artifacts <DIR>... subcommand (gated behind -Z unstable-options) that discovers *.kani-metadata.json in the provided directories, relocates each harness’ recorded goto_file to be adjacent to the metadata file (by basename), and then runs the existing verify_project() pipeline over the reconstructed Project.
Changes:
- Add
kani verify-artifactsstandalone subcommand with validation requiring-Z unstable-options. - Implement project construction from prebuilt artifacts by parsing metadata files and rewriting harness
goto_filepaths for relocation. - Add a
script-based-preintegration test that round-tripscargo kani --only-codegen→kani verify-artifactsand checks that a failing harness produces a non-zero exit code.
Reviewed changes
Copilot reviewed 10 out of 10 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
kani-driver/src/project.rs |
Adds metadata discovery/relocation logic and a prebuilt_project() constructor for verification from prebuilt artifacts. |
kani-driver/src/main.rs |
Wires the new VerifyArtifacts standalone subcommand into kani execution. |
kani-driver/src/args/verify_artifacts_args.rs |
Defines CLI args + validation for verify-artifacts, including the -Z unstable-options gate. |
kani-driver/src/args/mod.rs |
Registers the new args module and standalone subcommand variant; adds basic parsing tests. |
tests/script-based-pre/verify_artifacts_cmd/** |
Adds an integration test fixture, script, and expected output for the new subcommand. |
Cargo.toml |
Excludes the new script-based-pre fixture crate from the workspace. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| /// Parse all `*.kani-metadata.json` files under the given directories, rewriting | ||
| /// each harness's `goto_file` to be relative to the directory the metadata was | ||
| /// found in. |
|
@lovesegfault Thank you for your contribution! The thing that is missing the most for me is documentation. Usually for new features, we have an RFC. However, we could have at least a proper documentation for users on how to use this, short-comes, why is valuable... For instance:
Could you add some before I can do a review? Also, @tautschnig what do you think? |
cargo kaniandkaniboth insist on owning the compile phase. There is no way to verify artifacts from an earlier--only-codegenrun, a build system that driveskani-compilerdirectly, or a CI job that splits compilation and verification across machines: every invocation re-runs cargo or rustc, and a build system with its own per-crate cache ends up re-implementing kani-driver's verify half — the goto-cc/goto-instrument/cbmc pipeline, harness scheduling, verdict rendering — to avoid throwing the cache away. #4079 and #4212 are the same friction from the build side.Adds
kani verify-artifacts <DIR>..., a standalone subcommand that scans the given directories for*.kani-metadata.json, resolves each harness'sgoto_fileby basename against the directory the metadata was found in (the recorded path is the producing machine'sOUT_DIR, wrong after relocation), and runsverify_project()over the result. Mirrorsverify-std: sameProjectconstruction shape, gated behind-Z unstable-options. Thescript-based-pretest round-tripscargo kani --only-codegen→kani verify-artifactsagainst a fixture with one passing and one deliberately-failing harness, so a non-zero exit proves the verdict actually reached cbmc rather than silently no-op'd.Two known limitations, documented in the args help: artifacts must come from the same kani version that verifies them (kani-driver does not version-check the metadata schema; happy to add a stamp as a follow-up if there's appetite), and the artifact directory must be writable since
Project::try_new()writes the linked.outnext to each.symtab.out.