Repository: nodejs/node
Pull request: build: do not depend on V8 deps on `--without-bundled-v8` builds

The test-shared on ARM macOS goes from having to compile 328 things down to 213 – that should speed up a bit more the `test-shared.yml` workflow, and reduce the load on the shared binary cache a bit more (which should help with https://github.com/nodejs/node/issues/61436).

AFAICT it's not possible to build Node.js `--without-bundled-v8` without providing V8 deps, so this change should not break anything, I've added the `dont-land-` labels out of precaution.

<!--
Before submitting a pull request, please read:

- the CONTRIBUTING guide at https://github.com/nodejs/node/blob/HEAD/CONTRIBUTING.md
- the commit message formatting guidelines at
  https://github.com/nodejs/node/blob/HEAD/doc/contributing/pull-requests.md#commit-message-guidelines

For code changes:
1. Include tests for any bug fixes or new features.
2. Update documentation if relevant.
3. Ensure that `make -j4 test` (UNIX), or `vcbuild test` (Windows) passes.

If you believe this PR should be highlighted in the Node.js CHANGELOG
please add the `notable-change` label.

Developer's Certificate of Origin 1.1

By making a contribution to this project, I certify that:

(a) The contribution was created in whole or in part by me and I
    have the right to submit it under the open source license
    indicated in the file; or

(b) The contribution is based upon previous work that, to the best
    of my knowledge, is covered under an appropriate open source
    license and I have the right under that license to submit that
    work with modifications, whether created in whole or in part
    by me, under the same open source license (unless I am
    permitted to submit under a different license), as indicated
    in the file; or

(c) The contribution was provided directly to me by some other
    person who certified (a), (b) or (c) and I have not modified
    it.

(d) I understand and agree that this project and the contribution
    are public and that a record of the contribution (including all
    personal information I submit with it, including my sign-off) is
    maintained indefinitely and may be redistributed consistent with
    this project or the open source license(s) involved.
-->


Changed files:
filename: node.gyp
patch: @@ -895,7 +895,6 @@
         '<(SHARED_INTERMEDIATE_DIR)' # for node_natives.h
       ],
       'dependencies': [
-        'tools/v8_gypfiles/abseil.gyp:abseil',
         'node_js2c#host',
       ],
 
@@ -956,6 +955,9 @@
             'src/node_snapshot_stub.cc',
           ]
         }],
+        [ 'node_use_bundled_v8!="false"', {
+          'dependencies': [ 'tools/v8_gypfiles/abseil.gyp:abseil' ],
+        }],
         [ 'node_shared_gtest=="false"', {
           'dependencies': [
             'deps/googletest/googletest.gyp:gtest_prod',
@@ -1276,7 +1278,6 @@
 
       'dependencies': [
         '<(node_lib_target_name)',
-        'tools/v8_gypfiles/abseil.gyp:abseil',
       ],
 
       'includes': [
@@ -1310,6 +1311,9 @@
         [ 'node_shared_gtest=="true"', {
           'libraries': [ '-lgtest_main' ],
         }],
+        [ 'node_use_bundled_v8!="false"', {
+          'dependencies': [ 'tools/v8_gypfiles/abseil.gyp:abseil' ],
+        }],
         [ 'node_shared_hdr_histogram=="false"', {
           'dependencies': [
             'deps/histogram/histogram.gyp:histogram',
@@ -1548,7 +1552,7 @@
         [ 'OS=="mac"', {
           'libraries': [ '-framework CoreFoundation -framework Security' ],
         }],
-        [ 'node_shared_simdutf=="false"', {
+        [ 'node_shared_simdutf=="false" and node_use_bundled_v8!="false"', {
           'dependencies': [ 'tools/v8_gypfiles/v8.gyp:simdutf#host' ],
         }],
         [ 'node_shared_libuv=="false"', {

filename: node.gypi
patch: @@ -234,7 +234,7 @@
         'dependencies': [ 'deps/simdjson/simdjson.gyp:simdjson' ],
     }],
 
-    [ 'node_shared_simdutf=="false"', {
+    [ 'node_shared_simdutf=="false" and node_use_bundled_v8!="false"', {
         'dependencies': [ 'tools/v8_gypfiles/v8.gyp:simdutf' ],
     }],
 

filename: tools/nix/v8.nix
patch: @@ -8,6 +8,7 @@
 
 let
   nodejs = pkgs.nodejs-slim_latest;
+  v8Dir = ../../deps/v8;
 
   version =
     let
@@ -16,7 +17,7 @@ let
         + "#define V8_MINOR_VERSION ([0-9]+).*"
         + "#define V8_BUILD_NUMBER ([0-9]+).*"
         + "#define V8_PATCH_LEVEL ([0-9]+).*"
-      ) (builtins.readFile ../../deps/v8/include/v8-version.h);
+      ) (builtins.readFile "${v8Dir}/include/v8-version.h");
       v8_embedder_string = builtins.match ".*'v8_embedder_string': '-(node.[0-9]+)'.*" (
         builtins.readFile ../../common.gypi
       );
@@ -41,7 +42,7 @@ pkgs.stdenv.mkDerivation (finalAttrs: {
         ../../configure.py
         ../../deps/inspector_protocol/inspector_protocol.gyp
         ../../deps/ncrypto/ncrypto.gyp
-        ../../deps/v8
+        v8Dir
         ../../node.gyp
         ../../node.gypi
         ../../src/inspector/node_inspector.gypi
@@ -89,7 +90,7 @@ pkgs.stdenv.mkDerivation (finalAttrs: {
   '';
   installPhase = ''
     ${
-      if pkgs.stdenv.buildPlatform.isDarwin then
+      if pkgs.stdenv.hostPlatform.isDarwin then
         # Darwin is excluded from creating thin archive in tools/gyp/pylib/gyp/generator/ninja.py:2488
         "install -Dm644 out/Release/lib* -t $out/lib"
       else
@@ -109,22 +110,17 @@ pkgs.stdenv.mkDerivation (finalAttrs: {
           done
         ''
     }
-    libs=$(for f in $out/lib/lib*.a; do
-      b=$(basename "$f" .a)
-      printf " -l%s" "''${b#lib}"
-    done)
-
-    # copy v8 headers
-    cp -r deps/v8/include $out/
 
-    # create a pkgconfig file for v8
     mkdir -p $out/lib/pkgconfig
     cat -> $out/lib/pkgconfig/v8.pc << EOF
     Name: v8
     Description: V8 JavaScript Engine build for Node.js CI
     Version: ${version}
-    Libs: -L$out/lib $libs
-    Cflags: -I$out/include
+    Libs: -L$out/lib $(for f in $out/lib/lib*.a; do
+      b=$(basename "$f" .a)
+      printf " -l%s" "''${b#lib}"
+    done) -lstdc++
+    Cflags: -I${v8Dir}/include -I${v8Dir}/third_party/abseil-cpp -I${v8Dir}/third_party/simdutf
     EOF
   '';
 })