Skip to content

Commit bb4df4a

Browse files
kallal79GitHub Copilot
authored andcommitted
Fix protoc compilation requirements issue #32
- Add comprehensive protoc installation documentation for multiple platforms - Add dependency checks in Makefile with clear error messages - Add automated protoc installation support (install-protoc target) - Add complete dev environment setup (setup-dev target) - Add help target with comprehensive build instructions - Fix protoc-gen-go-grpc package path in Makefile and tools.go - Update mock imports to use go.uber.org/mock/gomock - Regenerate mocks with correct dependencies - Improve error handling for missing dependencies - Fix default Makefile target This resolves the build failure when protoc is not installed by: 1. Providing clear installation instructions 2. Adding dependency verification 3. Offering automated installation options 4. Giving helpful error messages when dependencies are missing Fixes #32 Signed-off-by: GitHub Copilot <[email protected]>
1 parent deca591 commit bb4df4a

File tree

8 files changed

+285
-235
lines changed

8 files changed

+285
-235
lines changed

Makefile

Lines changed: 112 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,73 @@
11
# Copyright 2025 Contributors to the Veraison project.
22
# SPDX-License-Identifier: Apache-2.0
33

4-
.DEFAULT_TARGET: all
4+
.DEFAULT_GOAL := all
55
BIN := ratsd
66

7+
.PHONY: help
8+
help:
9+
@echo "RATSD Makefile Commands:"
10+
@echo ""
11+
@echo "Building:"
12+
@echo " all Build everything (check deps, generate code, build binary and attesters)"
13+
@echo " build Build ratsd binary and all attesters"
14+
@echo " build-sa Build sub-attesters only"
15+
@echo " build-la Build ratsd binary only"
16+
@echo ""
17+
@echo "Code Generation:"
18+
@echo " generate Generate code from protobuf and OpenAPI specs"
19+
@echo " install-tools Install Go code generation tools (requires protoc)"
20+
@echo " install-protoc Install protoc compiler (requires sudo)"
21+
@echo " setup-dev Install protoc + Go tools (complete dev setup)"
22+
@echo ""
23+
@echo "Testing:"
24+
@echo " test Run all tests"
25+
@echo ""
26+
@echo "Certificates:"
27+
@echo " gen-certs Generate TLS certificates"
28+
@echo " clean-certs Clean generated certificates"
29+
@echo ""
30+
@echo "Cleanup:"
31+
@echo " clean Clean all build artifacts"
32+
@echo " clean-sa Clean sub-attester build artifacts"
33+
@echo " clean-la Clean ratsd binary"
34+
@echo ""
35+
@echo "Dependency Checks:"
36+
@echo " check-protoc Check if protoc is installed"
37+
@echo " check-generate-deps Check if all code generation tools are available"
38+
@echo ""
39+
@echo "Prerequisites:"
40+
@echo " - Install protoc: sudo apt-get install protobuf-compiler (Ubuntu/Debian)"
41+
@echo " - Run 'make install-tools' to install Go code generation tools"
42+
@echo " - See README.md for detailed installation instructions"
43+
@echo ""
44+
745
.PHONY: all
8-
all: generate build
46+
all: check-protoc generate build
947

1048
.PHONY: gen-certs
1149
gen-certs:
1250
./gen-certs create
1351

1452
.PHONY: generate
15-
generate:
53+
generate: check-generate-deps
1654
go generate ./...
1755

56+
.PHONY: check-generate-deps
57+
check-generate-deps: check-protoc
58+
@echo "Checking for required code generation tools..."
59+
@which protoc-gen-go > /dev/null 2>&1 || { \
60+
echo "ERROR: protoc-gen-go is not installed."; \
61+
echo "Please run 'make install-tools' first."; \
62+
exit 1; \
63+
}
64+
@which protoc-gen-go-grpc > /dev/null 2>&1 || { \
65+
echo "ERROR: protoc-gen-go-grpc is not installed."; \
66+
echo "Please run 'make install-tools' first."; \
67+
exit 1; \
68+
}
69+
@echo "All code generation dependencies are available."
70+
1871
.PHONY: build build-sa build-la
1972
build: build-sa build-la
2073

@@ -38,12 +91,66 @@ clean-la:
3891
rm -f $(BIN)
3992

4093
.PHONY: install-tools
41-
install-tools:
94+
install-tools: check-protoc
4295
go install github.com/oapi-codegen/oapi-codegen/v2/cmd/oapi-codegen
4396
go install google.golang.org/protobuf/cmd/protoc-gen-go
44-
go install google.golang.org/protobuf/cmd/protoc-gen-go-grpc
97+
go install google.golang.org/grpc/cmd/protoc-gen-go-grpc@latest
4598
go install go.uber.org/mock/mockgen
4699

100+
.PHONY: check-protoc
101+
check-protoc:
102+
@echo "Checking for protoc..."
103+
@which protoc > /dev/null 2>&1 || { \
104+
echo "ERROR: protoc (Protocol Buffer Compiler) is not installed or not in PATH."; \
105+
echo ""; \
106+
echo "Please install protoc using one of the following methods:"; \
107+
echo ""; \
108+
echo "Ubuntu/Debian:"; \
109+
echo " sudo apt-get update && sudo apt-get install -y protobuf-compiler"; \
110+
echo ""; \
111+
echo "RHEL/CentOS:"; \
112+
echo " sudo yum install -y protobuf-compiler"; \
113+
echo ""; \
114+
echo "Fedora:"; \
115+
echo " sudo dnf install -y protobuf-compiler"; \
116+
echo ""; \
117+
echo "macOS:"; \
118+
echo " brew install protobuf"; \
119+
echo ""; \
120+
echo "Or download from: https://github.com/protocolbuffers/protobuf/releases"; \
121+
echo ""; \
122+
exit 1; \
123+
}
124+
@echo "protoc found: $$(which protoc)"
125+
126+
.PHONY: install-protoc
127+
install-protoc:
128+
@echo "Attempting to install protoc..."
129+
@if command -v apt-get >/dev/null 2>&1; then \
130+
echo "Detected apt-get (Ubuntu/Debian). Installing protobuf-compiler..."; \
131+
sudo apt-get update && sudo apt-get install -y protobuf-compiler; \
132+
elif command -v yum >/dev/null 2>&1; then \
133+
echo "Detected yum (RHEL/CentOS). Installing protobuf-compiler..."; \
134+
sudo yum install -y protobuf-compiler; \
135+
elif command -v dnf >/dev/null 2>&1; then \
136+
echo "Detected dnf (Fedora). Installing protobuf-compiler..."; \
137+
sudo dnf install -y protobuf-compiler; \
138+
elif command -v brew >/dev/null 2>&1; then \
139+
echo "Detected brew (macOS). Installing protobuf..."; \
140+
brew install protobuf; \
141+
else \
142+
echo "Unable to detect package manager. Please install protoc manually."; \
143+
echo "See README.md for installation instructions."; \
144+
exit 1; \
145+
fi
146+
@echo "protoc installation completed. Verifying..."
147+
@which protoc || { echo "Installation failed. Please install protoc manually."; exit 1; }
148+
149+
.PHONY: setup-dev
150+
setup-dev: install-protoc install-tools
151+
@echo "Development environment setup complete!"
152+
@echo "You can now run 'make' to build RATSD."
153+
47154
.PHONY: clean-certs
48155
clean-certs:
49156
./gen-certs clean

README.md

Lines changed: 55 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,71 @@
33
A RATS conceptual message collection daemon
44

55
# Building
6+
7+
## Prerequisites
8+
9+
Before building RATSD, you need to install the following system dependencies:
10+
11+
### Protocol Buffer Compiler (protoc)
12+
13+
**Ubuntu/Debian:**
14+
```bash
15+
sudo apt-get update
16+
sudo apt-get install -y protobuf-compiler
17+
```
18+
19+
**RHEL/CentOS/Fedora:**
20+
```bash
21+
# For RHEL/CentOS
22+
sudo yum install -y protobuf-compiler
23+
# For Fedora
24+
sudo dnf install -y protobuf-compiler
25+
```
26+
27+
**macOS:**
28+
```bash
29+
brew install protobuf
30+
```
31+
32+
**From Source (if package not available):**
33+
```bash
34+
# Download and install protoc from https://github.com/protocolbuffers/protobuf/releases
35+
# Example for Linux x86_64:
36+
curl -LO https://github.com/protocolbuffers/protobuf/releases/download/v25.1/protoc-25.1-linux-x86_64.zip
37+
unzip protoc-25.1-linux-x86_64.zip -d $HOME/.local
38+
export PATH="$PATH:$HOME/.local/bin"
39+
```
40+
41+
### Go Dependencies
42+
643
The binary `ratsd` is built by using `make` using the following steps:
744
* Install golang version specified in go.mod
845
* Ensure GOPATH is available in the shell path (`export GOPATH="$HOME/go"; export PATH=$PATH:$GOPATH/bin`)
946
* Install build tools using `make install-tools`.
1047
* Build RATSd using `make`
1148

1249
## (Optional) Regenerate ratsd core code from OpenAPI spec
13-
Regeneration of the code for ratsd requires the installation of various protobuf packages beforehand. Use the following commands to install them:
50+
Regeneration of the code for ratsd requires the installation of protobuf compiler and Go protobuf plugins.
51+
52+
**Prerequisites:** Make sure you have installed the `protoc` compiler (see Prerequisites section above).
53+
54+
Then install the Go code generation tools:
1455
```bash
1556
make install-tools
1657
```
17-
Then generate the code with `make generate`
58+
59+
Generate the code:
60+
```bash
61+
make generate
62+
```
63+
64+
**Note:** The `make install-tools` command installs:
65+
- `protoc-gen-go` - Go protocol buffer plugin
66+
- `protoc-gen-go-grpc` - Go gRPC plugin
67+
- `oapi-codegen` - OpenAPI code generator
68+
- `mockgen` - Mock generation tool
69+
70+
All of these require the base `protoc` compiler to be installed separately.
1871

1972
## Building ratsd core and leaf attesters
2073

api/mocks/imanager.go

Lines changed: 8 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

api/mocks/ipluggable.go

Lines changed: 25 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

api/server_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import (
1212
"strings"
1313
"testing"
1414

15-
"github.com/golang/mock/gomock"
15+
"go.uber.org/mock/gomock"
1616
"github.com/moogar0880/problems"
1717
"github.com/stretchr/testify/assert"
1818
"github.com/veraison/cmw"

0 commit comments

Comments
 (0)