Skip to content

Latest commit

 

History

4 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

azazel-parity-sqlite

SQLite built two ways, to prove and compare azazel and zaza against a real third-party C library. This is the corpus's clean test of building a C library from source rather than consuming a prebuilt one.

  • azazel builds a Zig program that compiles SQLite's amalgamation (sqlite3.c) as a native C source, links libc, and calls into it through @cImport. The whole C-in-Zig build is declared as data in a CUE model.
  • zaza compiles libsqlite3.a from source as a C static library, then builds and links a downstream C consumer that runs a query.

Neither vendors SQLite's sources. Each side stages the pinned amalgamation with its own fetch.sh into a git-ignored vendor/.

Pinned upstream

Source SQLite amalgamation
Version 3.46.1 (sqlite-amalgamation-3460100)
Files sqlite3.c (9.1 MB) + sqlite3.h
Deps none

Build it

# azazel: compile sqlite3.c inside a Zig program via the CUE model
cd azazel && ./fetch.sh && sh gen_build_spec.sh && zig build && ./zig-out/bin/sqlite_demo
# -> sqlite 3.46.1
#    SELECT 2 + 3 = 5

# zaza: compile libsqlite3.a from source, link + run a C consumer
cd zaza && ./fetch.sh && zig build run
# -> zaza+sqlite slice: built libsqlite3 from source, SELECT sum(n) = 9 (sqlite 3.46.1)

Comparison

Clean-cache builds, Apple Silicon, fastest of two runs. Both sides compile the same 9.1 MB amalgamation, so the compile itself dominates.

Build Clean build Config
native cc -O2 7.1 s a compiler invocation, no build system
CMake (configure + build) 8.7 s CMakeLists.txt — 7 lines
zaza 11.7 s build.zig — 67 lines
azazel (cold) 14.1 s project.cue — 22 lines
azazel (warm shared cache) 0.25 s restores the artifact, skips the compile

Two honest readings:

  • Cold, on a single C file, plain cc wins. zig cc carries real overhead compiling the 9 MB amalgamation that clang alone does not, so azazel and zaza are slower than cc on a first build. Against CMake, the build system a C project would actually use, zaza and azazel are within a few seconds and skip the configure step.
  • Repeat builds invert it. The azazel key is computed from the model before compiling, so a warm shared-cache build restores the finished artifact in 0.25 s. Every rerun, every CI job, and every other machine skips the 7 s compile that cc pays every single time.

The point of this slice is not to beat cc at compiling one file. It is that both systems build a real C library from source, and that azazel's model-keyed cache turns the second build and every build after it into a restore.

Build process

Both roots stage the amalgamation with fetch.sh (a curl of the official zip) into a git-ignored vendor/; no upstream source is committed.

  • azazel: sh gen_build_spec.sh runs CUE and emits build_spec.zig (the build as data), then zig build compiles sqlite3.c into a Zig executable that links libc and calls the C API. The CUE step is memoized — it re-runs only when the model changes.
  • zaza: zig build compiles sqlite3.c into a static library with the feature defines as its own compile options, then links a C consumer against it through the Zig build graph.

The shared cache

azazel/cache_build.sh computes a content key from the model — the normalized CUE, the sources reachable via @import, the pinned inputs, and the toolchain — without invoking the compiler, then restores zig-out from a free GitHub Releases store on a hit. CI runs through it: the first build of a commit uploads the keyed artifact, and every rerun downloads it and skips the compile.

About

SQLite built two ways: azazel (CUE model) and zaza (Zig build graph). The corpus test for building a C library from source.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages