Patrick Jones
Patrick Jones

Reputation: 71

Cross-compiling Golang in Bitbucket Pipelines

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.

Upvotes: 0

Views: 804

Answers (1)

twotwotwo
twotwotwo

Reputation: 30007

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.

Upvotes: 1

Related Questions