diff --git a/.gitlab/build/bazel/defs.yml b/.gitlab/build/bazel/defs.yml index b1347c7d34f3..dce526fb7015 100644 --- a/.gitlab/build/bazel/defs.yml +++ b/.gitlab/build/bazel/defs.yml @@ -16,9 +16,16 @@ policy: pull$BAZEL_CACHE_POLICY_SUFFIX when: on_success - &bazel_cache - key: bazel-$CI_RUNNER_DESCRIPTION + # TODO(agent-build): revert key prefix to bazel-$CI_RUNNER_DESCRIPTION after switching to Go 1.26+: + # - issue: https://github.com/microsoft/go/issues/1994 + # - fix: https://github.com/microsoft/go/pull/1998 + key: + prefix: bazel-$CI_JOB_NAME + files: [ .go-version, .python-version ] paths: - .cache/bazel/*/cache + - .cache/go* + - .cache/ms-go* - .cache/pip policy: pull$BAZEL_CACHE_POLICY_SUFFIX when: on_success diff --git a/tools/bazel b/tools/bazel index 31aa9e40bad7..1e175adb8bd6 100755 --- a/tools/bazel +++ b/tools/bazel @@ -26,6 +26,9 @@ if [ -n "${XDG_CACHE_HOME:-}" ]; then >&2 echo "🔴 XDG_CACHE_HOME ($XDG_CACHE_HOME) must denote an absolute path!" exit 2 fi + unset GOCACHE # https://pkg.go.dev/cmd/go#hdr-Build_and_test_caching + export GOMODCACHE="$XDG_CACHE_HOME"/go/mod # https://wiki.archlinux.org/title/XDG_Base_Directory#Partial + unset PIP_CACHE_DIR # https://pip.pypa.io/en/stable/topics/caching/#default-paths if [[ -n "${CI:-}" && -z "${GITHUB_ACTIONS:-}" ]]; then exec "$BAZEL_REAL" ${1:+"$1" --config=ci} "${@:2}" fi diff --git a/tools/bazel.bat b/tools/bazel.bat index bee669f91fa5..082e7d7b8ace 100644 --- a/tools/bazel.bat +++ b/tools/bazel.bat @@ -21,13 +21,20 @@ if not exist "%XDG_CACHE_HOME%" ( ) ) -:: Ensure `bazel` & managed toolchains honor `XDG_CACHE_HOME` if set: https://github.com/bazelbuild/bazel/issues/27808 +:: Ensure `bazel` & managed toolchains honor `XDG_CACHE_HOME` as per https://wiki.archlinux.org/title/XDG_Base_Directory if defined XDG_CACHE_HOME ( set "XDG_CACHE_HOME=!XDG_CACHE_HOME:/=\!" if "!XDG_CACHE_HOME:~1,2!" neq ":\" if "!XDG_CACHE_HOME:~0,2!" neq "\\" ( >&2 echo 🔴 XDG_CACHE_HOME ^(!XDG_CACHE_HOME!^) must denote an absolute path! exit /b 2 ) + :: https://pkg.go.dev/cmd/go#hdr-Build_and_test_caching + set "GOCACHE=%XDG_CACHE_HOME%\go-build" + :: https://wiki.archlinux.org/title/XDG_Base_Directory#Partial + set "GOMODCACHE=%XDG_CACHE_HOME%\go\mod" + :: https://pip.pypa.io/en/stable/topics/caching/#default-paths + set "PIP_CACHE_DIR=%XDG_CACHE_HOME%\pip" + :: https://github.com/bazelbuild/bazel/issues/27808 set "bazel_home=%XDG_CACHE_HOME%\bazel" set bazel_home_startup_option="--output_user_root=!bazel_home!" ) else (