I'm trying to cross compile from Linux to Mac. I'm not even sure it's supposed to work, but according to the docs you can specify a dest-os and a --cross-compiling so I guess it should.
When I first tried to build on Linux for Mac, ./configure threw some errors that XCode was not installed. I understand that you need XCode if you build on a Mac, but is this a requirement when you build for a Mac? I found that if you include --ninja then the XCode dependency was removed. The configuration arguments I'm using are:
./configure --cross-compiling --without-intl --without-inspector --dest-cpu=x64 --dest-os=mac --without-snapshot --without-dtrace --ninja
However, if I then try to link the .a files on a Mac now (I'm linking against some other code I have), then I get the following:
ld: warning: ld: warning: ignoring file ../node.out/mac/x64/src/libv8_libbase.a, file was built for
unsupported file format ( 0x21 0x3C 0x74 0x68 0x69 0x6E 0x3E 0x0A 0x2F 0x20 0x20 0x20 0x20
0x20 0x20 0x20 ) which is not the architecture being linked (x86_64):
../node.out/mac/x64/src/libv8_libbase.aignoring file ../node.out/mac/x64/src/libv8_base.a, file was built
for unsupported file format ( 0x21 0x3C 0x74 0x68 0x69 0x6E 0x3E 0x0A 0x2F 0x20 0x20 0x20 0x20
0x20 0x20 0x20 ) which is not the architecture being linked (x86_64):
../node.out/mac/x64/src/libv8_base.a
Any ideas / pointers?
Are you sure you have an appropriate macos toolchain installed? It sounds like you may not or at least it's not being picked up (perhaps environment variables are not set correctly).
no, I likely don't. I don't have much experience with cross-compiling (especially from Linux to Mac) so if you have any pointers, that would be greatly appreciated. Thanks!
BTW, just for some context, I have node.js binding for Java, and I'm trying to improve the build process. Right now, I build node on each platform manually, and then link to J2V8, it's not fun :)
I don't have any experience with a macos cross-compiler toolchain, but a quick google search turns up this which may work.
The xcodebuild and xcrun errors are not a problem, see https://github.com/nodejs/node/issues/12531
Thanks!
I have managed to build the cross compiler from osxcross and the node.js build started fine. However, it failed part way through with a missing header:
../deps/v8/src/base/platform/platform-linux.cc:13:23: fatal error: sys/prctl.h: No such file or directory
Out of curiosity, how is node.js built? Is it built on a single platform using the --cross-compiler option for all the platforms you support, or is it built on each individual platform?
We don't do cross-compiling when we build Node. Basically if you'd like to fix cross-compiling and submit a PR we'll happily accept, but we currently don't test in CI, so you may run into all sorts of issues.
@gibfahn Thanks. At least I know what I'm up against -- I thought I was being dense that I couldn't figure it out. I'm trying to build it in a docker container too, so if I manage to get it working, it should be portable too. I'll post any progress I make here.
Thanks again for the pointers.
I have created a GitHub project that contains a set of Dockerfiles that describe the node.js build for a variety of different platforms -- include Android arm, Android x86 and Linux x64. I have also added one for Mac. It uses the toolchain from osxcross, however it doesn't work. The Dockerfiles are here.
It seems even when using a mac toolchain, and specifying --dest-os=mac, node.js still tries to build some Linux dependent code (See my comment above for the error message). I imagine this is because the v8 build is checking the platform on which the build is running, and not using the --dest-os flag.
I'm not sure how --dest-os is supposed to be passed to the V8 build. Furthermore, v8 has changed their build system again, so I'm not sure what docs are relevant for the node.js build.
I'll leave this here in case anyone has ideas how to fix this, or pointers for where to look in the node.js / v8 build.
@irbull Since it seems the docs have become irrelevant I'm going to change the title.
Since it seems the docs have become irrelevant I'm going to change the title.
I don't think the docs have become irrelevant, we should still document how it would work, and if someone wants to do the work to get it working (and maybe even tested in CI) then that would be fine. We just don't have anyone who's stepped up to do that yet.
@gibfahn It would be great if we could get this working. I've been pushing on it with the help of another J2V8 contributor. We've managed to get past the linux platform specific compile errors (by manually tweaking some gyp parameters), but now we're stuck at the linking stage. It's using the OSX toolchain, but it's passing linux specific linker arguments (which obviously don't work). I can't figure out where these are coming from.
Our progress is on https://github.com/eclipsesource/J2V8/issues/232. I'm happy to keep pushing forward with this, and if we get anywhere I'd be glad to parameterize this and put together a Pull Request. However, I think I might be stuck again. If anyone with knowledge of cross platform builds knows anything about linker args, I'm all ears.
BTW, the docker approach is really nice. If this works, then we should have an isolated build system that can (in theory) build Node for several platforms from a single command on a single machine.
@gibfahn Ok.
Updated title to indicate there is a discrepancy between the documentation and what actually works.
IMHO documentation should not promise things the code can't deliver, or describe broken process, as that is a source for frustration...
Closing due to lack of participation in the last nine month. If someone thinks differently, please reopen.