Skip to content

Commit ca9f4a1

Browse files
committed
Added a justfile recipe for installing protoc
1 parent cf3f0b1 commit ca9f4a1

3 files changed

Lines changed: 16 additions & 17 deletions

File tree

docs/docs/get_started/building.md

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -53,24 +53,17 @@ sudo apt update && sudo apt install -y openssl ca-certificates libssl3 libssl-de
5353
Install the Protobuf compiler:
5454

5555
:::note
56-
While many package repositories provide a `protobuf-compiler` package in lieu of manually installing protoc, we've found at the time of this writing that most of them use v3.21 which is quite out of date. We recommend getting the latest version manually.
56+
While many package repositories provide a `protobuf-compiler` package in lieu of manually installing protoc, we've found at the time of this writing that Debian-based ones use v3.21 which is quite out of date. We recommend getting the latest version manually.
5757
:::
5858

59+
We provide a convenient recipe to install the latest version directly from the GitHub releases page:
60+
5961
```bash
60-
PROTOC_VERSION=$(curl -s "https://api.github.com/repos/protocolbuffers/protobuf/releases/latest" | grep -Po '"tag_name": "v\K[0-9.]+')
61-
MACHINE_ARCH=$(uname -m)
62-
case "${MACHINE_ARCH}" in
63-
aarch64) PROTOC_ARCH=aarch_64;;
64-
x86_64) PROTOC_ARCH=x86_64;;
65-
*) echo "${MACHINE_ARCH} is not supported."; exit 1;;
66-
esac
67-
curl -sLo protoc.zip https://github.com/protocolbuffers/protobuf/releases/latest/download/protoc-$PROTOC_VERSION-linux-$PROTOC_ARCH.zip
68-
sudo unzip -q protoc.zip bin/protoc -d /usr
69-
sudo unzip -q protoc.zip "include/google/*" -d /usr
70-
sudo chmod a+x /usr/bin/protoc
71-
rm -rf protoc.zip
62+
just install-protoc
7263
```
7364

65+
This works on OSX and Linux systems, but you are welcome to download and install it manually as well.
66+
7467
With the prerequisites set up, pull the repository:
7568
```bash
7669
git clone https://github.com/Commit-Boost/commit-boost-client

justfile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,9 @@ _docker-build-image-multiarch version crate local-docker-registry: _create-docke
179179
# === Utilities ===
180180
# =================
181181

182+
install-protoc:
183+
provisioning/protoc.sh
184+
182185
docker-build-test-modules:
183186
docker build -t test_da_commit . -f examples/da_commit/Dockerfile
184187
docker build -t test_builder_log . -f examples/builder_log/Dockerfile

provisioning/protoc.sh

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,10 @@ case "$(uname)" in
2121
Linux*)
2222
PROTOC_OS="linux" ;
2323
TARGET_DIR="/usr" ; # Assumes the script is run as root or the user can do it manually
24-
apt update && apt install -y unzip curl ca-certificates jq ;;
24+
if [ $(id -u) != "0" ]; then
25+
CMD_PREFIX="sudo " ;
26+
fi
27+
${CMD_PREFIX}apt update && ${CMD_PREFIX}apt install -y unzip curl ca-certificates jq ;;
2528
*)
2629
echo "Unsupported OS: $(uname)" ;
2730
exit 1 ;;
@@ -50,8 +53,8 @@ echo "Installing protoc: $PROTOC_VERSION-$PROTOC_OS-$PROTOC_ARCH"
5053

5154
# Download and install protoc
5255
curl --retry 10 --retry-delay 2 --retry-all-errors -fsLo protoc.zip https://github.com/protocolbuffers/protobuf/releases/latest/download/protoc-$PROTOC_VERSION-$PROTOC_OS-$PROTOC_ARCH.zip || fail "Failed to download protoc"
53-
unzip -q protoc.zip bin/protoc -d $TARGET_DIR || fail "Failed to unzip protoc"
54-
unzip -q protoc.zip "include/google/*" -d $TARGET_DIR || fail "Failed to unzip protoc includes"
55-
chmod a+x $TARGET_DIR/bin/protoc || fail "Failed to set executable permissions for protoc"
56+
${CMD_PREFIX}unzip -qo protoc.zip bin/protoc -d $TARGET_DIR || fail "Failed to unzip protoc"
57+
${CMD_PREFIX}unzip -qo protoc.zip "include/google/*" -d $TARGET_DIR || fail "Failed to unzip protoc includes"
58+
${CMD_PREFIX}chmod a+x $TARGET_DIR/bin/protoc || fail "Failed to set executable permissions for protoc"
5659
rm -rf protoc.zip || fail "Failed to remove protoc zip file"
5760
echo "protoc ${PROTOC_VERSION} installed successfully for ${PROTOC_OS} ${PROTOC_ARCH}"

0 commit comments

Comments
 (0)