From 92ca419965ad85d4bd1c2cba051f152fb7c3ed00 Mon Sep 17 00:00:00 2001 From: Ivan Trubach Date: Tue, 16 Jul 2024 15:14:51 +0300 Subject: [PATCH] nodejs: use ninja for build --- .../nodejs/bypass-darwin-xcrun-node16.patch | 39 +++++- pkgs/development/web/nodejs/nodejs.nix | 111 +++++++++++++++--- 2 files changed, 130 insertions(+), 20 deletions(-) diff --git a/pkgs/development/web/nodejs/bypass-darwin-xcrun-node16.patch b/pkgs/development/web/nodejs/bypass-darwin-xcrun-node16.patch index e86fcc4d2973d84..ba998c0510be000 100644 --- a/pkgs/development/web/nodejs/bypass-darwin-xcrun-node16.patch +++ b/pkgs/development/web/nodejs/bypass-darwin-xcrun-node16.patch @@ -1,7 +1,42 @@ Avoids needing xcrun or xcodebuild in PATH for native package builds -diff --git a/deps/npm/node_modules/node-gyp/gyp/pylib/gyp/xcode_emulation.py b/deps/npm/node_modules/node-gyp/gyp/pylib/gyp/xcode_emulation.py -index a75d8ee..476440d 100644 +--- a/tools/gyp/pylib/gyp/xcode_emulation.py ++++ b/tools/gyp/pylib/gyp/xcode_emulation.py +@@ -522,7 +522,13 @@ class XcodeSettings: + # Since the CLT has no SDK paths anyway, returning None is the + # most sensible route and should still do the right thing. + try: +- return GetStdoutQuiet(["xcrun", "--sdk", sdk, infoitem]) ++ #return GetStdoutQuiet(["xcrun", "--sdk", sdk, infoitem]) ++ return { ++ "--show-sdk-platform-path": "/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform", ++ "--show-sdk-path": "/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.15.sdk", ++ "--show-sdk-build-version": "19A547", ++ "--show-sdk-version": "10.15" ++ }[infoitem] + except GypError: + pass + +@@ -1499,7 +1505,8 @@ def XcodeVersion(): + version = "" + build = "" + try: +- version_list = GetStdoutQuiet(["xcodebuild", "-version"]).splitlines() ++ #version_list = GetStdoutQuiet(["xcodebuild", "-version"]).splitlines() ++ version_list = [] + # In some circumstances xcodebuild exits 0 but doesn't return + # the right results; for example, a user on 10.7 or 10.8 with + # a bogus path set via xcode-select +@@ -1510,7 +1517,8 @@ def XcodeVersion(): + version = version_list[0].split()[-1] # Last word on first line + build = version_list[-1].split()[-1] # Last word on last line + except GypError: # Xcode not installed so look for XCode Command Line Tools +- version = CLTVersion() # macOS Catalina returns 11.0.0.0.1.1567737322 ++ #version = CLTVersion() # macOS Catalina returns 11.0.0.0.1.1567737322 ++ version = "11.0.0.0.1.1567737322" + if not version: + raise GypError("No Xcode or CLT version detected!") + # Be careful to convert "4.2.3" to "0423" and "11.0.0" to "1100": --- a/deps/npm/node_modules/node-gyp/gyp/pylib/gyp/xcode_emulation.py +++ b/deps/npm/node_modules/node-gyp/gyp/pylib/gyp/xcode_emulation.py @@ -522,7 +522,13 @@ class XcodeSettings: diff --git a/pkgs/development/web/nodejs/nodejs.nix b/pkgs/development/web/nodejs/nodejs.nix index 473f5be94f0f8cf..9f02b291218058f 100644 --- a/pkgs/development/web/nodejs/nodejs.nix +++ b/pkgs/development/web/nodejs/nodejs.nix @@ -1,13 +1,34 @@ -{ lib, stdenv, fetchurl, openssl, python, zlib, libuv, http-parser, icu, bash -, pkg-config, which, buildPackages -, testers -# for `.pkgs` attribute -, callPackage -# Updater dependencies -, writeScript, coreutils, gnugrep, jq, curl, common-updater-scripts, nix, runtimeShell -, gnupg -, darwin, xcbuild -, installShellFiles +{ + lib, + stdenv, + fetchurl, + ninja, + pkgconf, + darwin, + unixtools, + runCommand, + buildPackages, + installShellFiles, + openssl, + python, + zlib, + libuv, + http-parser, + icu, + bash, + testers, + # for `.pkgs` attribute + callPackage, + # Updater dependencies + writeScript, + coreutils, + gnugrep, + jq, + curl, + common-updater-scripts, + nix, + runtimeShell, + gnupg, }: { enableNpm ? true, version, sha256, patches ? [] } @args: @@ -78,6 +99,23 @@ let (name: "${lib.getDev sharedLibDeps.${name}}/include/*") (builtins.attrNames sharedLibDeps); + # Currently stdenv sets CC/LD/AR/etc environment variables to program names + # instead of absolute paths. If we add darwin.cctools to nativeBuildInputs, + # that would shadow stdenv’s bintools and potentially break other parts of + # the build. The correct behavior is to use absolute paths, and there is a PR + # for that, see https://github.com/NixOS/nixpkgs/pull/314920. However, the + # review process is painfully slow and at this pace it will take months if not + # years before even the prerequisite PRs are merged. So, as a temporary + # workaround, we use only a single program we need (and that is not part of + # the stdenv). + darwin-cctools-only-libtool = + # Would be nice to have onlyExe builder similar to onlyBin… + runCommand "darwin-cctools-only-libtool" { cctools = lib.getBin darwin.cctools; } + '' + mkdir -p -- "$out"/bin + ln -s -- "$cctools/bin/libtool" "$out/bin/libtool" + ''; + self = stdenv.mkDerivation { inherit pname version; @@ -94,14 +132,44 @@ let NIX_CFLAGS_COMPILE = "-D__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__=101300"; }; - # NB: technically, we do not need bash in build inputs since all scripts are - # wrappers over the corresponding JS scripts. There are some packages though - # that use bash wrappers, e.g. polaris-web. - buildInputs = lib.optionals stdenv.isDarwin [ CoreServices ApplicationServices ] - ++ [ zlib libuv openssl http-parser icu bash ]; + buildInputs = + [ + zlib + libuv + openssl + http-parser + icu + # NB: technically, we do not need bash in build inputs since all scripts are + # wrappers over the corresponding JS scripts. There are some packages though + # that use bash wrappers, e.g. polaris-web. + bash + ] + ++ lib.optionals stdenv.hostPlatform.isDarwin [ + CoreServices + ApplicationServices + ]; - nativeBuildInputs = [ installShellFiles pkg-config python which ] - ++ lib.optionals stdenv.isDarwin [ xcbuild ]; + nativeBuildInputs = + [ + installShellFiles + ninja + pkgconf + python + ] + ++ lib.optionals stdenv.buildPlatform.isDarwin [ + # gyp checks `sysctl -n hw.memsize` if `sys.platform == "darwin"`. + unixtools.sysctl + ] + ++ lib.optionals stdenv.hostPlatform.isDarwin [ + # For gyp-mac-tool if `flavor == "mac"`. + darwin-cctools-only-libtool + ]; + + # We currently rely on Makefile and stdenv for build phases, so do not let + # ninja’s setup hook to override default stdenv phases. + dontUseNinjaBuild = true; + dontUseNinjaCheck = true; + dontUseNinjaInstall = true; outputs = [ "out" "libv8" ]; setOutputFlags = false; @@ -109,6 +177,7 @@ let configureFlags = [ + "--ninja" "--no-cross-compiling" "--dest-os=${destOS}" # Note that ARM features are detected from C macros. MIPS features are @@ -153,6 +222,12 @@ let enableParallelBuilding = true; + makeFlags = [ + # Tell ninja to avoid ANSI sequences, otherwise we don’t see build + # progress in Nix logs. + "TERM=dumb" + ]; + # Don't allow enabling content addressed conversion as `nodejs` # checksums it's image before conversion happens and image loading # breaks: @@ -268,7 +343,7 @@ let # assemble a static v8 library and put it in the 'libv8' output mkdir -p $libv8/lib - pushd out/Release/obj.target + pushd out/Release/obj find . -path "./torque_*/**/*.o" -or -path "./v8*/**/*.o" | sort -u >files $AR -cqs $libv8/lib/libv8.a @files popd