Skip to content

Enable sccache for linux-x64 coreclr PR builds#127882

Open
agocke wants to merge 4 commits intodotnet:mainfrom
agocke:sccache-linux-pr
Open

Enable sccache for linux-x64 coreclr PR builds#127882
agocke wants to merge 4 commits intodotnet:mainfrom
agocke:sccache-linux-pr

Conversation

@agocke
Copy link
Copy Markdown
Member

@agocke agocke commented May 6, 2026

Note

This PR was created with assistance from GitHub Copilot.

Wire up sccache as a compiler cache for linux-x64 coreclr native builds in PR pipelines using the Azure Pipeline Cache task. This can likely be expanded to more runs/platforms in the future, but this is a good place to start.

Changes

  • src/coreclr/runtime-prereqs.proj: Add PackageDownload for sccache 0.15.0 (Linux CI only), piggybacking on the existing restore
  • eng/pipelines/coreclr/templates/setup-sccache.yml: Pre-build template that configures the Pipeline Cache for sccache storage, sets USE_SCCACHE/SCCACHE_DIR env vars, and prepends sccache to PATH
  • eng/pipelines/coreclr/templates/sccache-stats.yml: Post-build template that prints sccache --show-stats
  • eng/pipelines/runtime.yml: Wires both templates into the CoreCLR_Libraries and Libraries_CheckedCoreCLR jobs
  • src/coreclr/build-runtime.sh: chmod +x the sccache binary before use (NuGet strips execute permissions)

How it works

  1. Pre-build: Pipeline Cache restores the sccache storage dir → env vars configured (PATH, SCCACHE_DIR, USE_SCCACHE)
  2. Build: build.sh restores runtime-prereqs.proj (downloads sccache binary) → native build uses sccache as cmake compiler launcher
  3. Post-build: Stats printed for observability; Pipeline Cache saves storage dir for next run

Templates use compile-time ${{ if }} conditions so they are no-ops for non-linux-x64 platforms in multi-platform matrix jobs.

Wire up sccache as a compiler cache for linux-x64 coreclr native builds
in PR pipelines using the Azure Pipeline Cache task.

- Add PackageDownload for sccache 0.15.0 in runtime-prereqs.proj (Linux CI only)
- Add setup-sccache.yml pre-build template: configures Pipeline Cache,
  sets USE_SCCACHE/SCCACHE_DIR env vars, prepends sccache to PATH
- Add sccache-stats.yml post-build template for cache hit observability
- Wire both templates into CoreCLR_Libraries and Libraries_CheckedCoreCLR
  jobs in runtime.yml
- chmod +x the sccache binary in build-runtime.sh (NuGet strips permissions)

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR wires up sccache for Linux x64 CoreCLR native builds in PR pipelines, using Azure Pipelines Cache to persist the local sccache directory between runs and emitting stats after the build for observability.

Changes:

  • Downloads sccache via PackageDownload during existing CoreCLR prereqs restore (Linux CI only).
  • Adds CoreCLR pipeline templates to restore/save the sccache cache directory and to print sccache --show-stats.
  • Enables sccache as the CMake compiler launcher when USE_SCCACHE=true, including a chmod +x workaround for NuGet-stripped execute bits.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 6 comments.

Show a summary per file
File Description
src/coreclr/runtime-prereqs.proj Adds CI/Linux PackageDownload for the sccache NuGet package.
src/coreclr/build-runtime.sh Enables sccache as a CMake compiler launcher and ensures the binary is executable.
eng/pipelines/runtime.yml Hooks new pre-/post-build sccache templates into CoreCLR build jobs.
eng/pipelines/coreclr/templates/setup-sccache.yml Restores/saves sccache directory via Cache@2 and configures PATH + env vars.
eng/pipelines/coreclr/templates/sccache-stats.yml Prints sccache statistics after builds.

Comment thread eng/pipelines/coreclr/templates/setup-sccache.yml Outdated
Comment thread eng/pipelines/coreclr/templates/setup-sccache.yml Outdated
Comment on lines +27 to +30
- script: |
sccacheDir="$(Build.SourcesDirectory)/.packages/sccache/0.15.0/tools"
mkdir -p "$sccacheDir"
echo "##vso[task.prependpath]$sccacheDir"
Comment thread eng/pipelines/coreclr/templates/sccache-stats.yml Outdated
Comment thread src/coreclr/runtime-prereqs.proj
Comment thread eng/pipelines/runtime.yml
@agocke agocke marked this pull request as draft May 6, 2026 20:30
- Set SCCACHE_IDLE_TIMEOUT=0 to prevent server timeout before stats step
- Fix chmod +x to use known NuGet package paths instead of command -v
  (command -v won't find non-executable files)
- Exclude linux_musl legs via osSubgroup check (sccache package is glibc-only)
- Use rolling cache key (Build.BuildNumber) so cache updates each run
- Make stats step resilient with || true
- Centralize sccache version as a template parameter

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings May 6, 2026 20:52
…ns dot)

Cache@2 interprets key segments containing '.' as file paths.
Build.BuildNumber (e.g. 20260506.103) triggers FileNotFoundException.
Build.BuildId is a plain integer that is treated as a string literal.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@agocke agocke force-pushed the sccache-linux-pr branch from de00285 to 7884370 Compare May 6, 2026 20:56
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 5 out of 5 changed files in this pull request and generated 3 comments.

Comment thread src/coreclr/runtime-prereqs.proj
Comment thread eng/pipelines/coreclr/templates/setup-sccache.yml Outdated
Comment thread eng/pipelines/runtime.yml
Different jobs (CoreCLR_Libraries vs Libraries_CheckedCoreCLR) and
configurations (Release vs Checked vs Debug) produce different object
files. Without distinguishing them in the cache key, builds stomp
over each other in the shared sccache directory.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@agocke
Copy link
Copy Markdown
Member Author

agocke commented May 7, 2026

@steveisok This looks ready. By re-running the pipeline I simulated a hot cache and it looks to cut down our clr+libs build by ~half, as expected. We'll see how much it helps in practice with coreclr changes.

@agocke agocke requested a review from steveisok May 7, 2026 05:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Status: No status
Status: No status

Development

Successfully merging this pull request may close these issues.

2 participants