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

Build failure: nodejs cross compiling for raspberry pi armv6l #319036

Closed
jue89 opened this issue Jun 11, 2024 · 11 comments
Closed

Build failure: nodejs cross compiling for raspberry pi armv6l #319036

jue89 opened this issue Jun 11, 2024 · 11 comments
Labels
0.kind: build failure A package fails to build 6.topic: cross-compilation Building packages on a different platform than they will be used on

Comments

@jue89
Copy link
Contributor

jue89 commented Jun 11, 2024

Steps To Reproduce

Steps to reproduce the behavior on current master:

nix build github:NixOS/nixpkgs/14391a5980458824bbe541d48fb1e5c47f662bc4#legacyPackages.x86_64-linux.pkgsCross.raspberryPi.nodejs

Build log

error: builder for '/nix/store/7fswdflambmfdd759zvrjwrjkqpndlsy-nodejs-armv6l-unknown-linux-gnueabihf-20.12.2.drv' failed with exit code 2;
       last 10 log lines:
       >                  from /nix/store/14c6s4xzhy14i2b05s00rjns2j93gzz4-gcc-13.2.0/include/c++/13.2.0/atomic:41,
       >                  from ../deps/v8/src/libplatform/default-job.h:8,
       >                  from ../deps/v8/src/libplatform/default-job.cc:5:
       > /nix/store/fwh4fxd747m0py3ib3s5abamia9nrf90-glibc-2.39-52-dev/include/gnu/stubs.h:7:11: fatal error: gnu/stubs-32.h: No such file or directory
       >     7 | # include <gnu/stubs-32.h>
       >       |           ^~~~~~~~~~~~~~~~
       > compilation terminated.
       > make[1]: *** [tools/v8_gypfiles/v8_libplatform.host.mk:165: /build/node-v20.12.2/out/Release/obj.host/v8_libplatform/deps/v8/src/libplatform/default-job.o] Error 1
       > rm fab9cb8c89b21d255a082353fbb474ab1680b6f2.intermediate fb66f3594c458ae33beb8e684d290a388f861f36.intermediate
       > make: *** [Makefile:134: node] Error 2
       For full logs, run 'nix log /nix/store/7fswdflambmfdd759zvrjwrjkqpndlsy-nodejs-armv6l-unknown-linux-gnueabihf-20.12.2.drv'.

Additional context

Notify maintainers

@cillianderoiste
@cko
@aduh95

Metadata

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

[user@system:~]$ nix-shell -p nix-info --run "nix-info -m"
 - system: `"x86_64-linux"`
 - host os: `Linux 6.1.91, NixOS, 23.11 (Tapir), 23.11.20240525.9d29cd2`
 - multi-user?: `yes`
 - sandbox: `yes`
 - version: `nix-env (Nix) 2.18.1`
 - nixpkgs: `/nix/var/nix/profiles/per-user/root/channels/nixos`

Add a 👍 reaction to issues you find important.

@jue89 jue89 added the 0.kind: build failure A package fails to build label Jun 11, 2024
@eclairevoyant eclairevoyant added the 6.topic: cross-compilation Building packages on a different platform than they will be used on label Jun 11, 2024
@jue89
Copy link
Contributor Author

jue89 commented Jun 13, 2024

I hacked around this problem:

    preBuild = lib.optionalString isCross ''
      mkdir deps/v8/gnu
      touch deps/v8/gnu/stubs-32.h
    '';

This actually seems to work!

But now I run into a new Problem:

/nix/store/bgcaxhhxswzvmxjbbgvvaximm5hwghz1-binutils-2.41/bin/ld: /build/node-v20.12.2/out/Release/obj.host/deps/simdutf/libsimdutf.a: error adding symbols: archive has no index; run ranlib to add one
collect2: error: ld returned 1 exit status

Has anyone an idea how to fix this?

@tie
Copy link
Member

tie commented Jul 15, 2024

I think PR #220204 addresses this issue.

@tie tie mentioned this issue Jul 16, 2024
16 tasks
@tie
Copy link
Member

tie commented Jul 17, 2024

FWIW, for some reason raspberryPi is defined as gcc.fpu = "vfp" instead of vfpv2 in Nixpkgs.

https://wiki.debian.org/RaspberryPi#:~:text=The%20CPU%20in%20the%20Raspberry%20Pi,VFP2%29

I don’t think Node.js supports (armv6, vfp) combination (see nodejs/node#44357).

I’m not familiar with Raspberry Pi hardware, but if it supports vfpv2, I think it makes sense to update the platform preset:

fpu = "vfp";

@jue89
Copy link
Contributor Author

jue89 commented Jul 18, 2024

#327778 (comment)

@tie
Copy link
Member

tie commented Jul 18, 2024

I experimented with this a bit yesterday and I think setting gcc.arch = "armv6kz" alone should be enough for Node.js (though I also had gcc.fpu = "vfpv2" set so I can’t say that with 100% confidence). Note that Node.js needs yield instructions that are not available for armv6 and require at least armv6k (see https://redd.it/144sh53). According to Raspberry Pi specifications on the Wikipedia article, it is ARMv6Z (K implied as far as I understand). See also https://reviews.llvm.org/D14568 and nodejs/node#44357.

W.r.t. your comment #327778 (comment) (i.e. building Node.js for pkgsCross.raspberryPi with updated gcc arch/fpu), use #327653. The current Node.js derivation always cross-compiles, but that doesn’t work well for platforms with different bitness (e.g. AArch64 to AArch32). The PR in question makes it so that we don’t cross-compile and instead use an emulator when we need to run a few tools built for the host platform.

@jue89
Copy link
Contributor Author

jue89 commented Jul 18, 2024

Sry - I'm not an expert ... so building directly for the RPi's architecture using qemu / binfmt should create a working binary, right? I'll give this a try but I'll take some hours (or maybe days?) ;-)

@tie
Copy link
Member

tie commented Jul 18, 2024

It should take a few hours or so on a modern multi-core computer (though the PR is targeting staging and there is a bit of bottlenecking in the bootstrap process). E.g. something like

let
  system = builtins.currentSystem;
  lib = import ./lib;
  nixpkgsFun = import ./.;
  pkgs = nixpkgsFun {
    localSystem = { inherit system; };
    crossSystem = lib.systems.examples.raspberryPi // {
      gcc = {
        arch = "armv6kz";
        fpu = "vfpv2";
      };
    };
  };
in
pkgs.nodejs_22

(at the root of Nixpkgs repository checkout with #327653 applied)

@jue89
Copy link
Contributor Author

jue89 commented Jul 18, 2024

Ah and it'll use qemu for compiling nodejs?

Nice! Thank you a lot :)

@tie
Copy link
Member

tie commented Jul 18, 2024

Ah and it'll use qemu for compiling nodejs?

Yes, stdenv.hostPlatform.emulator buildPackages to be exact (that happens to be user mode QEMU when building Linux → Linux).

@tie
Copy link
Member

tie commented Aug 13, 2024

Should be fixed in #327653, but I’ll keep the issue open until we get a decision on #327778.

@jue89
Copy link
Contributor Author

jue89 commented Sep 19, 2024

$ nix build github:NixOS/nixpkgs/99dc8785f6a0adac95f5e2ab05cc2e1bf666d172#pkgsCross.raspberryPi.nodejs
$ file ./result/bin/node
./result/bin/node: ELF 32-bit LSB executable, ARM, EABI5 version 1 (GNU/Linux), dynamically linked, interpreter /nix/store/ba6dqdyljyj5hjny4z9dpxfbwmlhd2pn-glibc-armv6l-unknown-linux-gnueabihf-2.39-52/lib/ld-linux-armhf.so.3, for GNU/Linux 3.10.0, not stripped
$ ./result/bin/node --version
v20.17.0

I'd say this issue has been solved! Thank you all for your effort to fix the build issue :-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
0.kind: build failure A package fails to build 6.topic: cross-compilation Building packages on a different platform than they will be used on
Projects
None yet
Development

No branches or pull requests

3 participants