diff --git a/Makefile b/Makefile index 1d0648c4..a7ce65c1 100644 --- a/Makefile +++ b/Makefile @@ -36,7 +36,6 @@ COVERAGE_PATH := $(BUILD_PATH)/coverage PROTOBUF_VERSION = 3.20.1 PROTO_SOURCES = $(shell find pkg -name '*.proto' | grep -v /vendor/) -PROTO_GOFILES = $(patsubst %.proto,%.pb.go,$(PROTO_SOURCES)) PROTO_INCLUDE = -I $(PWD) -I$(PROTOC_PATH)/include PROTO_OPTIONS = --proto_path=. $(PROTO_INCLUDE) \ --go_opt=paths=source_relative --go_out=. \ @@ -80,11 +79,15 @@ FORCE: # build targets # -build-proto: check-protoc install-ttrpc-plugin install-wasm-plugin install-protoc-dependencies $(PROTO_GOFILES) +build-proto: check-protoc install-ttrpc-plugin install-wasm-plugin install-protoc-dependencies + for src in $(PROTO_SOURCES); do \ + $(PROTO_COMPILE) $$src; \ + done + sed -i '1s;^;//go:build !wasip1\n\n;' pkg/api/api_ttrpc.pb.go .PHONY: build-proto-dockerized build-proto-dockerized: - $(Q)docker build --build-arg ARTIFACTS="$(dir $(PROTO_GOFILES))" --target final \ + $(Q)docker build --build-arg ARTIFACTS="$(dir $(PROTO_SOURCES))" --target final \ --output type=local,dest=$(RESOLVED_PWD) \ -f hack/Dockerfile.buildproto . $(Q)tar xf artifacts.tgz && rm -f artifacts.tgz @@ -176,15 +179,6 @@ validate-repo-no-changes: exit 1; \ } -# -# proto generation targets -# - -%.pb.go: %.proto - $(Q)echo "Generating $@..."; \ - $(PROTO_COMPILE) $< - sed -i '1s;^;//go:build !wasip1\n\n;' pkg/api/api_ttrpc.pb.go - # # targets for installing dependencies # @@ -199,7 +193,7 @@ check-protoc: fi install-protoc install-protobuf: - $(Q)PROTOBUF_VERSION=$(PROTOBUF_VERSION) ./scripts/install-protobuf + $(Q)PROTOBUF_VERSION=$(PROTOBUF_VERSION) INSTALL_DIR=$(PROTOC_PATH) ./scripts/install-protobuf clean-protoc: $(Q)rm -rf $(PROTOC_PATH) diff --git a/hack/Dockerfile.buildproto b/hack/Dockerfile.buildproto index 11049a05..2c2a2ba7 100644 --- a/hack/Dockerfile.buildproto +++ b/hack/Dockerfile.buildproto @@ -23,12 +23,9 @@ WORKDIR /go/src RUN apt-get update && apt-get install -y unzip RUN --mount=type=cache,target=/go/pkg/mod/ \ - --mount=src=.,target=. \ - make install-protoc-dependencies install-ttrpc-plugin install-wasm-plugin install-protoc - -RUN --mount=type=cache,target=/go/pkg/mod/ \ + --mount=type=cache,target=/go/tools/,sharing=private \ --mount=src=.,target=.,rw=true \ - make build-proto && \ + make build-proto PROTOC_PATH=/go/tools/protoc && \ tar czf /artifacts.tgz ${ARTIFACTS} FROM scratch AS final diff --git a/scripts/install-protobuf b/scripts/install-protobuf index 4ab3023b..2f02ee5c 100755 --- a/scripts/install-protobuf +++ b/scripts/install-protobuf @@ -24,7 +24,7 @@ PROTOBUF_VERSION=${PROTOBUF_VERSION-3.20.1} GOARCH=$(go env GOARCH) GOOS=$(go env GOOS) PROTOBUF_DIR=$(mktemp -d) -INSTALL_DIR="$PWD/build/tools/protoc" +INSTALL_DIR=${INSTALL_DIR-"$PWD/build/tools/protoc"} mkdir -p "$INSTALL_DIR"