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

chore: Update proto build to use buf and the BSR #285

Merged
merged 5 commits into from
Mar 1, 2024
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
10 changes: 6 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ BUILDDIR ?= $(CURDIR)/build
TEST_DOCKER_REPO=jackzampolin/sommtest
HTTPS_GIT := https://github.com/peggyjv/sommelier.git
DOCKER := $(shell which docker)
DOCKER_BUF := $(DOCKER) run --rm -v $(CURDIR):/workspace --workdir /workspace bufbuild/buf
DOCKER_BUF := $(DOCKER) run --rm -v $(CURDIR):/workspace --workdir /workspace bufbuild/buf:1.29.0

export GO111MODULE = on

Expand Down Expand Up @@ -212,23 +212,25 @@ test-docker-push: test-docker
### Protobuf ###
###############################################################################

PROTO_BUILD_IMAGE=ghcr.io/cosmos/proto-builder:0.8

proto-all: proto-format proto-lint proto-gen

proto-gen:
@echo "Generating Protobuf files"
$(DOCKER) run --rm -v $(CURDIR):/workspace --workdir /workspace tendermintdev/sdk-proto-gen sh ./scripts/protocgen.sh
$(DOCKER) run --rm -v $(CURDIR):/workspace --workdir /workspace $(PROTO_BUILD_IMAGE) sh ./scripts/protocgen.sh

proto-format:
@echo "Formatting Protobuf files"
$(DOCKER) run --rm -v $(CURDIR):/workspace \
--workdir /workspace tendermintdev/docker-build-proto \
--workdir /workspace $PROTO_BUILD_IMAGE \
find ./ -not -path "./third_party/*" -name *.proto -exec .clang-format -i {} \;

proto-swagger-gen:
@./scripts/protoc-swagger-gen.sh

proto-lint:
@$(DOCKER_BUF) check lint --error-format=json
@$(DOCKER_BUF) lint --error-format=json

proto-check-breaking:
@$(DOCKER_BUF) check breaking --against-input $(HTTPS_GIT)#branch=main
Expand Down
4 changes: 4 additions & 0 deletions buf.work.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
version: v1
directories:
- proto
- third_party/proto
4,119 changes: 0 additions & 4,119 deletions docs/core/proto-docs.md

This file was deleted.

105 changes: 0 additions & 105 deletions docs/protodoc-markdown.tmpl

This file was deleted.

3 changes: 2 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@ go 1.19
require (
cosmossdk.io/errors v1.0.0-beta.7
cosmossdk.io/math v1.0.0-rc.0
github.com/cosmos/cosmos-proto v1.0.0-alpha8
github.com/cosmos/cosmos-sdk v0.46.14
github.com/cosmos/go-bip39 v1.0.0
github.com/cosmos/gogoproto v1.4.8
github.com/cosmos/ibc-go/v6 v6.2.0
github.com/ethereum/go-ethereum v1.10.22
github.com/gogo/protobuf v1.3.3
Expand Down Expand Up @@ -63,7 +65,6 @@ require (
github.com/confio/ics23/go v0.9.0 // indirect
github.com/containerd/continuity v0.3.0 // indirect
github.com/cosmos/btcutil v1.0.5 // indirect
github.com/cosmos/cosmos-proto v1.0.0-alpha8 // indirect
github.com/cosmos/gorocksdb v1.2.0 // indirect
github.com/cosmos/iavl v0.19.6 // indirect
github.com/cosmos/ledger-cosmos-go v0.12.4 // indirect
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,8 @@ github.com/cosmos/cosmos-sdk v0.46.14/go.mod h1:9MRixWsgoJ2UmVsCRRePtENFPP3cM+gT
github.com/cosmos/go-bip39 v0.0.0-20180819234021-555e2067c45d/go.mod h1:tSxLoYXyBmiFeKpvmq4dzayMdCjCnu8uqmCysIGBT2Y=
github.com/cosmos/go-bip39 v1.0.0 h1:pcomnQdrdH22njcAatO0yWojsUnCO3y2tNoV1cb6hHY=
github.com/cosmos/go-bip39 v1.0.0/go.mod h1:RNJv0H/pOIVgxw6KS7QeX2a0Uo0aKUlfhZ4xuwvCdJw=
github.com/cosmos/gogoproto v1.4.8 h1:BrHKc6WFZt8+jRV71vKSQE+JrfF+JAnzrKo2VP7wIZ4=
github.com/cosmos/gogoproto v1.4.8/go.mod h1:hnb0DIEWTv+wdNzNcqus5xCQXq5+CXauq1FJuurRfVY=
github.com/cosmos/gorocksdb v1.2.0 h1:d0l3jJG8M4hBouIZq0mDUHZ+zjOx044J3nGRskwTb4Y=
github.com/cosmos/gorocksdb v1.2.0/go.mod h1:aaKvKItm514hKfNJpUJXnnOWeBnk2GL4+Qw9NHizILw=
github.com/cosmos/iavl v0.19.6 h1:XY78yEeNPrEYyNCKlqr9chrwoeSDJ0bV2VjocTk//OU=
Expand Down
5 changes: 5 additions & 0 deletions proto/buf.gen.doc.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
version: v1
plugins:
- name: doc
out: ../docs/core/
opt: ../docs/protodoc-markdown.tmpl,proto-docs.md
8 changes: 8 additions & 0 deletions proto/buf.gen.gogo.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
version: v1
plugins:
- name: gocosmos
out: ..
opt: plugins=grpc,Mgoogle/protobuf/any.proto=github.com/cosmos/cosmos-sdk/codec/types
- name: grpc-gateway
out: ..
opt: logtostderr=true,allow_colon_final_segments=true
18 changes: 18 additions & 0 deletions proto/buf.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by buf. DO NOT EDIT.
version: v1
deps:
- remote: buf.build
owner: cosmos
repository: cosmos-proto
commit: 1935555c206d4afb9e94615dfd0fad31
digest: shake256:c74d91a3ac7ae07d579e90eee33abf9b29664047ac8816500cf22c081fec0d72d62c89ce0bebafc1f6fec7aa5315be72606717740ca95007248425102c365377
- remote: buf.build
owner: cosmos
repository: gogo-proto
commit: 88ef6483f90f478fb938c37dde52ece3
digest: shake256:89c45df2aa11e0cff97b0d695436713db3d993d76792e9f8dc1ae90e6ab9a9bec55503d48ceedd6b86069ab07d3041b32001b2bfe0227fa725dd515ff381e5ba
- remote: buf.build
owner: googleapis
repository: googleapis
commit: 7e6f6e774e29406da95bd61cdcdbc8bc
digest: shake256:fe43dd2265ea0c07d76bd925eeba612667cf4c948d2ce53d6e367e1b4b3cb5fa69a51e6acb1a6a50d32f894f054a35e6c0406f6808a483f2752e10c866ffbf73
10 changes: 10 additions & 0 deletions proto/buf.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
version: v1
name: buf.build/sommelier/sommelier
deps:
- buf.build/cosmos/cosmos-proto
- buf.build/cosmos/gogo-proto
- buf.build/googleapis/googleapis
breaking:
use:
- FILE

2 changes: 1 addition & 1 deletion proto/cork/v2/cork.proto
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
syntax = "proto3";
package cork.v2;

option go_package = "github.com/peggyjv/sommelier/v7/x/cork/types";
option go_package = "github.com/peggyjv/sommelier/v7/x/cork/types/v2";

message Cork {
// call body containing the ABI encoded bytes to send to the contract
Expand Down
3 changes: 1 addition & 2 deletions proto/cork/v2/genesis.proto
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ package cork.v2;
import "cork/v2/cork.proto";
import "gogoproto/gogo.proto";

option go_package = "github.com/peggyjv/sommelier/v7/x/cork/types";

option go_package = "github.com/peggyjv/sommelier/v7/x/cork/types/v2";

// GenesisState - all cork state that must be provided at genesis
message GenesisState {
Expand Down
2 changes: 1 addition & 1 deletion proto/cork/v2/proposal.proto
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package cork.v2;

import "cork/v2/cork.proto";

option go_package = "github.com/peggyjv/sommelier/v7/x/cork/types";
option go_package = "github.com/peggyjv/sommelier/v7/x/cork/types/v2";

message AddManagedCellarIDsProposal {
string title = 1;
Expand Down
2 changes: 1 addition & 1 deletion proto/cork/v2/query.proto
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import "google/api/annotations.proto";
import "cork/v2/genesis.proto";
import "cork/v2/cork.proto";

option go_package = "github.com/peggyjv/sommelier/v7/x/cork/types";
option go_package = "github.com/peggyjv/sommelier/v7/x/cork/types/v2";

// Query defines the gRPC query service for the cork module.
service Query {
Expand Down
2 changes: 1 addition & 1 deletion proto/cork/v2/tx.proto
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package cork.v2;

import "cork/v2/cork.proto";

option go_package = "github.com/peggyjv/sommelier/v7/x/cork/types";
option go_package = "github.com/peggyjv/sommelier/v7/x/cork/types/v2";

// MsgService defines the msgs that the cork module handles
service Msg {
Expand Down
7 changes: 0 additions & 7 deletions scripts/README.md

This file was deleted.

42 changes: 8 additions & 34 deletions scripts/protocgen.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,45 +2,19 @@

set -eo pipefail

protoc_gen_gocosmos() {
if ! grep "github.com/gogo/protobuf => github.com/regen-network/protobuf" go.mod &>/dev/null ; then
echo -e "\tPlease run this command from somewhere inside the sommelier folder."
return 1
fi

go get github.com/regen-network/cosmos-proto/protoc-gen-gocosmos@latest 2>/dev/null
}

echo "verifying protoc gocosmos"
protoc_gen_gocosmos
ROOT=$(git rev-parse --show-toplevel 2>/dev/null)

cd $ROOT/proto
echo "generating proto and gRPC gateway files..."
buf generate --template buf.gen.gogo.yaml
cd ..

proto_dirs=$(find ./proto -path -prune -o -name '*.proto' -print0 | xargs -0 -n1 dirname | sort | uniq)
for dir in $proto_dirs; do
buf protoc \
-I "proto" \
-I "third_party/proto" \
--gocosmos_out=plugins=interfacetype+grpc,\
Mgoogle/protobuf/any.proto=github.com/cosmos/cosmos-sdk/codec/types:. \
--grpc-gateway_out=logtostderr=true,allow_colon_final_segments=true:. \
$(find "${dir}" -maxdepth 1 -name '*.proto')

done
# move proto files to the right places
xpath=$(head -n 1 go.mod | sed 's/^module //')
cp -r $xpath/* ./

echo "generating proto docs..."
# command to generate docs using protoc-gen-doc
buf protoc \
-I "proto" \
-I "third_party/proto" \
--doc_out=./docs/core \
--doc_opt=./docs/protodoc-markdown.tmpl,proto-docs.md \
$(find "$(pwd)/proto" -maxdepth 5 -name '*.proto')
echo "cleaning up..."
go mod tidy

echo "(re)moving proto files.."
# move proto files to the right places
cp -r github.com/peggyjv/sommelier/* ./
rm -rf github.com

echo "done"
18 changes: 18 additions & 0 deletions third_party/proto/buf.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by buf. DO NOT EDIT.
version: v1
deps:
- remote: buf.build
owner: cosmos
repository: cosmos-proto
commit: 1935555c206d4afb9e94615dfd0fad31
digest: shake256:c74d91a3ac7ae07d579e90eee33abf9b29664047ac8816500cf22c081fec0d72d62c89ce0bebafc1f6fec7aa5315be72606717740ca95007248425102c365377
- remote: buf.build
owner: cosmos
repository: gogo-proto
commit: 88ef6483f90f478fb938c37dde52ece3
digest: shake256:89c45df2aa11e0cff97b0d695436713db3d993d76792e9f8dc1ae90e6ab9a9bec55503d48ceedd6b86069ab07d3041b32001b2bfe0227fa725dd515ff381e5ba
- remote: buf.build
owner: googleapis
repository: googleapis
commit: 7e6f6e774e29406da95bd61cdcdbc8bc
digest: shake256:fe43dd2265ea0c07d76bd925eeba612667cf4c948d2ce53d6e367e1b4b3cb5fa69a51e6acb1a6a50d32f894f054a35e6c0406f6808a483f2752e10c866ffbf73
19 changes: 7 additions & 12 deletions buf.yaml → third_party/proto/buf.yaml
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
build:
roots:
- proto
- third_party/proto
excludes:
- third_party/proto/google/protobuf
version: v1
deps:
- buf.build/cosmos/cosmos-proto
- buf.build/cosmos/gogo-proto
- buf.build/googleapis/googleapis
lint:
use:
- DEFAULT
Expand All @@ -16,15 +15,11 @@ lint:
- PACKAGE_VERSION_SUFFIX
- RPC_REQUEST_STANDARD_NAME
ignore:
- tendermint
- gogoproto
- cosmos_proto
- google
- tendermint/
- cosmos_proto/
breaking:
use:
- FILE
ignore:
- tendermint
- gogoproto
- cosmos_proto
- google
16 changes: 0 additions & 16 deletions third_party/proto/cosmos_proto/cosmos.proto

This file was deleted.

Loading
Loading