diff --git a/.gitignore b/.gitignore index 2dbb55a..7d73dc2 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,5 @@ example/csharp/Example/bin example/csharp/Example/obj api/csharp/ProtoPlus/obj api/csharp/ProtoPlus/bin +bin +*.gz diff --git a/Make.sh b/Make.sh new file mode 100644 index 0000000..8d84b8e --- /dev/null +++ b/Make.sh @@ -0,0 +1,34 @@ +#!/usr/bin/env bash +Version=2.0.0 + +export GOARCH=amd64 +BuildSourcePackage="github.com/davyxu/protoplus/build" +BinaryPackage="github.com/davyxu/protoplus/cmd/protoplus" +BinaryName="protoplus" + +BuildBinary() +{ + set -e + TargetDir=bin/"${1}" + mkdir -p "${TargetDir}" + export GOOS=${1} + BuildTime=$(date -R) + GitCommit=$(git rev-parse HEAD) + VersionString="-X \"${BuildSourcePackage}.BuildTime=${BuildTime}\" -X \"${BuildSourcePackage}.Version=${Version}\" -X \"${BuildSourcePackage}.GitCommit=${GitCommit}\"" + + go build -v -p 4 -o "${TargetDir}"/${BinaryName} -ldflags "${VersionString}" ${BinaryPackage} + PackageDir=$(pwd) + cd "${TargetDir}" + tar zcvf "${PackageDir}"/${BinaryName}-${Version}-"${1}"-x86_64.tar.gz ${BinaryName} + cd "${PackageDir}" +} + + + +if [[ ${1} == "" ]]; then + BuildBinary windows + BuildBinary linux + BuildBinary darwin +else + BuildBinary "${1}" +fi \ No newline at end of file diff --git a/build/build.go b/build/build.go new file mode 100644 index 0000000..e470cf3 --- /dev/null +++ b/build/build.go @@ -0,0 +1,15 @@ +package build + +import "fmt" + +var ( + Version string + GitCommit string + BuildTime string +) + +func Print() { + fmt.Println("Version: ", Version) + fmt.Println("GitCommit: ", GitCommit) + fmt.Println("BuildTime: ", BuildTime) +} diff --git a/cmd/protoplus/main.go b/cmd/protoplus/main.go index 8cf3b22..116ae39 100644 --- a/cmd/protoplus/main.go +++ b/cmd/protoplus/main.go @@ -3,6 +3,7 @@ package main import ( "flag" "fmt" + "github.com/davyxu/protoplus/build" _ "github.com/davyxu/protoplus/codegen" "github.com/davyxu/protoplus/gen" "github.com/davyxu/protoplus/gen/pbscheme" @@ -24,8 +25,6 @@ var ( flagCodec = flag.String("codec", "protoplus", "default codec in register entry") ) -const Version = "2.0.0" - type GenEntry struct { name string usage string @@ -97,7 +96,7 @@ func main() { // 版本 if *flagVersion { - fmt.Println(Version) + build.Print() return }