From 6d40dc862cf3577fec636c1a36085165e6862fa9 Mon Sep 17 00:00:00 2001 From: Arun Sharma Date: Sat, 28 Nov 2026 12:09:11 -0800 Subject: [PATCH 1/2] fix(nodejs): delay-load node.exe on Windows for Electron support The win32-x64 prebuild linked its node.exe imports eagerly, so loading lbugjs.node under any host other than node.exe (e.g. Electron's electron.exe) failed with 'A dynamic link library (DLL) initialization routine failed'. Link delayimp and pass /DELAYLOAD:node.exe on MSVC. The win_delay_load_hook.cc from cmake-js (already compiled in via CMAKE_JS_SRC) resolves the imports against the running host process at load time -- the same approach node-gyp uses for every addon. One prebuild now loads in both Node and Electron. Also scope -Wl,--export-dynamic to UNIX so it is not passed to the MSVC linker. Fixes LadybugDB/ladybug#1708. --- CMakeLists.txt | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index aa1bb5a..dff5969 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -180,10 +180,22 @@ set_target_properties(lbugjs ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/build") if(APPLE) target_link_options(lbugjs PRIVATE -undefined dynamic_lookup) -else() +elseif(UNIX) target_link_options(lbugjs PRIVATE -Wl,--export-dynamic) endif() target_link_libraries(lbugjs PRIVATE lbug ${NODEJS_LBUG_LINK_DEPS} ${CMAKE_JS_LIB}) +# Windows (MSVC): delay-load node.exe so the same prebuilt binary loads under +# both Node (node.exe) and Electron (electron.exe). This requires +# win_delay_load_hook.cc from cmake-js (added via CMAKE_JS_SRC above), which +# resolves the node.exe imports against the running host process at load time +# (same approach as node-gyp's win_delay_load_hook). +if(MSVC) + if(NOT CMAKE_JS_SRC) + message(WARNING "lbugjs: CMAKE_JS_SRC (win_delay_load_hook.cc) is empty; the Electron delay-load hook will be missing.") + endif() + target_link_libraries(lbugjs PRIVATE delayimp) + target_link_options(lbugjs PRIVATE "/DELAYLOAD:node.exe") +endif() if(LBUG_NODEJS_EXTRA_LINK_LIBS) target_link_libraries(lbugjs PRIVATE ${LBUG_NODEJS_EXTRA_LINK_LIBS}) endif() From 047e4ebfe2033eab585914958cf5a8fb372fb1ec Mon Sep 17 00:00:00 2001 From: Arun Sharma Date: Sat, 28 Nov 2026 12:09:11 -0800 Subject: [PATCH 2/2] ci(nodejs): verify node.exe is delay-loaded on Windows dumpbin /DEPENDENTS must list node.exe under delay-load dependencies; fail the Windows job otherwise so a regression of LadybugDB/ladybug#1708 is caught at build time. --- .github/workflows/ci.yml | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index a931756..c341420 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -145,6 +145,23 @@ jobs: ccache -s make GEN=Ninja nodejs && ccache -s + - name: Verify node.exe delay-load (Windows) + if: ${{ matrix.platform == 'win32' }} + shell: pwsh + working-directory: tools/nodejs_api + run: | + # The prebuilt binary must delay-load node.exe so it resolves its + # Node imports against whichever host process loads it (node.exe or + # e.g. Electron's electron.exe). Fail if node.exe is eagerly linked. + $imports = dumpbin /DEPENDENTS build/lbugjs.node | Out-String + Write-Host $imports + if ($imports -notmatch 'delay load dependencies') { + throw 'lbugjs.node has no delay-load dependencies; node.exe must be delay-loaded (see LadybugDB/ladybug#1708).' + } + if ($imports -notmatch 'node\.exe') { + throw 'node.exe not found in the delay-load dependencies of lbugjs.node.' + } + - name: Install OpenSSL 3 (macOS) if: ${{ matrix.mac_env }} run: |