NixOS / nixpkgs

Nix Packages collection & NixOS
MIT License
17.31k stars 13.54k forks source link

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

Open jue89 opened 2 months ago

jue89 commented 2 months ago

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 :+1: reaction to issues you find important.

jue89 commented 2 months ago

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 commented 1 month ago

I think PR #220204 addresses this issue.

tie commented 1 month ago

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 https://github.com/nodejs/node/issues/44357).

I’m not familiar with Raspberry Pi hardware, but if it supports vfpv2, I think it makes sense to update the platform preset: https://github.com/NixOS/nixpkgs/blob/43d306e7db4f7e8914de693a2d7c223f38c0a8f7/lib/systems/platforms.nix#L205

jue89 commented 1 month ago

https://github.com/NixOS/nixpkgs/pull/327778#issuecomment-2236365814

tie commented 1 month ago

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 https://github.com/nodejs/node/issues/44357.

W.r.t. your comment https://github.com/NixOS/nixpkgs/pull/327778#issuecomment-2236365814 (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 commented 1 month ago

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 commented 1 month ago

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 commented 1 month ago

Ah and it'll use qemu for compiling nodejs?

Nice! Thank you a lot :)

tie commented 1 month ago

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 commented 3 weeks ago

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