From 0a450f4b01f6e8b9685ac90aa91af2f738368559 Mon Sep 17 00:00:00 2001 From: Michael Gissing Date: Tue, 10 Sep 2024 11:15:12 +0200 Subject: [PATCH] feat: add Node 22 patch --- .github/workflows/build-alpine.yml | 4 +- .github/workflows/build-linux.yml | 6 +- .github/workflows/build-linuxstatic.yml | 4 +- .github/workflows/build-macos.yml | 12 +- .github/workflows/build-windows.yml | 10 +- .github/workflows/ci.yml | 2 +- Dockerfile.linux | 4 +- patches/node.v22.8.0.cpp.patch | 686 ++++++++++++++++++++++++ patches/patches.json | 1 + 9 files changed, 709 insertions(+), 20 deletions(-) create mode 100644 patches/node.v22.8.0.cpp.patch diff --git a/.github/workflows/build-alpine.yml b/.github/workflows/build-alpine.yml index 8be1f20f..2c0a77b5 100644 --- a/.github/workflows/build-alpine.yml +++ b/.github/workflows/build-alpine.yml @@ -6,12 +6,12 @@ on: jobs: alpine: - runs-on: ubuntu-20.04 + runs-on: ubuntu-22.04 strategy: fail-fast: false matrix: - target-node: [14, 16, 18, 20] + target-node: [16, 18, 20, 22] target-arch: [x64, arm64] include: - target-arch: x64 diff --git a/.github/workflows/build-linux.yml b/.github/workflows/build-linux.yml index 33efd429..926e07a3 100644 --- a/.github/workflows/build-linux.yml +++ b/.github/workflows/build-linux.yml @@ -11,7 +11,7 @@ jobs: strategy: fail-fast: false matrix: - target-node: [14, 16, 18, 20] + target-node: [16, 18, 20, 22] steps: - uses: actions/checkout@v4 @@ -43,12 +43,12 @@ jobs: path: dist/* linux-arm64: - runs-on: ubuntu-20.04 + runs-on: ubuntu-22.04 strategy: fail-fast: false matrix: - target-node: [14, 16, 18, 20] + target-node: [16, 18, 20, 22] steps: - uses: actions/checkout@v4 diff --git a/.github/workflows/build-linuxstatic.yml b/.github/workflows/build-linuxstatic.yml index 2b50d1a8..c21eb8df 100644 --- a/.github/workflows/build-linuxstatic.yml +++ b/.github/workflows/build-linuxstatic.yml @@ -6,12 +6,12 @@ on: jobs: linuxstatic: - runs-on: ubuntu-20.04 + runs-on: ubuntu-22.04 strategy: fail-fast: false matrix: - target-node: [14, 16, 18, 20] + target-node: [16, 18, 20, 22] target-arch: [x64, arm64, armv7] include: - target-arch: x64 diff --git a/.github/workflows/build-macos.yml b/.github/workflows/build-macos.yml index f894ee6f..2b25626d 100644 --- a/.github/workflows/build-macos.yml +++ b/.github/workflows/build-macos.yml @@ -11,7 +11,7 @@ jobs: strategy: fail-fast: false matrix: - target-node: [14, 16, 18, 20] + target-node: [16, 18, 20, 22] steps: - uses: actions/checkout@v4 @@ -20,10 +20,10 @@ jobs: with: xcode-version: latest - - name: Use Node.js 18 + - name: Use Node.js 20 uses: actions/setup-node@v4 with: - node-version: 18 + node-version: 20 - name: Check arch is x64 run: | @@ -61,7 +61,7 @@ jobs: strategy: fail-fast: false matrix: - target-node: [14, 16, 18, 20] + target-node: [16, 18, 20] # disabled 22 for now because of resource issues with GH actions steps: - uses: actions/checkout@v4 @@ -70,10 +70,10 @@ jobs: with: xcode-version: latest - - name: Use Node.js 18 + - name: Use Node.js 20 uses: actions/setup-node@v4 with: - node-version: 18 + node-version: 20 - name: Check arch is x64 # arm64 run: | diff --git a/.github/workflows/build-windows.yml b/.github/workflows/build-windows.yml index 7cad3a89..d3c1bdb7 100644 --- a/.github/workflows/build-windows.yml +++ b/.github/workflows/build-windows.yml @@ -5,22 +5,22 @@ on: workflow_call: jobs: - windows-vs2019: - runs-on: windows-2019 + windows-vs2022: + runs-on: windows-2022 strategy: fail-fast: false matrix: - target-node: [14, 16, 18, 20] + target-node: [16, 18, 20, 22] target-arch: [x64, arm64] steps: - uses: actions/checkout@v4 - - name: Use Node.js 16 + - name: Use Node.js 20 uses: actions/setup-node@v4 with: - node-version: 16 + node-version: 20 - run: yarn install --ignore-engines diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 6ae369a1..d2c391ae 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -11,7 +11,7 @@ jobs: strategy: fail-fast: false # prevent test to stop if one fails matrix: - node-version: [12, 14, 16, 18, 20] # match patched node versions + node-version: [16, 18, 20, 22] # match patched node versions os: [ubuntu-latest] # Skip macos-latest, windows-latest for now runs-on: ${{ matrix.os }} diff --git a/Dockerfile.linux b/Dockerfile.linux index 776e62c3..22f556b5 100644 --- a/Dockerfile.linux +++ b/Dockerfile.linux @@ -16,7 +16,9 @@ RUN dnf upgrade -y RUN dnf install -y \ gcc-toolset-10 glibc-headers kernel-headers \ make patch python2 \ - python3 + python3.12 + +RUN alternatives --set python3 /usr/bin/python3.12 # Install Node.js 20 and yarn RUN curl -fsSL https://rpm.nodesource.com/setup_20.x | bash - diff --git a/patches/node.v22.8.0.cpp.patch b/patches/node.v22.8.0.cpp.patch new file mode 100644 index 00000000..aa138ab7 --- /dev/null +++ b/patches/node.v22.8.0.cpp.patch @@ -0,0 +1,686 @@ +diff --git node/common.gypi node/common.gypi +index a97e77860e..09444e795f 100644 +--- node/common.gypi ++++ node/common.gypi +@@ -187,7 +187,7 @@ + ['clang==1', { + 'lto': ' -flto ', # Clang + }, { +- 'lto': ' -flto=4 -fuse-linker-plugin -ffat-lto-objects ', # GCC ++ 'lto': ' -flto=4 -ffat-lto-objects ', # GCC + }], + ], + }, +diff --git node/deps/ngtcp2/nghttp3/lib/nghttp3_ringbuf.c node/deps/ngtcp2/nghttp3/lib/nghttp3_ringbuf.c +index 61a7d06cad..eeebf67796 100644 +--- node/deps/ngtcp2/nghttp3/lib/nghttp3_ringbuf.c ++++ node/deps/ngtcp2/nghttp3/lib/nghttp3_ringbuf.c +@@ -33,17 +33,6 @@ + + #include "nghttp3_macro.h" + +-#if defined(_MSC_VER) && !defined(__clang__) && \ +- (defined(_M_ARM) || defined(_M_ARM64)) +-unsigned int __popcnt(unsigned int x) { +- unsigned int c = 0; +- for (; x; ++c) { +- x &= x - 1; +- } +- return c; +-} +-#endif +- + int nghttp3_ringbuf_init(nghttp3_ringbuf *rb, size_t nmemb, size_t size, + const nghttp3_mem *mem) { + if (nmemb) { +diff --git node/deps/ngtcp2/ngtcp2/lib/ngtcp2_ringbuf.c node/deps/ngtcp2/ngtcp2/lib/ngtcp2_ringbuf.c +index c381c23127..6894bc2308 100644 +--- node/deps/ngtcp2/ngtcp2/lib/ngtcp2_ringbuf.c ++++ node/deps/ngtcp2/ngtcp2/lib/ngtcp2_ringbuf.c +@@ -31,17 +31,6 @@ + + #include "ngtcp2_macro.h" + +-#if defined(_MSC_VER) && !defined(__clang__) && \ +- (defined(_M_ARM) || defined(_M_ARM64)) +-static unsigned int __popcnt(unsigned int x) { +- unsigned int c = 0; +- for (; x; ++c) { +- x &= x - 1; +- } +- return c; +-} +-#endif +- + int ngtcp2_ringbuf_init(ngtcp2_ringbuf *rb, size_t nmemb, size_t size, + const ngtcp2_mem *mem) { + uint8_t *buf = ngtcp2_mem_malloc(mem, nmemb * size); +diff --git node/deps/v8/include/v8-initialization.h node/deps/v8/include/v8-initialization.h +index d3e35d6ec5..6e9bbe3849 100644 +--- node/deps/v8/include/v8-initialization.h ++++ node/deps/v8/include/v8-initialization.h +@@ -89,6 +89,10 @@ class V8_EXPORT V8 { + static void SetFlagsFromCommandLine(int* argc, char** argv, + bool remove_flags); + ++ static void EnableCompilationForSourcelessUse(); ++ static void DisableCompilationForSourcelessUse(); ++ static void FixSourcelessScript(Isolate* v8_isolate, Local script); ++ + /** Get the version string. */ + static const char* GetVersion(); + +diff --git node/deps/v8/src/api/api.cc node/deps/v8/src/api/api.cc +index 2dd476dda3..8a51f25b57 100644 +--- node/deps/v8/src/api/api.cc ++++ node/deps/v8/src/api/api.cc +@@ -624,6 +624,28 @@ void V8::SetFlagsFromCommandLine(int* argc, char** argv, bool remove_flags) { + HelpOptions(HelpOptions::kDontExit)); + } + ++bool save_lazy; ++bool save_predictable; ++ ++void V8::EnableCompilationForSourcelessUse() { ++ save_lazy = i::v8_flags.lazy; ++ i::v8_flags.lazy = false; ++ save_predictable = i::v8_flags.predictable; ++ i::v8_flags.predictable = true; ++} ++ ++void V8::DisableCompilationForSourcelessUse() { ++ i::v8_flags.lazy = save_lazy; ++ i::v8_flags.predictable = save_predictable; ++} ++ ++void V8::FixSourcelessScript(Isolate* v8_isolate, Local unbound_script) { ++ auto isolate = reinterpret_cast(v8_isolate); ++ auto function_info = i::Handle::cast(Utils::OpenHandle(*unbound_script)); ++ i::Handle script(i::Script::cast(function_info->script()), isolate); ++ script->SetSource(isolate, script, isolate->factory()->empty_string()); ++} ++ + RegisteredExtension* RegisteredExtension::first_extension_ = nullptr; + + RegisteredExtension::RegisteredExtension(std::unique_ptr extension) +diff --git node/deps/v8/src/codegen/compiler.cc node/deps/v8/src/codegen/compiler.cc +index 49afab11b6..4c81f9f90b 100644 +--- node/deps/v8/src/codegen/compiler.cc ++++ node/deps/v8/src/codegen/compiler.cc +@@ -3627,7 +3627,7 @@ MaybeHandle GetSharedFunctionInfoForScriptImpl( + maybe_script = lookup_result.script(); + maybe_result = lookup_result.toplevel_sfi(); + is_compiled_scope = lookup_result.is_compiled_scope(); +- if (!maybe_result.is_null()) { ++ if (!maybe_result.is_null() && source->length()) { + compile_timer.set_hit_isolate_cache(); + } else if (can_consume_code_cache) { + compile_timer.set_consuming_code_cache(); +diff --git node/deps/v8/src/compiler/wasm-compiler.cc node/deps/v8/src/compiler/wasm-compiler.cc +index 16f1f1470b..4bfeca49e6 100644 +--- node/deps/v8/src/compiler/wasm-compiler.cc ++++ node/deps/v8/src/compiler/wasm-compiler.cc +@@ -8613,12 +8613,13 @@ wasm::WasmCompilationResult CompileWasmImportCallWrapper( + '-'); + + auto compile_with_turboshaft = [&]() { ++ wasm::WrapperCompilationInfo info; ++ info.code_kind = CodeKind::WASM_TO_JS_FUNCTION; ++ info.import_info.import_kind = kind; ++ info.import_info.expected_arity = expected_arity; ++ info.import_info.suspend = suspend; + return Pipeline::GenerateCodeForWasmNativeStubFromTurboshaft( +- env->module, sig, +- wasm::WrapperCompilationInfo{ +- .code_kind = CodeKind::WASM_TO_JS_FUNCTION, +- .import_info = {kind, expected_arity, suspend}}, +- func_name, WasmStubAssemblerOptions(), nullptr); ++ env->module, sig, info, func_name, WasmStubAssemblerOptions(), nullptr); + }; + auto compile_with_turbofan = [&]() { + //-------------------------------------------------------------------------- +@@ -8774,13 +8775,15 @@ MaybeHandle CompileWasmToJSWrapper(Isolate* isolate, + base::VectorOf(name_buffer.get(), kMaxNameLen) + kNamePrefixLen, sig); + + auto compile_with_turboshaft = [&]() { ++ wasm::WrapperCompilationInfo info; ++ info.code_kind = CodeKind::WASM_TO_JS_FUNCTION; ++ info.import_info.import_kind = kind; ++ info.import_info.expected_arity = expected_arity; ++ info.import_info.suspend = suspend; + std::unique_ptr job = + Pipeline::NewWasmTurboshaftWrapperCompilationJob( +- isolate, sig, +- wasm::WrapperCompilationInfo{ +- .code_kind = CodeKind::WASM_TO_JS_FUNCTION, +- .import_info = {kind, expected_arity, suspend}}, +- nullptr, std::move(name_buffer), WasmAssemblerOptions()); ++ isolate, sig, info, nullptr, std::move(name_buffer), ++ WasmAssemblerOptions()); + + // Compile the wrapper + if (job->ExecuteJob(isolate->counters()->runtime_call_stats()) == +diff --git node/deps/v8/src/heap/marking-visitor-inl.h node/deps/v8/src/heap/marking-visitor-inl.h +index 39a5bbd22c..4b860f55d5 100644 +--- node/deps/v8/src/heap/marking-visitor-inl.h ++++ node/deps/v8/src/heap/marking-visitor-inl.h +@@ -329,6 +329,13 @@ bool MarkingVisitorBase::HasBytecodeArrayForFlushing( + template + bool MarkingVisitorBase::ShouldFlushCode( + Tagged sfi) const { ++ auto script_obj = sfi->script(); ++ if (!IsUndefined(script_obj)) { ++ auto script = i::Script::cast(script_obj); ++ if (IsUndefined(script->source())) { ++ return false; ++ } ++ } + return IsStressFlushingEnabled(code_flush_mode_) || IsOld(sfi); + } + +diff --git node/deps/v8/src/objects/js-function.cc node/deps/v8/src/objects/js-function.cc +index 529e283bbf..c997c53a18 100644 +--- node/deps/v8/src/objects/js-function.cc ++++ node/deps/v8/src/objects/js-function.cc +@@ -1308,6 +1308,10 @@ Handle JSFunction::ToString(Handle function) { + Handle maybe_class_positions = JSReceiver::GetDataProperty( + isolate, function, isolate->factory()->class_positions_symbol()); + if (IsClassPositions(*maybe_class_positions)) { ++ if (IsUndefined( ++ String::cast(Script::cast(shared_info->script())->source()))) { ++ return isolate->factory()->NewStringFromAsciiChecked("class {}"); ++ } + Tagged class_positions = + ClassPositions::cast(*maybe_class_positions); + int start_position = class_positions->start(); +diff --git node/deps/v8/src/objects/objects.cc node/deps/v8/src/objects/objects.cc +index 8e013c2544..7ac03149d8 100644 +--- node/deps/v8/src/objects/objects.cc ++++ node/deps/v8/src/objects/objects.cc +@@ -4263,7 +4263,12 @@ void Script::InitLineEndsInternal(IsolateT* isolate, Handle