sccache is a ccache-like compiler caching tool created by Mozilla. This compiler wrapper that avoids compilation when possible and stores cached results locally or in remote storage. It supports caching the compilation of several languages including C, C++, and Rust. Many large projects use sccache, including Firefox, and optimizes for incremental builds and advanced local and remote caching.
Depot Cache provides a remote cache service that works with sccache, allowing you to incrementally cache and reuse parts of your builds. This cache is accessible from anywhere, both on your local machine and on CI/CD systems.
Note: You need a Depot API token to authenticate with the cache service.
Set two environment variables representing the Depot Cache service endpoint and your API token:
export SCCACHE_WEBDAV_ENDPOINT=https://cache.depot.dev
export SCCACHE_WEBDAV_TOKEN=DEPOT_TOKENIf you are a member of multiple organizations and authenticating with a user token, specify a password along with which organization to use for cache storage:
export SCCACHE_WEBDAV_ENDPOINT=https://cache.depot.dev
export SCCACHE_WEBDAV_USERNAME=DEPOT_ORG_ID
export SCCACHE_WEBDAV_PASSWORD=DEPOT_TOKENAfter you configure sccache to use Depot Cache, run your builds as you normally would. sccache automatically communicates with Depot Cache to fetch and reuse any stored build artifacts from your previous builds.
When building Docker images that contain Rust projects with sccache locally, your build needs access to sccache's remote cache credentials to benefit from caching. Containerized builds execute in isolated environments that require explicit configuration.
Update your Dockerfile to mount the secret as environment variables:
# syntax=docker/dockerfile:1
# ... other Dockerfile instructions
# Mount secrets with IDs matching the environment variable names
RUN --mount=type=secret,id=DEPOT_TOKEN,env=SCCACHE_WEBDAV_TOKEN \
SCCACHE_WEBDAV_ENDPOINT=https://cache.depot.dev sccache --start-server && \
cargo build --releaseAdding # syntax=docker/dockerfile:1 as the first line of your Dockerfile enables mounting secrets as environment variables.
depot build --secret id=DEPOT_TOKEN,env=DEPOT_TOKEN -t your-image:tag .docker buildx build --secret id=DEPOT_TOKEN,env=DEPOT_TOKEN -t your-image:tag .Define the secret in your docker-bake.hcl file:
target "default" {
context = "."
dockerfile = "Dockerfile"
tags = ["your-image:tag"]
secret = [
{
type = "env"
id = "DEPOT_TOKEN"
}
]
}Then run the build:
DEPOT_TOKEN=your_token depot bakeDepot GitHub Actions runners are pre-configured to use Depot Cache with sccache. Each runner launches with a SCCACHE_WEBDAV_ENDPOINT environment variable pre-configured with the connection details for Depot Cache.
You don't need additional configuration. Run your sccache builds as normal:
jobs:
build:
runs-on: depot-ubuntu-24.04
steps:
- uses: actions/checkout@v4
- run: sccache --start-server && cargo build --releaseTo disable automatic configuration, turn off Allow Actions jobs to automatically connect to Depot Cache in your organization settings page. You can then manually configure sccache as described in the Local workstation section.
When running containerized builds on Depot GitHub Actions runners, your build needs access to sccache's remote cache credentials. These credentials aren't automatically available inside your Docker build environment.
Update your Dockerfile to mount the secrets as environment variables:
# syntax=docker/dockerfile:1
# ... other Dockerfile instructions
# Mount secrets with IDs matching the environment variable names
RUN --mount=type=secret,id=DEPOT_TOKEN,env=SCCACHE_WEBDAV_TOKEN \
SCCACHE_WEBDAV_ENDPOINT=https://cache.depot.dev sccache --start-server && \
cargo build --releaseAdding # syntax=docker/dockerfile:1 as the first line of your Dockerfile enables mounting secrets as environment variables.
depot/build-push-actionStore the Depot token in a GitHub Secret named DEPOT_TOKEN, then configure your workflow:
- name: Build and push
uses: depot/build-push-action@v1
with:
context: .
file: ./Dockerfile
push: true
tags: your-image:tag
secrets: |
"DEPOT_TOKEN=${{ secrets.DEPOT_TOKEN }}"depot/bake-actionDefine the secret in your docker-bake.hcl file:
target "default" {
context = "."
dockerfile = "Dockerfile"
tags = ["your-image:tag"]
secret = [
{
type = "env"
id = "DEPOT_TOKEN"
}
]
}Then configure your workflow:
- name: Bake
uses: depot/bake-action@v1
with:
files: docker-bake.hcl
env:
DEPOT_TOKEN: ${{ secrets.DEPOT_TOKEN }}Store the Depot token in a GitHub Secret named DEPOT_TOKEN, then configure your workflow:
- name: Build
run: |
docker buildx build \
--secret id=DEPOT_TOKEN,env=DEPOT_TOKEN \
-t your-image:tag .
env:
DEPOT_TOKEN: ${{ secrets.DEPOT_TOKEN }}