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

nodejs doesn't cross-compile to non-executable hostPlatform #142651

Closed
dwf opened this issue Oct 23, 2021 · 4 comments
Closed

nodejs doesn't cross-compile to non-executable hostPlatform #142651

dwf opened this issue Oct 23, 2021 · 4 comments
Labels

Comments

@dwf
Copy link
Contributor

dwf commented Oct 23, 2021

Describe the bug

Cross-compiling nodejs for a hostPlatform whose binaries can't be executed on the buildPlatform fails.

Steps To Reproduce

Steps to reproduce the behavior:

  1. nix-build '<nixpkgs>' -A pkgsCross.raspberryPi.nodejs_latest

Also fails with nodejs-slim, nodejs-12_x, nodejs-14_x, etc.

Expected behavior

The package to be built successfully.

Additional context

The problem seems to be that binaries, notably out/Release/bytecode_builtins_list_generator, need to be built with the build environment toolchain, not the host toolchain. Node's build process allows specification of the location of the necessary build compilers via environment variables (AR_host, CXX_host, CC_host, LINK_host, CXXFLAGS_host and LDFLAGS_host are mentioned in one of the links below).

nodejs/node#32717 seems relevant, as does nodejs/node#24317. The latter mentions buildroot getting this right, here's what they do.

Notify maintainers

@goibhniu @gilligan @cko @marsam

Metadata

Please run nix-shell -p nix-info --run "nix-info -m" and paste the result.

[root@nixos-builder:~]# nix-shell -p nix-info --run "nix-info -m"
 - system: `"x86_64-linux"`
 - host os: `Linux 5.10.74, NixOS, 21.05.3892.70904d4a992 (Okapi)`
 - multi-user?: `yes`
 - sandbox: `yes`
 - version: `nix-env (Nix) 2.3.16`
 - channels(root): `"nixos-21.05.3892.70904d4a992, unstable-21.11pre323695.9aeeb7574fb"`
 - nixpkgs: `/nix/var/nix/profiles/per-user/root/channels/nixos`

Maintainer information:

# a list of nixpkgs attributes affected by the problem
attribute:

# a list of nixos modules affected by the problem
module:
@dwf dwf added the 0.kind: bug Something is broken label Oct 23, 2021
@dwf
Copy link
Contributor Author

dwf commented Oct 30, 2021

Adding additional context to this: I've successfully been able to build by using an i686 build platform and the following overlay:

    nodejs-cross = super.nodejs-14_x.overrideAttrs (old: {
      preConfigure = ''
         export CC_host="${self.stdenv.buildPlatform.config}-gcc"
         export CXX_host="${self.stdenv.buildPlatform.config}-g++"
         export LINK_host="${self.stdenv.buildPlatform.config}-g++ -Wl,-lstdc++ -Wl,-lm -B${self.buildPackages.stdenv.glibc}/lib"
      '';
      depsBuildBuild = with self.buildPackages; [ stdenv.cc stdenv.glibc libuv zlib openssl ];
    });

I suspect this isn't quite the right fix though for a number of reasons.

I also wasn't able to find a way to cross-compile from x86-64 to armv6l. It seems one needs a buildPlatform side toolchain with 32-bit support, which would suggest a multiStdenv for the buildPlatform but not the hostPlatform, and I'm not sure how to accomplish that.

@nixos-discourse
Copy link

This issue has been mentioned on NixOS Discourse. There might be relevant details there:

https://discourse.nixos.org/t/cross-compile-nodejs-broken-python-interpreter/18131/2

@Hjdskes
Copy link
Contributor

Hjdskes commented Mar 11, 2022

I am also running into this (the linked Discourse thread is mine). It looks like buildroot fixes this problem by compiling the build tools for the build platform first, and then using those binaries when compiling for the target platform (https://github.com/buildroot/buildroot/blob/master/package/nodejs/nodejs.mk#L105)

Do you have time to look at this, @goibhniu @gilligan @cko @marsam? I am willing to give this a shot but I'll need some pointers to get started...

@dwf
Copy link
Contributor Author

dwf commented Mar 11, 2022

The workaround I found is to replace pkgsCross with pkgsi686Linux.pkgsCross, so that you use x86-32 as the build platform. Not ideal as it requires installing a whole heck of a lot of 32-bit dependencies, but it's a testament to Nix that it works at all.

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

No branches or pull requests

4 participants