@@ -14,14 +14,19 @@ GOPATH := $(word 1,$(subst :, ,$(GOPATH)))
14
14
endif
15
15
export GOPATH
16
16
17
+ GOBIN := $(shell go env GOBIN)
18
+ ifeq (,$(strip $(GOBIN ) ) )
19
+ GOBIN := $(GOPATH ) /bin
20
+ endif
21
+
17
22
18
23
# #######################################################################
19
24
# # PROTOC ##
20
25
# #######################################################################
21
26
22
27
# Only set PROTOC_VER if it has an empty value.
23
28
ifeq (,$(strip $(PROTOC_VER ) ) )
24
- PROTOC_VER := 3.9.1
29
+ PROTOC_VER := 25.2
25
30
endif
26
31
27
32
PROTOC_OS := $(shell uname -s)
@@ -32,95 +37,60 @@ endif
32
37
PROTOC_ARCH := $(shell uname -m)
33
38
ifeq (i386,$(PROTOC_ARCH ) )
34
39
PROTOC_ARCH := x86_32
40
+ else ifeq (arm64,$(PROTOC_ARCH))
41
+ PROTOC_ARCH := aarch_64
35
42
endif
36
43
37
- PROTOC := ./protoc
38
44
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 )
40
46
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]
42
53
43
54
$(PROTOC ) :
44
55
-mkdir -p " $( PROTOC_TMP_DIR) " && \
45
56
curl -L $(PROTOC_URL ) -o " $( PROTOC_TMP_DIR) /$( PROTOC_ZIP) " && \
46
57
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 " $@ "
49
59
stat " $@ " > /dev/null 2>&1
50
60
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 )
71
62
72
63
# #######################################################################
73
64
# # PATH ##
74
65
# #######################################################################
75
66
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 )
80
70
81
71
82
72
# #######################################################################
83
73
# # BUILD ##
84
74
# #######################################################################
85
75
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
89
77
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
115
79
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) "
116
86
117
- build : $(CSI_GO )
87
+ build : $(CSI_GO ) $( CSI_GRPC )
118
88
119
89
clean :
120
90
go clean -i ./...
121
- rm -rf " $( CSI_GO ) " " $( CSI_BUILD ) "
91
+ rm -rf " $( CSI_PKG_SUB ) "
122
92
123
93
clobber : clean
124
- rm -fr " $( PROTOC ) " " $( PROTOC_GEN_GO ) " " $( CSI_PKG_SUB ) "
94
+ rm -fr " $( PROTOC_TMP_DIR ) "
125
95
126
96
.PHONY : clean clobber
0 commit comments