Skip to content

Commit abf6346

Browse files
authored
update protoc and related (#552)
* update protoc and related updated protoc to v25.2 updated protoc-gen-go to v1.32.0 added protoc-gen-go-grpc at v1.3.0 Modified the makefile to use "go install" to install tools. Use extended regular expressions in "sed" command. Fixes build on arm OSX host * fix github actions Always run "make build_go" on github actions Always update the timesptamp of spec.md/csi.proto to make sure lib/go is built on CI * remove github.com/golang/protobuf usage * simplify Makefile - use git to check for out-of-date generated files, avoids all the temp files and manual diff in the Makefile. - not specify version for protoc-gen-go, it will use the version from go.mod - do not copy over the protoc binary. Call it directly from unzipped path. So it can find the includes automatically, and we don't need the -I or --go_opts=Mxxx flags. - use paths=source_relative to generate go files directly into destination, avoid the copy. - simplify the sed command used to extract "csi.proto" file.
1 parent 886cd48 commit abf6346

File tree

9 files changed

+7712
-4615
lines changed

9 files changed

+7712
-4615
lines changed

.github/workflows/build.yaml

+2-3
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ jobs:
2222

2323
- name: Build Test
2424
run: |
25+
touch spec.md # Ensure its timestamp is newer than any generated files
2526
make
26-
make -C lib/go protoc
27-
make -C lib/go protoc-gen-go
28-
make build_go
27+
git diff --exit-code || (echo "Generated files are out of date. Please run 'make' and commit the changes." && exit 1)

Makefile

+9-37
Original file line numberDiff line numberDiff line change
@@ -4,50 +4,22 @@ CSI_SPEC := spec.md
44
CSI_PROTO := csi.proto
55
## Build go language bindings
66
CSI_A := csi.a
7-
CSI_GO := lib/go/csi/csi.pb.go
87
CSI_PKG := lib/go/csi
98

10-
# This is the target for building the temporary CSI protobuf file.
11-
#
12-
# The temporary file is not versioned, and thus will always be
13-
# built on GitHub Actions.
14-
$(CSI_PROTO).tmp: $(CSI_SPEC) Makefile
15-
echo "// Code generated by make; DO NOT EDIT." > "$@"
16-
cat $< | sed -n -e '/```protobuf$$/,/^```$$/ p' | sed '/^```/d' >> "$@"
17-
189
# This is the target for building the CSI protobuf file.
19-
#
20-
# This target depends on its temp file, which is not versioned.
21-
# Therefore when built on GitHub Actions the temp file will always
22-
# be built and trigger this target. On GitHub Actions the temp file
23-
# is compared with the real file, and if they differ the build
24-
# will fail.
25-
#
26-
# Locally the temp file is simply copied over the real file.
27-
$(CSI_PROTO): $(CSI_PROTO).tmp
28-
ifeq (true,$(GITHUB_ACTIONS))
29-
diff "$@" "$?"
30-
else
31-
diff "$@" "$?" > /dev/null 2>&1 || cp -f "$?" "$@"
32-
endif
33-
34-
build: check
35-
36-
# If this is not running on GitHub Actions then for sake of convenience
37-
# go ahead and update the language bindings as well.
38-
ifneq (true,$(GITHUB_ACTIONS))
39-
build: build_cpp build_go
40-
endif
10+
$(CSI_PROTO): $(CSI_SPEC) Makefile
11+
echo "// Code generated by make; DO NOT EDIT." > "$@"
12+
sed -n -e '/```protobuf$$/,/^```$$/ {//!p;}' $< >> "$@"
4113

14+
build: check build_cpp build_go
4215

4316
build_cpp:
4417
$(MAKE) -C lib/cxx
4518

46-
# The file exists, but could be out-of-date.
47-
$(CSI_GO): $(CSI_PROTO)
48-
$(MAKE) -C lib/go csi/csi.pb.go
19+
$(CSI_PKG)/%.pb.go: $(CSI_PROTO)
20+
$(MAKE) -C lib/go
4921

50-
$(CSI_A): $(CSI_GO)
22+
$(CSI_A): $(CSI_PKG)/*.go
5123
go mod download
5224
go install ./$(CSI_PKG)
5325
go build -o "$@" ./$(CSI_PKG)
@@ -60,10 +32,10 @@ clean:
6032

6133
clobber: clean
6234
$(MAKE) -C lib/go $@
63-
rm -f $(CSI_PROTO) $(CSI_PROTO).tmp
35+
rm -f $(CSI_PROTO)
6436

6537
# check generated files for violation of standards
6638
check: $(CSI_PROTO)
6739
awk '{ if (length > 72) print NR, $$0 }' $? | diff - /dev/null
6840

69-
.PHONY: clean clobber check
41+
.PHONY: clean clobber check build_go build_cpp

csi.proto

+2-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ import "google/protobuf/descriptor.proto";
66
import "google/protobuf/timestamp.proto";
77
import "google/protobuf/wrappers.proto";
88

9-
option go_package = "csi";
9+
option go_package =
10+
"github.com/container-storage-interface/spec/lib/go/csi";
1011

1112
extend google.protobuf.EnumOptions {
1213
// Indicates that this enum is OPTIONAL and part of an experimental

go.mod

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,14 @@ module github.com/container-storage-interface/spec
33
go 1.18
44

55
require (
6-
github.com/golang/protobuf v1.5.3
76
google.golang.org/grpc v1.57.0
7+
google.golang.org/protobuf v1.32.0
88
)
99

1010
require (
11+
github.com/golang/protobuf v1.5.3 // indirect
1112
golang.org/x/net v0.10.0 // indirect
1213
golang.org/x/sys v0.8.0 // indirect
1314
golang.org/x/text v0.9.0 // indirect
1415
google.golang.org/genproto/googleapis/rpc v0.0.0-20230803162519-f966b187b2e5 // indirect
15-
google.golang.org/protobuf v1.31.0 // indirect
1616
)

go.sum

+2-2
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,5 @@ google.golang.org/grpc v1.57.0 h1:kfzNeI/klCGD2YPMUlaGNT3pxvYfga7smW3Vth8Zsiw=
1616
google.golang.org/grpc v1.57.0/go.mod h1:Sd+9RMTACXwmub0zcNY2c4arhtrbBYD1AUHI/dt16Mo=
1717
google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw=
1818
google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc=
19-
google.golang.org/protobuf v1.31.0 h1:g0LDEJHgrBl9N9r17Ru3sqWhkIx2NB67okBHPwC7hs8=
20-
google.golang.org/protobuf v1.31.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I=
19+
google.golang.org/protobuf v1.32.0 h1:pPC6BG5ex8PDFnkbrGU3EixyhKcQ2aDuBS36lqK/C7I=
20+
google.golang.org/protobuf v1.32.0/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos=

lib/go/Makefile

+31-61
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,19 @@ GOPATH := $(word 1,$(subst :, ,$(GOPATH)))
1414
endif
1515
export GOPATH
1616

17+
GOBIN := $(shell go env GOBIN)
18+
ifeq (,$(strip $(GOBIN)))
19+
GOBIN := $(GOPATH)/bin
20+
endif
21+
1722

1823
########################################################################
1924
## PROTOC ##
2025
########################################################################
2126

2227
# Only set PROTOC_VER if it has an empty value.
2328
ifeq (,$(strip $(PROTOC_VER)))
24-
PROTOC_VER := 3.9.1
29+
PROTOC_VER := 25.2
2530
endif
2631

2732
PROTOC_OS := $(shell uname -s)
@@ -32,95 +37,60 @@ endif
3237
PROTOC_ARCH := $(shell uname -m)
3338
ifeq (i386,$(PROTOC_ARCH))
3439
PROTOC_ARCH := x86_32
40+
else ifeq (arm64,$(PROTOC_ARCH))
41+
PROTOC_ARCH := aarch_64
3542
endif
3643

37-
PROTOC := ./protoc
3844
PROTOC_ZIP := protoc-$(PROTOC_VER)-$(PROTOC_OS)-$(PROTOC_ARCH).zip
39-
PROTOC_URL := https://github.com/google/protobuf/releases/download/v$(PROTOC_VER)/$(PROTOC_ZIP)
45+
PROTOC_URL := https://github.com/protocolbuffers/protobuf/releases/download/v$(PROTOC_VER)/$(PROTOC_ZIP)
4046
PROTOC_TMP_DIR := .protoc
41-
PROTOC_TMP_BIN := $(PROTOC_TMP_DIR)/bin/protoc
47+
PROTOC := $(PROTOC_TMP_DIR)/bin/protoc
48+
49+
$(GOBIN)/protoc-gen-go: ../../go.mod
50+
go install google.golang.org/protobuf/cmd/protoc-gen-go
51+
$(GOBIN)/protoc-gen-go-grpc:
52+
go install google.golang.org/grpc/cmd/[email protected]
4253

4354
$(PROTOC):
4455
-mkdir -p "$(PROTOC_TMP_DIR)" && \
4556
curl -L $(PROTOC_URL) -o "$(PROTOC_TMP_DIR)/$(PROTOC_ZIP)" && \
4657
unzip "$(PROTOC_TMP_DIR)/$(PROTOC_ZIP)" -d "$(PROTOC_TMP_DIR)" && \
47-
chmod 0755 "$(PROTOC_TMP_BIN)" && \
48-
cp -f "$(PROTOC_TMP_BIN)" "$@"
58+
chmod 0755 "$@"
4959
stat "$@" > /dev/null 2>&1
5060

51-
52-
########################################################################
53-
## PROTOC-GEN-GO ##
54-
########################################################################
55-
56-
# This is the recipe for getting and installing the go plug-in
57-
# for protoc
58-
PROTOC_GEN_GO_PKG := github.com/golang/protobuf/protoc-gen-go
59-
PROTOC_GEN_GO := protoc-gen-go
60-
$(PROTOC_GEN_GO): PROTOBUF_PKG := $(dir $(PROTOC_GEN_GO_PKG))
61-
$(PROTOC_GEN_GO): PROTOBUF_VERSION := v1.3.2
62-
$(PROTOC_GEN_GO):
63-
mkdir -p $(dir $(GOPATH)/src/$(PROTOBUF_PKG))
64-
test -d $(GOPATH)/src/$(PROTOBUF_PKG)/.git || git clone https://$(PROTOBUF_PKG) $(GOPATH)/src/$(PROTOBUF_PKG)
65-
(cd $(GOPATH)/src/$(PROTOBUF_PKG) && \
66-
(test "$$(git describe --tags | head -1)" = "$(PROTOBUF_VERSION)" || \
67-
(git fetch && git checkout tags/$(PROTOBUF_VERSION))))
68-
(cd $(GOPATH)/src/$(PROTOBUF_PKG) && go get -v -d $$(go list -f '{{ .ImportPath }}' ./...)) && \
69-
go build -o "$@" $(PROTOC_GEN_GO_PKG)
70-
61+
PROTOC_ALL := $(GOBIN)/protoc-gen-go $(GOBIN)/protoc-gen-go-grpc $(PROTOC)
7162

7263
########################################################################
7364
## PATH ##
7465
########################################################################
7566

76-
# Update PATH with the current directory. This enables the protoc
77-
# binary to discover the protoc-gen-go binary, built inside this
78-
# directory.
79-
export PATH := $(shell pwd):$(PATH)
67+
# Update PATH with GOBIN. This enables the protoc binary to discover
68+
# the protoc-gen-go binary
69+
export PATH := $(GOBIN):$(PATH)
8070

8171

8272
########################################################################
8373
## BUILD ##
8474
########################################################################
8575
CSI_PROTO := ../../csi.proto
86-
CSI_PKG_ROOT := github.com/container-storage-interface/spec
87-
CSI_PKG_SUB := $(shell cat $(CSI_PROTO) | sed -n -e 's/^package.\([^;]*\).v[0-9]\+;$$/\1/p'|tr '.' '/')
88-
CSI_BUILD := $(CSI_PKG_SUB)/.build
76+
CSI_PKG_SUB := csi
8977
CSI_GO := $(CSI_PKG_SUB)/csi.pb.go
90-
CSI_GO_TMP := $(CSI_BUILD)/$(CSI_PKG_ROOT)/csi.pb.go
91-
92-
# This recipe generates the go language bindings to a temp area.
93-
$(CSI_GO_TMP): HERE := $(shell pwd)
94-
$(CSI_GO_TMP): PTYPES_PKG := github.com/golang/protobuf/ptypes
95-
$(CSI_GO_TMP): GO_OUT := plugins=grpc
96-
$(CSI_GO_TMP): GO_OUT := $(GO_OUT),Mgoogle/protobuf/descriptor.proto=github.com/golang/protobuf/protoc-gen-go/descriptor
97-
$(CSI_GO_TMP): GO_OUT := $(GO_OUT),Mgoogle/protobuf/wrappers.proto=$(PTYPES_PKG)/wrappers
98-
$(CSI_GO_TMP): GO_OUT := $(GO_OUT):"$(HERE)/$(CSI_BUILD)"
99-
$(CSI_GO_TMP): INCLUDE := -I$(GOPATH)/src -I$(HERE)/$(PROTOC_TMP_DIR)/include
100-
$(CSI_GO_TMP): $(CSI_PROTO) | $(PROTOC) $(PROTOC_GEN_GO)
101-
@mkdir -p "$(@D)"
102-
(cd "$(GOPATH)/src" && \
103-
$(HERE)/$(PROTOC) $(INCLUDE) --go_out=$(GO_OUT) "$(CSI_PKG_ROOT)/$(<F)")
104-
105-
# The temp language bindings are compared to the ones that are
106-
# versioned. If they are different then it means the language
107-
# bindings were not updated prior to being committed.
108-
$(CSI_GO): $(CSI_GO_TMP)
109-
ifeq (true,$(GITHUB_ACTIONS))
110-
diff "$@" "$?"
111-
else
112-
@mkdir -p "$(@D)"
113-
diff "$@" "$?" > /dev/null 2>&1 || cp -f "$?" "$@"
114-
endif
78+
CSI_GRPC := $(CSI_PKG_SUB)/csi_grpc.pb.go
11579

80+
# This recipe generates the go language bindings
81+
$(CSI_GO) $(CSI_GRPC): $(CSI_PROTO) $(PROTOC_ALL)
82+
@mkdir -p "$(@D)"
83+
$(PROTOC) -I../.. --go-grpc_out=$(CSI_PKG_SUB) --go_out=$(CSI_PKG_SUB) \
84+
--go_opt=paths=source_relative --go-grpc_opt=paths=source_relative \
85+
"$(<F)"
11686

117-
build: $(CSI_GO)
87+
build: $(CSI_GO) $(CSI_GRPC)
11888

11989
clean:
12090
go clean -i ./...
121-
rm -rf "$(CSI_GO)" "$(CSI_BUILD)"
91+
rm -rf "$(CSI_PKG_SUB)"
12292

12393
clobber: clean
124-
rm -fr "$(PROTOC)" "$(PROTOC_GEN_GO)" "$(CSI_PKG_SUB)"
94+
rm -fr "$(PROTOC_TMP_DIR)"
12595

12696
.PHONY: clean clobber

0 commit comments

Comments
 (0)