Skip to content

Commit bf974f8

Browse files
committed
Install protoc locally in the source tree
Install (and use) protoc and plugins under build/tools in the source tree in an attempt to ensure that the correct version of the tooling is always used. Signed-off-by: Markus Lehtonen <[email protected]>
1 parent d3daead commit bf974f8

File tree

3 files changed

+22
-20
lines changed

3 files changed

+22
-20
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ jobs:
5353
5454
- name: Install protoc and plugins
5555
run: |
56-
sudo make install-protoc
56+
make install-protoc
5757
make install-protoc-dependencies install-ttrpc-plugin install-wasm-plugin
5858
5959
- name: Force regeneration of protobuf files on build

Makefile

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,6 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15-
PROTO_SOURCES = $(shell find . -name '*.proto' | grep -v /vendor/)
16-
PROTO_GOFILES = $(patsubst %.proto,%.pb.go,$(PROTO_SOURCES))
17-
PROTO_INCLUDE = -I$(PWD):/usr/local/include:/usr/include
18-
PROTO_OPTIONS = --proto_path=. $(PROTO_INCLUDE) \
19-
--go_opt=paths=source_relative --go_out=. \
20-
--go-ttrpc_opt=paths=source_relative --go-ttrpc_out=. \
21-
--go-plugin_opt=paths=source_relative,disable_pb_gen=true --go-plugin_out=.
22-
PROTO_COMPILE = PATH=$(PATH):$(shell go env GOPATH)/bin; protoc $(PROTO_OPTIONS)
23-
2415
GO_CMD := go
2516
GO_BUILD := $(GO_CMD) build
2617
GO_INSTALL := $(GO_CMD) install
@@ -39,8 +30,18 @@ GINKGO := ginkgo
3930
RESOLVED_PWD := $(shell realpath $(shell pwd))
4031
BUILD_PATH := $(RESOLVED_PWD)/build
4132
BIN_PATH := $(BUILD_PATH)/bin
33+
TOOLS_PATH := $(BUILD_PATH)/tools
4234
COVERAGE_PATH := $(BUILD_PATH)/coverage
4335

36+
PROTO_SOURCES = $(shell find pkg -name '*.proto' | grep -v /vendor/)
37+
PROTO_GOFILES = $(patsubst %.proto,%.pb.go,$(PROTO_SOURCES))
38+
PROTO_INCLUDE = -I $(PWD) -I$(TOOLS_PATH)/include
39+
PROTO_OPTIONS = --proto_path=. $(PROTO_INCLUDE) \
40+
--go_opt=paths=source_relative --go_out=. \
41+
--go-ttrpc_opt=paths=source_relative --go-ttrpc_out=. \
42+
--go-plugin_opt=paths=source_relative,disable_pb_gen=true --go-plugin_out=.
43+
PROTO_COMPILE = PATH=$(TOOLS_PATH)/bin protoc $(PROTO_OPTIONS)
44+
4445
PLUGINS := \
4546
$(BIN_PATH)/logger \
4647
$(BIN_PATH)/device-injector \
@@ -190,13 +191,13 @@ install-protoc install-protobuf:
190191
$(Q)./scripts/install-protobuf
191192

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

195196
install-wasm-plugin:
196-
$(Q)$(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)
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)
197198

198199
install-protoc-dependencies:
199-
$(Q)$(GO_INSTALL) -mod=mod google.golang.org/protobuf/cmd/[email protected]
200+
$(Q)GOBIN="$(TOOLS_PATH)/bin" $(GO_INSTALL) -mod=mod google.golang.org/protobuf/cmd/[email protected]
200201

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

scripts/install-protobuf

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,13 @@ PROTOBUF_VERSION=3.20.1
2424
GOARCH=$(go env GOARCH)
2525
GOOS=$(go env GOOS)
2626
PROTOBUF_DIR=$(mktemp -d)
27+
INSTALL_DIR=build/tools
2728

2829
case $GOARCH in
2930

3031
arm64)
3132
wget -O "$PROTOBUF_DIR/protobuf" "https://github.com/protocolbuffers/protobuf/releases/download/v$PROTOBUF_VERSION/protoc-$PROTOBUF_VERSION-linux-aarch_64.zip"
32-
unzip "$PROTOBUF_DIR/protobuf" -d /usr/local
33+
unzip "$PROTOBUF_DIR/protobuf" -d "$INSTALL_DIR"
3334
;;
3435

3536
amd64|386)
@@ -38,17 +39,17 @@ amd64|386)
3839
elif [ "$GOOS" = linux ]; then
3940
wget -O "$PROTOBUF_DIR/protobuf" "https://github.com/protocolbuffers/protobuf/releases/download/v$PROTOBUF_VERSION/protoc-$PROTOBUF_VERSION-linux-x86_64.zip"
4041
fi
41-
unzip "$PROTOBUF_DIR/protobuf" -d /usr/local
42+
unzip "$PROTOBUF_DIR/protobuf" -d "$INSTALL_DIR"
4243
;;
4344

4445
ppc64le)
4546
wget -O "$PROTOBUF_DIR/protobuf" "https://github.com/protocolbuffers/protobuf/releases/download/v$PROTOBUF_VERSION/protoc-$PROTOBUF_VERSION-linux-ppcle_64.zip"
46-
unzip "$PROTOBUF_DIR/protobuf" -d /usr/local
47+
unzip "$PROTOBUF_DIR/protobuf" -d "$INSTALL_DIR"
4748
;;
4849
*)
4950
wget -O "$PROTOBUF_DIR/protobuf" "https://github.com/protocolbuffers/protobuf/releases/download/v$PROTOBUF_VERSION/protobuf-cpp-$PROTOBUF_VERSION.zip"
50-
unzip "$PROTOBUF_DIR/protobuf" -d /usr/src/protobuf
51-
cd "/usr/src/protobuf/protobuf-$PROTOBUF_VERSION"
51+
unzip "$PROTOBUF_DIR/protobuf" -d "$INSTALL_DIR/src/protobuf"
52+
cd "$INSTALL_DIR/src/protobuf/protobuf-$PROTOBUF_VERSION"
5253
./autogen.sh
5354
./configure --disable-shared
5455
make
@@ -62,7 +63,7 @@ rm -rf "$PROTOBUF_DIR"
6263
# Download status.proto. grpc repos' one seems copied from
6364
# https://github.com/googleapis/googleapis/blob/master/google/rpc/status.proto,
6465
# but we use grpc's since the repos has tags/releases.
65-
mkdir -p /usr/local/include/google/rpc
66+
mkdir -p "$INSTALL_DIR/include/google/rpc"
6667
curl \
6768
-L https://raw.githubusercontent.com/grpc/grpc/v1.45.2/src/proto/grpc/status/status.proto \
68-
-o /usr/local/include/google/rpc/status.proto
69+
-o "$INSTALL_DIR/include/google/rpc/status.proto"

0 commit comments

Comments
 (0)