From d162d8e50de274431d97bcf28c70751481e2ca82 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 This change cleans up build inputs and adjusts the build to use ninja. --- .../nodejs/bypass-darwin-xcrun-node16.patch | 39 +++++++++++- pkgs/development/web/nodejs/nodejs.nix | 60 +++++++++++++++---- 2 files changed, 86 insertions(+), 13 deletions(-) diff --git a/pkgs/development/web/nodejs/bypass-darwin-xcrun-node16.patch b/pkgs/development/web/nodejs/bypass-darwin-xcrun-node16.patch index e86fcc4d2973..ba998c0510be 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 b89fe4853091..cda26e84ab30 100644 --- a/pkgs/development/web/nodejs/nodejs.nix +++ b/pkgs/development/web/nodejs/nodejs.nix @@ -1,12 +1,12 @@ { lib, stdenv, fetchurl, openssl, python, zlib, libuv, http-parser, icu, bash -, pkg-config, which, buildPackages +, ninja, pkgconf, unixtools, runCommand, buildPackages , testers # for `.pkgs` attribute , callPackage # Updater dependencies , writeScript, coreutils, gnugrep, jq, curl, common-updater-scripts, nix, runtimeShell , gnupg -, darwin, xcbuild +, darwin , installShellFiles }: @@ -104,6 +104,20 @@ 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 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. 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 buildPackages.cctools; } '' + mkdir -p "$out/bin" + ln -s "$cctools/bin/libtool" "$out/bin/libtool" + ''; + package = stdenv.mkDerivation (finalAttrs: let /** the final package fixed point, after potential overrides */ @@ -128,11 +142,30 @@ let # 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 ] + buildInputs = lib.optionals stdenv.hostPlatform.isDarwin [ CoreServices ApplicationServices ] ++ [ zlib libuv openssl http-parser icu bash ]; - 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; @@ -140,6 +173,9 @@ let configureFlags = [ + "--ninja" + "--with-intl=system-icu" + "--openssl-use-def-ca-store" "--no-cross-compiling" "--dest-os=${destOS}" "--dest-cpu=${destCPU}" @@ -167,11 +203,7 @@ let FIXME: the statement above is outdated, we have to include pkg-config in build inputs for system-icu. */ - ]) (builtins.attrNames sharedLibDeps) - ++ [ - "--with-intl=system-icu" - "--openssl-use-def-ca-store" - ]; + ]) (builtins.attrNames sharedLibDeps); configurePlatforms = [ ]; @@ -183,6 +215,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: @@ -299,7 +337,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