The Sparkles toolchain — Decisions
Consequential choices behind the specification, each with the question it answers, the alternatives, the evidence, and the conditions for revisiting it. Decision states are proposed, accepted or superseded; they say nothing about implementation progress, which PLAN.md tracks.
TCD1: One fork for every target
State: accepted.
Question. Should the shader compiler, the WebAssembly compiler and the host compiler stay separate builds?
Alternatives. Keep a stock LDC for the host, a WASI fork of LDC on its own LLVM, and a Vulkan fork on a patched LLVM; or one fork of each project carrying every change.
Evidence. The separate builds put three LDCs and three LLVMs in one development closure. The WASI fork's twelve commits were all superseded by upstream LDC, and the remaining WASI gap was one missing test. The stock host compiler's closure was 1.4 GiB, of which its bootstrap compiler and LLVM 18 libraries made up most.
Choice. One LDC fork and one LLVM fork, each rebased on upstream, for every target (TC1, TC2).
Revisit when a target needs a compiler change that conflicts with another target's.
TCD2: Upstreaming after production use
State: accepted.
Question. When should the fork commits be proposed upstream?
Choice. After the terminal, hue, font-explorer and the shaders packaged for other projects ship on the toolchain, so the changes arrive with real-world validation. Until then each change stays an atomic commit with a regression test (TC3), ready to submit. The dlang.nix packages stay on a feature branch that Sparkles pins, for the same reason: they are proposed for dlang.nix's main together with the fork commits they build.
Revisit when an upstream release would make a fork commit redundant, or a maintainer asks for one of the changes.
TCD3: Sparkles' nixpkgs drives the toolchain
State: accepted.
Question. dlang.nix pinned a nixpkgs fourteen months older than Sparkles'. Which nixpkgs should the toolchain use?
Alternatives. Keep them separate; make dlang.nix pin Sparkles' revision; or let Sparkles override dlang.nix's nixpkgs input.
Evidence. Separate pins put two glibc versions and two GCC runtimes into applications (hue loads GCC 14's libgcc_s and GCC 15's libstdc++), and the glibc split required a wrapper that parses -mtriple to keep host linker flags off cross links.
Choice. Sparkles' flake makes dlang.nix's nixpkgs follow its own (TC4). dlang.nix keeps an independent pin for its other users and is moved to the same nixos-unstable revision when it updates. Both move to the latest nixos-unstable ahead of the LLVM rebuild of TC-M3, for its newer GCC and its native wasm32-wasip1 platform.
Trade-off. Toolchain builds no longer match dlang.nix's own cache; Sparkles' binary cache carries them (TC23).
TCD4: The C compiler is the fork's clang
State: accepted.
Question. Which C/C++ compiler should toolchain packages use?
Evidence. The LLVM fork already builds clang, for the WASI runtime. A prototype wrapped it with nixpkgs' compiler wrapper without rebuilding LLVM; C, C++20 (<format>) and, on macOS, Objective-C with Foundation and __builtin_available compiled and ran on x86_64-linux and aarch64-darwin. The unwrapped clang on LDC's search path broke LDC's macOS build because the standard environment calls its compiler clang++.
Choice. clang-sparkles, a wrapper over the fork's clang, and a stdenv built from it (TC6, TC8). The LLVM package exposes libraries and llvm-config through an output with no compiler drivers (TC7).
TCD5: Compiler-rt ships with the compiler
State: accepted.
Question. Is building compiler-rt worth it when Linux programs use libgcc for builtins?
Evidence. Without compiler-rt, LDC's -fsanitize=address on Linux falls back to GCC's libasan, macOS has no sanitizer runtime, and -fprofile-instr-generate, -fsanitize=fuzzer and -fxray-instrument do not link. Profile data is versioned with LLVM, so only a matching runtime works with the toolchain's llvm-profdata and llvm-cov.
Choice. Build compiler-rt from the fork and install it into LDC and clang-sparkles (TC10–TC12). Builtins replace libgcc only in the profile of TCD6.
TCD6: An all-LLVM runtime profile
State: accepted.
Question. Should D programs link compiler-rt, libunwind and libc++ instead of libgcc, libgcc_s and libstdc++?
Evidence. For the default build the gain is small: C++ libraries from nixpkgs are built with GCC and load libgcc_s anyway, and glibc loads it for thread cancellation, so mixing a second unwinder into one process risks exceptions and backtraces that cross languages. Fully static builds, where every dependency is compiled by the same clang against libc++, avoid the mix and drop the GCC runtime from the closure.
Choice. Keep libgcc and libstdc++ by default; provide an opt-in profile with LLVM's runtimes and build the three applications statically under it (TC18–TC20).
TCD7: WASI previews 1, 2 and 3
State: accepted.
Choice. Build every WASI library from source (TCW1); previews 1 and 2 are production targets and preview 3 is experimental and allowed to fail (TCW2), so that its progress in wasi-libc is followed rather than waited for.
Evidence. A prebuilt WASI SDK provides only the previews it was released with, and its link-time-optimization libraries cannot be used with LLVM 24.
TCD8: LLVM assertions
State: accepted.
Question. Should the toolchain's LLVM keep its internal assertions?
Evidence. Assertions cost about 10 % in optimized D builds (:base in the checked build type, 17.2 s to 18.8 s) and turn SPIR-V backend defects into reports.
Alternatives. One assertions-enabled toolchain for every use; or a release variant for every default build step, shaders included, with an assertions-enabled variant reachable only from an opt-in shell for debugging the SPIR-V backend.
Decision rule. Adopt the pair only if the checked variant can be kept out of every default closure and the two variants share no build step that would pull both into one closure; otherwise keep one assertions-enabled toolchain (TC17).
Outcome. One assertions-enabled toolchain. The two variants would share no artifact: every LLVM library, clang, compiler-rt and LDC itself differ between them, so the pair doubles the toolchain's cache pins (about 2.4 GiB compressed per host, against a 10 GiB cache for three hosts), and the shader build, a default step, would have to move to the release variant while SPIR-V backend work goes on in the checked one.
Revisit when the cache limit grows, or the SPIR-V backend's defects stop being found by its assertions.
TCD9: Target set
State: accepted.
Choice. LLVM is built for AArch64, X86, SPIRV and WebAssembly (TC2), not host: naming the targets gives every build host the same compiler and covers Android devices, Android emulators and Windows cross builds from each host. ARM and NVPTX are left out; nothing in Sparkles targets 32-bit ARM Android or CUDA.
Revisit when 32-bit Android devices or dcompute's CUDA target become targets.
TCD10: Fork inputs fetched as Git checkouts
State: accepted.
Evidence. llvm-project marks clang/bindings/python/.git_archival.txt with export-subst, so GitHub rewrites it in every tarball, and Nix 2.32 and 2.35 computed different hashes for the same revision. A shallow Git checkout hashes the commit's tree, with the same result on both.
Choice. TC5.
TCD11: Runtimes built beside LLVM, not inside it
State: accepted.
Question. Build compiler-rt, libunwind and libc++ inside the LLVM build (LLVM_ENABLE_RUNTIMES) or as separate derivations against it?
Evidence. The LLVM build is the toolchain's longest step, and the runtimes change more often than LLVM does. As separate derivations against LLVM's development view, compiler-rt and every WASI library rebuilt without LLVM; three LLVM fork commits the WASI sysroots needed were applied to them as patches, with no LLVM rebuild.
Choice. Separate derivations from the LLVM fork's source: compiler-rt (TC10), the WASI sysroots (TCW1), and the all-LLVM profile's libunwind and libc++ (TC18). Fork commits that only the runtimes need are applied to them until the next LLVM rebuild takes them in (WTD36).
TCD12: Dynamic dependency hygiene in default application builds
State: accepted.
Question. Should application profiles link optional or test-only C libraries at compile time (libs in dub recipes), or rely on dynamic loading (dlopen) and minimal packaging?
Evidence. Linking libcurl at compile time in hue pulled in OpenSSL, Kerberos (GSSAPI), SSH2, HTTP/3 QUIC (nghttp3, ngtcp2), Brotli, and Zstandard transitively—accounting for over 20 shared libraries in ldd—even though hue is predominantly a local syntax-highlighting viewer and TUI. Similarly, sparkles:wsi linked xcb-xtest in its core library configuration even though xcb_test_* is only ever called by external integration test injectors. HarfBuzz also bundled GLib 2.0, PCRE2, FreeType, and libpng transitively despite sparkles:font using only HarfBuzz's core C ABI (hb_*) for cluster shaping and implementing font parsing, outline decoding, rasterization, and PNG strike decoding in pure D (FTX3, FTX4).
Choice. TC20a:
- Strip test-only libraries (
xcb-xtest) from the production library configurations ofsparkles:wsi. - Do not declare
libs "curl"inhue's default and terminal configurations. Phobos'std.net.curlloadslibcurl.so.4viadlopenon demand, and Nix wrapshuewithpkgs.curlMinimalinLD_LIBRARY_PATHfor runtime resolution. - Package
harfbuzzwith GLib, Graphite2, ICU, FreeType, and PNG disabled to prevent leaking transitive dependencies (libglib-2.0,libpcre2-8,libfreetype,libpng16,libbrotli,libbz2) into text-rendering consumers.
TCD13: CI builds the toolchain outputs that fit a job
State: accepted (the owner's direction, November 15, 2026).
Question. When a pull request moves the lock to a toolchain revision whose outputs no cache serves, who builds them?
Alternatives.
- A developer host, always (TC23 as first written). The gate only checks, and whoever moves the lock builds and pins the outputs with
ci/toolchain-pin.dfirst. - CI, always. Every missing output is built on a hosted runner.
- CI, for the outputs whose build fits a job; a developer host for the rest. The deciding figure is the output's recorded build cost.
Evidence. Pull request #731 moved the lock, and its gate stayed red because ldc-android's new store path was in no cache: nothing in CI builds a pinned output, and the only copy of the R2 signing key is in CI, so a developer host can push to Cachix alone. That output needed two derivations that compile nothing. The fork's LLVM, the costliest output, measured 17 minutes on x86_64-linux, 10 on aarch64-darwin and 35 on aarch64-linux on the reference hosts (closure measurements), well inside a hosted job's 6 hours on a runner with a third of the cores. ci/with-cache.sh pushes each derivation as it finishes, so a timed-out build keeps its progress; a single derivation longer than the job never does.
Choice. Alternative 3, with R2 as the cache of record and Cachix best effort (the owner's direction: everything is pushed to R2). A pin-plan job evaluates the toolchain's outputs for every host, asks R2, and plans the ones it lacks (apps/ci/src/derivation_pin_build.d). One Cachix still serves is copied to R2 by the mirror step, not rebuilt. Of the rest, an output is built by a pin-build job on a runner of its system when its cost is within the budget, or is not recorded. One over the budget is deferred to a developer host, and so is every missing output whose derivation closure holds it, with the command that builds it. The gate runs after the builds. An output's cost is the median of the builds pin-build recorded for it, one pin-build:<pin> task each, in the run records on refs/perf/data (OD21); ci cache pin-costs hands them to the plan. Nothing is estimated: an output never built has no cost and is attempted. The budget is ci/placements.json's pinBuildBudgetMinutes.
Alternative 1 blocks a pull request on a person for work CI can do. Alternative 2 spends six runner hours on every retry of an output that cannot finish in one job.
Revisit when a recorded cost exceeds the budget, which leaves that output to a developer host until the R2 cache accepts a second signing key held by one; or when the measurements show a hosted build costing more than the time a person takes to start one.
Open questions
- Q2: musl. Whether the static builds of TC20 also target musl, which needs a druntime build for musl and dependencies from nixpkgs' musl set. Decided after TC-M4.
- Q3: Preview 3 readiness. When wasi-libc and the component linker support preview 3 well enough to promote it to production (TCW2). Reviewed at each WASI toolchain update.
- Q4: Browser components. Whether the documentation site moves its modules from preview 1 to components, which browsers run only through a transpiler. Out of scope until a site component needs a preview 2 interface.
- Q5: The native Windows test leg. CI tests Sparkles on Windows outside Nix with a released LDC, which TC1 exempts. Whether Windows gets the fork, through a cross build or a native package, is undecided; until then Windows results do not count as evidence for this specification.