Title here
Summary here
Accepted
2026-04-19
ADR-0002 chose scryer-prolog (Rust) as the Prolog backend. After 9 days of production use, several pain points emerged:
objcopy workaround for Rust’s libc GLIBC version symbols is fragile and Linux-only.cargo fmt, cargo clippy, and cross-compilation targets.Trealla Prolog is a C99 ISO-compliant Prolog implementation that can be compiled directly by Zig’s built-in C compiler, eliminating all Rust dependencies.
| Option | Pros | Cons |
|---|---|---|
| Keep scryer-prolog (Rust FFI) | Battle-tested; already working; full ISO compliance | Two toolchains; slow builds; GLIBC patching; large binary |
| Trealla Prolog (C99 FFI) | Single toolchain (Zig compiles C); fast builds; small binary; ISO compliant | Requires C compatibility wrapper; less community than scryer |
| Pure Zig Prolog engine | Ideal single-toolchain story | Multi-month effort; no production WAM in Zig exists |
Replace scryer-prolog with Trealla Prolog, vendored as a git submodule at ffi/trealla/ and compiled via Zig’s built-in C compiler.
Specifically:
ffi/trealla-wrapper.c file exposes the same 9 prolog_* C-ABI functions that ffi.zig declares, translating between Trealla’s native API (pl_create, pl_eval, pl_consult, pl_destroy) and the existing interface. This means ffi.zig, engine.zig, all 24 tool handlers, and all 190+ tests need zero changes.[{bindings}, ...] that engine.zig:parseQueryResult() expects, maintaining full compatibility.build.zig compiles Trealla’s C source files via addCSourceFiles(). No Cargo, no objcopy, no OpenSSL linkage.-DUSE_OPENSSL=0 -DUSE_FFI=0 for a minimal ISO Prolog core.cargo fmt/cargo clippy steps, no cross-compilation target matrix.-Dtarget=aarch64-linux-gnu).| Principle | Status | Justification |
|---|---|---|
| Flat module structure | Compliant | Trealla wrapper lives in ffi/, no new abstraction layers |
| Executable-only project | Compliant | No library module changes |
| Tool handler signatures unchanged | Compliant | C wrapper preserves all 9 FFI function signatures |
| Inline tests in every handler | Compliant | All 190+ existing tests pass against new backend |
| Engine public API preserved | Compliant | Engine struct, Term union, QueryResult — zero changes |