Package: sccache
sccache - Shared Compilation Cachesccache is accache-like compiler caching tool. It is used as a compiler wrapper and avoids compilation when possible, storing cached results either onlocal diskor in one ofseveral cloud storage backends.sccache includes support for caching the compilation of C/C++ code,Rust, as well as NVIDIA's CUDA usingnvcc, andclang.sccache also providesicecream-style distributed compilation (automatic packaging of local toolchains) for all supported compilers (including Rust). The distributed compilation system includes several security features that icecream lacks such as authentication, transport layer encryption, and sandboxed compiler execution on build servers. Seethe distributed quickstartguide for more information.sccache is also available as aGitHub Actionsto facilitate the deployment using GitHub Actions cache.Table of Contents (ToC)InstallationUsageBuild RequirementsBuildSeparating caches between invocationsOverwriting the cacheDebuggingInteraction with GNUmakejobserverKnown CaveatsStorage OptionsLocalS3R2RedisMemcachedGoogle Cloud StorageAzureGitHub ActionsWebDAV (Ccache/Bazel/Gradle compatible)InstallationThere are prebuilt x86-64 binaries available for Windows, Linux (a portable binary compiled against musl), and macOSon the releases page. Several package managers also include sccache packages, you can install the latest release from source using cargo, or build directly from a source checkout.macOSOn macOS sccache can be installed viaHomebrew:brewinstallsccacheor viaMacPorts:sudoportinstallsccacheWindowsOn Windows, sccache can be installed viascoop:scoop install sccacheVia cargoIf you have a Rust toolchain installed you can install sccache using cargo.Note that this will compile sccache from source which is fairly resource-intensive. For CI purposes you should use prebuilt binary packages.cargoinstallsccache--lockedUsageRunning sccache is like running ccache: prefix your compilation commands with it, like so:sccachegcc-ofoo.o-cfoo.cIf you want to use sccache for caching Rust builds you can definebuild.rustc-wrapperin thecargo configuration file.  For example, you can set it globally
in$HOME/.cargo/config.tomlby adding:[build]rustc-wrapper="/path/to/sccache"Note that you need to use cargo 1.40 or newer for this to work.Alternatively you can use the environment variableRUSTC_WRAPPER:exportRUSTC_WRAPPER=/path/to/sccache
cargobuildsccache supports gcc, clang, MSVC, rustc,NVCC,NVC++, andWind River's diab compiler. Both gcc and msvc support Response Files, read more about their implementationhere.If you don'tspecify otherwise, sccache will use a local disk cache.sccache works using a client-server model, where the server runs locally on the same machine as the client. The client-server model allows the server to be more efficient by keeping some state in memory. The sccache command will spawn a server process if one is not already running, or you can runsccache --start-serverto start the background server process without performing any compilation.You can runsccache --stop-serverto terminate the server. It will also terminate after (by default) 10 minutes of inactivity.Runningsccache --show-statswill print a summary of cache statistics.Some notes about usingsccachewithJenkinsarehere.To use sccache with cmake, provide the following command line arguments to cmake 3.4 or newer:-DCMAKE_C_COMPILER_LAUNCHER=sccache
-DCMAKE_CXX_COMPILER_LAUNCHER=sccacheTo generate PDB files for debugging with MSVC, you can use the/Z7option. Alternatively, the/Zioption together with/Fdcan work if/Fdnames a different PDB file name for each object file created. Note that CMake sets/Ziby default, so if you use CMake, you can use/Z7by adding code like this in your CMakeLists.txt:if(CMAKE_BUILD_TYPESTREQUAL"Debug")string(REPLACE"/Zi""/Z7"CMAKE_CXX_FLAGS_DEBUG"${CMAKE_CXX_FLAGS_DEBUG}")string(REPLACE"/Zi""/Z7"CMAKE_C_FLAGS_DEBUG"${CMAKE_C_FLAGS_DEBUG}")elseif(CMAKE_BUILD_TYPESTREQUAL"Release")string(REPLACE"/Zi""/Z7"CMAKE_CXX_FLAGS_RELEASE"${CMAKE_CXX_FLAGS_RELEASE}")string(REPLACE"/Zi""/Z7"CMAKE_C_FLAGS_RELEASE"${CMAKE_C_FLAGS_RELEASE}")elseif(CMAKE_BUILD_TYPESTREQUAL"RelWithDebInfo")string(REPLACE"/Zi""/Z7"CMAKE_CXX_FLAGS_RELWITHDEBINFO"${CMAKE_CXX_FLAGS_RELWITHDEBINFO}")string(REPLACE"/Zi""/Z7"CMAKE_C_FLAGS_RELWITHDEBINFO"${CMAKE_C_FLAGS_RELWITHDEBINFO}")endif()By default, sccache will fail your build if it fails to successfully communicate with its associated server. To have sccache instead gracefully failover to the local compiler without stopping, set the environment variableSCCACHE_IGNORE_SERVER_IO_ERROR=1.Update: On CMake 3.25, you have to use the newCMAKE_MSVC_DEBUG_INFORMATION_FORMAToption, meant to configure the-Z7flag:set(CMAKE_MSVC_DEBUG_INFORMATION_FORMATEmbedded)Example configuration where we automatically look forsccachein thePATH:find_program(SCCACHEsccacheREQUIRED)set(CMAKE_C_COMPILER_LAUNCHER${SCCACHE})set(CMAKE_CXX_COMPILER_LAUNCHER${SCCACHE})set(CMAKE_MSVC_DEBUG_INFORMATION_FORMATEmbedded)And you can build code as usual without any additional flags in the command line, useful for IDEs.Build Requirementssccache is aRustprogram. Building it requirescargo(and thusrustc). sccache currently requiresRust 1.67.1. We recommend you install Rust viaRustup.BuildIf you are building sccache for non-development purposes make sure you usecargo build --releaseto get optimized binaries:cargobuild--release[--no-default-features--features=s3|redis|gcs|memcached|azure]By default,sccachebuilds with support for all storage backends, but individual backends may be disabled by resetting the list of features and enabling all the other backends. Refer theCargo Documentationfor details on how to select features with Cargo.Featurevendored-opensslcan be used to statically link with openssl if feature openssl is enabled.Building portable binariesWhen building with thedist-serverfeature,sccachewill depend on OpenSSL, which can be an annoyance if you want to distribute portable binaries. It is possible to statically link against OpenSSL using theopenssl/vendoredfeature.LinuxBuild withcargoand uselddto check that the resulting binary does not depend on OpenSSL anymore.macOSBuild withcargoand useotool -Lto check that the resulting binary does not depend on OpenSSL anymore.WindowsOn Windows, the binary might also depend on a few MSVC CRT DLLs that are not available on older Windows versions.It is possible to statically link against the CRT using a.cargo/config.tomlfile with the following contents.[target.x86_64-pc-windows-msvc]rustflags=["-Ctarget-feature=+crt-static"]Build withcargoand usedumpbin /dependentsto check that the resulting binary does not depend on MSVC CRT DLLs anymore.When statically linking with OpenSSL, you will need Perl available in your$PATH.Separating caches between invocationsIn situations where several different compilation invocations
should not reuse the cached results from each other,
one can setSCCACHE_C_CUSTOM_CACHE_BUSTERto a unique value
that'll be mixed into the hash.MACOSX_DEPLOYMENT_TARGETandIPHONEOS_DEPLOYMENT_TARGETvariables
already exhibit such reuse-suppression behaviour.
There are currently no such variables for compiling Rust.Overwriting the cacheIn situations where the cache contains broken build artifacts, it can be necessary to overwrite the contents in the cache. That can be achieved by setting theSCCACHE_RECACHEenvironment variable.DebuggingYou can set theSCCACHE_ERROR_LOGenvironment variable to a path and setSCCACHE_LOGto get the server process to redirect its logging there (including the output of unhandled panics, since the server setsRUST_BACKTRACE=1internally).SCCACHE_ERROR_LOG=/tmp/sccache_log.txt SCCACHE_LOG=debug sccacheYou can also set these environment variables for your build system, for exampleSCCACHE_ERROR_LOG=/tmp/sccache_log.txt SCCACHE_LOG=debug cmake --build /path/to/cmake/build/directoryAlternatively, if you are compiling locally, you can run the server manually in foreground mode by runningSCCACHE_START_SERVER=1 SCCACHE_NO_DAEMON=1 sccache, and send logging to stderr by setting theSCCACHE_LOGenvironment variablefor example. This method is not suitable for CI services because you need to compile in another shell at the same time.SCCACHE_LOG=debug SCCACHE_START_SERVER=1 SCCACHE_NO_DAEMON=1 sccacheInteraction with GNUmakejobserversccache provides support for aGNU make jobserver. When the server is started from a process that provides a jobserver, sccache will use that jobserver and provide it to any processes it spawns. (If you are running sccache from a GNU make recipe, you will need to prefix the command with+to get this behavior.) If the sccache server is started without a jobserver present it will create its own with the number of slots equal to the number of available CPU cores.This is most useful when using sccache for Rust compilation, as rustc supports using a jobserver for parallel codegen, so this ensures that rustc will not overwhelm the system with codegen tasks. Cargo implements its own jobserver (see the information onNUM_JOBSin the cargo documentation) for rustc to use, so using sccache for Rust compilation in cargo viaRUSTC_WRAPPERshould do the right thing automatically.Known CaveatsGeneralAbsolute paths to files must match to get a cache hit. This means that even if you are using a shared cache, everyone will have to build at the same absolute path (i.e. not in$HOME) in order to benefit each other. In Rust this includes the source for third party crates which are stored in$HOME/.cargo/registry/cacheby default.RustCrates that invoke the system linker cannot be cached. This includesbin,dylib,cdylib, andproc-macrocrates. You may be able to improve compilation time of largebincrates by converting them to alibcrate with a thinbinwrapper.Incrementally compiled crates cannot be cached. By default, in the debug profile Cargo will use incremental compilation for workspace members and path dependencies.You can disable incremental compilation.More details on Rust caveatsSymbolic linksSymbolic links to sccache won't work. Use hardlinks:ln sccache /usr/local/bin/ccStorage OptionsLocalS3R2RedisMemcachedGoogle Cloud StorageAzureGitHub ActionsWebDAV (Ccache/Bazel/Gradle compatible)