# sccache (Rust / C / C++)

import { Aside } from '@astrojs/starlight/components';

Avrea provides a WebDAV remote storage endpoint for [sccache](https://github.com/mozilla/sccache).
Compilation outputs are cached so that unchanged source files skip recompilation
across jobs and branches.

<Aside type="note" title="sccache installation">
sccache is not pre-installed on Avrea runners. Your workflow needs to download it
from GitHub releases (see the example below). A future runner image update may
include sccache by default.
</Aside>

## On Avrea runners

The storage endpoint is pre-configured:

```bash
SCCACHE_WEBDAV_ENDPOINT="http://cache.avrea.com:8290/sccache-build/webdav"
SCCACHE_WEBDAV_KEY_PREFIX=""
```

You need to install sccache, set `RUSTC_WRAPPER`, and start the daemon in your workflow:

```yaml title="workflow.yml"
jobs:
  build:
    runs-on: avrea-ubuntu-latest
    env:
      RUSTC_WRAPPER: sccache
    steps:
      - uses: actions/checkout@v7
      - name: Install sccache
        run: |
          SCCACHE_VERSION="v0.10.0"
          curl -fsSL "https://github.com/mozilla/sccache/releases/download/${SCCACHE_VERSION}/sccache-${SCCACHE_VERSION}-x86_64-unknown-linux-musl.tar.gz" \
            | tar xz --strip-components=1 -C /usr/local/bin/ "sccache-${SCCACHE_VERSION}-x86_64-unknown-linux-musl/sccache"
      - run: sccache --start-server
      - run: cargo build --release
      - run: sccache --show-stats
```

## Manual setup

```yaml
env:
  RUSTC_WRAPPER: sccache
  SCCACHE_WEBDAV_ENDPOINT: "http://cache.avrea.com:8290/sccache-build/webdav"
  SCCACHE_WEBDAV_KEY_PREFIX: ""

steps:
  - uses: actions/checkout@v7
  - name: Install sccache
    run: |
      SCCACHE_VERSION="v0.10.0"
      curl -fsSL "https://github.com/mozilla/sccache/releases/download/${SCCACHE_VERSION}/sccache-${SCCACHE_VERSION}-x86_64-unknown-linux-musl.tar.gz" \
        | tar xz --strip-components=1 -C /usr/local/bin/ "sccache-${SCCACHE_VERSION}-x86_64-unknown-linux-musl/sccache"
  - run: sccache --start-server
  - run: cargo build --release
  - run: sccache --show-stats
```

## C/C++ usage

Set the compiler wrappers to route compilation through sccache:

```yaml
env:
  CC: sccache gcc
  CXX: sccache g++
```

Or with clang:

```yaml
env:
  CC: sccache clang
  CXX: sccache clang++
```