Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
c032b94
Test sccache with temp copy
agocke Feb 6, 2026
acc3583
Use portable binary
agocke Feb 6, 2026
2fc886e
Print sccache stats before running
agocke Feb 6, 2026
709d5dd
Apply suggestion from @Copilot
agocke Feb 6, 2026
f53e79d
Use anonymous acces
agocke Feb 7, 2026
e22b6fa
Typo
agocke Feb 7, 2026
7e67bc9
No creds
agocke Feb 7, 2026
a36ccd1
Use sccache with anon backend support
agocke Feb 7, 2026
b8aea3b
Also print stats at end
agocke Feb 7, 2026
3ba5ec6
Remove everything except a single job for testing
agocke Feb 7, 2026
b8c56ec
Add logging
agocke Feb 7, 2026
ce4729b
Update buildArgs for CoreCLR_Libraries job
agocke Feb 7, 2026
5bbdbad
Enable sccache for host
agocke Feb 7, 2026
86c6b1c
Update buildArgs in runtime.yml for CoreCLR_Libraries
agocke Feb 7, 2026
6164354
Refactor sccache log directory handling
agocke Feb 7, 2026
2ca0c95
Remove extra setting for host build
agocke Feb 7, 2026
4c64603
Build only host native
agocke Feb 7, 2026
8f1fe94
Use host native
agocke Feb 7, 2026
0808ed2
Bring back full runtime pipeline
agocke Feb 8, 2026
f2410b7
Only set variables if not already set
agocke Feb 8, 2026
7839ab6
Try to narrow down problem
agocke Feb 9, 2026
51f2995
Merge branch 'main' into test-sccache
agocke Feb 9, 2026
9f9e45c
Also remove libs build
agocke Feb 9, 2026
c578b5a
Bring back libs
agocke Feb 9, 2026
a33f540
Set unlimited cache timeout
agocke Feb 10, 2026
03b2030
Revert just the _version.c change
agocke Feb 10, 2026
b008128
Remove targets fixup for _version.c
agocke Feb 10, 2026
7bde7e7
Bring back base _version.h file
agocke Feb 10, 2026
45fa3d4
Restore copy_version_files
agocke Feb 10, 2026
c7b6d13
Typo
agocke Feb 10, 2026
163962b
Revert HardcodeNativeVersionFile
agocke Feb 10, 2026
d8e6ef8
Bring back version writing
agocke Feb 10, 2026
4e50efe
Merge branch 'main' into test-sccache
agocke Feb 11, 2026
fb90899
Update sccache binary
agocke Feb 11, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions eng/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -589,6 +589,33 @@ fi

initDistroRid "$os" "$arch" "$crossBuild"

# Enable sccache for linux-x64 builds if the binary is present in the repo root.
if [[ "${USE_SCCACHE:-}" != "true" && "$os" == "linux" && "$arch" == "x64" && -f "$scriptroot/../sccache" ]]; then
export PATH="$scriptroot/..:$PATH"
Copy link

Copilot AI Feb 7, 2026

Choose a reason for hiding this comment

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

Prepending the repo root to PATH can unintentionally shadow system tools if a same-named executable exists in the repo (now or in the future), making builds harder to reason about. A safer pattern is to invoke sccache via an explicit absolute path and/or add only a dedicated tools directory to PATH.

Suggested change
export PATH="$scriptroot/..:$PATH"
export PATH="$PATH:$scriptroot/.."

Copilot uses AI. Check for mistakes.
export USE_SCCACHE=true
export SCCACHE_AZURE_BLOB_CONTAINER=runtime-cache
export SCCACHE_AZURE_CONNECTION_STRING="BlobEndpoint=https://runsccache.blob.core.windows.net"
export SCCACHE_AZURE_NO_CREDENTIALS=true

sccache --stop-server || true

# Disable idle timeout so the server stays alive across long managed-build
# phases that separate native-compilation steps (e.g. clr then libs).
export SCCACHE_IDLE_TIMEOUT=0

# Write sccache logs to the AzDO artifact staging directory so they get published.
# Fall back to the local artifacts/log directory if not running in CI.
if [[ -n "${BUILD_ARTIFACTSTAGINGDIRECTORY:-}" ]]; then
__sccacheLogDir="$BUILD_ARTIFACTSTAGINGDIRECTORY/artifacts/log"
else
__sccacheLogDir="$scriptroot/../artifacts/log"
fi
mkdir -p "$__sccacheLogDir"
SCCACHE_ERROR_LOG="$__sccacheLogDir/sccache_debug.log" SCCACHE_LOG=debug sccache --start-server
Copy link

Copilot AI Feb 7, 2026

Choose a reason for hiding this comment

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

The comment says sccache logs will be written to the artifact log directory, but SCCACHE_ERROR_LOG and SCCACHE_LOG are only set for the sccache --start-server command (not exported), so compilation activity won’t log there. Export these variables for the whole build (or set them in the environment before invoking the build) so the intended logs are actually captured.

Suggested change
SCCACHE_ERROR_LOG="$__sccacheLogDir/sccache_debug.log" SCCACHE_LOG=debug sccache --start-server
export SCCACHE_ERROR_LOG="$__sccacheLogDir/sccache_debug.log"
export SCCACHE_LOG=debug
sccache --start-server

Copilot uses AI. Check for mistakes.
echo "sccache enabled for linux-x64 build"
sccache -s
Copy link

Copilot AI Feb 7, 2026

Choose a reason for hiding this comment

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

Because eng/build.sh runs with set -e, a failure from sccache -s (e.g., server startup failure, unsupported backend, transient network issue) will abort the entire build even though this is just a diagnostic step. Consider making the stats call best-effort (or gating it behind an explicit opt-in) so cache issues don't fail the build.

Suggested change
sccache -s
sccache -s || echo "sccache stats are unavailable; continuing without cache stats"

Copilot uses AI. Check for mistakes.
Comment on lines +592 to +616
Copy link

Copilot AI Feb 7, 2026

Choose a reason for hiding this comment

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

The guard only checks -f "$scriptroot/../sccache", but with set -e the build will still fail later if that file isn't executable or can't be invoked. It should check that the binary is executable (and ideally invoke it via its full path) before enabling USE_SCCACHE/modifying PATH.

Suggested change
# Enable sccache for linux-x64 builds if the binary is present in the repo root.
if [[ "$os" == "linux" && "$arch" == "x64" && -f "$scriptroot/../sccache" ]]; then
export PATH="$scriptroot/..:$PATH"
export USE_SCCACHE=true
export SCCACHE_AZURE_BLOB_CONTAINER=runtime-cache
export SCCACHE_AZURE_CONNECTION_STRING="BlobEndpoint=https://runsccache.blob.core.windows.net"
export SCCACHE_AZURE_NO_CREDENTIALS=true
echo "sccache enabled for linux-x64 build"
sccache -s
# Enable sccache for linux-x64 builds if the binary is present and executable in the repo root.
if [[ "$os" == "linux" && "$arch" == "x64" && -f "$scriptroot/../sccache" && -x "$scriptroot/../sccache" ]]; then
export PATH="$scriptroot/..:$PATH"
export USE_SCCACHE=true
export SCCACHE_AZURE_BLOB_CONTAINER=runtime-cache
export SCCACHE_AZURE_CONNECTION_STRING="BlobEndpoint=https://runsccache.blob.core.windows.net"
export SCCACHE_AZURE_NO_CREDENTIALS=true
echo "sccache enabled for linux-x64 build"
"$scriptroot/../sccache" -s

Copilot uses AI. Check for mistakes.
Comment on lines +613 to +616
Copy link

Copilot AI Feb 8, 2026

Choose a reason for hiding this comment

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

SCCACHE_LOG=debug is enabled unconditionally when sccache is detected, which can produce very large logs and artifacts on CI runs and slow down builds. Consider using a less verbose default (or honoring an existing SCCACHE_LOG value) and only enabling debug logging when explicitly requested.

Copilot uses AI. Check for mistakes.
Comment on lines +592 to +616
Copy link

Copilot AI Feb 10, 2026

Choose a reason for hiding this comment

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

The check for enabling sccache uses -f "$scriptroot/../sccache", which doesn't guarantee the file is executable. If the file exists but isn't marked executable (or is the wrong binary), later calls to sccache/CMake launcher will fail. Consider using -x (and possibly validating sccache --version) before exporting USE_SCCACHE=true.

Suggested change
# Enable sccache for linux-x64 builds if the binary is present in the repo root.
if [[ "${USE_SCCACHE:-}" != "true" && "$os" == "linux" && "$arch" == "x64" && -f "$scriptroot/../sccache" ]]; then
export PATH="$scriptroot/..:$PATH"
export USE_SCCACHE=true
export SCCACHE_AZURE_BLOB_CONTAINER=runtime-cache
export SCCACHE_AZURE_CONNECTION_STRING="BlobEndpoint=https://runsccache.blob.core.windows.net"
export SCCACHE_AZURE_NO_CREDENTIALS=true
sccache --stop-server || true
# Disable idle timeout so the server stays alive across long managed-build
# phases that separate native-compilation steps (e.g. clr then libs).
export SCCACHE_IDLE_TIMEOUT=0
# Write sccache logs to the AzDO artifact staging directory so they get published.
# Fall back to the local artifacts/log directory if not running in CI.
if [[ -n "${BUILD_ARTIFACTSTAGINGDIRECTORY:-}" ]]; then
__sccacheLogDir="$BUILD_ARTIFACTSTAGINGDIRECTORY/artifacts/log"
else
__sccacheLogDir="$scriptroot/../artifacts/log"
fi
mkdir -p "$__sccacheLogDir"
SCCACHE_ERROR_LOG="$__sccacheLogDir/sccache_debug.log" SCCACHE_LOG=debug sccache --start-server
echo "sccache enabled for linux-x64 build"
sccache -s
# Enable sccache for linux-x64 builds if a working sccache binary is present in the repo root.
if [[ "${USE_SCCACHE:-}" != "true" && "$os" == "linux" && "$arch" == "x64" && -x "$scriptroot/../sccache" ]]; then
if "$scriptroot/../sccache" --version >/dev/null 2>&1; then
export PATH="$scriptroot/..:$PATH"
export USE_SCCACHE=true
export SCCACHE_AZURE_BLOB_CONTAINER=runtime-cache
export SCCACHE_AZURE_CONNECTION_STRING="BlobEndpoint=https://runsccache.blob.core.windows.net"
export SCCACHE_AZURE_NO_CREDENTIALS=true
sccache --stop-server || true
# Disable idle timeout so the server stays alive across long managed-build
# phases that separate native-compilation steps (e.g. clr then libs).
export SCCACHE_IDLE_TIMEOUT=0
# Write sccache logs to the AzDO artifact staging directory so they get published.
# Fall back to the local artifacts/log directory if not running in CI.
if [[ -n "${BUILD_ARTIFACTSTAGINGDIRECTORY:-}" ]]; then
__sccacheLogDir="$BUILD_ARTIFACTSTAGINGDIRECTORY/artifacts/log"
else
__sccacheLogDir="$scriptroot/../artifacts/log"
fi
mkdir -p "$__sccacheLogDir"
SCCACHE_ERROR_LOG="$__sccacheLogDir/sccache_debug.log" SCCACHE_LOG=debug sccache --start-server
echo "sccache enabled for linux-x64 build"
sccache -s
fi

Copilot uses AI. Check for mistakes.
fi
Comment on lines +592 to +617
Copy link

Copilot AI Feb 6, 2026

Choose a reason for hiding this comment

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

The sccache integration only affects CoreCLR builds because only src/coreclr/build-runtime.sh checks the USE_SCCACHE environment variable. Other native components (Mono, native libs, host/corehost) do not currently respect this setting and will not use sccache even when enabled. Consider documenting this limitation in the comment, or adding USE_SCCACHE support to other native build scripts if caching is desired for those components as well.

Copilot uses AI. Check for mistakes.
Comment on lines +592 to +617
Copy link

Copilot AI Feb 11, 2026

Choose a reason for hiding this comment

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

This block auto-enables sccache for any linux-x64 build whenever a sccache file exists in the repo root, which changes default build behavior and introduces an external cache endpoint dependency for local developer builds as well as CI. It would be safer to make this explicitly opt-in (e.g., require USE_SCCACHE=true) or at least gate it to CI-only via a well-known environment variable (e.g., TF_BUILD/CI).

Copilot uses AI. Check for mistakes.

# Disable targeting pack caching as we reference a partially constructed targeting pack and update it later.
# The later changes are ignored when using the cache.
export DOTNETSDK_ALLOW_TARGETING_PACK_CACHING=0
Expand Down Expand Up @@ -626,3 +653,7 @@ if [[ "$bootstrap" == "1" ]]; then
fi

"$scriptroot/common/build.sh" ${arguments[@]+"${arguments[@]}"}

if [[ "$os" == "linux" && "$arch" == "x64" && -f "$scriptroot/../sccache" ]]; then
sccache -s
Comment on lines +657 to +658
Copy link

Copilot AI Feb 10, 2026

Choose a reason for hiding this comment

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

The final sccache -s runs whenever a ../sccache file exists, even if the earlier enablement block was skipped (e.g., USE_SCCACHE=true is already set). In that case PATH may not include the repo root and this can fail with sccache: command not found. Consider gating this on USE_SCCACHE==true and/or invoking "$scriptroot/../sccache" -s after ensuring it’s executable.

Suggested change
if [[ "$os" == "linux" && "$arch" == "x64" && -f "$scriptroot/../sccache" ]]; then
sccache -s
if [[ "$os" == "linux" && "$arch" == "x64" && "${USE_SCCACHE:-}" == "true" ]]; then
if command -v sccache >/dev/null 2>&1; then
sccache -s || true
elif [[ -x "$scriptroot/../sccache" ]]; then
"$scriptroot/../sccache" -s || true
fi

Copilot uses AI. Check for mistakes.
fi
Comment on lines +657 to +659
Copy link

Copilot AI Feb 7, 2026

Choose a reason for hiding this comment

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

The same linux/x64 + sccache-present condition is duplicated here and above. Consider factoring it into a single helper/variable to avoid future drift (e.g., if the condition or path changes in one place but not the other).

Copilot uses AI. Check for mistakes.
Comment on lines +657 to +659
Copy link

Copilot AI Feb 8, 2026

Choose a reason for hiding this comment

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

The linux-x64 + sccache-present condition is duplicated for the post-build stats print. To avoid the two checks drifting over time, consider factoring the condition into a single boolean/variable and reusing it for both the setup and the final sccache -s.

Copilot uses AI. Check for mistakes.
Loading
Loading