mirror of
https://github.com/xiaoqidun/goenv.git
synced 2024-12-22 21:48:15 +08:00
goenv
golang environment
docker
拉取镜像
docker pull xiaoqidun/goenv:latest
运行镜像
docker run -it --rm xiaoqidun/goenv
交叉编译
以编译android arm64程序为例
export CC=aarch64-linux-android21-clang
export GOOS=android
export GOARCH=arm64
export CGO_ENABLED=1
go build -o main_android_arm64 main.go
编译项目
将项目文件映射到容器内部
linux - bash
docker run --rm -it -v $(pwd):/go/src/app -w /go/src/app xiaoqidun/goenv
windows - cmd
docker run --rm -it -v %cd%:/go/src/app -w /go/src/app xiaoqidun/goenv
windows - powershell
docker run --rm -it -v "${pwd}:/go/src/app" -w /go/src/app xiaoqidun/goenv
在容器内执行命令进行编译
export GOOS=windows
export GOARCH=amd64
export CGO_ENABLED=0
go build -o main_windows_amd64.exe main.go