Skip to content

Instantly share code, notes, and snippets.

@moul
Created October 8, 2019 21:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save moul/0d8a8e72d07e7d461bdc9c243893fcc7 to your computer and use it in GitHub Desktop.
Save moul/0d8a8e72d07e7d461bdc9c243893fcc7 to your computer and use it in GitHub Desktop.
Caching-friendly Makefile Rule to use Protoc within Docker
PROTOS_SRC := $(wildcard ./api/*.proto)
GEN_SRC := $(PROTOS_SRC) Makefile
GEN_SUM := gen.sum
GO_PKG := moul.io/test
GO_DIR := ./go
.PHONY: clean
clean:
rm -f gen.sum $(wildcard *.swagger.json)
.PHONY: generate
generate: gen.sum
$(GEN_SUM): $(GEN_SRC)
shasum $(GEN_SRC) | sort -k 2 > $(GEN_SUM).tmp
diff -q $(GEN_SUM).tmp $(GEN_SUM) || ( \
set -e; \
(set -e; cd $(GO_DIR) && GO111MODULE=on go mod vendor); \
docker run \
--user=`id -u` \
--volume="$(PWD):/go/src/$(GO_PKG)" \
--workdir="/go/src/$(GO_PKG)" \
--entrypoint="sh" \
--rm \
moul/protoc-gen-gotemplate \
-xec 'make generate_local' \
)
.PHONY: generate_local
generate_local:
protoc -I ../api:../go/vendor:/protobuf --swagger_out=logtostderr=true:. ../api/bertyprotocol.proto
protoc -I ../api:../go/vendor:/protobuf --swagger_out=logtostderr=true:. ../api/bertychat.proto
shasum $(GEN_SRC) | sort -k 2 > $(GEN_SUM).tmp
mv $(GEN_SUM).tmp $(GEN_SUM)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment