Skip to content

Commit acbec80

Browse files
janiszclaude
andcommitted
feat: Add automatic protoc installation to Makefile
Implements automatic protoc download and installation similar to the main stackrox repo, eliminating the need for manual protoc installation. Changes: - Add protoc auto-download logic to Makefile with OS/arch detection - Downloads protoc 32.1 from GitHub releases to .proto/ directory - Update proto-generate target to depend on local protoc installation - Update generate-proto-descriptors.sh to use PROTOC_BIN env var - Add .proto/ to .gitignore - Add .proto/ cleanup to clean target Benefits: - Developers no longer need to manually install protoc - Consistent protoc version across all developers and CI - Works offline after first download Usage: make proto-install # Install protoc (automatic on proto-generate) make proto-generate # Generate descriptors (auto-installs protoc) Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
1 parent 74fc864 commit acbec80

File tree

3 files changed

+53
-6
lines changed

3 files changed

+53
-6
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@
1717
# Lint output
1818
/report.xml
1919

20+
# Proto tools
21+
/.proto/
22+
2023
# E2E tests
2124
/e2e-tests/.env
2225
/e2e-tests/mcp-reports/

Makefile

Lines changed: 42 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,13 +91,52 @@ lint: ## Run golangci-lint
9191
go install -v "github.com/golangci/golangci-lint/v2/cmd/golangci-lint@v2.6"
9292
golangci-lint run
9393

94+
##############
95+
## Protobuf ##
96+
##############
97+
98+
# Protoc version and paths
99+
PROTOC_VERSION := 32.1
100+
UNAME_S := $(shell uname -s)
101+
ifeq ($(UNAME_S),Linux)
102+
PROTOC_OS = linux
103+
endif
104+
ifeq ($(UNAME_S),Darwin)
105+
PROTOC_OS = osx
106+
endif
107+
PROTOC_ARCH=$(shell case $$(uname -m) in (arm64|aarch64) echo aarch_64 ;; (s390x) echo s390_64 ;; (*) uname -m ;; esac)
108+
109+
PROTO_PRIVATE_DIR := .proto
110+
PROTOC_DIR := $(PROTO_PRIVATE_DIR)/protoc-$(PROTOC_OS)-$(PROTOC_ARCH)-$(PROTOC_VERSION)
111+
PROTOC := $(PROTOC_DIR)/bin/protoc
112+
PROTOC_ZIP := protoc-$(PROTOC_VERSION)-$(PROTOC_OS)-$(PROTOC_ARCH).zip
113+
PROTOC_DOWNLOADS_DIR := $(PROTO_PRIVATE_DIR)/.downloads
114+
PROTOC_FILE := $(PROTOC_DOWNLOADS_DIR)/$(PROTOC_ZIP)
115+
116+
$(PROTOC_DOWNLOADS_DIR):
117+
@mkdir -p "$@"
118+
119+
$(PROTOC_FILE): $(PROTOC_DOWNLOADS_DIR)
120+
@echo "Downloading protoc $(PROTOC_VERSION)..."
121+
@curl -fSL -o "$@" "https://github.com/protocolbuffers/protobuf/releases/download/v$(PROTOC_VERSION)/$(PROTOC_ZIP)"
122+
123+
$(PROTOC): $(PROTOC_FILE)
124+
@echo "Installing protoc to $(PROTOC_DIR)..."
125+
@mkdir -p "$(PROTOC_DIR)"
126+
@unzip -q -o -d "$(PROTOC_DIR)" "$(PROTOC_FILE)"
127+
@test -x "$@"
128+
@echo "✓ protoc $(PROTOC_VERSION) installed"
129+
130+
.PHONY: proto-install
131+
proto-install: $(PROTOC) ## Install protoc locally
132+
94133
.PHONY: proto-setup
95134
proto-setup: ## Setup proto files from go mod cache
96135
@./scripts/setup-proto-files.sh
97136

98137
.PHONY: proto-generate
99-
proto-generate: ## Generate proto descriptors for WireMock
100-
@./scripts/generate-proto-descriptors.sh
138+
proto-generate: $(PROTOC) ## Generate proto descriptors for WireMock
139+
@PROTOC_BIN=$(PROTOC) ./scripts/generate-proto-descriptors.sh
101140

102141
.PHONY: proto-clean
103142
proto-clean: ## Clean generated proto files
@@ -154,3 +193,4 @@ clean: ## Clean build artifacts and coverage files
154193
rm -f $(BINARY_NAME)
155194
rm -f $(COVERAGE_OUT)
156195
rm -f $(LINT_OUT)
196+
rm -rf $(PROTO_PRIVATE_DIR)

scripts/generate-proto-descriptors.sh

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,19 @@ if [ ! -d "$ROX_PROTO_PATH" ]; then
1414
./scripts/setup-proto-files.sh
1515
fi
1616

17-
if ! command -v protoc &> /dev/null; then
17+
# Use PROTOC_BIN if set (from Makefile), otherwise use system protoc
18+
PROTOC_CMD="${PROTOC_BIN:-protoc}"
19+
20+
if ! command -v "$PROTOC_CMD" &> /dev/null; then
1821
echo "Error: protoc is not installed"
19-
echo "Install from: https://grpc.io/docs/protoc-installation/"
22+
echo "Install with: make proto-install"
23+
echo "Or install manually from: https://grpc.io/docs/protoc-installation/"
2024
exit 1
2125
fi
2226

23-
echo "Generating proto descriptors..."
27+
echo "Generating proto descriptors with $PROTOC_CMD..."
2428

25-
protoc \
29+
"$PROTOC_CMD" \
2630
--descriptor_set_out="$DESCRIPTOR_DIR/stackrox.dsc" \
2731
--include_imports \
2832
--proto_path="$ROX_PROTO_PATH" \

0 commit comments

Comments
 (0)