From 679398b160ccb36674b2b21ccf79896daf2d9f70 Mon Sep 17 00:00:00 2001 From: talyz Date: Fri, 26 Nov 2021 13:39:50 +0100 Subject: nodejs: Provide a static v8 library output Since building nodejs also builds v8, one way to get a static v8 library is to manually assemble it from the leftover object files. This seems like an easier way to get an up-to-date v8 library than trying to keep the v8 package updated. --- pkgs/development/web/nodejs/nodejs.nix | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) (limited to 'pkgs/development/web/nodejs') diff --git a/pkgs/development/web/nodejs/nodejs.nix b/pkgs/development/web/nodejs/nodejs.nix index 3f0f0e78e07a..56c83e38c4ff 100644 --- a/pkgs/development/web/nodejs/nodejs.nix +++ b/pkgs/development/web/nodejs/nodejs.nix @@ -58,6 +58,10 @@ let nativeBuildInputs = [ which pkg-config python ] ++ optionals stdenv.isDarwin [ xcbuild ]; + outputs = [ "out" "libv8" ]; + setOutputFlags = false; + moveToDev = false; + configureFlags = let isCross = stdenv.hostPlatform != stdenv.buildPlatform; inherit (stdenv.hostPlatform) gcc isAarch32; @@ -130,6 +134,35 @@ let # install the missing headers for node-gyp cp -r ${concatStringsSep " " copyLibHeaders} $out/include/node + + # assemble a static v8 library and put it in the 'libv8' output + mkdir -p $libv8/lib + pushd out/Release/obj.target + find . -path "./torque_*/**/*.o" -or -path "./v8*/**/*.o" | sort -u >files + ${if stdenv.buildPlatform.isGnu then '' + ar -cqs $libv8/lib/libv8.a @files + '' else '' + cat files | while read -r file; do + ar -cqS $libv8/lib/libv8.a $file + done + ''} + popd + + # copy v8 headers + cp -r deps/v8/include $libv8/ + + # create a pkgconfig file for v8 + major=$(grep V8_MAJOR_VERSION deps/v8/include/v8-version.h | cut -d ' ' -f 3) + minor=$(grep V8_MINOR_VERSION deps/v8/include/v8-version.h | cut -d ' ' -f 3) + patch=$(grep V8_PATCH_LEVEL deps/v8/include/v8-version.h | cut -d ' ' -f 3) + mkdir -p $libv8/lib/pkgconfig + cat > $libv8/lib/pkgconfig/v8.pc << EOF + Name: v8 + Description: V8 JavaScript Engine + Version: $major.$minor.$patch + Libs: -L$libv8/lib -lv8 -pthread -licui18n + Cflags: -I$libv8/include + EOF '' + optionalString (stdenv.isDarwin && enableNpm) '' sed -i 's/raise.*No Xcode or CLT version detected.*/version = "7.0.0"/' $out/lib/node_modules/npm/node_modules/node-gyp/gyp/pylib/gyp/xcode_emulation.py ''; -- cgit 1.4.1