Compiling the Swift compiler is a somewhat time consuming, especially for cold builds. This is particularly painful if
- You're bisecting an issue over a large period of time.
- You're switching between Xcode versions to debug issues.
- You have multiple distinct work directories, say for working on multiple things at once.
sccache provides a mostly automatic caching experience for build artifacts. I was putting off setting it up because I thought it might be complicated. I finally set it up on my Mac yesterday and it was surprisingly painless! I figured I'd write down the steps here, so other people can easily refer to it.
$ brew install sccache $ sccache --start-server $ utils/build-script MY_ARGS --cmake-c-launcher $(which sccache) --cmake-cxx-launcher $(which sccache)
Given the size of artifacts generated, you might also want to bump the cache size from the default 10GB to something larger, say by putting
export SCCACHE_CACHE_SIZE="50G" in your dotfile(s).
You can run some compiles to see if it is actually doing something by running
sccache --show-stats. In my very limited experience so far, it isn't super amazing (I got ~40 cache hits out of ~700 compilation requests once), but that's probably because I was changing some Swift compiler headers which were affecting many things. Also, the stat tracking seems to reset between shells or something . Maybe someone more experienced with
sccache knows what's up with that?
My understanding is that it is very effective for things like LLVM, which doesn't change so frequently from the Swift compiler's perspective. @codafi mentioned compiling 6 compilers at once (!) thanks to sccache (how he managed to free up sufficient storage space for that remains a mystery to me).
Overall: I got some faster builds without a lot of work, particularly without having to read/write any CMake, so 10/10 would recommend.