Question about compiling for multiple architectures
danprince opened this issue · comments
Hey folks, I'm trying build binaries (for multiple architectures) in a project that uses v8go and not having much luck. I haven't compiled projects with CGO enabled before, so it's possible that there are important gaps in my understanding.
Everything builds fine for my own architecture (Darwin arm64) but as soon as I try to build for another architecture or OS, I start seeing C compiler errors/warnings (usually about JSError, although not sure that's relevant).
In theory, should it be possible for me to build my project for, say Intel Macs, or Linux/arm, on this machine? I'm assuming that cross compilation is going to be limited to the vendored builds of V8 in the deps
folder, but do I also need to be building on the targeted OS/architecture too?
A rough rundown of how to tackle this kind of cross compilation would be great. Thanks for the project!
v8go has a dependency on your system's libc. When you compile for your own architecture, your machine's libc gets bundled in. When you compile for a different architecture, it doesn't have the other architecture's libc (and can't use your architecture's), so it won't work.
The way we get around this is by having all the different architectures as remote servers that a build script builds on.
Example here: https://github.com/terrastruct/d2/blob/master/ci/release/build.sh