spn treats your toolchain as a proper input to your build, just as much as your source code. Its aims are:
- Work, out of the box, with the stock toolchains that come with your distro or OS
- Make it easy to express what arbitrary custom toolchains can do
- Provide mechanisms for fetching toolchains pinned, verified tarballs
Zig
spn bundles the excellent Zig toolchain. The folks at Zig have done the tedious work of putting together sources, headers, and stubs for quite a few platforms, and when we say "the Zig toolchain", we mean the tarball that contains these sources, a Zig compiler, various bits of Zig code which implement smaller pieces of the puzzle, and, most importantly, a build of Clang which is preconfigured to use all of it.
spn downloads it on the first build and verifies its checksum if no toolchain is specified, which means you don't even need a compiler installed to use it!
Defining a toolchain
- A
[[toolchain]]goes in the project manifest or the user config, and the project's wins. - Every field is in the manifest reference.
System toolchains
A system toolchain is just our shorthand for such a [[toolchain]] entry that, instead of pointing at a path inside an extracter tarball, points at e.g. "whatever gcc resolves to on this machine". Specifically, clang, llvm, gcc, and msvc are builtin names for compilers already on the machine1.
System toolchains are designed to represent a reasonable subset of what you can expect to find on any given distro, and since most stock toolchains are either (a) fundamentally limited to one compilation target, or (b) capable of cross compiling, but only if given the appropriate sources, these system toolchain entries do not assume cross compilation.
Fear not! "Enabling" cross compilation with whatever toolchain you happen to have just means telling spn what it is that you actually happen to have. Writing a few lines of TOML, in other words. And, of course, those of us over in Zigland will be getting hand fed grapes and fanned with giant palm fronds and if you'd care to join us.
A compiler on your PATH
- A bare program name is looked up on
PATH; an absolute path works too. driveris the command line the compiler speaks:gcc,clang,msvc, orzig.hostlists the machines the toolchain runs on, andtargetwhat it builds for; withouttarget, only the host.
[[toolchain]]
name = "mingw"
driver = "gcc"
compiler = "x86_64-w64-mingw32-gcc"
archiver = "x86_64-w64-mingw32-ar"
cxx = "x86_64-w64-mingw32-g++"
host = { x86_64-linux = {}, aarch64-linux = {} }
target = [{ arch = "x86_64", os = "windows", abi = "gnu" }]A downloaded toolchain
[toolchain.host]maps each host to an archive'surlandsha256;spndownloads it once and verifies it.- The program paths are then relative to the root of the archive.
[[toolchain]]
name = "arm-gnu"
version = "14.2.rel1"
driver = "gcc"
compiler = "bin/aarch64-none-linux-gnu-gcc"
archiver = "bin/aarch64-none-linux-gnu-ar"
cxx = "bin/aarch64-none-linux-gnu-g++"
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" }
aarch64-linux = { url = "https://developer.arm.com/-/media/Files/downloads/gnu/14.2.rel1/binrel/arm-gnu-toolchain-14.2.rel1-aarch64-aarch64-none-linux-gnu.tar.xz", sha256 = "299c56db1644c135670afabbf801b97a42e5ef6069d73157ab869458cbda2096" }Sysroots and SDKs
sdkon a target row is the sysroot or SDK to build that target against."host"keeps the toolchain's own host target beside the rows you list.
A system clang cross compiling to ARM Linux against a sysroot:
[[toolchain]]
name = "clang-sysroot"
driver = "clang"
compiler = "clang"
archiver = "llvm-ar"
linker = "lld"
link_args = ["-fuse-ld=lld"]
host = { x86_64-linux = {} }
target = ["host", { arch = "aarch64", os = "linux", abi = "gnu", sdk = "/sysroot/arm64" }]The MSVC ABI from Linux, against an xwin SDK:
[[toolchain]]
name = "clang-xwin"
driver = "clang"
compiler = "clang"
archiver = "llvm-ar"
cxx = "clang++"
linker = "lld"
link_args = ["-fuse-ld=lld"]
host = { x86_64-linux = {} }
target = [{ arch = "x86_64", os = "windows", abi = "msvc", sdk = "/opt/xwin" }]macOS from Linux, against a macOS SDK:
[[toolchain]]
name = "osxcross"
driver = "clang"
compiler = "clang"
archiver = "llvm-ar"
linker = "lld"
link_args = ["-fuse-ld=lld"]
host = { x86_64-linux = {}, aarch64-linux = {} }
target = [{ arch = "aarch64", os = "macos", abi = "apple", sdk = "/opt/MacOSX15.sdk" }]Sanitizers
spnnever probes a compiler for what it supports; that comes from the declaration.- The builtin system toolchains carry defaults, which can't match every install. If yours differs, declare it under the same name with its actual capabilities.
sanitizerson a target row lists what the toolchain has for that target; anything unlisted is refused.
[[toolchain]]
name = "clang"
driver = "clang"
compiler = "clang"
archiver = "ar"
cxx = "clang++"
target = [{ arch = "x86_64", os = "linux", abi = "gnu", sanitizers = ["address", "undefined"] }]MSVC
Look, there's more important things to finish in these docs, but I just wanted to point out that not only does spn not need a Developer Command Prompt, it provides one for you. It detects your Visual Studio and Windows SDK installations and provides a handy spn msvc command which you can use like this:
spn msvc --format powershell | Invoke-ExpressionOr, if you prefer:
spn msvc -- whatever.exeYou can also pass --toolset, --sdk, and --arch to specify the specific shell you want. Right now, it only adds what's needed to the path for compiling and linking, but I have a branch ready to go which gives you the rest!
- From another host, declare the SDK on a target row.
Footnotes
-
llvmisclangwithlldandllvm-ar. ↩