Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
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
19 changes: 19 additions & 0 deletions eng/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -584,6 +584,21 @@ arguments+=("-clp:ForceNoAlign")

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

# 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"
Comment on lines +588 to +589
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 enablement check uses -f "$scriptroot/../sccache", but that doesn't guarantee the file is executable. If the file exists without execute permissions, the later sccache -s/compiler launcher will fail and stop the build. Prefer checking -x (and/or verifying command -v sccache after updating PATH) before enabling.

Copilot uses AI. Check for mistakes.
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
mkdir -p "$scriptroot/../artifacts/log"
export SCCACHE_ERROR_LOG="$scriptroot/../artifacts/log/sccache_debug.log"
export SCCACHE_LOG=debug
sccache --start-server
echo "sccache enabled for linux-x64 build"
sccache -s
Comment on lines 588 to 599
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 condition only checks -f "$scriptroot/../sccache", but the code later executes sccache as a command name. If the file exists but isn’t executable (or isn’t found via PATH), this will fail. Prefer checking -x and executing "$scriptroot/../sccache" (or ensuring PATH is updated before any invocation).

Copilot uses AI. Check for mistakes.
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 587 to 599
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 +588 to +599
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 sccache presence check uses -f but the script immediately executes sccache. If the file exists but isn’t executable (or is the wrong binary), the build will fail (this script runs with set -e). Prefer checking -x and/or validating that invoking sccache --version succeeds before enabling it.

Suggested change
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
mkdir -p "$scriptroot/../artifacts/log"
export SCCACHE_ERROR_LOG="$scriptroot/../artifacts/log/sccache_debug.log"
export SCCACHE_LOG=debug
sccache --start-server
echo "sccache enabled for linux-x64 build"
sccache -s
if [[ "$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
mkdir -p "$scriptroot/../artifacts/log"
export SCCACHE_ERROR_LOG="$scriptroot/../artifacts/log/sccache_debug.log"
export SCCACHE_LOG=debug
"$scriptroot/../sccache" --start-server
echo "sccache enabled for linux-x64 build"
"$scriptroot/../sccache" -s
fi

Copilot uses AI. Check for mistakes.
fi
Comment on lines 587 to 600
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 +597 to +600
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.

sccache --start-server and sccache -s will hard-fail the entire build if sccache can’t start or the remote backend isn’t reachable (because eng/build.sh runs with set -e). If sccache is intended to be a best-effort accelerator, wrap these invocations so failures don’t abort the build, and only emit stats when the server is actually running.

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 @@ -621,3 +636,7 @@ if [[ "$bootstrap" == "1" ]]; then
fi

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

if [[ "$os" == "linux" && "$arch" == "x64" && -f "$scriptroot/../sccache" ]]; then
sccache -s
fi
Comment on lines +640 to +642
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.
Loading
Loading