-
Notifications
You must be signed in to change notification settings - Fork 28
/
Copy pathbuild.sh
executable file
·75 lines (59 loc) · 1.67 KB
/
build.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#!/bin/bash
set -e
PROTOBUF_VERSION="26.0"
UNAME_S=`uname -s`
OS=""
GENERATE_PROTOS=0
if [ $UNAME_S = "Linux" ]
then
OS="linux-x86_64"
elif [ $UNAME_S = "Darwin" ]
then
OS="osx-x86_64"
else
echo "Unsupported operating system"
exit 1
fi
PROTOC_TARBALL="protoc-$PROTOBUF_VERSION-$OS.zip"
PROTOC_URL="https://github.com/protocolbuffers/protobuf/releases/download/v$PROTOBUF_VERSION/$PROTOC_TARBALL"
# Collect submitted flags.
for flag in "$@"
do
if [ $flag = "--generate-protos" ]
then
GENERATE_PROTOS=1
fi
done
#end
go version
# Required tools
mkdir -p tools
pushd tools > /dev/null
if [ ! -d protobuf ]
then
echo "Installing protoc $PROTOBUF_VERSION locally..."
curl -LOs $PROTOC_URL
unzip -qu $PROTOC_TARBALL -d protobuf
rm $PROTOC_TARBALL
echo "done."
fi
popd > /dev/null
# end
if [ $GENERATE_PROTOS -eq 1 ]
then
go install "google.golang.org/protobuf/cmd/protoc-gen-go@latest"
go install "google.golang.org/grpc/cmd/protoc-gen-go-grpc@latest"
gopath=`go env GOPATH`
for proto in $(find protos -name "*.proto")
do
bname=`basename $proto .proto`
mkdir -p protos/$bname
echo "Compiling $bname.proto ..."
tools/protobuf/bin/protoc --proto_path=$PWD/protos --go_out=./protos/$(basename $proto .proto) --go-grpc_out=./protos/$(basename $proto .proto) --go_opt=paths=source_relative --go-grpc_opt=paths=source_relative --plugin=protoc-gen-go=$gopath/bin/protoc-gen-go --plugin=protoc-gen-go-grpc=$gopath/bin/protoc-gen-go-grpc $PWD/$proto
echo "done."
done
echo "Protobuf code generation completed!"
fi
echo "Compiling project..."
go build -v ./esdb ./samples
echo "done."