spn is the build system that C deserves
in which we spatchcock the elephant
2026/11/24
Happy Thanksgiving! spn is a build system and package manager for C and C++ that aims to bring the first rate developer experience of other languages to ours.
It’s written in plain C99, and ships as a single binary with no dependencies. You can bring your own toolchain, or use the bundled Zig. From any Windows, macOS, or Linux machine, it can compile (or cross compile) curl, OpenSSL, SDL3, and about 70 other libraries from source. And as of today, it’s available as a public alpha!
It natively executes every compile and link in your build. It doesn’t wrap CMake, or any other build system. It comes with a CI-friendly build cache, like Nix or Bazel, a stable C ABI for driving builds programmatically, and a flexible, Git based package manager which works equally well resolving versions from an index as it does pinning to commits. Packages are plain TOML manifests, and build scripts run in a sandbox.
I have plenty to say about why I believe spn is very different from the glut of tools we currently use to build C and C++, but I just made some pretty bold claims. So first, let’s walk through an example. Everything I’m going to show you here is real, today, and you can install it and read the docs if you’d prefer.
Finally, this is an announcement that spn is in alpha. There’s so much more to be done, and if you’re unsure whether some limitation is by design, by error, or because there’s only so much time in a day, check the roadmap.
Demo: Cross compiling libcurl
After, of course, reading the installer’s source code, install spn and set up a new project:
curl -fsSL https://github.com/boonbane/spn/releases/latest/download/install.sh | sh
spn initThis gives a familiar looking package manifest in spn.toml:
[package]
name = "hello"
version = "0.1.0"
[[bin]]
name = "hello"
source = ["main.c"]
And let’s write a simple C program that uses libcurl to fetch a web page:
#include <curl/curl.h>
#include <stdio.h>
int main(void) {
CURL* curl = curl_easy_init();
curl_easy_setopt(curl, CURLOPT_URL, "https://example.com/");
curl_easy_setopt(curl, CURLOPT_NOBODY, 1L);
curl_easy_perform(curl);
#if defined(SPN_BUILD_OS_MACOS)
curl_easy_setopt(curl, CURLOPT_CAINFO, "/etc/ssl/cert.pem");
#elif defined(SPN_BUILD_OS_LINUX)
curl_easy_setopt(curl, CURLOPT_CAPATH, "/etc/ssl/certs");
#endif
long status = 0;
curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &status);
printf("https://example.com/: %ld\n", status);
curl_easy_cleanup(curl);
return 0;
}
Since C isn’t a monoculture like Rust or JS, package indexes are decentralized. Add spam, an index that provides some packages out of the box, and add curl to your project:
spn index add https://github.com/boonbane/spam.git
spn add curlAnd finally, build. Cross compilation is first class, regardless of your host OS. I’m on x86_64-linux-gnu1, so let’s cross compile to aarch64-linux-gnu
> spn build --mode release --target aarch64-linux-gnu
Resolving ▐ hello
Resolved ▐ 3 packages in 1.6 ms
Downloading ▐ curl https://github.com/boonbane/spam.git
Downloading ▐ curl https://github.com/curl/curl.git
Downloading ▐ mbedtls https://github.com/Mbed-TLS/mbedtls.git
Downloading ▐ zig https://zig.chainsafe.dev/zig-x86_64-linux-0.16.0.tar.xz?source=spn
Downloaded ▐ 3 packages in 4 s
Building ▐ hello release, aarch64-linux-gnu, zig 0.16.0
Building ▐ libc aarch64-linux-gnu
Compiling ▐ curl v8.19.0
Compiling ▐ hello v0.1.0
Compiling ▐ mbedtls v3.6.7
Finished ▐ profile release in 5 s (304 executed, 0 cached)
Let’s do a little horn tooting! We just cross compiled, from source, not just libcurl but also mbedTLS and libc itself. We did not invoke cmake, autoconf, make, or anything except the compiler, archiver, and linker. We’ll look at what the curl package looks like, but first, a few more things that are difficult-to-impossible elsewhere.
Bring your own toolchain
Let us first of all give thanks to the folks at Zig, whose excellent toolchain bundles everything we need to cross to tons of targets and which spn uses as its default toolchain. But nothing in spn demands, or even prefers, any particular toolchain.
For example, let’s switch to the official ARM GCC cross toolchain for x86_64 hosts. Add the toolchain to spn.toml
[[toolchain]]
name = "arm-gnu"
version = "14.2.rel1"
driver = "gcc"
compiler = "bin/aarch64-none-linux-gnu-gcc"
archiver = "bin/aarch64-none-linux-gnu-ar"
target = [{ arch = "aarch64", os = "linux", abi = "gnu" }]
[toolchain.host]
x86_64-linux = { url = "https://developer.arm.com/-/media/Files/downloads/gnu/14.2.rel1/binrel/arm-gnu-toolchain-14.2.rel1-x86_64-aarch64-none-linux-gnu.tar.xz", sha256 = "47aeefc02b0ee39f6d4d1812110952975542d365872a7474b5306924bca4faa1" }
And then let’s build an ARM binary:
> spn build --toolchain arm-gnu --mode release --target aarch64-linux-gnu
Resolving ▐ hello
Resolved ▐ 3 packages in 1.7 ms
Downloading ▐ arm-gnu https://developer.arm.com/-/media/Files/downloads/gnu/14.2.rel1/binrel/arm-gnu-toolchain-14.2.rel1-x86_64-aarch64-none-linux-gnu.tar.xz
Downloaded ▐ 1 package in 23.8 s
Building ▐ hello release, aarch64-linux-gnu, arm-gnu 14.2.rel1
Compiling ▐ curl v8.19.0
Compiling ▐ hello v0.1.0
Compiling ▐ mbedtls v3.6.7
Finished ▐ profile release in 1.9 s (303 executed, 0 cached)
You can always bring your own toolchain, because like everything else, toolchains are just data. They can exist locally, like in a Docker image, or spn can fetch them for you, but the important part is that the toolchain is an input to the build. For platform toolchains, like Xcode SDKs or Visual Studio, spn knows how to detect them.
Builds are cached
Let’s say that you decide that this whole TLS nonsense is more trouble than it’s worth. Lucky for you, spn packages provide optional features, and this curl package has one for just this case. Add this to your project’s spn.toml:
[config.curl]
options = { tls = false }
Then, we’ll build again:
> spn build --toolchain arm-gnu --mode release --target aarch64-linux-gnu
Resolving ▐ hello
Resolved ▐ 2 packages in 697.7 us
Building ▐ hello release, aarch64-linux-gnu, arm-gnu 14.2.rel1
Compiling ▐ curl v8.19.0
Compiling ▐ hello v0.1.0
Finished ▐ profile release in 884.3 ms (185 executed, 1 cached)
Notice a few things:
- Only 2 packages are resolved; the package manager is expressive enough for most kinds of dependencies
- Disabling TLS touches every curl object, so they need to be recompiled, but publishing
include/curl/*.his a cache hit
When we later see the error of our ways and turn TLS back on, everything is cached:
> spn build --toolchain arm-gnu --mode release --target aarch64-linux-gnu
Resolving ▐ hello
Resolved ▐ 3 packages in 1.6 ms
Building ▐ hello release, aarch64-linux-gnu, arm-gnu 14.2.rel1
Finished ▐ profile release in 11.7 ms (0 executed, 303 cached)
spn uses a content-addressed cache, which makes it more closely related to Nix or Bazel than to Make or Ninja. Practically, it means that you can move between worktrees, toggle options deep in your dependency tree, and upload your cache to CI and spn will always rebuild as little as possible.
Windows is first class
Windows is first class. Too often, the real value in CMake is simply providing a build that can run on all three major OS. Many builds are quite simple, but the glue needed to write two parallel builds is a nonstarter. spn happily solves this problem.
Out of the box, you can cross compile hello.exe with the MinGW provided by Zig:
> spn build --target x86_64-windows-gnu --mode release
Resolving ▐ hello
Resolved ▐ 2 packages in 742.1 us
Building ▐ hello release, x86_64-windows-gnu, zig 0.16.0
Building ▐ libc x86_64-windows-gnu
Compiling ▐ curl v8.19.0
Compiling ▐ hello v0.1.0
◇ Building
│ ████████████████████████████ 100%
│ 187/187 units
Finished ▐ profile release in 2.4 s (187 executed, 0 cached)
But…Windows is first class! spn fully supports MSVC. Here, I’m building from a Windows box with a Visual Studio install (you don’t need to run it from a developer shell), but e.g. xwin with a compatible clang, or any other Windows-targeting compiler, works just as well:
> spn build --mode release --toolchain msvc
Resolving ▐ hello
Resolved ▐ 2 packages in 1.2 ms
Building ▐ hello release, x86_64-windows-msvc, msvc
Compiling ▐ curl v8.19.0
Compiling ▐ hello v0.1.0
Finished ▐ profile release in 14.3 s (187 executed, 0 cached)
Where did the build go?
You’re probably wondering what eldritch monstrosity must be hidden behind spn add curl for this to work so simply when just the top level CMakeLists.txt upstream is 2500 lines of code. Here’s what we used to build, with a little repetition omitted for brevity:
[package]
name = "curl"
version = "8.19.0"
[package.upstream]
url = "https://github.com/curl/curl.git"
commit = "8c908d2d0a6d32abdedda2c52e90bd56ec76c24d"
[deps.package]
mbedtls = { version = "3.6.7", when = { tls = true, os = { not = "windows" } } }
[options.tls]
type = "bool"
default = true
[options.ftp]
type = "bool"
default = true
# ...20 or so options omitted
[[lib]]
name = "curl"
kinds = ["static"]
include = ["lib", { path = "config", tree = "manifest" }]
define = [
"BUILDING_LIBCURL",
"HAVE_CONFIG_H",
{ value = "USE_SCHANNEL", when = { os = "windows", tls = true } },
{ value = "USE_MBEDTLS", when = { os = { not = "windows" }, tls = true } },
{ value = "CURL_DISABLE_FTP", when = { ftp = false } },
# ...one per feature option
]
source = [
"lib/*.c",
"lib/curlx/*.c",
"lib/vauth/*.c",
"lib/vtls/*.c",
"lib/vquic/*.c",
"lib/vssh/*.c",
]
system_deps = [
{ lib = "pthread", when = { os = "linux" } },
{ lib = "ws2_32", when = { os = "windows" } },
# ...five more on Windows
{ lib = "normaliz", when = { os = "windows", idn = true } },
{ lib = "icucore", when = { os = "macos", idn = true } },
{ framework = "SystemConfiguration" },
{ framework = "CoreFoundation" },
]
This is a very minimal packaging of curl that can be compiled as a static library and provides optional support for around 20 features. Paired with this is a simple configuration header, just like the one the upstream build might produce:
#if defined(SPN_BUILD_OS_WINDOWS)
#include "config-win32.h" // Upstream already gives us this!
#if defined(SPN_BUILD_ABI_GNU)
#include "platform/mingw.h"
#endif
#elif defined(SPN_BUILD_OS_MACOS)
#include "platform/posix.h"
#include "platform/macos.h"
#elif defined(SPN_BUILD_OS_LINUX)
#include "platform/posix.h"
#include "platform/linux.h"
#if defined(SPN_BUILD_ABI_GNU)
#include "platform/glibc.h"
#elif defined(SPN_BUILD_ABI_MUSL)
#include "platform/musl.h"
#else
#error "spn curl: unsupported libc"
#endif
#else
#error "spn curl: unsupported platform"
#endif
// The Linux header
#ifndef SPN_CURL_LINUX_H
#define SPN_CURL_LINUX_H
#define CURL_OS "Linux"
#define _FILE_OFFSET_BITS 64
#define HAVE_ACCEPT4 1
#define HAVE_CLOCK_GETTIME_MONOTONIC_RAW 1
#define HAVE_EVENTFD 1
// ...
#endif
In other words, there’s no trick to it. Instead of letting a program detect things we already knew, imperatively, we wrote them down ourselves, declaratively. Where it’s truly a choice, like whether you want TLS and if so which backend, it becomes an option that the consumer sets.
The discerning reader may be thinking, “Wait a minute, I lived in a world where you had to handwrite HAVE_ACCEPT4, and it sucked! autoconf solved this problem before you were born!” But these tools were made for a different world; a world with proprietary Unixes where you really couldn’t know whether a function existed, which header it was in, and whether the platform’s implementation was broken. Now, we live in a world of homogeneity, where software is compiled in containers and VMs using open source toolchains which implement standards that have had thirty years to settle.
We don’t live in that world anymore. This package reproducibly builds perhaps the most important C library for Linux, macOS, and Windows across two architectures, GNU, musl, MinGW, and MSVC, and does it from any host machine.
Of course, this packaging doesn’t write down every fact that any consumer of curl may ever need, and it may hardcode some things an unusual consumer needs to configure. The difference is that instead of forcing you to own an imperative build which may span the package manager’s language, the CMake generator it calls, and the project a lower level tool finally executes, you own data.
Builds are data
Builds are data. Or, more precisely, builds are functional. One of the best and most seminal papers on build systems compares them by implementing them Haskell programs.
But even most precisely would be: Builds are functional until they aren’t. There are tons of things your build needs to do which simply can’t be supported by something in the spn core. For example, it’s the most natural thing in the world to take a schema and use it to generate some code. Maybe you’d even like to generate reference docs from them. Any build system which doesn’t understand this as a first class need is not going to be useful in practice.
spn gives you very basic TOML expressions for gating things on the facts of your build (e.g. “when targeting Windows, link an extra library”), but sometimes you have a schema and you need a C file. Build systems traditionally had two answers to this:
- DSLs. They’re hard to write, hard to read, and hard to debug. Nobody likes these, and they fall apart when you need them most.
- Give up, and let builds run arbitrary native code.
Builds are code
In spn, build scripts (called metaprograms) are plain, unrestricted C code which is compiled to WebAssembly by the bundled toolchain and run in a sandbox in-process. They link to wasi-libc, and they can have their own dependencies.
[package.build]
source = ["tools/build.c"]
[deps.build]
yyjson = "0.14.0"
SPN_EXPORT spn_err_t generate_config(spn_t* spn) {
yyjson_doc* doc = yyjson_read_file("/source/config.json", 0, NULL, NULL);
yyjson_val* foo = yyjson_obj_get(yyjson_doc_get_root(doc), "foo");
FILE* header = fopen("/work/config.h", "w");
fprintf(header, "#define CONFIG_FOO %d\n", yyjson_get_int(foo));
fclose(header);
return SPN_OK;
}
A few more lines register this as a step in the build; the docs have the whole thing.
Code is data?
WASM programs are pure by definition; they interact with the host system through mounted directories and syscall-shaped interfaces. spn hooks these interfaces such that it can trace every file opened, written to, or read for every build action in your metaprogram. This means that it can cache the execution of code, just like compilation, so that even your custom build actions get the benefit of sophisticated caching and correct ordering.
Modern language runtimes are often so complex and abstracted that the idea of running them on any substrate except a commercial OS is unfathomable. In other words, this is tenable because of C, not in spite of it. The runtime is so thin that most libraries compile to WASM without hassle, and the ones that don’t are the ones that want to shell out or talk to the network. In other words, exactly the things that ought not run inside a reproducible build.
Shut up and build it
Sometimes, though, you really just need to run a Python script that someone else wrote. And, to quote myself:
Any build system which doesn’t understand this as a first class need is not going to be useful in practice.
I don’t want theory or purity to get in the way of the most important thing: spn is a tool, and tools exist to serve. Sometimes, tools need to be rigid and people need to be malleable. And sometimes, tools need to be malleable so people can be rigid. spn is designed to be rigid at its core; once inside the build, each step must be provable.
But outside the build, it’s meant to help you get into all kinds of zany antics. [[tool]] executables let you write your build glue with the same code and dependencies as the rest of your code (a la this wisdom from the great Matklad). spn path and spn env give arbitrary programs what they need to find the source code and tools that are used inside your build.
Take, for example OpenSSL. The upstream build runs Perl to generate source code. Instead of rewriting the Perl code or forcing consumers to install Perl, the package carries a small native tool that runs upstream’s code generation once. Then, I publish these files along with the package. The impure part of the build is quarantined, and instead of fighting me, spn helps me by downloading and caching the source code and any external executables I might need2.
Cool story bro
When I started this project, I did a lot of research online about what folks actually thought about the status quo. And by far, the most common response was something like this:
That’s cool, but why wouldn’t you just use $(insert tool here, but usually CMake)?
CMake is as close to a standard as C and C++ have ever had. How could something with a wacky DSL, CMAKE_MINIMUM_REQUIRED, no actual build system, and a package manager which is roughly “whatever the hell your distro ships” become the standard option? Well, because it works3.
Why wouldn’t you use something that works? Even if it’s flawed, a flawed ecosystem that works is always better than one that fixes the warts but is fragmented or broken. In other words, it’s not enough to simply fix CMake’s quirks. Nobody cares that you have to write stuff like this:
target_link_libraries(app PRIVATE libwhatever)
Let me say that again: If writing that piece of code lets you do your job, nobody gives a shit about purity or WebAssembly or compiler probes or anything I just droned on about for probably too long. All people want is to do their job; this is a good thing.
People want this so badly that even new features aren’t enough to switch. For example, Meson lets you programmatically manipulate meson.build. You can hook it into an IDE and get first class support for all kinds of stuff. And nobody cares, because the whole world uses CMake and people just want to compile the program.
People only switch off of things like CMake when the new thing solves entire classes of problems for them. Meson4 has a lot of nice stuff, but it’s still a generator. You cannot succeed writing a generator, no matter how nice, because the sum total of all that niceness is still less than CMake’s inertia.
This is why I’m building spn. It is a fundamentally different bet.
The entire world
The ecosystem of tools that build C and C++ can roughly be split three ways:
- Generators. These are programs that generate inputs to another program which actually compiles your code.
- Executors. These are the programs that actually invoke the compiler.
- Package managers. These are programs that know how to produce named packages. Sometimes they build them, sometimes they serve binaries.
The bet spn makes is:
- By owning the entire build, it will solve entire classes of problems that no standalone generator or executor can
- By having a singular purpose, it will have a UX that no general purpose tool can have
Why not X?
I made a table of, roughly, the current ecosystem. Most tools blur the line between categories, but this is reasonably accurate. I’d like to talk about a few tools in particular.
| Tool | Kind | Package manager |
|---|---|---|
| cmake | generator | |
| meson | generator | |
| ninja | executor | |
| make | executor | |
| xmake | both | yes |
| bazel | executor | yes |
| build2 | executor | yes |
| zig build | executor | yes |
| premake | generator | |
| autotools | generator | |
| gn | generator | |
| msbuild | executor | |
| xcodebuild | executor | |
| buck2 | executor | |
| conan | yes | |
| vcpkg | yes |
Bazel
spn is like a purpose built Bazel which can provide much better UX for its purpose by virtue of being so much narrower.
We can provide better ergonomics for C, because all we do is compile C code. Easier setup, easier cross compilation, better Windows support. But…Bazel is Bazel. It’s got remote execution and caching, a queryable build graph, and many, many years of hammering out all the fiddly bits of reproducible builds at scale.
build2
Probably the closest in spirit to spn. It refuses to wrap other build systems, and it replaces probes with declarative data. However, it doesn’t reap all the rewards that come from owning the entire build (like a true, remote-friendly build cache), uses a custom data language, and doesn’t have a mechanism for running sandboxed code inside a build.
zig build
The fact that spn bundles Zig’s toolchain should tell you all you need to know about my opinion of Zig. Their approach to systems programming is my single biggest influence as a programmer and engineer, and I can’t thank them enough for the work they do and the care they do it with.
Many C libraries have quality zig.build ports, and zig cc has proven that just because it’s “not C” doesn’t mean a damn thing. But at the end of the day, Zig is rightfully focused on Zig. If your needs begin and end with compiling C binaries into Zig programs, it will be better than spn. But if you need to use any other toolchain, want sandboxed builds, or want a tool built for the weird corners of C, it won’t.
xmake
xmake is another build system that’s close in spirit. It’s a true executor, scheduling and invoking calls to the compiler itself, but only for your build. At the package layer, it mostly wraps external build tools. It’s also designed around compiler probes, and uses a traditional, mtime-based cache.
Roadmap
spn is nowhere near finished. It’s full of little misses, gaps, features it ought to have but doesn’t. Plus a couple, ahem, bigger misses. I’ve tried to catalog these, what’s shaky and what’s solid, plus my rough plans on the roadmap. Give it a read.
But damn it, I’m confident that it is based on a rock solid foundation and that one day, soon, you’ll look up and realize that it’s the best tool on the market by a long shot.
Arch, btw ↩︎
Nothing about WebAssembly rules out running Python or Perl, by the by. It’s just a matter of only so many hours in a day rather than a technical block. I have written a manifest for CPython, compiled it to a WASM module, and then used it to run a Python script in the same build. Or, if running it truly inside the build is still a nonstarter,
spncould provide basicpythonorperlbinaries without relying on a distro package manager. For example. ↩︎The aforementioned are not knocks on the folks who make CMake, who have willed their product to success through an unbelievable amount of the kind of raw, dirty engineering that nobody wants to do. CMake may be good in spite of itself, but it’s good because of its maintainers. ↩︎
If you work on Meson, I’m sorry that I’m picking on you. You have a good solution to the problem you wanted to solve, but I’m just arguing that it’s a problem that’s impossible to gain traction by solving. ↩︎