From 0659516823d4921e7b3870b5130f3ece0c4ddac6 Mon Sep 17 00:00:00 2001 From: Michael Dawson Date: Thu, 29 Aug 2024 20:20:08 +0000 Subject: [PATCH] deps: allow amaro to be externalizable - allow amaro to be externalized like other builtins containing WASM. More context is available in https://github.com/nodejs/node/blob/main/doc/contributing/maintaining/maintaining-dependencies.md#supporting-externalizable-dependencies-with-javascript-code Signed-off-by: Michael Dawson PR-URL: https://github.com/nodejs/node/pull/54646 Reviewed-By: Marco Ippolito Reviewed-By: Richard Lau Reviewed-By: Luigi Pinca Reviewed-By: Chengzhong Wu Reviewed-By: James M Snell --- configure.py | 8 +++++++- node.gni | 1 + node.gyp | 5 ----- src/node_builtins.cc | 7 +++++++ src/node_metadata.cc | 2 ++ src/node_metadata.h | 2 +- test/parallel/test-process-versions.js | 5 ++++- 7 files changed, 22 insertions(+), 8 deletions(-) diff --git a/configure.py b/configure.py index a51288a1590e45..31e0aa65cb7018 100755 --- a/configure.py +++ b/configure.py @@ -57,9 +57,11 @@ valid_intl_modes = ('none', 'small-icu', 'full-icu', 'system-icu') icu_versions = json.loads((tools_path / 'icu' / 'icu_versions.json').read_text(encoding='utf-8')) +# builtins may be removed later if they have been disabled by options shareable_builtins = {'cjs_module_lexer/lexer': 'deps/cjs-module-lexer/lexer.js', 'cjs_module_lexer/dist/lexer': 'deps/cjs-module-lexer/dist/lexer.js', - 'undici/undici': 'deps/undici/undici.js' + 'undici/undici': 'deps/undici/undici.js', + 'amaro/dist/index': 'deps/amaro/dist/index.js' } # create option groups @@ -2199,6 +2201,10 @@ def make_bin_override(): configure_inspector(output) configure_section_file(output) +# remove builtins that have been disabled +if options.without_amaro: + del shareable_builtins['amaro/dist/index'] + # configure shareable builtins output['variables']['node_builtin_shareable_builtins'] = [] for builtin, value in shareable_builtins.items(): diff --git a/node.gni b/node.gni index f7d896f0ef1c13..9dca810decebd7 100644 --- a/node.gni +++ b/node.gni @@ -20,6 +20,7 @@ declare_args() { "deps/cjs-module-lexer/lexer.js", "deps/cjs-module-lexer/dist/lexer.js", "deps/undici/undici.js", + "deps/amaro/dist/index.js", ] } diff --git a/node.gyp b/node.gyp index 1c78addcd47cb1..11474953b186c7 100644 --- a/node.gyp +++ b/node.gyp @@ -465,11 +465,6 @@ }, { 'use_openssl_def%': 0, }], - [ 'node_use_amaro=="true"', { - 'deps_files': [ - 'deps/amaro/dist/index.js', - ] - } ] ], }, diff --git a/src/node_builtins.cc b/src/node_builtins.cc index 97dde02295c975..2bc7155f7c075e 100644 --- a/src/node_builtins.cc +++ b/src/node_builtins.cc @@ -50,6 +50,13 @@ BuiltinLoader::BuiltinLoader() AddExternalizedBuiltin("internal/deps/undici/undici", STRINGIFY(NODE_SHARED_BUILTIN_UNDICI_UNDICI_PATH)); #endif // NODE_SHARED_BUILTIN_UNDICI_UNDICI_PATH + +#if HAVE_AMARO +#ifdef NODE_SHARED_BUILTIN_AMARO_DIST_INDEX_PATH + AddExternalizedBuiltin("internal/deps/amaro/dist/index", + STRINGIFY(NODE_SHARED_BUILTIN_AMARO_DIST_INDEX_PATH)); +#endif // NODE_SHARED_BUILTIN_AMARO_DIST_INDEX_PATH +#endif // HAVE_AMARO } bool BuiltinLoader::Exists(const char* id) { diff --git a/src/node_metadata.cc b/src/node_metadata.cc index d6e812df8161e6..f31b07490c6bf5 100644 --- a/src/node_metadata.cc +++ b/src/node_metadata.cc @@ -127,9 +127,11 @@ Metadata::Versions::Versions() { cjs_module_lexer = CJS_MODULE_LEXER_VERSION; uvwasi = UVWASI_VERSION_STRING; +#ifndef NODE_SHARED_BUILTIN_AMARO_DIST_INDEX_PATH #if HAVE_AMARO amaro = AMARO_VERSION; #endif +#endif #if HAVE_OPENSSL openssl = GetOpenSSLVersion(); diff --git a/src/node_metadata.h b/src/node_metadata.h index 76ec862fda187b..c59e65ad1fe3fa 100644 --- a/src/node_metadata.h +++ b/src/node_metadata.h @@ -27,7 +27,7 @@ namespace node { #define NODE_HAS_RELEASE_URLS #endif -#if HAVE_AMARO +#if HAVE_AMARO && !defined(NODE_SHARED_BUILTIN_AMARO_DIST_INDEX_PATH) #define NODE_VERSIONS_KEY_AMARO(V) V(amaro) #else #define NODE_VERSIONS_KEY_AMARO(V) diff --git a/test/parallel/test-process-versions.js b/test/parallel/test-process-versions.js index 7475b2759407c3..3b8af4b5b52526 100644 --- a/test/parallel/test-process-versions.js +++ b/test/parallel/test-process-versions.js @@ -27,9 +27,12 @@ const expected_keys = [ ]; const hasUndici = process.config.variables.node_builtin_shareable_builtins.includes('deps/undici/undici.js'); +const hasAmaro = process.config.variables.node_builtin_shareable_builtins.includes('deps/amaro/dist/index.js'); if (process.config.variables.node_use_amaro) { - expected_keys.push('amaro'); + if (hasAmaro) { + expected_keys.push('amaro'); + } } if (hasUndici) { expected_keys.push('undici');