Quickstart

Install

spn doesn't provide any packages for OS package managers at the moment. Install by grabbing and running the latest install script, which you can and should read:

curl -fsSL https://github.com/boonbane/spn/releases/latest/download/install.sh | sh

This launches a short, interactive installer which will put spn on your PATH and configure your shell(s). Set SPN_INSTALL_AUTO for unattended installation. By default, it is installed to $HOME/.spn/bin everywhere.

Hello, world!

To create a project:

spn init

This will create three files, spn.toml, main.c, and .gitignore, failing if any already exist. The command prompts you for a name, and creates a manifest like this:

[package]
name = "hello"
version = "0.1.0"

[[bin]]
name = "hello"
source = ["main.c"]

Build your project:

spn build
./build/debug/hello

By default, builds go in build/$profile, uses the debug profile, and compiles all libraries, executables, tests, and examples. Pass the name of a target to just build that target, or e.g. --test for just tests. Next, we'll look at how to use a dependency.

Dependencies

Let's use the following program, which needs to link to Lua, as an example:

#include <stdio.h>
#include "lauxlib.h"
#include "lualib.h"

int main(void) {
  lua_State *L = luaL_newstate();
  luaL_openlibs(L);
  luaL_dostring(L, "print('hello, world!')");
  lua_close(L);
  return 0;
}

Since C, unlike many languages, has no central package registry, you need to choose where your Lua package comes from. Out of the box, you can use spam1, which has packages for many common C libraries written and maintained alongside spn. Add it, and then add Lua:

spn index add https://github.com/boonbane/spam.git
spn add lua

This adds an entry to your manifest's [deps.package]. Packages can be vendored, or come from self-contained directories locally, or properly published to an index of releases; they can come from public or private repositories. You can read more about packaging here.

With your new main, build:

spn build
./build/debug/hello

Cross compilation

Cross compilation is first class in spn. You can cross compile the same Lua example trivially:

spn build --target x86_64-windows-gnu
spn build --target aarch64-macos
spn build --target x86_64-linux-gnu

When you explicitly pass a target, the build goes in build/$target/$profile. The above commands produce:

  • build/x86_64-windows-gnu/debug/hello.exe
  • build/aarch64-macos-apple/debug/hello
  • build/x86_64-linux-gnu/debug/hello

Build directory

In addition to executables, the build directory for a given profile (e.g. build/x86_64-windows-gnu/debug) also contains:

  • test/, your test executables
  • store/$pkg, an install prefix for every package in your workspace
  • .spn/, build metadata and work directories for metaprograms
  • .spn/build.jsonl, a rich, structured JSONL event stream from your build (equivalent to --json output)

compile_commands.json

spn generates compile_commands.json out of the box, no configuration needed.

Installer

The installer comes as either a shell script or a PowerShell script. Both of these scripts are extremely thin programs which mostly just download and verify the appropriate spn executable. Any logic is implemented in spn itself, and exposed via spn self.

The entry point for that code is here, roughly. I encourage you (or your helpful digital assistant) to read these sources. If you find anything in the installer difficult, insecure, or in any way wrong, I'd be happy to hear from you on our Discord or personally over email.

What's next?

If you'd like to get a feel for the tool, clone the repository and experiment with the many examples we have. You can also read packages for existing libraries to understand what real world usage looks like

If you'd rather work through more documentation and see what spn is capable of, you might want to read about:

Footnotes

  1. spn's package manifests ↩