···22222323 canExecute = stdenv.buildPlatform.canExecute stdenv.hostPlatform;
2424 emulator = stdenv.hostPlatform.emulator buildPackages;
2525+ canEmulate = stdenv.hostPlatform.emulatorAvailable buildPackages;
2626+ buildNode = buildPackages."${pname}_${majorVersion}";
25272628 # See valid_os and valid_arch in configure.py.
2729 destOS =
···126128 ln -s "$cctools/bin/libtool" "$out/bin/libtool"
127129 '';
128130131131+ # a script which claims to be a different script but switches to simply touching its output
132132+ # when an environment variable is set. See CC_host, --cross-compiling, and postConfigure.
133133+ touchScript = real: writeScript "touch-script" ''
134134+ #!${stdenv.shell}
135135+ if [ -z "$FAKE_TOUCH" ]; then
136136+ exec "${real}" "$@"
137137+ fi
138138+ while [ "$#" != "0" ]; do
139139+ if [ "$1" == "-o" ]; then
140140+ shift
141141+ touch "$1"
142142+ fi
143143+ shift
144144+ done
145145+ '';
146146+129147 package = stdenv.mkDerivation (finalAttrs:
130148 let
131149 /** the final package fixed point, after potential overrides */
···148166 # Note: do not set TERM=dumb environment variable globally, it is used in
149167 # test-ci-js test suite to skip tests that otherwise run fine.
150168 NINJA = "TERM=dumb ninja";
169169+ } // lib.optionalAttrs (!canExecute && !canEmulate) {
170170+ # these are used in the --cross-compiling case. see comment at postConfigure.
171171+ CC_host = touchScript "${buildPackages.stdenv.cc}/bin/cc";
172172+ CXX_host = touchScript "${buildPackages.stdenv.cc}/bin/c++";
173173+ AR_host = touchScript "${buildPackages.stdenv.cc}/bin/ar";
151174 };
152175153176 # NB: technically, we do not need bash in build inputs since all scripts are
···179202 dontUseNinjaCheck = true;
180203 dontUseNinjaInstall = true;
181204182182- outputs = [ "out" "libv8" ];
205205+ outputs = [ "out" "libv8" ] ++ lib.optionals (stdenv.hostPlatform == stdenv.buildPlatform) [ "dev" ];
183206 setOutputFlags = false;
184207 moveToDev = false;
185208···188211 "--ninja"
189212 "--with-intl=system-icu"
190213 "--openssl-use-def-ca-store"
191191- "--no-cross-compiling"
214214+ # --cross-compiling flag enables use of CC_host et. al
215215+ (if canExecute || canEmulate then "--no-cross-compiling" else "--cross-compiling")
192216 "--dest-os=${destOS}"
193217 "--dest-cpu=${destCPU}"
194218 ]
195219 ++ lib.optionals (destARMFPU != null) [ "--with-arm-fpu=${destARMFPU}" ]
196220 ++ lib.optionals (destARMFloatABI != null) [ "--with-arm-float-abi=${destARMFloatABI}" ]
197197- ++ lib.optionals (!canExecute) [
221221+ ++ lib.optionals (!canExecute && canEmulate) [
198222 # Node.js requires matching bitness between build and host platforms, e.g.
199223 # for V8 startup snapshot builder (see tools/snapshot) and some other
200224 # tools. We apply a patch that runs these tools using a host platform
···225249 exec ${python.executable} configure.py "$@"
226250 '';
227251252252+ # In order to support unsupported cross configurations, we copy some intermediate executables
253253+ # from a native build and replace all the build-system tools with a script which simply touches
254254+ # its outfile. We have to indiana-jones-swap the build-system-targeted tools since they are
255255+ # tested for efficacy at configure time.
256256+ postConfigure = lib.optionalString (!canEmulate && !canExecute) ''
257257+ cp ${buildNode.dev}/bin/* out/Release
258258+ export FAKE_TOUCH=1
259259+ '';
260260+228261 enableParallelBuilding = true;
229262230263 # Don't allow enabling content addressed conversion as `nodejs`
···343376 ])}"
344377 ];
345378346346- postInstall = ''
379379+ postInstall = lib.optionalString (stdenv.hostPlatform == stdenv.buildPlatform) ''
380380+ mkdir -p $dev/bin
381381+ cp out/Release/{bytecode_builtins_list_generator,mksnapshot,torque,node_js2c,gen-regexp-special-case} $dev/bin
382382+ '' + ''
383383+347384 HOST_PATH=$out/bin patchShebangs --host $out
348385349386 ${lib.optionalString canExecute ''
···416453 changelog = "https://github.com/nodejs/node/releases/tag/v${version}";
417454 license = licenses.mit;
418455 maintainers = with maintainers; [ aduh95 ];
419419- platforms = platforms.linux ++ platforms.darwin;
456456+ platforms = platforms.linux ++ platforms.darwin ++ platforms.freebsd;
457457+ # This broken condition is likely too conservative. Feel free to loosen it if it works.
458458+ broken = !canExecute && !canEmulate && (stdenv.buildPlatform.parsed.cpu != stdenv.hostPlatform.parsed.cpu);
420459 mainProgram = "node";
421460 knownVulnerabilities = optional (versionOlder version "18") "This NodeJS release has reached its end of life. See https://nodejs.org/en/about/releases/.";
422461 };
+18-2
pkgs/development/web/nodejs/v22.nix
···11-{ callPackage, openssl, python3, enableNpm ? true }:
11+{ lib, stdenv, buildPackages, callPackage, fetchpatch2, openssl, python3, enableNpm ? true }:
2233let
44 buildNodejs = callPackage ./nodejs.nix {
···1010 inherit enableNpm;
1111 version = "22.14.0";
1212 sha256 = "c609946bf793b55c7954c26582760808d54c16185d79cb2fb88065e52de21914";
1313- patches = [
1313+ patches = (if (stdenv.hostPlatform.emulatorAvailable buildPackages) then [
1414 ./configure-emulator.patch
1515+ ] else [
1616+ (fetchpatch2 {
1717+ url = "https://raw.githubusercontent.com/buildroot/buildroot/2f0c31bffdb59fb224387e35134a6d5e09a81d57/package/nodejs/nodejs-src/0003-include-obj-name-in-shared-intermediate.patch";
1818+ hash = "sha256-3g4aS+NmmUYNOYRNc6UMJKYoaTlpP5Knt9UHegx+o0Y=";
1919+ })
2020+ ]) ++ lib.optionals (stdenv.hostPlatform != stdenv.buildPlatform && stdenv.hostPlatform.isFreeBSD) [
2121+ # This patch is concerning.
2222+ # https://github.com/nodejs/node/issues/54576
2323+ # It is only supposed to affect clang >= 17, but I'm seeing it on clang 19.
2424+ # I'm keeping the predicate for this patch pretty strict out of caution,
2525+ # so if you see the error it's supposed to prevent, feel free to loosen it.
2626+ (fetchpatch2 {
2727+ url = "https://raw.githubusercontent.com/rubyjs/libv8-node/62476a398d4c9c1a670240a3b070d69544be3761/patch/v8-no-assert-trivially-copyable.patch";
2828+ hash = "sha256-hSTLljmVzYmc3WAVeRq9EPYluXGXFeWVXkykufGQPVw=";
2929+ })
3030+ ] ++ [
1531 ./configure-armv6-vfpv2.patch
1632 ./disable-darwin-v8-system-instrumentation-node19.patch
1733 ./bypass-darwin-xcrun-node16.patch
+26-2
pkgs/development/web/nodejs/v23.nix
···11{
22 lib,
33 stdenv,
44+ buildPackages,
45 callPackage,
56 fetchpatch2,
67 openssl,
···1920 version = "23.10.0";
2021 sha256 = "b39e5fbd3debb8318ddea6af3e89b07dafb891421fb7ca99fbe19c99adabe5fd";
2122 patches =
2222- [
2323- ./configure-emulator.patch
2323+ (
2424+ if (stdenv.hostPlatform.emulatorAvailable buildPackages) then
2525+ [
2626+ ./configure-emulator.patch
2727+ ]
2828+ else
2929+ [
3030+ (fetchpatch2 {
3131+ url = "https://raw.githubusercontent.com/buildroot/buildroot/2f0c31bffdb59fb224387e35134a6d5e09a81d57/package/nodejs/nodejs-src/0003-include-obj-name-in-shared-intermediate.patch";
3232+ hash = "sha256-3g4aS+NmmUYNOYRNc6UMJKYoaTlpP5Knt9UHegx+o0Y=";
3333+ })
3434+ ]
3535+ )
3636+ ++ lib.optionals (stdenv.hostPlatform != stdenv.buildPlatform && stdenv.hostPlatform.isFreeBSD) [
3737+ # This patch is concerning.
3838+ # https://github.com/nodejs/node/issues/54576
3939+ # It is only supposed to affect clang >= 17, but I'm seeing it on clang 19.
4040+ # I'm keeping the predicate for this patch pretty strict out of caution,
4141+ # so if you see the error it's supposed to prevent, feel free to loosen it.
4242+ (fetchpatch2 {
4343+ url = "https://raw.githubusercontent.com/rubyjs/libv8-node/62476a398d4c9c1a670240a3b070d69544be3761/patch/v8-no-assert-trivially-copyable.patch";
4444+ hash = "sha256-hSTLljmVzYmc3WAVeRq9EPYluXGXFeWVXkykufGQPVw=";
4545+ })
4646+ ]
4747+ ++ [
2448 ./configure-armv6-vfpv2.patch
2549 ./disable-darwin-v8-system-instrumentation-node19.patch
2650 ./bypass-darwin-xcrun-node16.patch