Commit 8612d93aed9 for nodejs

commit 8612d93aed9491b13da3473d99f4ae4c6b3b8e21
Author: Joyee Cheung <joyeec9h3@gmail.com>
Date:   Wed Dec 2 16:36:06 2026 +0100

    build: add --shared-v8-zlib to share the zlib copy in V8

    Previously, --shared-zlib only affects the Node.js internals, but V8
    still uses a bundled copy. This new configure option makes that part
    shared as well. This is implied by --shared-zlib by default but
    can be turned off independently with --no-shared-v8-zlib.

    Signed-off-by: Joyee Cheung <joyeec9h3@gmail.com>
    PR-URL: https://github.com/nodejs/node/pull/67828
    Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
    Reviewed-By: Richard Lau <richard.lau@ibm.com>

diff --git a/configure.py b/configure.py
index bc9ae3fab6c..66cc89a2cc8 100755
--- a/configure.py
+++ b/configure.py
@@ -600,6 +600,13 @@ shared_optgroup.add_argument('--shared-zlib-libpath',
     dest='shared_zlib_libpath',
     help='a directory to search for the shared zlib DLL')

+shared_optgroup.add_argument('--shared-v8-zlib',
+    action=argparse.BooleanOptionalAction,
+    dest='shared_v8_zlib',
+    default=None,
+    help='in addition to Node.js internals, link V8 to the shared zlib, '
+         'requires --shared-zlib, by default it follows --shared-zlib')
+
 shared_optgroup.add_argument('--shared-simdjson',
     action='store_true',
     dest='shared_simdjson',
@@ -2301,6 +2308,13 @@ def configure_library(lib, output, pkgname=None, libraries_key='libraries', with
       libraries += [f'-l{l}' for l in pkg] if isinstance(pkg, list) else f'-l${pkg}'


+def configure_v8_zlib(o):
+  if options.shared_v8_zlib is None:
+    options.shared_v8_zlib = bool(options.shared_zlib)
+  elif options.shared_v8_zlib and not options.shared_zlib:
+    error('--shared-v8-zlib requires --shared-zlib')
+  o['variables']['node_shared_v8_zlib'] = b(options.shared_v8_zlib)
+
 def configure_v8(o, configs):
   set_configuration_variable(configs, 'v8_enable_v8_checks', release=0, debug=1)

@@ -2990,6 +3004,7 @@ configure_node_lib_files(output)
 configure_node_cctest_sources(output)
 configure_napi(output)
 configure_library('zlib', output, with_separate_include_var=True)
+configure_v8_zlib(output)
 configure_library('http_parser', output, pkgname='libllhttp')
 configure_library('libuv', output, with_separate_include_var=True)
 configure_library('abseil', output, pkgname=[
diff --git a/node.gyp b/node.gyp
index c5f3c99dedc..3d7c29c6bdb 100644
--- a/node.gyp
+++ b/node.gyp
@@ -34,6 +34,7 @@
     'node_shared_ffi%': 'false',
     'node_shared_temporal_capi%': 'false',
     'node_shared_uvwasi%': 'false',
+    'node_shared_v8_zlib%': 'false',
     'node_shared_zlib%': 'false',
     'node_shared_zstd%': 'false',
     'node_shared%': 'false',
diff --git a/shell.nix b/shell.nix
index a42f70ed7b5..930d762cd80 100644
--- a/shell.nix
+++ b/shell.nix
@@ -65,6 +65,7 @@ let
     "perfetto"
     "simdutf"
     "temporal_capi"
+    "zlib"
   ]);

   nativeBuildInputs =
diff --git a/tools/nix/non-v8-deps-mock.nix b/tools/nix/non-v8-deps-mock.nix
index 5275c829767..f1ed515adaa 100644
--- a/tools/nix/non-v8-deps-mock.nix
+++ b/tools/nix/non-v8-deps-mock.nix
@@ -8,7 +8,6 @@

 let
   sharedLibsToMock = {
-    zlib = [ "zlib" ];
     http-parser = [ "libllhttp" ];
     libuv = [ "libuv" ];
     ada = [ "ada" ];
diff --git a/tools/nix/v8.nix b/tools/nix/v8.nix
index 9b8961457f4..91d978b4e9c 100644
--- a/tools/nix/v8.nix
+++ b/tools/nix/v8.nix
@@ -28,6 +28,7 @@ let
   useSharedPerfetto = builtins.elem "--shared-perfetto" configureFlags;
   useSharedSimdutf = builtins.elem "--shared-simdutf" configureFlags;
   useSharedTemporal = builtins.elem "--shared-temporal_capi" configureFlags;
+  useSharedZlib = builtins.elem "--shared-zlib" configureFlags;

   src =
     let
@@ -50,6 +51,7 @@ let
       ++ lib.optional (!useSharedAbseil) ../../tools/v8_gypfiles/abseil.gyp
       ++ lib.optional (!useSharedHighway) ../../tools/v8_gypfiles/highway.gyp
       ++ lib.optional (!useSharedSimdutf) ../../tools/v8_gypfiles/simdutf.gyp
+      ++ lib.optional useSharedZlib ../../tools/v8_gypfiles/shared_zlib
       ++ lib.optional (
         if useSharedTemporal then
           icu == null
diff --git a/tools/v8_gypfiles/shared_zlib/third_party/zlib/zlib.h b/tools/v8_gypfiles/shared_zlib/third_party/zlib/zlib.h
new file mode 100644
index 00000000000..e60eb7b0532
--- /dev/null
+++ b/tools/v8_gypfiles/shared_zlib/third_party/zlib/zlib.h
@@ -0,0 +1,4 @@
+// In V8 zlib is included as "third_party/zlib/zlib.h", which
+// resolves under <(V8_ROOT). When zlib is shared, use the shim
+// to forward to external zlib headers like the rest of Node.js.
+#include <zlib.h>
diff --git a/tools/v8_gypfiles/v8.gyp b/tools/v8_gypfiles/v8.gyp
index 2668d623e63..e846ac22d39 100644
--- a/tools/v8_gypfiles/v8.gyp
+++ b/tools/v8_gypfiles/v8.gyp
@@ -50,6 +50,12 @@
       }
     },
     'conditions': [
+      # In V8 zlib is included as "third_party/zlib/zlib.h", which
+      # resolves under <(V8_ROOT). When zlib is shared, the shim directory
+      # that forwards to the external header should come first.
+      ['node_shared_v8_zlib=="true"', {
+        'include_dirs+': ['shared_zlib'],
+      }],
       # Build with -fvisibility=hidden and -fvisibility-inlines-hidden to avoid
       # including unnecessary internal symbols, which may lead to run-time fixups.
       # This is not done on AIX where symbols are exported by tools/create_expfile.sh
@@ -2451,63 +2457,74 @@
       'target_name': 'v8_zlib',
       'type': 'static_library',
       'toolsets': ['host', 'target'],
-      'conditions': [
-        ['OS=="win"', {
-          'conditions': [
-            ['"<(target_arch)"=="arm64" and _toolset=="target"', {
-              'defines': ['CPU_NO_SIMD']
-            }, {
-              'defines': ['X86_WINDOWS']
-            }]
-          ]
-        }],
-      ],
-      'direct_dependent_settings': {
-        'include_dirs': [
-          '<(V8_ROOT)/third_party/zlib',
-          '<(V8_ROOT)/third_party/zlib/google',
-        ],
-      },
-      'defines': [ 'ZLIB_IMPLEMENTATION' ],
-      'include_dirs': [
-        '<(V8_ROOT)/third_party/zlib',
-        '<(V8_ROOT)/third_party/zlib/google',
-      ],
       'sources': [
-        '<(V8_ROOT)/third_party/zlib/adler32.c',
-        '<(V8_ROOT)/third_party/zlib/chromeconf.h',
-        '<(V8_ROOT)/third_party/zlib/compress.c',
-        '<(V8_ROOT)/third_party/zlib/contrib/optimizations/insert_string.h',
-        '<(V8_ROOT)/third_party/zlib/contrib/optimizations/insert_string.h',
-        '<(V8_ROOT)/third_party/zlib/cpu_features.c',
-        '<(V8_ROOT)/third_party/zlib/cpu_features.h',
-        '<(V8_ROOT)/third_party/zlib/crc32.c',
-        '<(V8_ROOT)/third_party/zlib/crc32.h',
-        '<(V8_ROOT)/third_party/zlib/deflate.c',
-        '<(V8_ROOT)/third_party/zlib/deflate.h',
-        '<(V8_ROOT)/third_party/zlib/gzclose.c',
-        '<(V8_ROOT)/third_party/zlib/gzguts.h',
-        '<(V8_ROOT)/third_party/zlib/gzlib.c',
-        '<(V8_ROOT)/third_party/zlib/gzread.c',
-        '<(V8_ROOT)/third_party/zlib/gzwrite.c',
-        '<(V8_ROOT)/third_party/zlib/infback.c',
-        '<(V8_ROOT)/third_party/zlib/inffast.c',
-        '<(V8_ROOT)/third_party/zlib/inffast.h',
-        '<(V8_ROOT)/third_party/zlib/inffixed.h',
-        '<(V8_ROOT)/third_party/zlib/inflate.c',
-        '<(V8_ROOT)/third_party/zlib/inflate.h',
-        '<(V8_ROOT)/third_party/zlib/inftrees.c',
-        '<(V8_ROOT)/third_party/zlib/inftrees.h',
-        '<(V8_ROOT)/third_party/zlib/trees.c',
-        '<(V8_ROOT)/third_party/zlib/trees.h',
-        '<(V8_ROOT)/third_party/zlib/uncompr.c',
-        '<(V8_ROOT)/third_party/zlib/zconf.h',
-        '<(V8_ROOT)/third_party/zlib/zlib.h',
-        '<(V8_ROOT)/third_party/zlib/zutil.c',
-        '<(V8_ROOT)/third_party/zlib/zutil.h',
         '<(V8_ROOT)/third_party/zlib/google/compression_utils_portable.cc',
         '<(V8_ROOT)/third_party/zlib/google/compression_utils_portable.h',
       ],
+      'conditions': [
+        ['node_shared_v8_zlib=="false"', {
+          'conditions': [
+            ['OS=="win"', {
+              'conditions': [
+                ['"<(target_arch)"=="arm64" and _toolset=="target"', {
+                  'defines': ['CPU_NO_SIMD']
+                }, {
+                  'defines': ['X86_WINDOWS']
+                }]
+              ]
+            }],
+          ],
+          'direct_dependent_settings': {
+            'include_dirs': [
+              '<(V8_ROOT)/third_party/zlib',
+              '<(V8_ROOT)/third_party/zlib/google',
+            ],
+          },
+          'defines': [ 'ZLIB_IMPLEMENTATION' ],
+          'include_dirs': [
+            '<(V8_ROOT)/third_party/zlib',
+            '<(V8_ROOT)/third_party/zlib/google',
+          ],
+          'sources': [
+            '<(V8_ROOT)/third_party/zlib/adler32.c',
+            '<(V8_ROOT)/third_party/zlib/chromeconf.h',
+            '<(V8_ROOT)/third_party/zlib/compress.c',
+            '<(V8_ROOT)/third_party/zlib/contrib/optimizations/insert_string.h',
+            '<(V8_ROOT)/third_party/zlib/contrib/optimizations/insert_string.h',
+            '<(V8_ROOT)/third_party/zlib/cpu_features.c',
+            '<(V8_ROOT)/third_party/zlib/cpu_features.h',
+            '<(V8_ROOT)/third_party/zlib/crc32.c',
+            '<(V8_ROOT)/third_party/zlib/crc32.h',
+            '<(V8_ROOT)/third_party/zlib/deflate.c',
+            '<(V8_ROOT)/third_party/zlib/deflate.h',
+            '<(V8_ROOT)/third_party/zlib/gzclose.c',
+            '<(V8_ROOT)/third_party/zlib/gzguts.h',
+            '<(V8_ROOT)/third_party/zlib/gzlib.c',
+            '<(V8_ROOT)/third_party/zlib/gzread.c',
+            '<(V8_ROOT)/third_party/zlib/gzwrite.c',
+            '<(V8_ROOT)/third_party/zlib/infback.c',
+            '<(V8_ROOT)/third_party/zlib/inffast.c',
+            '<(V8_ROOT)/third_party/zlib/inffast.h',
+            '<(V8_ROOT)/third_party/zlib/inffixed.h',
+            '<(V8_ROOT)/third_party/zlib/inflate.c',
+            '<(V8_ROOT)/third_party/zlib/inflate.h',
+            '<(V8_ROOT)/third_party/zlib/inftrees.c',
+            '<(V8_ROOT)/third_party/zlib/inftrees.h',
+            '<(V8_ROOT)/third_party/zlib/trees.c',
+            '<(V8_ROOT)/third_party/zlib/trees.h',
+            '<(V8_ROOT)/third_party/zlib/uncompr.c',
+            '<(V8_ROOT)/third_party/zlib/zconf.h',
+            '<(V8_ROOT)/third_party/zlib/zlib.h',
+            '<(V8_ROOT)/third_party/zlib/zutil.c',
+            '<(V8_ROOT)/third_party/zlib/zutil.h',
+          ],
+        }, {
+          # Only build the Chromium glue for zlib, so when zlib is shared,
+          # the include shim added in target_defaults forwards
+          # V8's "third_party/zlib/zlib.h" includes to the external headers.
+          'defines': [ 'USE_SYSTEM_ZLIB' ],
+        }],
+      ],
     },  # v8_zlib
     {
       'target_name': 'fp16',