···2223 canExecute = stdenv.buildPlatform.canExecute stdenv.hostPlatform;
24 emulator = stdenv.hostPlatform.emulator buildPackages;
002526 # See valid_os and valid_arch in configure.py.
27 destOS =
···126 ln -s "$cctools/bin/libtool" "$out/bin/libtool"
127 '';
1280000000000000000129 package = stdenv.mkDerivation (finalAttrs:
130 let
131 /** the final package fixed point, after potential overrides */
···148 # Note: do not set TERM=dumb environment variable globally, it is used in
149 # test-ci-js test suite to skip tests that otherwise run fine.
150 NINJA = "TERM=dumb ninja";
00000151 };
152153 # NB: technically, we do not need bash in build inputs since all scripts are
···179 dontUseNinjaCheck = true;
180 dontUseNinjaInstall = true;
181182- outputs = [ "out" "libv8" ];
183 setOutputFlags = false;
184 moveToDev = false;
185···188 "--ninja"
189 "--with-intl=system-icu"
190 "--openssl-use-def-ca-store"
191- "--no-cross-compiling"
0192 "--dest-os=${destOS}"
193 "--dest-cpu=${destCPU}"
194 ]
195 ++ lib.optionals (destARMFPU != null) [ "--with-arm-fpu=${destARMFPU}" ]
196 ++ lib.optionals (destARMFloatABI != null) [ "--with-arm-float-abi=${destARMFloatABI}" ]
197- ++ lib.optionals (!canExecute) [
198 # Node.js requires matching bitness between build and host platforms, e.g.
199 # for V8 startup snapshot builder (see tools/snapshot) and some other
200 # tools. We apply a patch that runs these tools using a host platform
···225 exec ${python.executable} configure.py "$@"
226 '';
227000000000228 enableParallelBuilding = true;
229230 # Don't allow enabling content addressed conversion as `nodejs`
···343 ])}"
344 ];
345346- postInstall = ''
0000347 HOST_PATH=$out/bin patchShebangs --host $out
348349 ${lib.optionalString canExecute ''
···416 changelog = "https://github.com/nodejs/node/releases/tag/v${version}";
417 license = licenses.mit;
418 maintainers = with maintainers; [ aduh95 ];
419- platforms = platforms.linux ++ platforms.darwin;
00420 mainProgram = "node";
421 knownVulnerabilities = optional (versionOlder version "18") "This NodeJS release has reached its end of life. See https://nodejs.org/en/about/releases/.";
422 };
···2223 canExecute = stdenv.buildPlatform.canExecute stdenv.hostPlatform;
24 emulator = stdenv.hostPlatform.emulator buildPackages;
25+ canEmulate = stdenv.hostPlatform.emulatorAvailable buildPackages;
26+ buildNode = buildPackages."${pname}_${majorVersion}";
2728 # See valid_os and valid_arch in configure.py.
29 destOS =
···128 ln -s "$cctools/bin/libtool" "$out/bin/libtool"
129 '';
130131+ # a script which claims to be a different script but switches to simply touching its output
132+ # when an environment variable is set. See CC_host, --cross-compiling, and postConfigure.
133+ touchScript = real: writeScript "touch-script" ''
134+ #!${stdenv.shell}
135+ if [ -z "$FAKE_TOUCH" ]; then
136+ exec "${real}" "$@"
137+ fi
138+ while [ "$#" != "0" ]; do
139+ if [ "$1" == "-o" ]; then
140+ shift
141+ touch "$1"
142+ fi
143+ shift
144+ done
145+ '';
146+147 package = stdenv.mkDerivation (finalAttrs:
148 let
149 /** the final package fixed point, after potential overrides */
···166 # Note: do not set TERM=dumb environment variable globally, it is used in
167 # test-ci-js test suite to skip tests that otherwise run fine.
168 NINJA = "TERM=dumb ninja";
169+ } // lib.optionalAttrs (!canExecute && !canEmulate) {
170+ # these are used in the --cross-compiling case. see comment at postConfigure.
171+ CC_host = touchScript "${buildPackages.stdenv.cc}/bin/cc";
172+ CXX_host = touchScript "${buildPackages.stdenv.cc}/bin/c++";
173+ AR_host = touchScript "${buildPackages.stdenv.cc}/bin/ar";
174 };
175176 # NB: technically, we do not need bash in build inputs since all scripts are
···202 dontUseNinjaCheck = true;
203 dontUseNinjaInstall = true;
204205+ outputs = [ "out" "libv8" ] ++ lib.optionals (stdenv.hostPlatform == stdenv.buildPlatform) [ "dev" ];
206 setOutputFlags = false;
207 moveToDev = false;
208···211 "--ninja"
212 "--with-intl=system-icu"
213 "--openssl-use-def-ca-store"
214+ # --cross-compiling flag enables use of CC_host et. al
215+ (if canExecute || canEmulate then "--no-cross-compiling" else "--cross-compiling")
216 "--dest-os=${destOS}"
217 "--dest-cpu=${destCPU}"
218 ]
219 ++ lib.optionals (destARMFPU != null) [ "--with-arm-fpu=${destARMFPU}" ]
220 ++ lib.optionals (destARMFloatABI != null) [ "--with-arm-float-abi=${destARMFloatABI}" ]
221+ ++ lib.optionals (!canExecute && canEmulate) [
222 # Node.js requires matching bitness between build and host platforms, e.g.
223 # for V8 startup snapshot builder (see tools/snapshot) and some other
224 # tools. We apply a patch that runs these tools using a host platform
···249 exec ${python.executable} configure.py "$@"
250 '';
251252+ # In order to support unsupported cross configurations, we copy some intermediate executables
253+ # from a native build and replace all the build-system tools with a script which simply touches
254+ # its outfile. We have to indiana-jones-swap the build-system-targeted tools since they are
255+ # tested for efficacy at configure time.
256+ postConfigure = lib.optionalString (!canEmulate && !canExecute) ''
257+ cp ${buildNode.dev}/bin/* out/Release
258+ export FAKE_TOUCH=1
259+ '';
260+261 enableParallelBuilding = true;
262263 # Don't allow enabling content addressed conversion as `nodejs`
···376 ])}"
377 ];
378379+ postInstall = lib.optionalString (stdenv.hostPlatform == stdenv.buildPlatform) ''
380+ mkdir -p $dev/bin
381+ cp out/Release/{bytecode_builtins_list_generator,mksnapshot,torque,node_js2c,gen-regexp-special-case} $dev/bin
382+ '' + ''
383+384 HOST_PATH=$out/bin patchShebangs --host $out
385386 ${lib.optionalString canExecute ''
···453 changelog = "https://github.com/nodejs/node/releases/tag/v${version}";
454 license = licenses.mit;
455 maintainers = with maintainers; [ aduh95 ];
456+ platforms = platforms.linux ++ platforms.darwin ++ platforms.freebsd;
457+ # This broken condition is likely too conservative. Feel free to loosen it if it works.
458+ broken = !canExecute && !canEmulate && (stdenv.buildPlatform.parsed.cpu != stdenv.hostPlatform.parsed.cpu);
459 mainProgram = "node";
460 knownVulnerabilities = optional (versionOlder version "18") "This NodeJS release has reached its end of life. See https://nodejs.org/en/about/releases/.";
461 };