工作生活

用go来做嵌入式开发-交叉编译和自动版本号

2019-06-30  本文已影响0人  斗破苍穷

用go来做嵌入式开发-交叉编译和自动版本号

多平台教程编译脚本


@echo off
set GOARCH=arm
set GOOS=linux
set CGO_ENABLED=0



set dd=%date:~8,2%
set mm=%date:~5,2%
set yy=%date:~0,4%

set Tss=%TIME:~6,2%
set Tmm=%TIME:~3,2%
set Thh=%TIME:~0,2%
set Thh=%Thh: =0%


set BUILD_VERSION=1.0.5
set BUILD_TIME=%yy%-%mm%-%dd%_%Thh%.%Tmm%.%Tss%
set BUILD_NAME=goftpd
set BUILD_PATH=bylib/byutils
echo %BUILD_NAME%%BUILD_VERSION%%BUILD_TIME%
go build -ldflags "-w -s -X %BUILD_PATH%.BuildTime=%BUILD_TIME% -X %BUILD_PATH%.BuildVersion=%BUILD_VERSION% -X %BUILD_PATH%.BuildName=%BUILD_NAME%" -v -o %BUILD_NAME%

::upx -9 %BUILD_NAME%
upx  %BUILD_NAME%

@echo off
set GOARCH=mipsle
set GOOS=linux
set GOMIPS=softfloat
set CGO_ENABLED=0



set dd=%date:~8,2%
set mm=%date:~5,2%
set yy=%date:~0,4%

set Tss=%TIME:~6,2%
set Tmm=%TIME:~3,2%
set Thh=%TIME:~0,2%
set Thh=%Thh: =0%


set BUILD_VERSION=1.0.5
set BUILD_TIME=%yy%-%mm%-%dd%_%Thh%.%Tmm%.%Tss%
set BUILD_NAME=goftpd
set BUILD_PATH=bylib/byutils
echo %BUILD_NAME%%BUILD_VERSION%%BUILD_TIME%
go build -ldflags "-w -s -X %BUILD_PATH%.BuildTime=%BUILD_TIME% -X %BUILD_PATH%.BuildVersion=%BUILD_VERSION% -X %BUILD_PATH%.BuildName=%BUILD_NAME%" -v -o %BUILD_NAME%

::upx -9 %BUILD_NAME%
upx  %BUILD_NAME%

如何自动生成版本号

  1. 定义一个包含版本号信息的通用包 ,建立一个version.go的文件
package byutil



var (
    BuildVersion string
    BuildTime    string
    BuildName    string
)

  1. 在项目中引用该包中的版本号和编译时间变量

var build_info= byutil.BuildVersion+byutil.BuildTime

  1. 编译的时候通过tag传递当前时间和版本号给byutil包中的相关变量,具体参考第一节中的交叉编译脚本
上一篇 下一篇

猜你喜欢

热点阅读