@@ -21,7 +21,7 @@ export GOPATH
21
21
22
22
# Only set PROTOC_VER if it has an empty value.
23
23
ifeq (,$(strip $(PROTOC_VER ) ) )
24
- PROTOC_VER := 3.5.1
24
+ PROTOC_VER := 25.2
25
25
endif
26
26
27
27
PROTOC_OS := $(shell uname -s)
@@ -32,42 +32,26 @@ endif
32
32
PROTOC_ARCH := $(shell uname -m)
33
33
ifeq (i386,$(PROTOC_ARCH ) )
34
34
PROTOC_ARCH := x86_32
35
+ else ifeq (arm64,$(PROTOC_ARCH))
36
+ PROTOC_ARCH := aarch_64
35
37
endif
36
38
37
- PROTOC := ./protoc
38
39
PROTOC_ZIP := protoc-$(PROTOC_VER ) -$(PROTOC_OS ) -$(PROTOC_ARCH ) .zip
39
40
PROTOC_URL := https://github.com/protocolbuffers/protobuf/releases/download/v$(PROTOC_VER ) /$(PROTOC_ZIP )
40
41
PROTOC_TMP_DIR := .protoc
41
- PROTOC_TMP_BIN := $(PROTOC_TMP_DIR ) /bin/protoc
42
+ PROTOC := $(PROTOC_TMP_DIR ) /bin/protoc
43
+
44
+ $(GOBIN ) /protoc-gen-go : ../../go.mod
45
+ go install -mod=readonly google.golang.org/protobuf/cmd/protoc-gen-go
42
46
43
47
$(PROTOC ) :
44
48
-mkdir -p " $( PROTOC_TMP_DIR) " && \
45
49
curl -L $(PROTOC_URL ) -o " $( PROTOC_TMP_DIR) /$( PROTOC_ZIP) " && \
46
50
unzip " $( PROTOC_TMP_DIR) /$( PROTOC_ZIP) " -d " $( PROTOC_TMP_DIR) " && \
47
- chmod 0755 " $( PROTOC_TMP_BIN) " && \
48
- cp -f " $( PROTOC_TMP_BIN) " " $@ "
51
+ chmod 0755 " $@ "
49
52
stat " $@ " > /dev/null 2>&1
50
53
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.2.0
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
-
54
+ PROTOC_ALL := $(GOBIN ) /protoc-gen-go $(PROTOC )
71
55
72
56
# #######################################################################
73
57
# # PATH ##
@@ -78,59 +62,27 @@ $(PROTOC_GEN_GO):
78
62
# directory.
79
63
export PATH := $(shell pwd) :$(PATH )
80
64
81
-
82
65
# #######################################################################
83
66
# # BUILD ##
84
67
# #######################################################################
85
68
CSI_PROTO := ./csitest.proto
86
- CSI_PKG_ROOT := github.com/kubernetes-csi/csi-lib-utils/protosanitizer/test
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
69
+ CSI_PKG_SUB := csitest
89
70
CSI_GO := $(CSI_PKG_SUB ) /csitest.pb.go
90
- CSI_A := csi.a
91
- CSI_GO_TMP := $(CSI_BUILD ) /$(CSI_PKG_ROOT ) /csitest.pb.go
92
-
93
- # This recipe generates the go language bindings to a temp area.
94
- $(CSI_GO_TMP ) : HERE := $(shell pwd)
95
- $(CSI_GO_TMP ) : PTYPES_PKG := github.com/golang/protobuf/ptypes
96
- $(CSI_GO_TMP ) : GO_OUT := plugins=grpc
97
- $(CSI_GO_TMP ) : GO_OUT := $(GO_OUT ) ,Mgoogle/protobuf/descriptor.proto=github.com/golang/protobuf/protoc-gen-go/descriptor
98
- $(CSI_GO_TMP ) : GO_OUT := $(GO_OUT ) ,Mgoogle/protobuf/wrappers.proto=$(PTYPES_PKG ) /wrappers
99
- $(CSI_GO_TMP ) : GO_OUT := $(GO_OUT ) :"$(HERE ) /$(CSI_BUILD ) "
100
- $(CSI_GO_TMP ) : INCLUDE := -I$(GOPATH ) /src -I$(HERE ) /$(PROTOC_TMP_DIR ) /include
101
- $(CSI_GO_TMP ) : $(CSI_PROTO ) | $(PROTOC ) $(PROTOC_GEN_GO )
102
- @mkdir -p " $( @D) "
103
- (cd " $( GOPATH) /src" && \
104
- $(HERE ) /$(PROTOC ) $(INCLUDE ) --go_out=$(GO_OUT ) " $( CSI_PKG_ROOT) /$( < F) " )
105
-
106
- # The temp language bindings are compared to the ones that are
107
- # versioned. If they are different then it means the language
108
- # bindings were not updated prior to being committed.
109
- $(CSI_GO ) : $(CSI_GO_TMP )
110
- ifeq (true,$(TRAVIS ) )
111
- diff "$@" "$?"
112
- else
113
- @mkdir -p "$(@D)"
114
- diff "$@" "$?" > /dev/null 2>&1 || cp -f "$?" "$@"
115
- endif
116
71
117
- # This recipe builds the Go archive from the sources in three steps:
118
- #
119
- # 1. Go get any missing dependencies.
120
- # 2. Cache the packages.
121
- # 3. Build the archive file.
122
- $(CSI_A ) : $(CSI_GO )
123
- go get -v -d ./...
124
- go install ./$(CSI_PKG_SUB )
125
- go build -o " $@ " ./$(CSI_PKG_SUB )
72
+ # This recipe generates the go language bindings
73
+ $(CSI_GO ) : $(CSI_PROTO ) $(PROTOC_ALL )
74
+ @mkdir -p " $( @D) "
75
+ $(PROTOC ) --go_out=$(CSI_PKG_SUB ) \
76
+ --go_opt=paths=source_relative \
77
+ " $( < F) "
126
78
127
- build : $(CSI_A )
79
+ build : $(CSI_GO ) $( CSI_GRPC )
128
80
129
81
clean :
130
82
go clean -i ./...
131
- rm -rf " $( CSI_A ) " " $( CSI_GO ) " " $( CSI_BUILD ) "
83
+ rm -rf " $( CSI_PKG_SUB ) "
132
84
133
85
clobber : clean
134
- rm -fr " $( PROTOC ) " " $( PROTOC_GEN_GO ) " " $( CSI_PKG_SUB ) " " $( PROTOC_TMP_DIR) "
86
+ rm -fr " $( PROTOC_TMP_DIR) "
135
87
136
88
.PHONY : clean clobber
0 commit comments