Skip to content

Commit

Permalink
增加build shell
Browse files Browse the repository at this point in the history
  • Loading branch information
davyxu committed Jun 20, 2021
1 parent 2b52e6b commit 2d149a6
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 3 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,5 @@ example/csharp/Example/bin
example/csharp/Example/obj
api/csharp/ProtoPlus/obj
api/csharp/ProtoPlus/bin
bin
*.gz
34 changes: 34 additions & 0 deletions Make.sh
Original file line number Diff line number Diff line change
@@ -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
15 changes: 15 additions & 0 deletions build/build.go
Original file line number Diff line number Diff line change
@@ -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)
}
5 changes: 2 additions & 3 deletions cmd/protoplus/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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
Expand Down Expand Up @@ -97,7 +96,7 @@ func main() {

// 版本
if *flagVersion {
fmt.Println(Version)
build.Print()
return
}

Expand Down

0 comments on commit 2d149a6

Please sign in to comment.