dongsou3041
dongsou3041
2017-06-22 21:54

在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 dongyi7901 4年前

    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.

    点赞 评论 复制链接分享

相关推荐