From 0250bba06687125d411797a1841124a294de58a3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=83=A1=E7=8E=AE=E6=96=87?= Date: Fri, 18 Jul 2025 03:57:22 +0800 Subject: [PATCH] Use go tool to manage protoc plugins Avoid any dependency on global GOBIN --- .github/workflows/build.yaml | 12 ++++------- go.mod | 6 ++++++ go.sum | 2 ++ lib/go/.gitignore | 1 - lib/go/Makefile | 41 ++++-------------------------------- lib/go/protoc-gen-go | 2 ++ lib/go/protoc-gen-go-grpc | 2 ++ 7 files changed, 20 insertions(+), 46 deletions(-) create mode 100755 lib/go/protoc-gen-go create mode 100755 lib/go/protoc-gen-go-grpc diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index b45c62f5..ed27319e 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -10,15 +10,11 @@ jobs: name: Build runs-on: ubuntu-latest steps: - - - name: Set up Go 1.x - uses: actions/setup-go@v3 + + - uses: actions/checkout@v4 + - uses: actions/setup-go@v5 with: - go-version: ^1.19 - id: go - - - name: Check out code into the Go module directory - uses: actions/checkout@v3 + go-version-file: go.mod - name: Build Test run: | diff --git a/go.mod b/go.mod index e9ff34b7..4b15f21f 100644 --- a/go.mod +++ b/go.mod @@ -2,6 +2,11 @@ module github.com/container-storage-interface/spec go 1.24.0 +tool ( + google.golang.org/grpc/cmd/protoc-gen-go-grpc + google.golang.org/protobuf/cmd/protoc-gen-go +) + require ( google.golang.org/grpc v1.79.3 google.golang.org/protobuf v1.36.10 @@ -12,4 +17,5 @@ require ( golang.org/x/sys v0.39.0 // indirect golang.org/x/text v0.32.0 // indirect google.golang.org/genproto/googleapis/rpc v0.0.0-20251202230838-ff82c1b0f217 // indirect + google.golang.org/grpc/cmd/protoc-gen-go-grpc v1.3.0 // indirect ) diff --git a/go.sum b/go.sum index 87cd2070..7cf93454 100644 --- a/go.sum +++ b/go.sum @@ -34,5 +34,7 @@ google.golang.org/genproto/googleapis/rpc v0.0.0-20251202230838-ff82c1b0f217 h1: google.golang.org/genproto/googleapis/rpc v0.0.0-20251202230838-ff82c1b0f217/go.mod h1:7i2o+ce6H/6BluujYR+kqX3GKH+dChPTQU19wjRPiGk= google.golang.org/grpc v1.79.3 h1:sybAEdRIEtvcD68Gx7dmnwjZKlyfuc61Dyo9pGXXkKE= google.golang.org/grpc v1.79.3/go.mod h1:KmT0Kjez+0dde/v2j9vzwoAScgEPx/Bw1CYChhHLrHQ= +google.golang.org/grpc/cmd/protoc-gen-go-grpc v1.3.0 h1:rNBFJjBCOgVr9pWD7rs/knKL4FRTKgpZmsRfV214zcA= +google.golang.org/grpc/cmd/protoc-gen-go-grpc v1.3.0/go.mod h1:Dk1tviKTvMCz5tvh7t+fh94dhmQVHuCt2OzJB3CTW9Y= google.golang.org/protobuf v1.36.10 h1:AYd7cD/uASjIL6Q9LiTjz8JLcrh/88q5UObnmY3aOOE= google.golang.org/protobuf v1.36.10/go.mod h1:HTf+CrKn2C3g5S8VImy6tdcUvCska2kB7j23XfzDpco= diff --git a/lib/go/.gitignore b/lib/go/.gitignore index 44dae3ea..36933a03 100644 --- a/lib/go/.gitignore +++ b/lib/go/.gitignore @@ -1,4 +1,3 @@ /protoc -/protoc-gen-go /csi.a /.protoc diff --git a/lib/go/Makefile b/lib/go/Makefile index 0541c6d1..ba6f3f78 100644 --- a/lib/go/Makefile +++ b/lib/go/Makefile @@ -1,25 +1,5 @@ all: build -######################################################################## -## GOLANG ## -######################################################################## - -# If GOPATH isn't defined then set its default location. -ifeq (,$(strip $(GOPATH))) -GOPATH := $(HOME)/go -else -# If GOPATH is already set then update GOPATH to be its own -# first element. -GOPATH := $(word 1,$(subst :, ,$(GOPATH))) -endif -export GOPATH - -GOBIN := $(shell go env GOBIN) -ifeq (,$(strip $(GOBIN))) -GOBIN := $(GOPATH)/bin -endif - - ######################################################################## ## PROTOC ## ######################################################################## @@ -46,11 +26,6 @@ PROTOC_URL := https://github.com/protocolbuffers/protobuf/releases/download/v$(P PROTOC_TMP_DIR := .protoc PROTOC := $(PROTOC_TMP_DIR)/bin/protoc -$(GOBIN)/protoc-gen-go: ../../go.mod - go install google.golang.org/protobuf/cmd/protoc-gen-go -$(GOBIN)/protoc-gen-go-grpc: - go install google.golang.org/grpc/cmd/protoc-gen-go-grpc@v1.3.0 - $(PROTOC): -mkdir -p "$(PROTOC_TMP_DIR)" && \ curl -L $(PROTOC_URL) -o "$(PROTOC_TMP_DIR)/$(PROTOC_ZIP)" && \ @@ -58,16 +33,7 @@ $(PROTOC): chmod 0755 "$@" stat "$@" > /dev/null 2>&1 -PROTOC_ALL := $(GOBIN)/protoc-gen-go $(GOBIN)/protoc-gen-go-grpc $(PROTOC) - -######################################################################## -## PATH ## -######################################################################## - -# Update PATH with GOBIN. This enables the protoc binary to discover -# the protoc-gen-go binary -export PATH := $(GOBIN):$(PATH) - +PROTOC_ALL := protoc-gen-go protoc-gen-go-grpc $(PROTOC) ######################################################################## ## BUILD ## @@ -78,9 +44,10 @@ CSI_GO := $(CSI_PKG_SUB)/csi.pb.go CSI_GRPC := $(CSI_PKG_SUB)/csi_grpc.pb.go # This recipe generates the go language bindings -$(CSI_GO) $(CSI_GRPC): $(CSI_PROTO) $(PROTOC_ALL) +$(CSI_GO) $(CSI_GRPC): $(CSI_PROTO) $(PROTOC_ALL) ../../go.mod @mkdir -p "$(@D)" - $(PROTOC) -I../.. --go-grpc_out=$(CSI_PKG_SUB) --go_out=$(CSI_PKG_SUB) \ + $(PROTOC) --plugin=./protoc-gen-go --plugin=./protoc-gen-go-grpc \ + -I../.. --go-grpc_out=$(CSI_PKG_SUB) --go_out=$(CSI_PKG_SUB) \ --go_opt=paths=source_relative --go-grpc_opt=paths=source_relative \ "$(