Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 3 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,20 @@ SHELL := /bin/bash
SRC_DIR := proto
# Output directory for compiled Go files
GO_OUT_DIR := go
# Output directory for compiled C++ files
CPP_OUT_DIR := cpp
# Output directory for compiled Rust files
RUST_OUT_DIR := rust

all: protos

.PHONY: protos
protos: check-tools
mkdir -p $(GO_OUT_DIR) $(CPP_OUT_DIR) $(RUST_OUT_DIR)
mkdir -p $(GO_OUT_DIR) $(RUST_OUT_DIR)
protoc -I $(SRC_DIR) \
--go_opt=module="github.com/thinkparq/protobuf/go" \
--go_opt=default_api_level=API_HYBRID \
--go_out=$(GO_OUT_DIR) \
--go-grpc_opt=module="github.com/thinkparq/protobuf/go" \
--go-grpc_out=$(GO_OUT_DIR) \
--cpp_out=$(CPP_OUT_DIR) \
$(SRC_DIR)/*.proto
protoc-rs -I $(SRC_DIR) --out=$(RUST_OUT_DIR) $(SRC_DIR)/*.proto

Expand All @@ -35,7 +32,7 @@ protos: check-tools
test: test-protos

test-protos: protos
@out="$$(git status --porcelain $$(find $(GO_OUT_DIR) $(CPP_OUT_DIR) $(RUST_OUT_DIR)))"; \
@out="$$(git status --porcelain $$(find $(GO_OUT_DIR) $(RUST_OUT_DIR)))"; \
if [ -n "$$out" ]; then \
echo "Protobuf files are not up to date. Please run 'make protos' and commit the changes."; \
echo "The following files are not up to date:"; \
Expand All @@ -48,7 +45,7 @@ test-protos: protos
# Clean up
.PHONY: clean
clean:
rm -rf $(GO_OUT_DIR) $(CPP_OUT_DIR) $(RUST_OUT_DIR)
rm -rf $(GO_OUT_DIR) $(RUST_OUT_DIR)
rm -rf target/
rm -f Cargo.lock

Expand Down
9 changes: 7 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,11 @@ Languages with precompiled/generated code:

| Language | Availability | Notes |
| -------- | ------------ | ------------------------------------------------------------------------------------------ |
| C++ | Yes | A target has been added to the Makefile, but the resulting files have not been tested yet. |
| Go | Yes | N/A |
| Rust | Yes | N/A |

C++ files are generated by the C++ build system during configure/build.

# Quick Start

Most users will not need to worry about generating code themselves, and can simply import the
Expand Down Expand Up @@ -130,7 +131,7 @@ The reasons are:

The project Makefile is setup with targets to compile all protobuf files under the `./proto`
directory into a multiple target languages when `make` or `make protos` is executed. Each languages
output is put into a separate output directory (e.g. `./go`, `./rust`, `./cpp`).
output is put into a separate output directory (e.g. `./go`, `./rust`).

To add a new language amend the Makefile as follows:

Expand All @@ -145,6 +146,10 @@ To add a new language amend the Makefile as follows:

In general, you can likely just copy the code for one of the existing languages and modify it to your needs.

Note that dependend on the language (e.g. C++), it might be more reasonable to build the output
from the consumer repository as that ensures matching versions between the generator and the
protobuf/gRPC libraries consuming the generated code.

## Generating Code for Golang

If you plan to make changes to the protocol buffers (.proto files) or simply
Expand Down
Loading
Loading