From bed622ca1bee83db90d6a009f652958c065393c8 Mon Sep 17 00:00:00 2001 From: James Harris Date: Wed, 18 Aug 2021 12:58:51 +1000 Subject: [PATCH] Use x86_64 builds on Apple Silicon. --- bin/install-protoc | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/bin/install-protoc b/bin/install-protoc index 7e2967e..8e9c997 100755 --- a/bin/install-protoc +++ b/bin/install-protoc @@ -13,6 +13,17 @@ case "$(uname -s)" in OS="linux";; esac +ARCH="$(uname -m)" + +# Use x86_64 on Apple Silicon, as there is no official arm64 support. +# +# See https://github.com/protocolbuffers/protobuf/issues/8062. +# See https://github.com/protocolbuffers/protobuf/issues/8428. +if [[ "$OS" == "osx" && "$ARCH" == "arm64" ]]; then + softwareupdate --install-rosetta --agree-to-license + ARCH="x86_64" +fi + VERSION="$(curl --head --silent https://github.com/protocolbuffers/protobuf/releases/latest | grep -i '^Location:' | egrep -o '[0-9]+.[0-9]+.[0-9]+')" if [[ -f "${PROTOC_ROOT}/bin/protoc" ]]; then @@ -20,12 +31,12 @@ if [[ -f "${PROTOC_ROOT}/bin/protoc" ]]; then [[ "${VERSION}" == "${LOCAL_VERSION}" ]] && exit 0 fi -ARCHIVE="protoc-${VERSION}-${OS}-$(uname -m).zip" +ARCHIVE="protoc-${VERSION}-${OS}-${ARCH}.zip" URL="https://github.com/protocolbuffers/protobuf/releases/download/v${VERSION}/${ARCHIVE}" mkdir -p "${PROTOC_ROOT}" pushd "${PROTOC_ROOT}" -curl --location --silent --output "${ARCHIVE}" "${URL}" +curl --fail --silent --show-error --location --output "${ARCHIVE}" "${URL}" unzip -o "${ARCHIVE}" chmod +x bin/protoc find include/google -type d -exec chmod 755 {} \;