xcache (pronounced 'ten cache')

A remote content-addressable store for swiftc's compilation caching, hosted on Cloudflare Workers®.

Native clients (castool, the swiftc plugin) speak to /__rpc over a WebSocket.

Install the prebuilt plugin and the local cache daemon (macOS arm64, Linux x86_64) and point the plugin at it:

curl --proto '=https' --tlsv1.2 -sSf https://xcache.devtoo.ls/setup | sh

The daemon (casd) listens on 127.0.0.1:4170 and keeps one connection to this cache, so a build does not open one per compiler process; without it builds are much slower. The installer starts it as a user service and uses it only once it answers; if it cannot (no systemd user session, no release yet), it points the plugin at this cache directly and says so. LLBUILD_CAS_NO_DAEMON=1 skips it.

The cache requires an access token. The installer asks for it (or reads LLBUILD_CAS_TOKEN) and saves it to ~/.config/llbuild-cas-remote-token, where the plugin, the daemon and castool look for it.

swiftc

swift build --product CASPlugin

swiftc -c main.swift -explicit-module-build -cache-compile-job \
  -cas-path ~/.cache/llbuild-cas \
  -cas-plugin-path .build/debug/libCASPlugin.so \
  -cas-plugin-option remote-url=https://xcache.devtoo.ls \
  -Rcache-compile-job

Without remote-url the plugin is a plain local CAS. Build the plugin in release (swift build -c release --product CASPlugin) for real use.

Xcode® / Swift® Build

Swift Build loads a CAS plugin from COMPILATION_CACHE_PLUGIN_PATH and reads COMPILATION_CACHE_REMOTE_SERVICE_PATH as a path to a file holding the Worker's URL (or the URL itself):

echo https://xcache.devtoo.ls > ~/.config/llbuild-cas-remote
swift build -c release --product CASPlugin   # libCASPlugin.dylib on macOS, .so on Linux
COMPILATION_CACHE_ENABLE_CACHING = YES
SWIFT_ENABLE_EXPLICIT_MODULES = YES
SWIFT_USE_INTEGRATED_DRIVER = YES
COMPILATION_CACHE_ENABLE_PLUGIN = YES
COMPILATION_CACHE_PLUGIN_PATH = /path/to/libCASPlugin.dylib
COMPILATION_CACHE_REMOTE_SERVICE_PATH = /Users/you/.config/llbuild-cas-remote