github.com/decred/dcrlnd@v0.7.6/lnrpc/gen_protos.sh (about) 1 #!/usr/bin/env sh 2 3 build_protoc_gen_go() { 4 5 echo "Install protoc-gen-go" 6 mkdir -p bin 7 export GOBIN=$PWD/bin 8 go build . 9 go install github.com/golang/protobuf/protoc-gen-go \ 10 github.com/grpc-ecosystem/grpc-gateway/v2/protoc-gen-grpc-gateway \ 11 github.com/grpc-ecosystem/grpc-gateway/v2/protoc-gen-openapiv2 12 } 13 14 generate() { 15 16 GGWVERSION=$(go list -m all | grep "github.com/grpc-ecosystem/grpc-gateway " | sed 's/ /@/' -) 17 PROTOSVERSION=$(go list -m all | grep "github.com/matheusd/google-protobuf-protos" | sed 's/ /@/' -) 18 GOOGAPIS="$GOPATH/pkg/mod/$GGWVERSION/third_party/googleapis" 19 PROTOBUFAPIS="$GOPATH/pkg/mod/$PROTOSVERSION" 20 21 echo "Generating root gRPC server protos" 22 23 PROTOS="lightning.proto walletunlocker.proto stateservice.proto **/*.proto" 24 25 # For each of the sub-servers, we then generate their protos, but a restricted 26 # set as they don't yet require REST proxies, or swagger docs. 27 for file in $PROTOS; do 28 DIRECTORY=$(dirname "${file}") 29 echo "Generating protos from ${file}, into ${DIRECTORY}" 30 31 # Generate the protos. 32 protoc -I. \ 33 -I$GOOGAPIS -I$PROTOBUFAPIS \ 34 --go_out=plugins=grpc,paths=source_relative:. \ 35 "${file}" 36 37 # Generate the REST reverse proxy. 38 annotationsFile=${file//proto/yaml} 39 protoc -I. \ 40 -I$GOOGAPIS -I$PROTOBUFAPIS \ 41 --grpc-gateway_out . \ 42 --grpc-gateway_opt logtostderr=true \ 43 --grpc-gateway_opt paths=source_relative \ 44 --grpc-gateway_opt grpc_api_configuration=${annotationsFile} \ 45 "${file}" 46 47 # Finally, generate the swagger file which describes the REST API in detail. 48 protoc -I. \ 49 -I$GOOGAPIS -I$PROTOBUFAPIS \ 50 --openapiv2_out . \ 51 --openapiv2_opt logtostderr=true \ 52 --openapiv2_opt grpc_api_configuration=${annotationsFile} \ 53 --openapiv2_opt json_names_for_fields=false \ 54 "${file}" 55 done 56 } 57 58 (cd tools && build_protoc_gen_go) 59 PATH=$PWD/tools/bin:$PATH generate 60 61 rm -rf tools/bin