Skip to content

Commit 25d9391

Browse files
authored
build: ensure we use correct version of protoc and its deps.
Use protoc-specific local install directory to allow safely wiping protoc and its dependencies without affecting other tools that might get installed under the build/tools directory in the future. Add a check-protoc target to check protoc version during builds and install the correct one if it is not found. Simplify and align the installation of protoc dependencies. Maintain tool versions in go.mod. Update auto-generated code regenerating them with the latest tool version we use. Signed-off-by: Markus Lehtonen <markus.lehtonen@intel.com>
1 parent b7e9de9 commit 25d9391

File tree

6 files changed

+38
-13
lines changed

6 files changed

+38
-13
lines changed

Makefile

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,16 +31,18 @@ RESOLVED_PWD := $(shell realpath $(shell pwd))
3131
BUILD_PATH := $(RESOLVED_PWD)/build
3232
BIN_PATH := $(BUILD_PATH)/bin
3333
TOOLS_PATH := $(BUILD_PATH)/tools
34+
PROTOC_PATH := $(TOOLS_PATH)/protoc
3435
COVERAGE_PATH := $(BUILD_PATH)/coverage
3536

37+
PROTOBUF_VERSION = 3.20.1
3638
PROTO_SOURCES = $(shell find pkg -name '*.proto' | grep -v /vendor/)
3739
PROTO_GOFILES = $(patsubst %.proto,%.pb.go,$(PROTO_SOURCES))
38-
PROTO_INCLUDE = -I $(PWD) -I$(TOOLS_PATH)/include
40+
PROTO_INCLUDE = -I $(PWD) -I$(PROTOC_PATH)/include
3941
PROTO_OPTIONS = --proto_path=. $(PROTO_INCLUDE) \
4042
--go_opt=paths=source_relative --go_out=. \
4143
--go-ttrpc_opt=paths=source_relative --go-ttrpc_out=. \
4244
--go-plugin_opt=paths=source_relative,disable_pb_gen=true --go-plugin_out=.
43-
PROTO_COMPILE = PATH=$(TOOLS_PATH)/bin protoc $(PROTO_OPTIONS)
45+
PROTO_COMPILE = PATH=$(PROTOC_PATH)/bin protoc $(PROTO_OPTIONS)
4446

4547
PLUGINS := \
4648
$(BIN_PATH)/logger \
@@ -78,7 +80,7 @@ FORCE:
7880
# build targets
7981
#
8082

81-
build-proto: $(PROTO_GOFILES)
83+
build-proto: check-protoc install-ttrpc-plugin install-wasm-plugin install-protoc-dependencies $(PROTO_GOFILES)
8284

8385
.PHONY: build-proto-dockerized
8486
build-proto-dockerized:
@@ -186,18 +188,30 @@ validate-repo-no-changes:
186188
#
187189
# targets for installing dependencies
188190
#
191+
check-protoc:
192+
$(Q)found_proto=$(shell $(PROTO_COMPILE) --version 2> /dev/null | awk '{print $$2}'); \
193+
if [ "$$found_proto" != "$(PROTOBUF_VERSION)" ]; then \
194+
echo "installing protoc version $(PROTOBUF_VERSION) (found: $$found_proto)"; \
195+
make clean-protoc; \
196+
make install-protoc; \
197+
else \
198+
echo "protoc version $$found_proto found."; \
199+
fi
189200

190201
install-protoc install-protobuf:
191-
$(Q)./scripts/install-protobuf
202+
$(Q)PROTOBUF_VERSION=$(PROTOBUF_VERSION) ./scripts/install-protobuf
203+
204+
clean-protoc:
205+
$(Q)rm -rf $(PROTOC_PATH)
192206

193207
install-ttrpc-plugin:
194-
$(Q)GOBIN="$(TOOLS_PATH)/bin" $(GO_INSTALL) -mod=mod github.com/containerd/ttrpc/cmd/protoc-gen-go-ttrpc@74421d10189e8c118870d294c9f7f62db2d33ec1
208+
$(Q)GOBIN="$(PROTOC_PATH)/bin" $(GO_INSTALL) github.com/containerd/ttrpc/cmd/protoc-gen-go-ttrpc
195209

196210
install-wasm-plugin:
197-
$(Q)GOBIN="$(TOOLS_PATH)/bin" $(GO_INSTALL) -mod=mod github.com/knqyf263/go-plugin/cmd/protoc-gen-go-plugin@$(shell go list -m -f {{.Version}} github.com/knqyf263/go-plugin)
211+
$(Q)GOBIN="$(PROTOC_PATH)/bin" $(GO_INSTALL) github.com/knqyf263/go-plugin/cmd/protoc-gen-go-plugin
198212

199213
install-protoc-dependencies:
200-
$(Q)GOBIN="$(TOOLS_PATH)/bin" $(GO_INSTALL) -mod=mod google.golang.org/protobuf/cmd/protoc-gen-go@v1.28.0
214+
$(Q)GOBIN="$(PROTOC_PATH)/bin" $(GO_INSTALL) google.golang.org/protobuf/cmd/protoc-gen-go
201215

202216
install-ginkgo:
203217
$(Q)$(GO_INSTALL) -mod=mod github.com/onsi/ginkgo/v2/ginkgo

go.mod

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ require (
2828
github.com/golang/protobuf v1.5.3 // indirect
2929
github.com/google/pprof v0.0.0-20240424215950-a892ee059fd6 // indirect
3030
github.com/kr/pretty v0.3.1 // indirect
31+
github.com/planetscale/vtprotobuf v0.4.0 // indirect
3132
github.com/pmezard/go-difflib v1.0.0 // indirect
3233
github.com/rogpeppe/go-internal v1.10.0 // indirect
3334
github.com/syndtr/gocapability v0.0.0-20200815063812-42c35b437635 // indirect
@@ -39,3 +40,9 @@ require (
3940
)
4041

4142
replace github.com/opencontainers/runtime-tools v0.9.0 => github.com/opencontainers/runtime-tools v0.0.0-20221026201742-946c877fa809
43+
44+
tool (
45+
github.com/containerd/ttrpc/cmd/protoc-gen-go-ttrpc
46+
github.com/knqyf263/go-plugin/cmd/protoc-gen-go-plugin
47+
google.golang.org/protobuf/cmd/protoc-gen-go
48+
)

go.sum

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@ github.com/opencontainers/runtime-tools v0.0.0-20221026201742-946c877fa809/go.mo
5050
github.com/opencontainers/selinux v1.9.1 h1:b4VPEF3O5JLZgdTDBmGepaaIbAo0GqoF6EBRq5f/g3Y=
5151
github.com/opencontainers/selinux v1.9.1/go.mod h1:2i0OySw99QjzBBQByd1Gr9gSjvuho1lHsJxIJ3gGbJI=
5252
github.com/pkg/diff v0.0.0-20210226163009-20ebb0f2a09e/go.mod h1:pJLUxLENpZxwdsKMEsNbx1VGcRFpLqf3715MtcvvzbA=
53+
github.com/planetscale/vtprotobuf v0.4.0 h1:NEI+g4woRaAZgeZ3sAvbtyvMBRjIv5kE7EWYQ8m4JwY=
54+
github.com/planetscale/vtprotobuf v0.4.0/go.mod h1:wm1N3qk9G/4+VM1WhpkLbvY/d8+0PbwYYpP5P5VhTks=
5355
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
5456
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
5557
github.com/prometheus/procfs v0.6.0 h1:mxy4L2jP6qMonqmq+aTtOx1ifVWUgG/TAmntgbh3xv4=
@@ -64,6 +66,7 @@ github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+
6466
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
6567
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
6668
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
69+
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
6770
github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
6871
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
6972
github.com/syndtr/gocapability v0.0.0-20200815063812-42c35b437635 h1:kdXcSzyDtseVEc4yCz2qF8ZrQvIDBJLl4S1c3GCXmoI=
@@ -90,6 +93,7 @@ golang.org/x/text v0.23.0/go.mod h1:/BLNzu4aZCJ1+kcD0DNRotWKage4q2rGVAg4o22unh4=
9093
golang.org/x/tools v0.21.1-0.20240508182429-e35e4ccd0d2d h1:vU5i/LfpvrRCpgM/VPfJLg5KjxD3E+hfT1SH+d9zLwg=
9194
golang.org/x/tools v0.21.1-0.20240508182429-e35e4ccd0d2d/go.mod h1:aiJjzUbINMkxbQROHiO6hDPo2LHcIPhhQsa9DLh0yGk=
9295
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
96+
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
9397
google.golang.org/genproto/googleapis/rpc v0.0.0-20230731190214-cbb8c96f2d6d h1:pgIUhmqwKOUlnKna4r6amKdUngdL8DrkpFeV8+VBElY=
9498
google.golang.org/genproto/googleapis/rpc v0.0.0-20230731190214-cbb8c96f2d6d/go.mod h1:TUfxEVdsvPg18p6AslUXFoLdpED4oBnGwyqk3dV1XzM=
9599
google.golang.org/grpc v1.57.1 h1:upNTNqv0ES+2ZOOqACwVtS3Il8M12/+Hz41RCPzAjQg=

pkg/api/api.pb.go

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/api/api_ttrpc.pb.go

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

scripts/install-protobuf

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,11 @@
2020
#
2121
set -eu -o pipefail
2222

23-
PROTOBUF_VERSION=3.20.1
23+
PROTOBUF_VERSION=${PROTOBUF_VERSION-3.20.1}
2424
GOARCH=$(go env GOARCH)
2525
GOOS=$(go env GOOS)
2626
PROTOBUF_DIR=$(mktemp -d)
27-
INSTALL_DIR="$PWD/build/tools"
27+
INSTALL_DIR="$PWD/build/tools/protoc"
2828

2929
mkdir -p "$INSTALL_DIR"
3030

0 commit comments

Comments
 (0)