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: | 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()