tywkeene/go-fsevents

Build failing with go modules

markschmid opened this issue · 6 comments

When using go modules (go mod ...) building fails. I'm on macOS, cross-compiling for Linux.

go: finding github.com/tywkeene/go-fsevents v0.0.0-20190911221857-8a6f3576d56d
go build github.com/tywkeene/go-fsevents: build constraints exclude all Go files in /go/pkg/mod/github.com/tywkeene/go-fsevents@v0.0.0-20190911221857-8a6f3576d56d

I'm building for Docker, using:

RUN GOARCH=amd64 CGO_ENABLED=0 GOOS=linux go build -tags netgo -a -installsuffix 'static' -o /app .

Any ideas?

PS: It used to work fine and has only stopped since changing to Go Modules.

Hmm, I just realized it actually also fails without Go Modules.

CGO_ENABLED=0

Since go-fsevents needs to import unistd.h from the c std library, CGO is required to build.

Give it a try with CGO_ENABLED=1, you may also have to make a few extra changes depending on the base docker image you're using. e.g alpine requires you to install an extra package for the C stdlib iirc

Building the example works with CGO_ENABLED=1:

$ CGO_ENABLED=1 go build -v handlers.go
$ ls -hal handlers
-rwxrwxr-x 1 tywkeene tywkeene 2.1M Sep 12 11:35 handlers

And fails with CGO_ENABLED=0:

$ CGO_ENABLED=0 go build -v handlers.go
github.com/tywkeene/go-fsevents
go build github.com/tywkeene/go-fsevents: build constraints exclude all Go files in /home/tywkeene/go/src/github.com/tywkeene/go-fsevents

Also, I see that you're building on MacOS, but cross compiling for Linux on Docker. This may also be a problem, but I'm not entirely sure as I don't have access to a MacOS machine, and I'm not entirely sure if any intricacies docker on mac may impact the build. Any insight you can give would be greatly appreciated for anyone in the future attempting the same thing.

Hope this helps, don't hesitate to reach out with any more problems you run into.

I've added support for go modules a bit earlier, so that is now covered. Thanks for bringing that to my attention as well.

Thanks, there is some progress made, specifically it now builds with Go Modules and CGO_ENABLED=1.
The problem now is that my application binary won't start as it used to. Error message:

standard_init_linux.go:207: exec user process caused "no such file or directory"

Prior versions of this library I was able to build using CGO_ENABLED=0 which used to be much easier. I use an alpine container to build a single application binary and a ubuntu container onto which I copy the binary and (try to) run it.

I have changed to a normal golang container for building (not alpine). Now it builds and runs. Please never mind and thanks again!

If I remember correctly, you can install libc6-compat in your alpine to get binaries built with CGO_ENABLED=1 to run.

RUN apk add --no-cache ca-certificates libc6-compat

(ca-certificates is unnecessary for the binary to run, but it's recommended by the alpine folks)

Just thought I'd let you know if you still want to pursue that option, I don't blame you, alpine is tiny, makes deployments and uploads so much faster :)

Anyways, closing this issue for now. Feel free to re-open it or open new issues if you run into anything else, I'll be more than glad to help.