dongsou3041 2017-06-22 21:54
浏览 58
已采纳

在Bitbucket管道中交叉编译Golang

I'm trying to configure Bitbucket Pipelines to automatically compile Golang code to Linux, OSX, and Windows. I'm using Go's cross-compile functionality for this; the pipeline is running a Linux environment, and cross-compiling to OSX and Windows by setting the values of GOOS and GOARCH. However, I can't get the Windows build to work- it errors and tells me that it can't find a certain package. Both the Linux and OSX builds succeed. However, the Windows build fails, telling me it can't find /go/src/github.com/sirupsen/logrus/hooks/syslog. Both of the previous builds used this package successfully, and running both of

ls /go/src/github.com/sirupsen/logrus/hooks/syslog
ls ${GOPATH}/src/github.com/sirupsen/logrus/hooks/syslog

the line before the build command displays two Go files in that folder. I suspect something might be wrong with maybe the windows filesystem trying to talk to the Linux filesystem? I've spent a few hours searching and experimenting, but nothing seems to resolve the issue.

  • 写回答

1条回答 默认 最新

  • dongyi7901 2017-06-22 22:07
    关注

    syslog is a platform-specific service, so the Logrus syslog hook code has a special comment, called a build tag, to tell the Go tools not to build it on Windows (or Native Client or Plan9):

    // +build !windows,!nacl,!plan9
    

    Unless you don't want syslog integration even on Linux, you probably want to fork the application code that currently always imports hooks/syslog into two versions, one for platforms with syslog, one for those without. If the file importing hooks/syslog is currently, say, logconfig.go, you could create two files logconfig_syslog.go and logconfig_nosyslog.go, the syslog version with a constraint like the one above, and the nosyslog version with the opposite (// +build windows,nacl,plan9).

    Dave Cheney wrote a bit more about build tags and the various flavors of Go conditional compilation.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 求chat4.0解答一道线性规划题,用lingo编程运行,第一问要求写出数学模型和lingo语言编程模型,第二问第三问解答就行,我的ddl要到了谁来求了
  • ¥15 Ubuntu在安装序列比对软件STAR时出现报错如何解决
  • ¥50 树莓派安卓APK系统签名
  • ¥15 maple软件,用solve求反函数出现rootof,怎么办?
  • ¥65 汇编语言除法溢出问题
  • ¥15 Visual Studio问题
  • ¥20 求一个html代码,有偿
  • ¥100 关于使用MATLAB中copularnd函数的问题
  • ¥20 在虚拟机的pycharm上
  • ¥15 jupyterthemes 设置完毕后没有效果