如何在Travis-CI上将Linux的Go项目交叉编译到Windows

时间:2019-05-15 15:43:19

标签: go travis-ci cross-compiling

由于似乎缺少Travis-CI原生Windows对Go的支持, 我虽然打算走这条路。

我最好怎么做?

1 个答案:

答案 0 :(得分:0)

这是Linux的本机版本,OSX的本机版本,以及Windows的交叉编译,这是linux的一部分:

.travis.yml

language: go
sudo: false

matrix:
  include:
    - go: tip
      os: linux
      env: CROSS_COMPILE=true
    - go: tip
      os: osx

before_install:
  - if [ "$CROSS_COMPILE" = "true" ]; then sudo apt update; fi

install:
  - if [ "$CROSS_COMPILE" = "true" ]; then sudo apt install gcc-mingw-w64 libc6-dev-i386; fi
  - go get github.com/some/go-dependency
  - go get -t -v ./...

script:
  - go build
  - go test
  - if [ "$TRAVIS_OS_NAME" = "linux" -a "$CROSS_COMPILE" = "true" ]; then env CGO_ENABLED=1 GOOS=windows GOARCH=amd64 CC=x86_64-w64-mingw32-gcc go build -v; fi