From 4ea400060d36bc0a0b81de236419920ea1b2eb0f Mon Sep 17 00:00:00 2001 From: Steve Pfister Date: Wed, 27 May 2026 18:41:33 -0400 Subject: [PATCH 1/6] Enable sccache as compiler launcher in build-commons (with macOS -Xarch wrapper) Consolidate the -DCMAKE_C/CXX_COMPILER_LAUNCHER injection into eng/native/build-commons.sh so every native component invoked through build_native picks up sccache when USE_SCCACHE=true (CoreCLR, corehost, native libraries, etc.) instead of only the components that hand-rolled the flag themselves. On macOS, CMake wraps PCH includes in -Xarch_ -include, which sccache cannot parse and which also strips bare -include during preprocessing. Use a thin wrapper script that drops -Xarch_ (safe in single-architecture builds) and rewrites -include to -Xclang -include -Xclang , which sccache passes through to the clang frontend correctly. Remove the now-redundant per-component sccache flag injection from src/coreclr/build-runtime.sh; build-commons.sh handles it for all build_native invocations. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- eng/native/build-commons.sh | 12 ++++++++++++ eng/native/sccache-xarch-wrapper.sh | 30 +++++++++++++++++++++++++++++ src/coreclr/build-runtime.sh | 4 ---- 3 files changed, 42 insertions(+), 4 deletions(-) create mode 100755 eng/native/sccache-xarch-wrapper.sh diff --git a/eng/native/build-commons.sh b/eng/native/build-commons.sh index 2a036677feaf66..e154f64fad7efa 100755 --- a/eng/native/build-commons.sh +++ b/eng/native/build-commons.sh @@ -60,6 +60,18 @@ build_native() cmakeArgs="$6" message="$7" + # When sccache is enabled, use it as the compiler launcher. + # On macOS, CMake wraps PCH includes with -Xarch_ which sccache + # cannot parse. Use a thin wrapper that strips -Xarch_ flags + # (safe in single-architecture builds) before forwarding to sccache. + if [[ "${USE_SCCACHE:-}" == "true" ]]; then + local __sccacheLauncher="sccache" + if [[ "$targetOS" == osx || "$targetOS" == maccatalyst ]]; then + __sccacheLauncher="$__RepoRootDir/eng/native/sccache-xarch-wrapper.sh" + fi + cmakeArgs="-DCMAKE_C_COMPILER_LAUNCHER=$__sccacheLauncher -DCMAKE_CXX_COMPILER_LAUNCHER=$__sccacheLauncher $cmakeArgs" + fi + # All set to commence the build echo "Commencing build of \"$target\" target in \"$message\" for $__TargetOS.$__TargetArch.$__BuildType in $intermediatesDir" diff --git a/eng/native/sccache-xarch-wrapper.sh b/eng/native/sccache-xarch-wrapper.sh new file mode 100755 index 00000000000000..5dcc9eeae2a579 --- /dev/null +++ b/eng/native/sccache-xarch-wrapper.sh @@ -0,0 +1,30 @@ +#!/usr/bin/env bash +# Wrapper around sccache for macOS builds. +# sccache cannot parse -Xarch_ flags that CMake generates for PCH +# includes, and also drops plain -include flags during compilation. +# We rewrite "-Xarch_ -include" to "-Xclang -include -Xclang " +# which sccache passes through correctly to the clang frontend. + +args=() +skip_xarch=false + +for arg in "$@"; do + if $skip_xarch; then + skip_xarch=false + if [[ "$arg" == -include* ]]; then + # Rewrite -include to -Xclang -include -Xclang + local_path="${arg#-include}" + args+=("-Xclang" "-include" "-Xclang" "$local_path") + else + args+=("$arg") + fi + continue + fi + if [[ "$arg" == -Xarch_* ]]; then + skip_xarch=true + continue + fi + args+=("$arg") +done + +exec sccache "${args[@]}" diff --git a/src/coreclr/build-runtime.sh b/src/coreclr/build-runtime.sh index 6147564b20c11b..6809330b216d33 100755 --- a/src/coreclr/build-runtime.sh +++ b/src/coreclr/build-runtime.sh @@ -173,10 +173,6 @@ if [[ "$__TargetArch" != "$__HostArch" ]]; then __CMakeArgs="-DCLR_CMAKE_TARGET_ARCH=$__TargetArch $__CMakeArgs" fi -if [[ "$USE_SCCACHE" == "true" ]]; then - __CMakeArgs="-DCMAKE_C_COMPILER_LAUNCHER=sccache -DCMAKE_CXX_COMPILER_LAUNCHER=sccache $__CMakeArgs" -fi - eval "$__RepoRootDir/eng/native/version/copy_version_files.sh" build_native "$__HostOS" "$__HostArch" "$__ProjectRoot" "$__IntermediatesDir" "$__CMakeTarget" "$__CMakeArgs" "CoreCLR component" From 8c3499bc0b2d121d0c37b305197b05b4321de902 Mon Sep 17 00:00:00 2001 From: Steve Pfister Date: Wed, 27 May 2026 19:18:18 -0400 Subject: [PATCH 2/6] Enable sccache for osx_arm64 CI legs Widen the gate in setup-sccache.yml and sccache-stats.yml to also include osx + arm64 alongside linux + x64. The CoreCLR_Libraries leg in runtime.yml already lists osx_arm64 and references both templates, so widening the gate activates Mac sccache there without any change to runtime.yml. On linux/freebsd we keep using the linux-musl-x64 sccache NuGet package (also works for arm64 cross-compile on x64 hosts, per dotnet/runtime#128065). The NuGet package has no Mac binary, so on macOS we download the official tarball from the mozilla/sccache GitHub release matching the host CPU (uname -m, not archType: the sccache executable must match the agent's CPU). A pinned sha256 guards against tarball tampering and surfaces transient GitHub-side issues. --strip-components=1 places the binary directly in the tools directory so the existing prependpath line still finds it. Bump SCCACHE_CACHE_SIZE to 5120M to match dotnet/runtime#128065. The 3584M limit was evicting useful entries; the larger cache keeps hit rates consistent across the now-larger fleet of jobs. Starting narrow on osx_arm64 only: the xarch wrapper in eng/native/sccache-xarch-wrapper.sh assumes single-arch builds, so we widen to osx_x64 / additional Mac legs in follow-ups after validating server startup and cache hits in CI. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- .../coreclr/templates/sccache-stats.yml | 2 +- .../coreclr/templates/setup-sccache.yml | 59 +++++++++++++++++-- 2 files changed, 55 insertions(+), 6 deletions(-) diff --git a/eng/pipelines/coreclr/templates/sccache-stats.yml b/eng/pipelines/coreclr/templates/sccache-stats.yml index fdef7e530fc2fd..05a08f5f7393f7 100644 --- a/eng/pipelines/coreclr/templates/sccache-stats.yml +++ b/eng/pipelines/coreclr/templates/sccache-stats.yml @@ -12,7 +12,7 @@ parameters: osSubgroup: '' steps: - - ${{ if and(eq(parameters.osGroup, 'linux'), or(eq(parameters.osSubgroup, ''), eq(parameters.osSubgroup, '_musl')), eq(parameters.archType, 'x64')) }}: + - ${{ if or(and(eq(parameters.osGroup, 'linux'), or(eq(parameters.osSubgroup, ''), eq(parameters.osSubgroup, '_musl')), eq(parameters.archType, 'x64')), and(eq(parameters.osGroup, 'osx'), eq(parameters.archType, 'arm64'))) }}: - script: sccache --show-stats || true displayName: Sccache stats condition: always() diff --git a/eng/pipelines/coreclr/templates/setup-sccache.yml b/eng/pipelines/coreclr/templates/setup-sccache.yml index cdd232589cd80a..045229bed20652 100644 --- a/eng/pipelines/coreclr/templates/setup-sccache.yml +++ b/eng/pipelines/coreclr/templates/setup-sccache.yml @@ -11,11 +11,14 @@ parameters: shouldContinueOnError: false osSubgroup: '' - # sccache NuGet package version + # sccache version. On linux/freebsd we use the linux-musl-x64 NuGet + # package; on macOS we download the matching tag from the mozilla/sccache + # GitHub release. Keep the version in sync across platforms so all + # jobs cache against the same compiler-launcher behavior. sccacheVersion: '0.15.0' steps: - - ${{ if and(eq(parameters.osGroup, 'linux'), or(eq(parameters.osSubgroup, ''), eq(parameters.osSubgroup, '_musl')), eq(parameters.archType, 'x64')) }}: + - ${{ if or(and(eq(parameters.osGroup, 'linux'), or(eq(parameters.osSubgroup, ''), eq(parameters.osSubgroup, '_musl')), eq(parameters.archType, 'x64')), and(eq(parameters.osGroup, 'osx'), eq(parameters.archType, 'arm64'))) }}: # Set up the Azure Pipeline Cache for sccache's local cache directory. # Use a rolling key so each build can update the cache; restoreKeys # falls back to the most recent saved entry. @@ -26,6 +29,10 @@ steps: # flags are controlled by RuntimeConfiguration (-rc), which is # constant per leg regardless of buildConfig. Omitting it lets PR # builds warm-start from rolling-build caches saved in the main scope. + # + # osGroup/osSubgroup/archType keep each platform's cache isolated so + # Mac jobs don't poison the Linux entries (different compiler, different + # cache contents). - task: Cache@2 displayName: Sccache cache continueOnError: true @@ -35,15 +42,57 @@ steps: restoreKeys: | sccache | ${{ parameters.osGroup }}${{ parameters.osSubgroup }} | ${{ parameters.archType }} | ${{ parameters.nameSuffix }} - # Download the sccache NuGet package and configure the environment. + # Download sccache and configure the environment. + # + # On linux/freebsd we use the linux-musl-x64 NuGet package (the same + # x64 binary works for arm64 cross-compile on x64 hosts). + # + # On macOS we download the official tarball from the mozilla/sccache + # GitHub release matching the host CPU (sccache itself must match the + # agent's CPU; archType describes the target output and is captured in + # the cache key above). A pinned sha256 guards against tarball + # tampering and surfaces transient GitHub-side issues. - script: | + set -euo pipefail sccacheVersion="${{ parameters.sccacheVersion }}" + osGroup="${{ parameters.osGroup }}" sccacheDir="$(Build.SourcesDirectory)/.packages/sccache/${sccacheVersion}/tools" - "$(Build.SourcesDirectory)/eng/common/dotnet.sh" package download "sccache@${sccacheVersion}" -o "$(Build.SourcesDirectory)/.packages" -v quiet + + if [[ "$osGroup" == "osx" ]]; then + case "$(uname -m)" in + arm64) + hostTriple="aarch64-apple-darwin" + sccacheSha256="430ef7b5f54256d3ed5bfe77e8b0afc51aa209aeebe4f95b69c3a52ce3acc6e9" + ;; + x86_64) + hostTriple="x86_64-apple-darwin" + sccacheSha256="f8da93e0689122268f720ddb48c8357f3da18be8c88aff23a8e75a7a219367db" + ;; + *) + echo "Unsupported macOS host arch: $(uname -m)" >&2 + exit 1 + ;; + esac + mkdir -p "$sccacheDir" + tarballName="sccache-v${sccacheVersion}-${hostTriple}.tar.gz" + tarballPath="$(Agent.TempDirectory)/${tarballName}" + url="https://github.com/mozilla/sccache/releases/download/v${sccacheVersion}/${tarballName}" + curl -fsSL -o "$tarballPath" "$url" + echo "${sccacheSha256} ${tarballPath}" | shasum -a 256 -c - + # Tarball layout: sccache-v${ver}-${triple}/{sccache,README,LICENSE}. + # Strip the top directory and extract just the binary so it + # lands directly in $sccacheDir, matching the NuGet layout. + tar -xzf "$tarballPath" -C "$sccacheDir" --strip-components=1 \ + "sccache-v${sccacheVersion}-${hostTriple}/sccache" + rm -f "$tarballPath" + else + "$(Build.SourcesDirectory)/eng/common/dotnet.sh" package download "sccache@${sccacheVersion}" -o "$(Build.SourcesDirectory)/.packages" -v quiet + fi + chmod +x "$sccacheDir/sccache" echo "##vso[task.prependpath]$sccacheDir" echo "##vso[task.setvariable variable=SCCACHE_DIR]$(Pipeline.Workspace)/.sccache" - echo "##vso[task.setvariable variable=SCCACHE_CACHE_SIZE]3584M" + echo "##vso[task.setvariable variable=SCCACHE_CACHE_SIZE]5120M" echo "##vso[task.setvariable variable=SCCACHE_IDLE_TIMEOUT]0" echo "##vso[task.setvariable variable=USE_SCCACHE]true" displayName: Download and configure sccache From da190c5e29241443800b509b9c55913d41521fda Mon Sep 17 00:00:00 2001 From: Steve Pfister Date: Wed, 27 May 2026 21:12:18 -0400 Subject: [PATCH 3/6] Enable sccache for osx_x64 CoreCLR_Libraries leg MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Two changes together actually activate sccache on the x64 leg: 1. Widen the gate in setup-sccache.yml and sccache-stats.yml to also include (osGroup == osx && archType == x64). Without this, the templates short-circuit and do nothing on the x64 platform. 2. Reference both templates from the osx_x64 CoreCLR_Libraries job in runtime.yml (the one that builds for installer tests). That job previously had no sccache plumbing at all, so widening the gate alone would have been a no-op. The xarch wrapper script is target-arch agnostic — it strips any -Xarch_ (matches both -Xarch_arm64 cross-builds and -Xarch_x86_64 native builds) and its only correctness precondition is single-arch builds, which build-commons.sh already enforces via single-valued CMAKE_OSX_ARCHITECTURES. The setup-sccache.yml binary picker uses uname -m to select the sccache executable, so an x64 host that cross-compiles arm64 still gets the correct x86_64-apple- darwin sccache binary while the cache key continues to differentiate target archs. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- eng/pipelines/coreclr/templates/sccache-stats.yml | 2 +- eng/pipelines/coreclr/templates/setup-sccache.yml | 2 +- eng/pipelines/runtime.yml | 3 +++ 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/eng/pipelines/coreclr/templates/sccache-stats.yml b/eng/pipelines/coreclr/templates/sccache-stats.yml index 05a08f5f7393f7..5af59b0b71eb4b 100644 --- a/eng/pipelines/coreclr/templates/sccache-stats.yml +++ b/eng/pipelines/coreclr/templates/sccache-stats.yml @@ -12,7 +12,7 @@ parameters: osSubgroup: '' steps: - - ${{ if or(and(eq(parameters.osGroup, 'linux'), or(eq(parameters.osSubgroup, ''), eq(parameters.osSubgroup, '_musl')), eq(parameters.archType, 'x64')), and(eq(parameters.osGroup, 'osx'), eq(parameters.archType, 'arm64'))) }}: + - ${{ if or(and(eq(parameters.osGroup, 'linux'), or(eq(parameters.osSubgroup, ''), eq(parameters.osSubgroup, '_musl')), eq(parameters.archType, 'x64')), and(eq(parameters.osGroup, 'osx'), or(eq(parameters.archType, 'arm64'), eq(parameters.archType, 'x64')))) }}: - script: sccache --show-stats || true displayName: Sccache stats condition: always() diff --git a/eng/pipelines/coreclr/templates/setup-sccache.yml b/eng/pipelines/coreclr/templates/setup-sccache.yml index 045229bed20652..aea99b6a56d02a 100644 --- a/eng/pipelines/coreclr/templates/setup-sccache.yml +++ b/eng/pipelines/coreclr/templates/setup-sccache.yml @@ -18,7 +18,7 @@ parameters: sccacheVersion: '0.15.0' steps: - - ${{ if or(and(eq(parameters.osGroup, 'linux'), or(eq(parameters.osSubgroup, ''), eq(parameters.osSubgroup, '_musl')), eq(parameters.archType, 'x64')), and(eq(parameters.osGroup, 'osx'), eq(parameters.archType, 'arm64'))) }}: + - ${{ if or(and(eq(parameters.osGroup, 'linux'), or(eq(parameters.osSubgroup, ''), eq(parameters.osSubgroup, '_musl')), eq(parameters.archType, 'x64')), and(eq(parameters.osGroup, 'osx'), or(eq(parameters.archType, 'arm64'), eq(parameters.archType, 'x64')))) }}: # Set up the Azure Pipeline Cache for sccache's local cache directory. # Use a rolling key so each build can update the cache; restoreKeys # falls back to the most recent saved entry. diff --git a/eng/pipelines/runtime.yml b/eng/pipelines/runtime.yml index 6c3951315d1fcb..932eb6fc31b933 100644 --- a/eng/pipelines/runtime.yml +++ b/eng/pipelines/runtime.yml @@ -329,7 +329,10 @@ extends: nameSuffix: CoreCLR_Libraries buildArgs: -s clr+libs -c $(_BuildConfig) timeoutInMinutes: 120 + preBuildSteps: + - template: /eng/pipelines/coreclr/templates/setup-sccache.yml postBuildSteps: + - template: /eng/pipelines/coreclr/templates/sccache-stats.yml - template: /eng/pipelines/common/upload-artifact-step.yml parameters: rootFolder: $(Build.SourcesDirectory)/artifacts/bin From 8be4c69e2348e8e4c8c54ea804496075f315d5ac Mon Sep 17 00:00:00 2001 From: Steve Pfister Date: Wed, 27 May 2026 21:28:25 -0400 Subject: [PATCH 4/6] Expand sccache to remaining applicable macOS CI legs Wire setup-sccache.yml / sccache-stats.yml into the macOS legs in runtime.yml whose buildArgs are clean CoreCLR/libs/host invocations. Mono-flavored legs are deliberately excluded for this PR (see below). Legs added: - Libraries_CheckedCoreCLR (osx_arm64, osx_x64) - NativeAOT (osx_arm64) - NativeAOT_Libraries (osx_arm64) - Installer_Build_And_Test (osx_x64, osx_arm64) For Installer_Build_And_Test the new setup-sccache template is appended to the existing preBuildSteps (which downloads the CoreCLR_Libraries artifact); sccache-stats is inserted as the first postBuildStep so stats are emitted even if later steps fail. Mono legs (AllSubsets_Mono, AllSubsets_Mono_LLVMAOT, the *_RuntimeTests variants, Mono_MiniJIT_LibrariesTests) are intentionally NOT wired. src/mono/mono.proj invokes cmake directly via _MonoCMakeArgs and bypasses eng/native/build-commons.sh, so the launcher injection on this branch does not reach Mono's native build. Wiring sccache into those legs would download the binary and report a misleading hit rate dominated by Mono cache-misses without speeding the dominant work. Extending Mono itself to use sccache (by adding the launcher flags to _MonoCMakeArgs when USE_SCCACHE=true) is left as a follow-up. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- eng/pipelines/runtime.yml | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/eng/pipelines/runtime.yml b/eng/pipelines/runtime.yml index 932eb6fc31b933..74a854eb40c989 100644 --- a/eng/pipelines/runtime.yml +++ b/eng/pipelines/runtime.yml @@ -363,7 +363,10 @@ extends: nameSuffix: Libraries_CheckedCoreCLR buildArgs: -s clr+libs+libs.tests -c $(_BuildConfig) -rc Checked /p:ArchiveTests=true timeoutInMinutes: 120 + preBuildSteps: + - template: /eng/pipelines/coreclr/templates/setup-sccache.yml postBuildSteps: + - template: /eng/pipelines/coreclr/templates/sccache-stats.yml - template: /eng/pipelines/coreclr/templates/build-native-test-assets-step.yml - template: /eng/pipelines/common/upload-artifact-step.yml parameters: @@ -474,7 +477,10 @@ extends: nameSuffix: Libraries_CheckedCoreCLR buildArgs: -s clr+libs -c $(_BuildConfig) -rc Checked timeoutInMinutes: 120 + preBuildSteps: + - template: /eng/pipelines/coreclr/templates/setup-sccache.yml postBuildSteps: + - template: /eng/pipelines/coreclr/templates/sccache-stats.yml - template: /eng/pipelines/coreclr/templates/build-native-test-assets-step.yml - template: /eng/pipelines/common/upload-artifact-step.yml parameters: @@ -762,7 +768,10 @@ extends: timeoutInMinutes: 180 nameSuffix: NativeAOT buildArgs: -s clr.aot+libs+tools.illink -c $(_BuildConfig) -rc $(_BuildConfig) -lc Release /p:RunAnalyzers=false + preBuildSteps: + - template: /eng/pipelines/coreclr/templates/setup-sccache.yml postBuildSteps: + - template: /eng/pipelines/coreclr/templates/sccache-stats.yml - template: /eng/pipelines/coreclr/nativeaot-post-build-steps.yml parameters: creator: dotnet-bot @@ -800,8 +809,11 @@ extends: nameSuffix: NativeAOT_Libraries buildArgs: -s clr.aot+libs+libs.tests -c $(_BuildConfig) /p:TestNativeAot=true /p:RunSmokeTestsOnly=true /p:ArchiveTests=true /p:RunAnalyzers=false timeoutInMinutes: 240 # Doesn't actually take long, but we've seen the ARM64 Helix queue often get backlogged for 2+ hours + preBuildSteps: + - template: /eng/pipelines/coreclr/templates/setup-sccache.yml # extra steps, run tests postBuildSteps: + - template: /eng/pipelines/coreclr/templates/sccache-stats.yml - template: /eng/pipelines/libraries/helix.yml parameters: creator: dotnet-bot @@ -1572,6 +1584,7 @@ extends: - nameSuffix: CoreCLR_Libraries buildConfig: release preBuildSteps: + - template: /eng/pipelines/coreclr/templates/setup-sccache.yml - template: /eng/pipelines/common/download-artifact-step.yml parameters: artifactName: CoreCLR_Libraries_BuildArtifacts_$(osGroup)$(osSubgroup)_$(archType)_Release @@ -1580,6 +1593,7 @@ extends: displayName: 'unified artifacts' timeoutInMinutes: 150 postBuildSteps: + - template: /eng/pipelines/coreclr/templates/sccache-stats.yml - template: /eng/pipelines/installer/helix.yml parameters: creator: dotnet-bot @@ -1634,6 +1648,7 @@ extends: - nameSuffix: CoreCLR_Libraries buildConfig: ${{ variables.debugOnPrReleaseOnRolling }} preBuildSteps: + - template: /eng/pipelines/coreclr/templates/setup-sccache.yml - template: /eng/pipelines/common/download-artifact-step.yml parameters: artifactName: CoreCLR_Libraries_BuildArtifacts_$(osGroup)$(osSubgroup)_$(archType)_$(debugOnPrReleaseOnRolling) @@ -1642,6 +1657,7 @@ extends: displayName: 'unified artifacts' timeoutInMinutes: 150 postBuildSteps: + - template: /eng/pipelines/coreclr/templates/sccache-stats.yml - template: /eng/pipelines/installer/helix.yml parameters: creator: dotnet-bot From 1e45d965ad102a3cf8aa8b4716205122690ad2f6 Mon Sep 17 00:00:00 2001 From: Andy Gocke Date: Thu, 30 Jul 2026 16:21:40 -0700 Subject: [PATCH 5/6] Use NuGet sccache package for macOS CI Use the sccache.osx-x64 package because both macOS target matrices run on x64 Azure Pipelines hosts. Restore the exact PackageReference for macOS because the package is unlisted and dotnet package download filters it out; keep the existing download path for the listed Unix package. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 356ad667-b44e-4469-aadb-1527c3d1fe24 --- .../coreclr/templates/setup-sccache.yml | 63 +++++++------------ 1 file changed, 23 insertions(+), 40 deletions(-) diff --git a/eng/pipelines/coreclr/templates/setup-sccache.yml b/eng/pipelines/coreclr/templates/setup-sccache.yml index 954dbf824ff318..4ea9217a1da636 100644 --- a/eng/pipelines/coreclr/templates/setup-sccache.yml +++ b/eng/pipelines/coreclr/templates/setup-sccache.yml @@ -11,10 +11,8 @@ parameters: shouldContinueOnError: false osSubgroup: '' - # sccache version. On linux/freebsd we use the linux-musl-x64 NuGet - # package; on macOS we download the matching tag from the mozilla/sccache - # GitHub release. Keep the version in sync across platforms so all - # jobs cache against the same compiler-launcher behavior. + # sccache version. Keep the version in sync across platforms so all jobs + # cache against the same compiler-launcher behavior. sccacheVersion: '0.15.0' steps: @@ -44,51 +42,36 @@ steps: # Download sccache and configure the environment. # - # On linux/freebsd we use the linux-musl-x64 NuGet package (the same - # x64 binary works for arm64 cross-compile on x64 hosts). - # - # On macOS we download the official tarball from the mozilla/sccache - # GitHub release matching the host CPU (sccache itself must match the - # agent's CPU; archType describes the target output and is captured in - # the cache key above). A pinned sha256 guards against tarball - # tampering and surfaces transient GitHub-side issues. + # All supported platforms build on x64 hosts, including macOS arm64 + # cross-builds. The unsuffixed package contains the linux-musl-x64 binary; + # macOS uses the osx-x64 package. - script: | set -euo pipefail sccacheVersion="${{ parameters.sccacheVersion }}" osGroup="${{ parameters.osGroup }}" - sccacheDir="$(Build.SourcesDirectory)/.packages/sccache/${sccacheVersion}/tools" + sccachePackage="sccache" if [[ "$osGroup" == "osx" ]]; then - case "$(uname -m)" in - arm64) - hostTriple="aarch64-apple-darwin" - sccacheSha256="430ef7b5f54256d3ed5bfe77e8b0afc51aa209aeebe4f95b69c3a52ce3acc6e9" - ;; - x86_64) - hostTriple="x86_64-apple-darwin" - sccacheSha256="f8da93e0689122268f720ddb48c8357f3da18be8c88aff23a8e75a7a219367db" - ;; - *) - echo "Unsupported macOS host arch: $(uname -m)" >&2 - exit 1 - ;; - esac - mkdir -p "$sccacheDir" - tarballName="sccache-v${sccacheVersion}-${hostTriple}.tar.gz" - tarballPath="$(Agent.TempDirectory)/${tarballName}" - url="https://github.com/mozilla/sccache/releases/download/v${sccacheVersion}/${tarballName}" - curl -fsSL -o "$tarballPath" "$url" - echo "${sccacheSha256} ${tarballPath}" | shasum -a 256 -c - - # Tarball layout: sccache-v${ver}-${triple}/{sccache,README,LICENSE}. - # Strip the top directory and extract just the binary so it - # lands directly in $sccacheDir, matching the NuGet layout. - tar -xzf "$tarballPath" -C "$sccacheDir" --strip-components=1 \ - "sccache-v${sccacheVersion}-${hostTriple}/sccache" - rm -f "$tarballPath" + sccachePackage="sccache.osx-x64" + restoreDir="$(mktemp -d "$(Agent.TempDirectory)/sccache-restore.XXXXXX")" + trap 'rm -rf "$restoreDir"' EXIT + cat > "$restoreDir/sccache.csproj" < + + net8.0 + + + + + + EOF + "$(Build.SourcesDirectory)/eng/common/dotnet.sh" restore "$restoreDir/sccache.csproj" --packages "$(Build.SourcesDirectory)/.packages" --verbosity quiet else - "$(Build.SourcesDirectory)/eng/common/dotnet.sh" package download "sccache@${sccacheVersion}" -o "$(Build.SourcesDirectory)/.packages" -v quiet + "$(Build.SourcesDirectory)/eng/common/dotnet.sh" package download "${sccachePackage}@${sccacheVersion}" -o "$(Build.SourcesDirectory)/.packages" -v quiet fi + sccacheDir="$(Build.SourcesDirectory)/.packages/${sccachePackage}/${sccacheVersion}/tools" + chmod +x "$sccacheDir/sccache" echo "##vso[task.prependpath]$sccacheDir" echo "##vso[task.setvariable variable=SCCACHE_DIR]$(Pipeline.Workspace)/.sccache" From 98655bb290af78ebbe1b0ea4c61ab3b390fbafc3 Mon Sep 17 00:00:00 2001 From: Andy Gocke Date: Thu, 30 Jul 2026 16:26:54 -0700 Subject: [PATCH 6/6] Simplify macOS sccache package download Parameterize the existing dotnet package download command by package id instead of creating a temporary restore project. Select sccache.osx-x64 on macOS and specify nuget.org because the package is unlisted and is not present in the repository's default feeds. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 356ad667-b44e-4469-aadb-1527c3d1fe24 --- .../coreclr/templates/setup-sccache.yml | 18 +++--------------- 1 file changed, 3 insertions(+), 15 deletions(-) diff --git a/eng/pipelines/coreclr/templates/setup-sccache.yml b/eng/pipelines/coreclr/templates/setup-sccache.yml index 4ea9217a1da636..fd04d5bb9f0d5f 100644 --- a/eng/pipelines/coreclr/templates/setup-sccache.yml +++ b/eng/pipelines/coreclr/templates/setup-sccache.yml @@ -50,26 +50,14 @@ steps: sccacheVersion="${{ parameters.sccacheVersion }}" osGroup="${{ parameters.osGroup }}" sccachePackage="sccache" + sccacheSource=() if [[ "$osGroup" == "osx" ]]; then sccachePackage="sccache.osx-x64" - restoreDir="$(mktemp -d "$(Agent.TempDirectory)/sccache-restore.XXXXXX")" - trap 'rm -rf "$restoreDir"' EXIT - cat > "$restoreDir/sccache.csproj" < - - net8.0 - - - - - - EOF - "$(Build.SourcesDirectory)/eng/common/dotnet.sh" restore "$restoreDir/sccache.csproj" --packages "$(Build.SourcesDirectory)/.packages" --verbosity quiet - else - "$(Build.SourcesDirectory)/eng/common/dotnet.sh" package download "${sccachePackage}@${sccacheVersion}" -o "$(Build.SourcesDirectory)/.packages" -v quiet + sccacheSource=(--source https://api.nuget.org/v3/index.json) fi + "$(Build.SourcesDirectory)/eng/common/dotnet.sh" package download "${sccachePackage}@${sccacheVersion}" -o "$(Build.SourcesDirectory)/.packages" -v quiet ${sccacheSource[@]+"${sccacheSource[@]}"} sccacheDir="$(Build.SourcesDirectory)/.packages/${sccachePackage}/${sccacheVersion}/tools" chmod +x "$sccacheDir/sccache"