Skip to content

Commit

Permalink
install bazel directly instead of using the installer script
Browse files Browse the repository at this point in the history
bazel team isn't publishing any new installer scripts: bazelbuild/bazel#11775
  • Loading branch information
korbin authored and klardotsh committed Aug 2, 2022
1 parent 62813b6 commit 40559a0
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 18 deletions.
2 changes: 1 addition & 1 deletion .buildkite/build-static-release.sh
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ fi

echo will run with $CONFIG_OPTS

./bazel build //main:sorbet --strip=always $CONFIG_OPTS
./bazel build //main:sorbet --strip=always $CONFIG_OPTS --toolchain_resolution_debug=@bazel_tools//tools/cpp:toolchain_type

mkdir gems/sorbet-static/libexec/
cp bazel-bin/main/sorbet gems/sorbet-static/libexec/
Expand Down
10 changes: 6 additions & 4 deletions WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,12 @@ load("@build_bazel_rules_nodejs//:index.bzl", "node_repositories")

node_repositories()

BAZEL_VERSION = "5.0.0"
BAZEL_VERSION = "4.2.1"

BAZEL_INSTALLER_VERSION_LINUX_X86_64_SHA = "42cfb37d2834d075996b9d02698674be7f322f0acd864b17c3191301329845f9"
BAZEL_VERSION_LINUX_X86_64_SHA = "1a4f3a3ce292307bceeb44f459883859c793436d564b95319aacb8af1f20557c"

BAZEL_INSTALLER_VERSION_DARWIN_X86_64_SHA = "f7e8d1eac85ec125c430f9553e35d522c057895262956201ccea8a27d87054cc"
BAZEL_VERSION_LINUX_ARM64_SHA = "0a849f99d59eab7058212a89b2a0d2b6a17f1ef7ba7fb7a42523a7171bb1c64f"

BAZEL_INSTALLER_VERSION_DARWIN_ARM64_SHA = "785900dfadb14b20db4edc76019cd1c9048c4216ed8052c34e72816b7ed358e9"
BAZEL_VERSION_DARWIN_X86_64_SHA = "74d93848f0c9d592e341e48341c53c87e3cb304a54a2a1ee9cff3df422f0b23c"

BAZEL_VERSION_DARWIN_ARM64_SHA = "f0375d77afe61a7167cd6d9cda1fde0eb29839e0ca8718002da73ea895b31dc0"
30 changes: 17 additions & 13 deletions bazel
Original file line number Diff line number Diff line change
Expand Up @@ -52,23 +52,26 @@ echo >&2 "No cached Bazel v$BAZEL_VERSION found, installing..."
kernel_name="$(uname -s | tr 'A-Z' 'a-z')"
processor_name="$(uname -m)"

bazel_installer_platform="${kernel_name}-${processor_name}"
case "$bazel_installer_platform" in
bazel_platform="${kernel_name}-${processor_name}"
case "$bazel_platform" in
linux-x86_64) ;;
linux-aarch64)
bazel_platform="linux-arm64"
;;
darwin-x86_64) ;;
darwin-arm64)
# Pseudo Apple Silicon support by forcing x86_64 (Rosetta) for now
bazel_installer_platform="darwin-x86_64"
bazel_platform="darwin-x86_64"
;;
*)
echo >&2 "Building on $bazel_installer_platform is not implemented"
echo >&2 "Building on $bazel_platform is not implemented"
exit 1
;;
esac

bazel_installer_platform_var="$(echo "$bazel_installer_platform" | tr 'a-z-' 'A-Z_')"
bazel_installer_sha_regex="BAZEL_INSTALLER_VERSION_${bazel_installer_platform_var}_SHA = \"([^\"]+)\""
if [[ $workspace_contents =~ $bazel_installer_sha_regex ]]; then
bazel_platform_var="$(echo "$bazel_platform" | tr 'a-z-' 'A-Z_')"
bazel_sha_regex="BAZEL_VERSION_${bazel_platform_var}_SHA = \"([^\"]+)\""
if [[ $workspace_contents =~ $bazel_sha_regex ]]; then
export expected_sha="${BASH_REMATCH[1]}"
else
echo >&2 "$0: Failed to extract Bazel version from WORKSPACE"
Expand All @@ -84,13 +87,13 @@ mkdir -p "$BUILD_DIR"
cd "$BUILD_DIR"
echo "$PWD"

installer_name="bazel-${BAZEL_VERSION}-installer-${bazel_installer_platform}.sh"
name="bazel-${BAZEL_VERSION}-${bazel_platform}"
BAZEL_REMOTE_SOURCE="${BAZEL_REMOTE_SOURCE:-https://github.com/bazelbuild/bazel/releases/download}"
BAZEL_INSTALLER_PATH="${BAZEL_INSTALLER_PATH:-$BAZEL_REMOTE_SOURCE/${BAZEL_VERSION}/$installer_name}"
BAZEL_PATH="${BAZEL_PATH:-$BAZEL_REMOTE_SOURCE/${BAZEL_VERSION}/$name}"

curl -O -L "$BAZEL_INSTALLER_PATH"
curl -O -L "$BAZEL_PATH"

actual_sha="$(shasum -a 256 "$installer_name" | awk '{print $1}')"
actual_sha="$(shasum -a 256 "$name" | awk '{print $1}')"
if [ "$actual_sha" != "$expected_sha" ]; then
echo >&2 "Installer checksum mismatch:"
echo >&2 " Expected: $expected_sha"
Expand All @@ -99,9 +102,10 @@ mkdir -p "$BUILD_DIR"
exit 1
fi

chmod +x "$installer_name"
chmod +x "$name"
mkdir -p "$bazel_bin_loc"
"./${installer_name}" --base="${bazel_bin_loc}/${BAZEL_VERSION}" --bin="${bazel_bin_loc}/${BAZEL_VERSION}/bin_t"
mkdir -p "$(dirname "$bazel_exec_path")"
mv "$name" "$bazel_exec_path"
)
rm -rf "$BUILD_DIR"

Expand Down

0 comments on commit 40559a0

Please sign in to comment.