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.

图片转代码服务由CSDN问答提供 功能建议

我正在尝试配置Bitbucket管道以自动将Golang代码编译到Linux,OSX和Windows。 我正在为此使用Go的交叉编译功能。 管道正在运行Linux环境,并通过设置GOOS和GOARCH的值交叉编译到OSX和Windows。 但是,我无法使Windows版本正常工作-它报错,并告诉我找不到特定的程序包。 Linux和OSX构建均成功。 但是,Windows构建失败,告诉我找不到/go/src/github.com/sirupsen/logrus/hooks/syslog。 先前的两个版本都成功使用了此软件包,并同时运行

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

build命令之前的那一行在该文件夹中显示两个Go文件。 我怀疑Windows文件系统试图与Linux文件系统对话可能出了问题? 我已经花了几个小时进行搜索和实验,但似乎没有任何解决方法。

  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

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.

    打赏 评论

相关推荐 更多相似问题