Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: fix zeromq on Electron Windows by delay loading node.exe #673

Merged
merged 4 commits into from
Nov 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -195,15 +195,14 @@ jobs:
- name: Clean Tmp
run: rm -rf ./tmp
shell: bash

- name: Test Electron Windows/MacOS
if: "${{ !matrix.docker }}"
uses: nick-fields/retry@v3
with:
timeout_minutes: 5
max_attempts: 1
command: |
pnpm install -g electron@latest
pnpm run test.electron.main
continue-on-error: true

Expand All @@ -215,7 +214,6 @@ jobs:
max_attempts: 1
command: |
sudo apt-get install xvfb
pnpm install -g electron@latest
xvfb-run --auto-servernum pnpm run test.electron.main
continue-on-error: true

Expand Down
30 changes: 20 additions & 10 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,29 @@ cmake_minimum_required(VERSION 3.16)

macro(set_option_from_env OPTION_NAME)
string(TOLOWER ${OPTION_NAME} OPTION_NAME_LOWER)

if(DEFINED ENV{npm_config_${OPTION_NAME_LOWER}})
if("$ENV{npm_config_${OPTION_NAME_LOWER}}" STREQUAL "true")
set("${OPTION_NAME}"
ON
CACHE BOOL "npm_config_${OPTION_NAME_LOWER}")
ON
CACHE BOOL "npm_config_${OPTION_NAME_LOWER}")
elseif("$ENV{npm_config_${OPTION_NAME_LOWER}}" STREQUAL "false")
set("${OPTION_NAME}"
OFF
CACHE BOOL "npm_config_${OPTION_NAME_LOWER}")
OFF
CACHE BOOL "npm_config_${OPTION_NAME_LOWER}")
else()
set("${OPTION_NAME}"
"$ENV{npm_config_${OPTION_NAME_LOWER}}"
CACHE STRING "npm_config_${OPTION_NAME_LOWER}")
"$ENV{npm_config_${OPTION_NAME_LOWER}}"
CACHE STRING "npm_config_${OPTION_NAME_LOWER}")
endif()
endif()

if(${OPTION_NAME})
string(REPLACE "zmq_" "" OPTION_NAME_LOWER "${OPTION_NAME_LOWER}")
string(REPLACE "_" "-" OPTION_NAME_LOWER "${OPTION_NAME_LOWER}")
list(APPEND VCPKG_MANIFEST_FEATURES ${OPTION_NAME_LOWER})
endif()

message(STATUS "${OPTION_NAME}: ${${OPTION_NAME}}")
endmacro()

Expand Down Expand Up @@ -61,13 +64,16 @@ if(WIN32)
set(CMAKE_SYSTEM_PROCESSOR "$ENV{PROCESSOR_ARCHITECTURE}")
set(VCPKG_TARGET_TRIPLET "x64-windows-static")
endif()

# Avoid loading of project_optinos/WindowsToolchain
set(CMAKE_TOOLCHAIN_FILE ";")

# use static runtime library
set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>")
endif()

include(FetchContent)

if(CMAKE_VERSION VERSION_GREATER_EQUAL "3.24.0")
cmake_policy(SET CMP0135 NEW)
endif()
Expand All @@ -88,11 +94,11 @@ include(${_project_options_SOURCE_DIR}/Index.cmake)
# MacOS flags that should be set prior to any project calls
if(APPLE)
set(CMAKE_SHARED_LINKER_FLAGS
"${CMAKE_SHARED_LINKER_FLAGS} -undefined dynamic_lookup")
"${CMAKE_SHARED_LINKER_FLAGS} -undefined dynamic_lookup")
endif()

run_vcpkg(VCPKG_URL "https://github.com/microsoft/vcpkg.git" VCPKG_REV
"ee2d2a100103e0f3613c60655dcf15be7d5157b8")
"ee2d2a100103e0f3613c60655dcf15be7d5157b8")

# Name of the project (will be the name of the plugin)
project(addon LANGUAGES C CXX)
Expand All @@ -103,15 +109,17 @@ file(GLOB_RECURSE SOURCES "./src/*.cc")
add_library(addon SHARED ${SOURCES})

if(CMAKE_CXX_COMPILER_ID STREQUAL GNU
OR CMAKE_CXX_COMPILER_ID STREQUAL Clang
OR CMAKE_CXX_COMPILER_ID STREQUAL AppleClang)
OR CMAKE_CXX_COMPILER_ID STREQUAL Clang
OR CMAKE_CXX_COMPILER_ID STREQUAL AppleClang)
target_compile_options(project_warnings INTERFACE "-Wno-shadow")
endif()

target_link_libraries(addon PRIVATE project_options project_warnings)

if(ZMQ_DRAFT)
target_compile_definitions(addon PRIVATE ZMQ_BUILD_DRAFT_API)
endif()

if(ZMQ_NO_SYNC_RESOLVE)
target_compile_definitions(addon PRIVATE ZMQ_NO_SYNC_RESOLVE)
endif()
Expand All @@ -129,6 +137,7 @@ target_compile_definitions(addon PRIVATE V8_31BIT_SMIS_ON_64BIT_ARCH)
target_compile_definitions(addon PRIVATE V8_REVERSE_JSARGS)
target_compile_definitions(addon PRIVATE BUILDING_NODE_EXTENSION)
target_compile_definitions(addon PRIVATE NAPI_CPP_EXCEPTIONS)

if(WIN32)
target_compile_definitions(addon PRIVATE "NOMINMAX")
target_compile_definitions(addon PRIVATE "NOGDI")
Expand All @@ -140,5 +149,6 @@ set_target_properties(addon PROPERTIES PREFIX "" SUFFIX ".node")

# Windows
if(WIN32)
set_property(TARGET addon PROPERTY LINK_FLAGS "-Xlinker /DELAYLOAD:NODE.EXE")
target_link_libraries(addon PRIVATE "ShLwApi.lib" "delayimp.lib")
endif()
12 changes: 8 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
"cross-env": "^7.0.3",
"deasync": "^0.1.30",
"downlevel-dts": "^0.11.0",
"electron": "^33.1.0",
"electron-mocha": "^13.0.0",
"eslint": "^8.57.1",
"eslint-config-atomic": "^1.22.1",
Expand All @@ -63,6 +64,9 @@
"overrides": {
"typescript": "~4.9.5",
"node-gyp": "10.0.1"
},
"patchedDependencies": {
"electron-mocha": "patches/electron-mocha.patch"
}
},
"engines": {
Expand Down Expand Up @@ -99,15 +103,15 @@
"build": "run-p build.js build.native",
"build.debug": "run-s build.js build.native.debug",
"test": "run-s test.unit",
"test.unit": "run-s clean.temp build && cross-env INCLUDE_COMPAT_TESTS=false mocha ./test/unit/*-test.ts",
"test.unit": "run-s clean.temp build && mocha ./test/unit/*-test.ts",
"test.unit.compat": "run-s clean.temp build && cross-env INCLUDE_COMPAT_TESTS=true mocha ./test/unit/compat/*-test.ts",
"test.unit.nogc": "run-s clean.temp build && cross-env SKIP_GC_TESTS=true mocha",
"test.electron.main": "run-s clean.temp build && electron-mocha ./test/unit/*-test.ts",
"test.electron.renderer": "run-s build && electron-mocha --renderer ./test/unit/*-test.ts",
"test.smoke": "bash ./script/smoke-test.bash",
"test.skip_gc_tests": "run-s clean.temp build && cross-env SKIP_GC_TESTS=true mocha",
"test.electron.main": "run-s clean.temp build && electron-mocha",
"format": "run-s format.prettier format.clang-format",
"format.prettier": "prettier -l --cache --cache-location ./.cache/prettier --write .",
"format.clang-format": "clang-format -i -style=file ./src/*.cc ./src/*.h ./src/util/*.h",
"test.electron.renderer": "run-s build && electron-mocha --renderer",
"lint-test.eslint": "eslint ./**/*.{ts,tsx,js,jsx,cjs,mjs,json,yaml} --no-error-on-unmatched-pattern --cache --cache-location ./.cache/eslint/",
"lint.eslint": "pnpm run lint-test.eslint --fix",
"lint.tsc": "tsc --noEmit -p ./src/tsconfig.json",
Expand Down
27 changes: 27 additions & 0 deletions patches/electron-mocha.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
diff --git a/bin/electron-mocha b/bin/electron-mocha
index 038b2a00322cfaf98824ff33729b917c80d12828..30ed87458181ae7b7efe2970726b2eedd25f2138 100755
--- a/bin/electron-mocha
+++ b/bin/electron-mocha
@@ -35,7 +35,7 @@ function run (electron) {
...process.argv.slice(2)
]

- let child = spawn(electron, args)
+ let child = spawn(electron, args, { shell: process.platform === 'win32' })

// stdio 'inherit' not work reliably in Renderer!
child.stdout.pipe(process.stdout)
diff --git a/lib/main.js b/lib/main.js
index b8d0f8e80a86318d2a90fac3332514adda379ad9..0e1d55c3a996ddf0b5c8d98da8f04339da34788d 100644
--- a/lib/main.js
+++ b/lib/main.js
@@ -54,7 +54,8 @@ app.on('quit', () => {
detached: true,
stdio: 'ignore',
env: { ELECTRON_RUN_AS_NODE: 1 },
- cwd: __dirname
+ cwd: __dirname,
+ shell: process.platform === 'win32'
})
child.unref()
})
Loading
Loading