Skip to content

Delay-load node.exe on Windows so the prebuild loads in Electron - #31

Open
adsharma wants to merge 2 commits into
mainfrom
fix/win32-delay-load-node-exe
Open

adsharma wants to merge 2 commits into
mainfrom
fix/win32-delay-load-node-exe

Conversation

@adsharma

Copy link
Copy Markdown
Contributor

Fixes LadybugDB/ladybug#1708.

Problem

The win32-x64 prebuild links its Node imports against node.exe eagerly, so loading lbugjs.node under any host other than node.exe (e.g. Electron's electron.exe) fails with A dynamic link library (DLL) initialization routine failed. The addon is N-API, so there is no Node/Electron version mismatch involved — this is purely the Windows loader binding imports by executable name.

Fix

  • Link delayimp and pass /DELAYLOAD:node.exe on MSVC. The win_delay_load_hook.cc from cmake-js was already compiled in via ${CMAKE_JS_SRC}; it now resolves the imports against the running host process at load time — the same approach node-gyp uses for every addon. One prebuild loads in both Node and Electron.
  • Scoped -Wl,--export-dynamic to UNIX so that GNU-ld flag is no longer passed to the MSVC linker.

Verification

  • Added a Windows CI step asserting dumpbin /DEPENDENTS lists node.exe under delay-load dependencies.
  • Existing npm test suite runs on all four platform jobs as before.

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.
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.
@adsharma

Copy link
Copy Markdown
Contributor Author

CI runs to watch

Full run: https://github.com/LadybugDB/ladybug-nodejs/actions/runs/46184884024

Job Link
Windows (win32-x64) — key one: MSVC link with /DELAYLOAD:node.exe + new dumpbin check + npm test https://github.com/LadybugDB/ladybug-nodejs/actions/runs/46184884024/job/141102453471
Linux x64 https://github.com/LadybugDB/ladybug-nodejs/actions/runs/46184884024/job/141102453430
Linux arm64 https://github.com/LadybugDB/ladybug-nodejs/actions/runs/46184884024/job/141102453289
macOS arm64 https://github.com/LadybugDB/ladybug-nodejs/actions/runs/46184884024/job/141102453417

On the Windows job, look for the Verify node.exe delay-load (Windows) step: it prints dumpbin /DEPENDENTS build/lbugjs.node and fails unless node.exe appears under delay-load dependencies (i.e. it loads under both node.exe and electron.exe).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug: win32-x64 prebuild is missing the Windows delay-load hook, so the addon cannot load in Electron

1 participant