Package indexes

A package index is just metadata about what packages exist and what versions are available for them. Indexes are just directories of either package manifests (spn.toml) or packages releases (JSONL metadata pointing at manifests).

Packages, whether for code written by you or for upstream libraries, whether public or private, should be simple to publish and simple to consume. If you can make a Git repository, you have everything you need to share packages across all your code!

Manifest format

The simplest possible index is just a directory of packages:

packages
├── flecs
│   └── spn.toml
├── fmt
│   └── spn.toml
├── imgui
│   └── spn.toml
├── sdl2
│   ├── spn.c
│   └── spn.toml
├── sdl2_mixer
│   └── spn.toml
└── tracy
    └── spn.toml

This is an index, believe it or not. It uses the manifest format, since the index itself is just a directory of manifests. Point your build at it like this, or enable it globally in ~/.config/spn/spn.toml:

[[index]]
name = "whatever"
path = "./packages"

Each folder has to be named after the package inside it, so flecs/spn.toml is the manifest that says name = "flecs".

Hosting on Git

That directory doesn't have to live on your disk. Push it to a Git repository and it works the same way; that's all that spam is. Add a metadata file, spn.index.toml, at the root of the repository:

version = 1
format = "manifests"

Once you've pushed, you can add the repository as an index by URL:

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

Adding an index clones it, validates it, and then adds the following configuration to your spn.toml. Pass --global to write it to your user config file instead of the project.

[[index]]
name = "spam"
url = "https://github.com/boonbane/spam.git"

Multiple package versions

If you need multiple versions to exist at the same time, each subdirectory of a top level package directory is treated as a separate version of the package:

packages
├── libfoo
│   └── 1.0.0
│       └── spn.toml
│   └── 2.0.0
│       └── spn.toml

The subfolder's name is up to you; the version is read from version in the manifest, not the directory name. Versions must be unique, and if e.g. libfoo/spn.toml exists, the versions are ignored.

Updating an index

These indexes work like a tiny, self contained ecosystem, like how vcpkg works. Every package lives in one commit. The first build takes the tip of the default branch and writes it to spn.lock:

[[index]]
name = "spam"
url = "https://github.com/boonbane/spam.git"
rev = "9b3cd3ebd05f5b39df7652d8f9372eeac08471b3"

Every build after that reads the index at that commit, so nothing you get from it changes until you move it. spn update moves this commit to the tip of the repository, and since every package must live at this commit, every package from this index is updated to the newest valid version.

Updating a package

Updating a single package (e.g. spn update lua), leaves the index itself where it is. It chooses among the versions of lua already in the pinned commit of the index.

Publishing

It's just a directory! If it's local only, add the file and you're done. If it's remote, git push.

This is all that most folks need. However, when you have a package with multiple versions that are used downstream, duplicating the entire spn.toml just to make one small change is inconvenient and unmaintainable. For this problem, we turn to releases.

Release format

Let's say you have a project that uses sqlite at 3.51.0. You like it. But then, Richard Hipp returns from an ayahuasca retreat having had a vision: 4.0. You can prompt an LLM from inside a SQL query, to say the least.

You want to start a new project and use it, but you still need 3.51.0. This is where releases come in. A release allows you to keep manifest changes in version control and use metadata, rather than directory structure, to list which versions exist.

In spn, a release format index is a directory of JSONL files, one for each package, plus spn.index.toml.

index
├── spn.index.toml
└── sqlite.jsonl

Each JSONL entry is a release specifying the version, where the source code is, where the manifest is, etc. They're created with spn publish, not by hand.

{
  "name": "sqlite",
  "version": "4.0.0",
  "yanked": false,
  "v": 1,
  "source": {
    "url": "https://github.com/sqlite/sqllm.git",
    "rev": "a1de0694c693a5d741b2b424e5dfea45eaa30e69"
  },
  "manifest": {
    "url": "https://github.com/you/manifests.git",
    "rev": "c7faa527fd3e91b04a6d2c8f5e7a1b9d0c4f6e82",
    "dir": "sqlite"
  },
  "paths": {
    "manifest": "spn.toml"
  },
  "deps": [
    { "name": "zlib", "version": "^1.3.0", "kind": "normal" },
    { "name": "curl", "version": "^8.0.0", "kind": "normal", "when": { "llm": true } }
  ],
  "targets": [
    { "name": "sqlite", "linkages": ["static", "shared"] }
  ],
  "options": {
    "llm": { "type": "bool", "default": [{ "value": true }] }
  }
}

Note the manifest field. If sqlite decided that spn is the tool of the future, and decided to have a first party manifest that lives in their repo, this field would point to the real sqlite/sqlite.git. But since we're writing a package for a third party library that doesn't know we exist, we point it at a repository that we own.

Add the index the same way, producing the same TOML configuration. This time, it's an SSH URL, just to show that both are supported:

spn index add git@github.com:you/whatever.git
[[index]]
name = "whatever"
url = "git@github.com:you/whatever.git"

Updating

Unlike a manifest index, a release index isn't pinned to a commit. That's the point! Each release already names the exact commits of its source and manifest, and those are what spn.lock records. New releases can land in the index without changing anything you've locked.

spn update is therefore not needed to see newly published packages or versions. However, spn doesn't try to grab the index on every build. It fetches at most once every ten minutes, and if a fetch fails, it warns you and uses the copy it already has. If you just published a release and don't want to wait, fetch by hand:

spn index sync

Publishing

You don't need to do anything special to start an index of releases. Create an empty Git repository, write its [[index]] entry by hand (spn index add can't clone an empty repository). Run spn publish from the package's directory to to append a release to the package's JSONL file and push:

spn publish --index whatever

This doesn't upload any code; the release points at your origin remote and the commit you have checked out, so commit and push before you publish. Pass --dry to print the release without publishing it.

To take a release back, set yanked to true in its entry and push. Projects that already locked it keep it, and nothing else resolves to it.

Manifest revisions

Let's say you're writing a package for SQLite (again). You package 3.51, publish it, and all's good.

But, ah! You made a mistake. You don't need to change the source code, but you need to define ENABLE_FROBNICATOR when you build it. You can't bump to 3.52, because at some point SQLite itself will release 3.52. You want something like 3.51-2.

This is called a manifest revision, and spn doesn't have them yet. There's no structural problem, and it's on the roadmap, but if you need this behavior you can edit the JSONL release.

Metadata

An index describes itself with an spn.index.toml at its root:

version = 1
format = "releases"
path = "index"

Here's the full schema; it's very simple, and mostly intended to make forward compatibility easy.

KeyMeaning
versionThe version of the index layout, which is 1 today
formatmanifests for a directory of $name/spn.toml packages, or releases for $name.jsonl files
pathThe folder inside the index that holds the packages or releases, if that isn't the root. Optional

A remote index has to have this file, and spn refuses a repository without it. A local index can skip it, in which case it's read as manifests.

spn publish, which writes JSONL release entries to an index of releases, writes this file if it's not present. You only need to handwrite it when you're using a simple, flat directory of manifests.

The ecosystem

Here's some of the packages which have native, high quality spn manifests. The full list is in spam, the package manifest repository. If a package is on this list, it has full support. That means you can cross compile it, pull in its optional dependencies, build its examples, and so on.