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

fix: protoc gen with docker not working #232

Closed
wants to merge 6 commits into from
Closed
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
8 changes: 1 addition & 7 deletions simapp/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -188,17 +188,11 @@ mod-tidy:
###############################################################################
### Protobuf ###
###############################################################################
protoVer=0.13.2
protoImageName=ghcr.io/cosmos/proto-builder:$(protoVer)
protoImage=$(DOCKER) run --rm -v $(CURDIR):/workspace --workdir /workspace $(protoImageName)

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

proto-gen:
@go install cosmossdk.io/orm/cmd/[email protected]
@echo "Generating Protobuf files"
@$(protoImage) sh ./scripts/protocgen.sh
# generate the stubs for the proto files from the proto directory
@sh ./scripts/protocgen.sh
@spawn stub-gen
@go mod tidy

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ plugins:
opt: plugins=grpc,Mgoogle/protobuf/any.proto=github.com/cosmos/cosmos-sdk/codec/types,Mcosmos/orm/v1/orm.proto=cosmossdk.io/orm
- name: grpc-gateway
out: ..
opt: logtostderr=true,allow_colon_final_segments=true
opt: logtostderr=true
15 changes: 12 additions & 3 deletions simapp/proto/buf.lock
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,24 @@ deps:
owner: cosmos
repository: cosmos-proto
commit: 1935555c206d4afb9e94615dfd0fad31
digest: shake256:c74d91a3ac7ae07d579e90eee33abf9b29664047ac8816500cf22c081fec0d72d62c89ce0bebafc1f6fec7aa5315be72606717740ca95007248425102c365377
- remote: buf.build
owner: cosmos
repository: cosmos-sdk
commit: d5661b4f6ef64bb1b5beb6cb7bd705b7
commit: 5a6ab7bc14314acaa912d5e53aef1c2f
digest: shake256:02c00c73493720055f9b57553a35b5550023a3c1914123b247956288a78fb913aff70e66552777ae14d759467e119079d484af081264a5dd607a94d9fbc8116b
- remote: buf.build
owner: cosmos
repository: gogo-proto
commit: 5e5b9fdd01804356895f8f79a6f1ddc1
commit: 34d970b699f84aa382f3c29773a60836
digest: shake256:3d3bee5229ba579e7d19ffe6e140986a228b48a8c7fe74348f308537ab95e9135210e81812489d42cd8941d33ff71f11583174ccc5972e86e6112924b6ce9f04
- remote: buf.build
owner: cosmos
repository: ics23
commit: 55085f7c710a45f58fa09947208eb70b
digest: shake256:9bf0bc495b5a11c88d163d39ef521bc4b00bc1374a05758c91d82821bdc61f09e8c2c51dda8452529bf80137f34d852561eacbe9550a59015d51cecb0dacb628
- remote: buf.build
owner: googleapis
repository: googleapis
commit: cc916c31859748a68fd229a3c8d7a2e8
commit: 8d7204855ec14631a499bd7393ce1970
digest: shake256:40bf4112960cad01281930beed85829910768e32e80e986791596853eccd42c0cbd9d96690b918f658020d2d427e16f8b6514e2ac7f4a10306fd32e77be44329
9 changes: 5 additions & 4 deletions simapp/proto/buf.yaml
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
version: v1
deps:
- buf.build/cosmos/cosmos-sdk:v0.50.3
- buf.build/cosmos/cosmos-proto
- buf.build/cosmos/gogo-proto
- buf.build/googleapis/googleapis
- buf.build/cosmos/cosmos-sdk:v0.50.0
- buf.build/cosmos/cosmos-proto:1935555c206d4afb9e94615dfd0fad31
- buf.build/cosmos/gogo-proto:a14993478f40695898ed8a86931094b6656e8a5d
- buf.build/googleapis/googleapis:8d7204855ec14631a499bd7393ce1970
- buf.build/cosmos/ics23:b1abd8678aab07165efd453c96796a179eb3131f
lint:
use:
- DEFAULT
Expand Down
60 changes: 37 additions & 23 deletions simapp/scripts/protocgen.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,48 +3,62 @@
set -e

GO_MOD_PACKAGE="github.com/rollchains/spawn/simapp"

echo "Generating gogo proto code"
cd proto
proto_dirs=$(find . -path -prune -o -name '*.proto' -print0 | xargs -0 -n1 dirname | sort | uniq)
for dir in $proto_dirs; do
for file in $(find "${dir}" -maxdepth 1 -name '*.proto'); do
# this regex checks if a proto file has its go_package set to github.com/strangelove-ventures/poa/...
# gogo proto files SHOULD ONLY be generated if this is false
# we don't want gogo proto to run for proto files which are natively built for google.golang.org/protobuf
if grep -q "option go_package" "$file" && grep -H -o -c "option go_package.*$GO_MOD_PACKAGE/api" "$file" | grep -q ':0$'; then
buf generate --template buf.gen.gogo.yaml $file
fi
done
done

protoImageName=ghcr.io/cosmos/proto-builder:0.13.1

if ! [ -x "$(command -v buf)" ]; then
echo "Installing buf as it is not found"
# https://buf.build/docs/installation
BIN="/usr/local/bin" && \
VERSION="1.45.0" && \
curl -sSL \
"https://github.com/bufbuild/buf/releases/download/v${VERSION}/buf-$(uname -s)-$(uname -m)" \
-o "${BIN}/buf" && \
chmod +x "${BIN}/buf"
fi

if ! [ -x "$(command -v protoc-gen-gocosmos)" ]; then
docker create --name cosmos-proto-builder $protoImageName
docker cp cosmos-proto-builder:/go/bin/. $(go env GOPATH)/bin/
docker rm -f cosmos-proto-builder
# https://github.com/cosmos/cosmos-sdk/blob/e84c0eb86b20dc95be413b21b0da7377a9bbedc6/contrib/devtools/Dockerfile#L30
go install github.com/grpc-ecosystem/grpc-gateway/[email protected]
go install cosmossdk.io/orm/cmd/[email protected]
fi

echo "Generating gogo proto code"
buf generate
custom_modules=$(find . -name 'module' -type d -not -path "./proto/*"); echo $custom_modules
base_namespace=$(echo $custom_modules | sed -e 's|/module||g' | sed -e 's|\./||g'); echo $base_namespace

echo "Generating pulsar proto code"
buf generate --template buf.gen.pulsar.yaml

# Go back to then move files to their correct locations
cd ..

cp -r $GO_MOD_PACKAGE/* ./
([ -z "$GO_MOD_PACKAGE" ] && echo "Go Mod Package is empty!!"; exit 1) && cp -r $GO_MOD_PACKAGE/* ./
rm -rf github.com

# Copy files over for dep injection
rm -rf api && mkdir api
custom_modules=$(find . -name 'module' -type d -not -path "./proto/*")

# get the 1 up directory (so ./cosmos/mint/module becomes ./cosmos/mint)
# remove the relative path starter from base namespaces. so ./cosmos/mint becomes cosmos/mint
base_namespace=$(echo $custom_modules | sed -e 's|/module||g' | sed -e 's|\./||g')

# echo "Base namespace: $base_namespace"
for module in $base_namespace; do
echo " [+] Moving: ./$module to ./api/$module"

mkdir -p api/$module

mv $module/* ./api/$module/
cp -r ./$module/* ./api/$module/

# # incorrect reference to the module for coins
# # incorrect reference to the modules with the builder
find api/$module -type f -name '*.go' -exec sed -i -e 's|types "github.com/cosmos/cosmos-sdk/types"|types "cosmossdk.io/api/cosmos/base/v1beta1"|g' {} \;
find api/$module -type f -name '*.go' -exec sed -i -e 's|types1 "github.com/cosmos/cosmos-sdk/x/bank/types"|types1 "cosmossdk.io/api/cosmos/bank/v1beta1"|g' {} \;
find api/$module -type f -name '*.go' -exec sed -i -e 's|"cosmos/app/v1alpha1"|"cosmossdk.io/api/cosmos/app/v1alpha1"|g' {} \;

rm -rf $module
done
# remove incorrect reference from other generation
rm ./api/$module/module/v1/module.pb.go

rm -rf ./$module
done
Loading