Skip to content

Commit

Permalink
update protoc and related
Browse files Browse the repository at this point in the history
updated protoc to v24.3
updated protoc-gen-go to v1.31.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
Fixes container-storage-interface#471
  • Loading branch information
huww98 committed Oct 1, 2023
1 parent 80d5310 commit f8982a9
Show file tree
Hide file tree
Showing 6 changed files with 7,690 additions and 4,556 deletions.
2 changes: 1 addition & 1 deletion csi.proto
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import "google/protobuf/descriptor.proto";
import "google/protobuf/timestamp.proto";
import "google/protobuf/wrappers.proto";

option go_package = "csi";
option go_package = "github.com/container-storage-interface/spec/csi";

extend google.protobuf.EnumOptions {
// Indicates that this enum is OPTIONAL and part of an experimental
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ go 1.18
require (
github.com/golang/protobuf v1.5.3
google.golang.org/grpc v1.57.0
google.golang.org/protobuf v1.31.0
)

require (
golang.org/x/net v0.10.0 // indirect
golang.org/x/sys v0.8.0 // indirect
golang.org/x/text v0.9.0 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20230803162519-f966b187b2e5 // indirect
google.golang.org/protobuf v1.31.0 // indirect
)
76 changes: 27 additions & 49 deletions lib/go/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export GOPATH

# Only set PROTOC_VER if it has an empty value.
ifeq (,$(strip $(PROTOC_VER)))
PROTOC_VER := 3.9.1
PROTOC_VER := 24.3
endif

PROTOC_OS := $(shell uname -s)
Expand All @@ -32,75 +32,46 @@ endif
PROTOC_ARCH := $(shell uname -m)
ifeq (i386,$(PROTOC_ARCH))
PROTOC_ARCH := x86_32
else ifeq (arm64,$(PROTOC_ARCH))
PROTOC_ARCH := aarch_64
endif

PROTOC := ./protoc
PROTOC_ZIP := protoc-$(PROTOC_VER)-$(PROTOC_OS)-$(PROTOC_ARCH).zip
PROTOC_URL := https://github.com/google/protobuf/releases/download/v$(PROTOC_VER)/$(PROTOC_ZIP)
PROTOC_URL := https://github.com/protocolbuffers/protobuf/releases/download/v$(PROTOC_VER)/$(PROTOC_ZIP)
PROTOC_TMP_DIR := .protoc
PROTOC_TMP_BIN := $(PROTOC_TMP_DIR)/bin/protoc

$(PROTOC):
-mkdir -p "$(PROTOC_TMP_DIR)" && \
-go install google.golang.org/protobuf/cmd/protoc-gen-go@v1.31.0 && \
go install google.golang.org/grpc/cmd/protoc-gen-go-grpc@v1.3.0 && \
mkdir -p "$(PROTOC_TMP_DIR)" && \
curl -L $(PROTOC_URL) -o "$(PROTOC_TMP_DIR)/$(PROTOC_ZIP)" && \
unzip "$(PROTOC_TMP_DIR)/$(PROTOC_ZIP)" -d "$(PROTOC_TMP_DIR)" && \
chmod 0755 "$(PROTOC_TMP_BIN)" && \
cp -f "$(PROTOC_TMP_BIN)" "$@"
stat "$@" > /dev/null 2>&1


########################################################################
## PROTOC-GEN-GO ##
########################################################################

# This is the recipe for getting and installing the go plug-in
# for protoc
PROTOC_GEN_GO_PKG := github.com/golang/protobuf/protoc-gen-go
PROTOC_GEN_GO := protoc-gen-go
$(PROTOC_GEN_GO): PROTOBUF_PKG := $(dir $(PROTOC_GEN_GO_PKG))
$(PROTOC_GEN_GO): PROTOBUF_VERSION := v1.3.2
$(PROTOC_GEN_GO):
mkdir -p $(dir $(GOPATH)/src/$(PROTOBUF_PKG))
test -d $(GOPATH)/src/$(PROTOBUF_PKG)/.git || git clone https://$(PROTOBUF_PKG) $(GOPATH)/src/$(PROTOBUF_PKG)
(cd $(GOPATH)/src/$(PROTOBUF_PKG) && \
(test "$$(git describe --tags | head -1)" = "$(PROTOBUF_VERSION)" || \
(git fetch && git checkout tags/$(PROTOBUF_VERSION))))
(cd $(GOPATH)/src/$(PROTOBUF_PKG) && go get -v -d $$(go list -f '{{ .ImportPath }}' ./...)) && \
go build -o "$@" $(PROTOC_GEN_GO_PKG)


########################################################################
## PATH ##
########################################################################

# Update PATH with the current directory. This enables the protoc
# binary to discover the protoc-gen-go binary, built inside this
# directory.
export PATH := $(shell pwd):$(PATH)


########################################################################
## BUILD ##
########################################################################
CSI_PROTO := ../../csi.proto
CSI_PKG_ROOT := github.com/container-storage-interface/spec
CSI_PKG_SUB := $(shell cat $(CSI_PROTO) | sed -n -e 's/^package.\([^;]*\).v[0-9]\+;$$/\1/p'|tr '.' '/')
CSI_PKG_SUB := $(shell cat $(CSI_PROTO) | sed -nE -e 's/^package.([^;]*).v[0-9]+;$$/\1/p'|tr '.' '/')
CSI_BUILD := $(CSI_PKG_SUB)/.build
CSI_GO := $(CSI_PKG_SUB)/csi.pb.go
CSI_GO_TMP := $(CSI_BUILD)/$(CSI_PKG_ROOT)/csi.pb.go
CSI_GRPC := $(CSI_PKG_SUB)/csi_grpc.pb.go
CSI_GRPC_TMP := $(CSI_BUILD)/$(CSI_PKG_ROOT)/$(CSI_PKG_SUB)/csi_grpc.pb.go
CSI_GO_TMP := $(CSI_BUILD)/$(CSI_PKG_ROOT)/$(CSI_PKG_SUB)/csi.pb.go

# This recipe generates the go language bindings to a temp area.
$(CSI_GO_TMP): HERE := $(shell pwd)
$(CSI_GO_TMP): PTYPES_PKG := github.com/golang/protobuf/ptypes
$(CSI_GO_TMP): GO_OUT := plugins=grpc
$(CSI_GO_TMP): GO_OUT := $(GO_OUT),Mgoogle/protobuf/descriptor.proto=github.com/golang/protobuf/protoc-gen-go/descriptor
$(CSI_GO_TMP): GO_OUT := $(GO_OUT),Mgoogle/protobuf/wrappers.proto=$(PTYPES_PKG)/wrappers
$(CSI_GO_TMP): GO_OUT := $(GO_OUT):"$(HERE)/$(CSI_BUILD)"
$(CSI_GO_TMP): INCLUDE := -I$(GOPATH)/src -I$(HERE)/$(PROTOC_TMP_DIR)/include
$(CSI_GO_TMP): $(CSI_PROTO) | $(PROTOC) $(PROTOC_GEN_GO)
$(CSI_GO_TMP) $(CSI_GRPC_TMP): INCLUDE := -I$(GOPATH)/src -I$(PROTOC_TMP_DIR)/include
$(CSI_GO_TMP) $(CSI_GRPC_TMP): $(CSI_PROTO) | $(PROTOC)
@mkdir -p "$(@D)"
(cd "$(GOPATH)/src" && \
$(HERE)/$(PROTOC) $(INCLUDE) --go_out=$(GO_OUT) "$(CSI_PKG_ROOT)/$(<F)")
$(PROTOC) $(INCLUDE) --go-grpc_out=$(CSI_BUILD) --go_out=$(CSI_BUILD) \
--go_opt=Mgoogle/protobuf/descriptor.proto=github.com/golang/protobuf/protoc-gen-go/descriptor \
--go_opt=Mgoogle/protobuf/wrappers.proto=github.com/golang/protobuf/ptypes/wrappers \
"$(CSI_PKG_ROOT)/$(<F)"

# The temp language bindings are compared to the ones that are
# versioned. If they are different then it means the language
Expand All @@ -112,15 +83,22 @@ else
@mkdir -p "$(@D)"
diff "$@" "$?" > /dev/null 2>&1 || cp -f "$?" "$@"
endif
$(CSI_GRPC): $(CSI_GRPC_TMP)
ifeq (true,$(GITHUB_ACTIONS))
diff "$@" "$?"
else
@mkdir -p "$(@D)"
diff "$@" "$?" > /dev/null 2>&1 || cp -f "$?" "$@"
endif


build: $(CSI_GO)
build: $(CSI_GO) $(CSI_GRPC)

clean:
go clean -i ./...
rm -rf "$(CSI_GO)" "$(CSI_BUILD)"
rm -rf "$(CSI_GO)" "$(CSI_GRPC)" "$(CSI_BUILD)"

clobber: clean
rm -fr "$(PROTOC)" "$(PROTOC_GEN_GO)" "$(CSI_PKG_SUB)"
rm -fr "$(PROTOC)" "$(CSI_PKG_SUB)"

.PHONY: clean clobber
Loading

0 comments on commit f8982a9

Please sign in to comment.