Skip to content

Commit

Permalink
nodejs: use ninja for build
Browse files Browse the repository at this point in the history
  • Loading branch information
tie committed Jul 16, 2024
1 parent 693c7c1 commit 92ca419
Show file tree
Hide file tree
Showing 2 changed files with 130 additions and 20 deletions.
39 changes: 37 additions & 2 deletions pkgs/development/web/nodejs/bypass-darwin-xcrun-node16.patch
Original file line number Diff line number Diff line change
@@ -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:
Expand Down
111 changes: 93 additions & 18 deletions pkgs/development/web/nodejs/nodejs.nix
Original file line number Diff line number Diff line change
@@ -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:
Expand Down Expand Up @@ -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;

Expand All @@ -94,21 +132,52 @@ 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;
moveToDev = false;

configureFlags =
[
"--ninja"
"--no-cross-compiling"
"--dest-os=${destOS}"
# Note that ARM features are detected from C macros. MIPS features are
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 92ca419

Please sign in to comment.