Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cross-compile for Linux? #35

Closed
matthewmueller opened this issue Apr 1, 2020 · 4 comments
Closed

Cross-compile for Linux? #35

matthewmueller opened this issue Apr 1, 2020 · 4 comments

Comments

@matthewmueller
Copy link

matthewmueller commented Apr 1, 2020

Hey, thanks a lot for creating this package!

I've found it the example script works beautifully on mac but when I try to cross-compile for Linux, I get the following:

$ GOOS=linux go run main.go
./main.go:10:14: undefined: v8go.NewContext

This looks a bit like I'm just missing the package or something, but it does work when I remove the GOOS=linux.

$ go run main.go
addition result: 7

Here's my details:

OSX 10.5 (Catalina)
go version go1.13.4 darwin/amd64
(using go.mod)
@jimafisk
Copy link

jimafisk commented Aug 4, 2020

I'm having the same issue, I can only compile the binary that corresponds to the OS of my laptop. I've ran the following tests on the same project:

On Mac:

  • env GOOS=darwin GOARCH=amd64 go build ✔️
  • env GOOS=linux GOARCH=amd64 go build

On Ubuntu:

  • env GOOS=darwin GOARCH=amd64 go build
  • env GOOS=linux GOARCH=amd64 go build ✔️

It would be great to be able to cross-compile for using things like Goreleaser with CI.

@matthewmueller
Copy link
Author

matthewmueller commented Aug 4, 2020

@jimafisk chiming in here after learning more. Cross-compiling any cgo packages without additional compiler flags is not possible.

What you can try doing is installing different compilers to cross-compile. I haven't tested this with V8, but the general idea is here: mattn/go-sqlite3#384 (comment)

You can also try: https://github.com/mattn/go-sqlite3#cross-compiling-from-mac-osx.

Hope this helps. Please report back if you come up with anything.

@jimafisk
Copy link

Thanks for pointing me in the right direction here @matthewmueller! There was a lot I didn't know about cross compiling CGO.

Looks like goreleaser has a cgo docker image you could use: goreleaser/goreleaser#795

I was already using GoReleaser Action and wanted to continue using it: goreleaser/goreleaser-action#233. So ultimately I created a project that lets me do that: https://github.com/plentico/osxcross-target. Hopefully it helps someone else out!

@matthewmueller
Copy link
Author

Very cool, thanks for sharing!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants