sat-solvers
A unified Rust interface to multiple SAT solvers with automatic source compilation.
Overview
sat-solvers provides a simple way to use popular SAT solvers (CaDiCaL, MiniSat, Glucose, Lingeling, Kissat) without requiring pre-installed binaries. The solvers are compiled from source during cargo build, ensuring reproducible builds across different systems.
Key Features
- Self-contained builds: Solvers are built from bundled source code during compilation
- Unified interface: All solvers implement the
SolverExecutortrait - Feature-gated: Only compile the solvers you need
- Timeout support: Built-in timeout handling for long-running problems
- DIMACS format: Standard CNF input format supported by all solvers
Installation
Add sat-solvers to your Cargo.toml:
[]
= "0.1"
By default, CaDiCaL and MiniSat are enabled. To use specific solvers:
[]
= { = "0.1", = false, = ["cadical", "kissat"] }
Available Features
| Feature | Solver | Description |
|---|---|---|
cadical |
CaDiCaL | State-of-the-art CDCL solver, SAT Competition winner |
minisat |
MiniSat | Classic, widely-used SAT solver |
glucose |
Glucose | MiniSat derivative with improved learning |
lingeling |
Lingeling | High-performance solver by Armin Biere |
kissat |
Kissat | Successor to CaDiCaL, SAT Competition 2020+ winner |
Usage
Basic Example
use CaDiCaLExecutor;
use SolverExecutor;
use SATResult;
use Duration;
DIMACS CNF Format
The solvers accept input in DIMACS CNF format:
p cnf <num_variables> <num_clauses>
<literal1> <literal2> ... 0
<literal1> <literal2> ... 0
...
- Variables are positive integers (1, 2, 3, ...)
- Negative literals represent negation (-1 means NOT x1)
- Each clause ends with 0
Example - encoding (x1 OR x2) AND (NOT x1 OR x3) AND (NOT x2 OR NOT x3):
p cnf 3 3
1 2 0
-1 3 0
-2 -3 0
Using Different Solvers
All solver executors implement the same SolverExecutor trait:
use SolverExecutor;
use Duration;
// Use any solver through the trait
// With CaDiCaL
solve_with;
// With MiniSat
solve_with;
// With Kissat
solve_with;
Build Requirements
Since solvers are compiled from source, you need:
- C++ compiler: g++ or clang++
- make: GNU Make
- cmake: Required for Glucose
On Ubuntu/Debian:
On macOS:
On Arch Linux:
macOS Compatibility Note
MiniSat has C++ compatibility issues with the default macOS clang compiler. All other solvers (CaDiCaL, Glucose, Kissat, Lingeling) work correctly on macOS.
If you need MiniSat on macOS, you can try installing GCC via Homebrew and setting the CXX environment variable:
CXX=g++-14
Comparison with Alternatives
| Crate | Approach | Pros | Cons |
|---|---|---|---|
| sat-solvers | Builds solvers from source at build time | Self-contained, reproducible, no system deps | Longer build times |
| rustsat | FFI bindings to C/C++ code | Zero-overhead, full API access | Complex build, tight coupling |
| exec-sat | Executes pre-installed binaries | Simple, flexible | Requires manual binary installation |
| splr | Pure Rust implementation | No native dependencies | Single solver, may differ from C versions |
Choose sat-solvers when you want:
- Reproducible builds without system dependencies
- Easy switching between multiple established solvers
- Simple integration with timeout support
License
Licensed under the MIT license (LICENSE).
Bundled Solver Licenses
The bundled SAT solver source code is subject to their respective licenses:
- CaDiCaL: MIT License
- MiniSat: MIT License
- Glucose: MIT License
- Lingeling: MIT License
- Kissat: MIT License
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.