z3-sys
Low-level rust bindings to the Z3 SMT solver
Licensed under the MIT license.
See https://github.com/Z3Prover/z3 for details on Z3.
Documentation
The API is fully documented with examples: https://docs.rs/z3-sys/
Installation
This crate works with Cargo and is on
crates.io.
Add it to your project with cargo add:
Finding Z3 Libraries
Note: This library has a dependency on Z3.
There are 4 ways for this crate to currently find Z3:
-
By default, it will look for a system-installed copy of Z3. On Linux, this would be via the package manager. On macOS, this might be via Homebrew (
brew install z3). Users can use the environment variableZ3_LIBRARY_PATH_OVERRIDEto manually specify the library search path. -
Enabling the
bundledfeature will usecmaketo build and statically link Z3 from source. Despite the name, Z3 source is not included in the crate tarball. On a first build from crates.io, the build script queries the GitHub Contents API to find which Z3 commit thez3-syssubmodule pointed to at release time (via thez3-sys-vX.Y.Zgit tag), then downloads and extracts that Z3 source archive. The result is cached in Cargo's build output directory and reused untilcargo clean.Using your own Z3 checkout: Set
Z3_SYS_BUNDLED_DIR_OVERRIDEto the absolute path of a Z3 source tree to build from that instead:Z3_SYS_BUNDLED_DIR_OVERRIDE=/absolute/path/to/z3To use a path relative to your project root, add the following to your project's
.cargo/config.toml. Therelative = truekey tells Cargo to resolve the path relative to the config file's location rather than as an absolute path:[] = { = "path/to/z3", = true }Note: A
z3directory in your own project or workspace is not picked up automatically. Even if you have a Z3 git submodule in your repo, you must pointZ3_SYS_BUNDLED_DIR_OVERRIDEat it explicitly.Pinning a Z3 version without a source checkout: The
gh-releasefeature (see below) lets you pin a specific Z3 version viaZ3_SYS_Z3_VERSIONwithout managing a source tree yourself. -
Enabling the
vcpkgfeature will usevcpkgto build and install a copy of Z3 which is then used. -
Enabling the
gh-releasefeature will download a pre-compiled copy of Z3 from the GitHub release page for the current platform, if available.- You may specify the version of Z3 to download via the
Z3_SYS_Z3_VERSIONenvironment variable. - Note: Github throttles unauthenticated requests from the
same IP fairly aggressively. If you are using the
gh-releasefeature inside a CI pipeline (or if youcargo cleanand rebuild a lot), you will likely experience random403responses downloading thez3build artifacts. To mitigate this, generate a read-only Personal Access Token (https://github.com/settings/personal-access-tokens) and provide it to theREAD_ONLY_GITHUB_TOKENenvironment variable. Thebuild.rsstep will automatically use this token (if present) to prevent throttling.
- You may specify the version of Z3 to download via the
Note: This crate requires a z3.h during build time.
- By default, the crate will look for a
z3.hin standard/system include paths. TheZ3_SYS_Z3_HEADERenvironment variable can also be used to customize this. - Enabling the
bundledfeature will cause the bundled copy ofz3.hto be used. TheZ3_SYS_Z3_HEADERenvironment variable can also be used to customize this. - Enabling the
vcpkgorgh-releasefeature will cause the copy ofz3.hprovided by that version to be used. In this case, there is no override via the environment variable.
Support and Maintenance
I am developing this library largely on my own so far. I am able to offer support and maintenance, but would very much appreciate donations via Patreon. I can also provide commercial support, so feel free to contact me.
Contribution
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, shall be dual licensed as above, without any additional terms or conditions.