Skip to content

Commit

Permalink
Merge pull request #11 from na4ma4/v1
Browse files Browse the repository at this point in the history
added install-protoc command from lib-gha to pkg-protobuf(v1)
  • Loading branch information
jmalloc authored Apr 13, 2021
2 parents 1671b2c + 074b742 commit 7053c1d
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 2 deletions.
12 changes: 10 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ PROTO_FILES += $(shell PATH="$(PATH)" git-find '*.proto')
# via the 'artifacts/protobuf/go.proto_paths' file.
PROTO_INCLUDE_PATHS ?=

# PROTOC_COMMAND is the path to the protoc command, if this is not specified
# the latest version of protoc is installed for the host operating system.
PROTOC_COMMAND ?= $(MF_PROJECT_ROOT)/artifacts/protobuf/bin/protoc

################################################################################

# This Makefile provides the recipes used to build each language's source files
Expand Down Expand Up @@ -51,14 +55,18 @@ PROTO_INCLUDE_PATHS ?=
#
# NOTE: The $$(cat ...) syntax can NOT be swapped to $$(< ...). For reasons
# unknown this syntax does NOT work under Travis CI.
%.pb.go: %.proto artifacts/protobuf/bin/protoc-gen-go artifacts/protobuf/go.proto_paths
PATH="$(MF_PROJECT_ROOT)/artifacts/protobuf/bin:$$PATH" protoc \
%.pb.go: %.proto $(PROTOC_COMMAND) artifacts/protobuf/bin/protoc-gen-go artifacts/protobuf/go.proto_paths
PATH="$(MF_PROJECT_ROOT)/artifacts/protobuf/bin:$$PATH" $(PROTOC_COMMAND) \
--proto_path="$(dir $(PROTOC_COMMAND))../include" \
--go_out=plugins=grpc:. \
--go_opt=module=$$(go list -m) \
$$(cat artifacts/protobuf/go.proto_paths) \
$(addprefix --proto_path=,$(PROTO_INCLUDE_PATHS)) \
"$(MF_PROJECT_ROOT)/$(@D)"/*.proto

artifacts/protobuf/bin/protoc:
$(MF_ROOT)/pkg/protobuf/v1/bin/install-protoc "$(MF_PROJECT_ROOT)/artifacts/protobuf"

artifacts/protobuf/bin/protoc-gen-go: go.mod
$(MF_ROOT)/pkg/protobuf/v1/bin/install-protoc-gen-go "$(MF_PROJECT_ROOT)/$(@D)"

Expand Down
33 changes: 33 additions & 0 deletions bin/install-protoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#!/usr/bin/env bash
set -euo pipefail

PROTOC_ROOT="${1}"
shift

case "$(uname -s)" in
"Darwin")
OS="osx";;
"Linux")
OS="linux";;
*)
OS="linux";;
esac

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
LOCAL_VERSION="$(${PROTOC_ROOT}/bin/protoc --version | sed -e 's/.* //')"
[[ "${VERSION}" == "${LOCAL_VERSION}" ]] && exit 0
fi

ARCHIVE="protoc-${VERSION}-${OS}-$(uname -m).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}"
unzip -o "${ARCHIVE}"
chmod +x bin/protoc
find include/google -type d -exec chmod 755 {} \;
find include/google -type f -exec chmod 644 {} \;
popd

0 comments on commit 7053c1d

Please sign in to comment.