Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

multi: migrate protoc to buf #350

Merged
merged 2 commits into from
Feb 8, 2025
Merged
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
7 changes: 4 additions & 3 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,13 @@
"ghcr.io/devcontainers/features/nix:1": {},
"ghcr.io/devcontainers-contrib/features/direnv:1": {}
},
"postCreateCommand": "echo 'experimental-features = nix-command flakes' | sudo tee -a /etc/nix/nix.conf > /dev/null && nix-env -iA nixpkgs.nixpkgs-fmt && nix-env -iA cachix -f https://cachix.org/api/v1/install", // Configure tool-specific properties.
"postCreateCommand": "echo 'experimental-features = nix-command flakes' | sudo tee -a /etc/nix/nix.conf > /dev/null && nix-env -iA nixpkgs.nixpkgs-fmt && nix-env -iA cachix -f https://cachix.org/api/v1/install && sudo chmod a+w /usr/local/bin/ && GOBIN=/usr/local/bin go install github.com/bufbuild/buf/cmd/buf@v1.50.0", // Configure tool-specific properties.
"customizations": {
"vscode": {
"extensions": [
"jnoortheen.nix-ide",
"mkhl.direnv"
"mkhl.direnv",
"bufbuild.vscode-buf"
]
}
},
Expand All @@ -22,4 +23,4 @@
"GOROOT": "",
"CACHIX_AUTH_TOKEN": "eyJhbGciOiJIUzI1NiJ9.eyJqdGkiOiJmNTg3ZjViZi00ZWJiLTRhYmQtYmYzOC0xYzFlZGE3ZGE4NTQiLCJzY29wZXMiOiJjYWNoZSJ9.pzmsXqBwHFAExdVFhbdrtN1mpc4h3U3JWnej7PC-NAA"
}
}
}
24 changes: 24 additions & 0 deletions buf.gen.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
version: v2
plugins:
- local: protoc-gen-go
out: peerswaprpc
opt:
- paths=source_relative

- local: protoc-gen-go-grpc
out: peerswaprpc
opt:
- paths=source_relative

- local: protoc-gen-grpc-gateway
out: peerswaprpc
opt:
- logtostderr=true
- paths=source_relative
- grpc_api_configuration=peerswaprpc/peerswap.yaml

- local: protoc-gen-openapiv2
out: peerswaprpc
opt:
- logtostderr=true
- grpc_api_configuration=peerswaprpc/peerswap.yaml
11 changes: 11 additions & 0 deletions buf.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# For details on buf.yaml configuration, visit https://buf.build/docs/configuration/v2/buf-yaml
version: v2
modules:
- path: peerswaprpc

# lint:
# use:
# - STANDARD
# breaking:
# use:
# - FILE
5 changes: 4 additions & 1 deletion peerswaprpc/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,11 @@ RUN cd /tmp \
&& go install google.golang.org/grpc/cmd/protoc-gen-go-grpc@${PROTOC_GEN_GO_GRPC_VERSION} \
&& go install github.com/grpc-ecosystem/grpc-gateway/v2/protoc-gen-grpc-gateway@${GRPC_GATEWAY_VERSION} \
&& go install github.com/grpc-ecosystem/grpc-gateway/v2/protoc-gen-openapiv2@${GRPC_GATEWAY_VERSION} \
&& GOBIN=/usr/local/bin go install github.com/bufbuild/buf/cmd/buf@v1.50.0 \
&& chmod -R 777 /tmp/build/

WORKDIR /build

CMD ["/bin/sh", "/build/peerswaprpc/gen_protos.sh"]
ENV BUF_CACHE_DIR=/tmp/.cache

CMD ["sh", "-c", "buf generate"]
32 changes: 7 additions & 25 deletions peerswaprpc/Makefile
Original file line number Diff line number Diff line change
@@ -1,36 +1,18 @@
DIR=peerswaprpc

PROTOC_OPTS= \
-I. \
--go_out=paths=source_relative:. \
--go-grpc_out=paths=source_relative:. \
--grpc-gateway_out=. \
--grpc-gateway_opt logtostderr=true \
--grpc-gateway_opt paths=source_relative \
--grpc-gateway_opt grpc_api_configuration=${DIR}/peerswap.yaml

PROTOC_SWAGGER_OPTS= \
--openapiv2_out=. \
--openapiv2_opt logtostderr=true \
--openapiv2_opt grpc_api_configuration=${DIR}/peerswap.yaml

STUBS= \
${DIR}/peerswaprpc_grpc.pb.go \
${DIR}/peerswaprpc.pb.go \
${DIR}/peerswaprpc.pb.gw.go
${DIR}/peerswaprpc.pb.gw.go \
${DIR}/peerswaprpc.swagger.json

all-rpc: ${STUBS} ${DIR}/peerswaprpc.swagger.json
all-rpc:
buf generate

clean-rpc:
rm -f ${STUBS} ${DIR}/peerswaprpc.swagger.json

${DIR}/peerswaprpc.swagger.json:
protoc ${PROTOC_SWAGGER_OPTS} ${DIR}/peerswaprpc.proto

${DIR}/peerswaprpc_grpc.pb.go ${DIR}/peerswaprpc.pb.go ${DIR}/peerswaprpc.pb.gw.go: ${DIR}/peerswaprpc.proto
protoc ${PROTOC_OPTS} ${DIR}/peerswaprpc.proto
PHONY:
rm -f ${STUBS}

.PHONY: all-rpc-docker
all-rpc-docker:
./gen_protos_docker.sh
./gen_protos_docker.sh

Loading