Skip to content

Commit a749b83

Browse files
authored
Merge pull request #673 from zeromq/electron
2 parents 028169e + 7b24bf9 commit a749b83

File tree

8 files changed

+452
-21
lines changed

8 files changed

+452
-21
lines changed

.github/workflows/CI.yml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -195,15 +195,14 @@ jobs:
195195
- name: Clean Tmp
196196
run: rm -rf ./tmp
197197
shell: bash
198-
198+
199199
- name: Test Electron Windows/MacOS
200200
if: "${{ !matrix.docker }}"
201201
uses: nick-fields/retry@v3
202202
with:
203203
timeout_minutes: 5
204204
max_attempts: 1
205205
command: |
206-
pnpm install -g electron@latest
207206
pnpm run test.electron.main
208207
continue-on-error: true
209208

@@ -215,7 +214,6 @@ jobs:
215214
max_attempts: 1
216215
command: |
217216
sudo apt-get install xvfb
218-
pnpm install -g electron@latest
219217
xvfb-run --auto-servernum pnpm run test.electron.main
220218
continue-on-error: true
221219

CMakeLists.txt

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,26 +2,29 @@ cmake_minimum_required(VERSION 3.16)
22

33
macro(set_option_from_env OPTION_NAME)
44
string(TOLOWER ${OPTION_NAME} OPTION_NAME_LOWER)
5+
56
if(DEFINED ENV{npm_config_${OPTION_NAME_LOWER}})
67
if("$ENV{npm_config_${OPTION_NAME_LOWER}}" STREQUAL "true")
78
set("${OPTION_NAME}"
8-
ON
9-
CACHE BOOL "npm_config_${OPTION_NAME_LOWER}")
9+
ON
10+
CACHE BOOL "npm_config_${OPTION_NAME_LOWER}")
1011
elseif("$ENV{npm_config_${OPTION_NAME_LOWER}}" STREQUAL "false")
1112
set("${OPTION_NAME}"
12-
OFF
13-
CACHE BOOL "npm_config_${OPTION_NAME_LOWER}")
13+
OFF
14+
CACHE BOOL "npm_config_${OPTION_NAME_LOWER}")
1415
else()
1516
set("${OPTION_NAME}"
16-
"$ENV{npm_config_${OPTION_NAME_LOWER}}"
17-
CACHE STRING "npm_config_${OPTION_NAME_LOWER}")
17+
"$ENV{npm_config_${OPTION_NAME_LOWER}}"
18+
CACHE STRING "npm_config_${OPTION_NAME_LOWER}")
1819
endif()
1920
endif()
21+
2022
if(${OPTION_NAME})
2123
string(REPLACE "zmq_" "" OPTION_NAME_LOWER "${OPTION_NAME_LOWER}")
2224
string(REPLACE "_" "-" OPTION_NAME_LOWER "${OPTION_NAME_LOWER}")
2325
list(APPEND VCPKG_MANIFEST_FEATURES ${OPTION_NAME_LOWER})
2426
endif()
27+
2528
message(STATUS "${OPTION_NAME}: ${${OPTION_NAME}}")
2629
endmacro()
2730

@@ -61,13 +64,16 @@ if(WIN32)
6164
set(CMAKE_SYSTEM_PROCESSOR "$ENV{PROCESSOR_ARCHITECTURE}")
6265
set(VCPKG_TARGET_TRIPLET "x64-windows-static")
6366
endif()
67+
6468
# Avoid loading of project_optinos/WindowsToolchain
6569
set(CMAKE_TOOLCHAIN_FILE ";")
70+
6671
# use static runtime library
6772
set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>")
6873
endif()
6974

7075
include(FetchContent)
76+
7177
if(CMAKE_VERSION VERSION_GREATER_EQUAL "3.24.0")
7278
cmake_policy(SET CMP0135 NEW)
7379
endif()
@@ -88,11 +94,11 @@ include(${_project_options_SOURCE_DIR}/Index.cmake)
8894
# MacOS flags that should be set prior to any project calls
8995
if(APPLE)
9096
set(CMAKE_SHARED_LINKER_FLAGS
91-
"${CMAKE_SHARED_LINKER_FLAGS} -undefined dynamic_lookup")
97+
"${CMAKE_SHARED_LINKER_FLAGS} -undefined dynamic_lookup")
9298
endif()
9399

94100
run_vcpkg(VCPKG_URL "https://github.com/microsoft/vcpkg.git" VCPKG_REV
95-
"ee2d2a100103e0f3613c60655dcf15be7d5157b8")
101+
"ee2d2a100103e0f3613c60655dcf15be7d5157b8")
96102

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

105111
if(CMAKE_CXX_COMPILER_ID STREQUAL GNU
106-
OR CMAKE_CXX_COMPILER_ID STREQUAL Clang
107-
OR CMAKE_CXX_COMPILER_ID STREQUAL AppleClang)
112+
OR CMAKE_CXX_COMPILER_ID STREQUAL Clang
113+
OR CMAKE_CXX_COMPILER_ID STREQUAL AppleClang)
108114
target_compile_options(project_warnings INTERFACE "-Wno-shadow")
109115
endif()
116+
110117
target_link_libraries(addon PRIVATE project_options project_warnings)
111118

112119
if(ZMQ_DRAFT)
113120
target_compile_definitions(addon PRIVATE ZMQ_BUILD_DRAFT_API)
114121
endif()
122+
115123
if(ZMQ_NO_SYNC_RESOLVE)
116124
target_compile_definitions(addon PRIVATE ZMQ_NO_SYNC_RESOLVE)
117125
endif()
@@ -129,6 +137,7 @@ target_compile_definitions(addon PRIVATE V8_31BIT_SMIS_ON_64BIT_ARCH)
129137
target_compile_definitions(addon PRIVATE V8_REVERSE_JSARGS)
130138
target_compile_definitions(addon PRIVATE BUILDING_NODE_EXTENSION)
131139
target_compile_definitions(addon PRIVATE NAPI_CPP_EXCEPTIONS)
140+
132141
if(WIN32)
133142
target_compile_definitions(addon PRIVATE "NOMINMAX")
134143
target_compile_definitions(addon PRIVATE "NOGDI")
@@ -140,5 +149,6 @@ set_target_properties(addon PROPERTIES PREFIX "" SUFFIX ".node")
140149

141150
# Windows
142151
if(WIN32)
152+
set_property(TARGET addon PROPERTY LINK_FLAGS "-Xlinker /DELAYLOAD:NODE.EXE")
143153
target_link_libraries(addon PRIVATE "ShLwApi.lib" "delayimp.lib")
144154
endif()

package.json

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
"cross-env": "^7.0.3",
4040
"deasync": "^0.1.30",
4141
"downlevel-dts": "^0.11.0",
42+
"electron": "^33.1.0",
4243
"electron-mocha": "^13.0.0",
4344
"eslint": "^8.57.1",
4445
"eslint-config-atomic": "^1.22.1",
@@ -63,6 +64,9 @@
6364
"overrides": {
6465
"typescript": "~4.9.5",
6566
"node-gyp": "10.0.1"
67+
},
68+
"patchedDependencies": {
69+
"electron-mocha": "patches/electron-mocha.patch"
6670
}
6771
},
6872
"engines": {
@@ -99,15 +103,15 @@
99103
"build": "run-p build.js build.native",
100104
"build.debug": "run-s build.js build.native.debug",
101105
"test": "run-s test.unit",
102-
"test.unit": "run-s clean.temp build && cross-env INCLUDE_COMPAT_TESTS=false mocha ./test/unit/*-test.ts",
106+
"test.unit": "run-s clean.temp build && mocha ./test/unit/*-test.ts",
103107
"test.unit.compat": "run-s clean.temp build && cross-env INCLUDE_COMPAT_TESTS=true mocha ./test/unit/compat/*-test.ts",
108+
"test.unit.nogc": "run-s clean.temp build && cross-env SKIP_GC_TESTS=true mocha",
109+
"test.electron.main": "run-s clean.temp build && electron-mocha ./test/unit/*-test.ts",
110+
"test.electron.renderer": "run-s build && electron-mocha --renderer ./test/unit/*-test.ts",
104111
"test.smoke": "bash ./script/smoke-test.bash",
105-
"test.skip_gc_tests": "run-s clean.temp build && cross-env SKIP_GC_TESTS=true mocha",
106-
"test.electron.main": "run-s clean.temp build && electron-mocha",
107112
"format": "run-s format.prettier format.clang-format",
108113
"format.prettier": "prettier -l --cache --cache-location ./.cache/prettier --write .",
109114
"format.clang-format": "clang-format -i -style=file ./src/*.cc ./src/*.h ./src/util/*.h",
110-
"test.electron.renderer": "run-s build && electron-mocha --renderer",
111115
"lint-test.eslint": "eslint ./**/*.{ts,tsx,js,jsx,cjs,mjs,json,yaml} --no-error-on-unmatched-pattern --cache --cache-location ./.cache/eslint/",
112116
"lint.eslint": "pnpm run lint-test.eslint --fix",
113117
"lint.tsc": "tsc --noEmit -p ./src/tsconfig.json",

patches/electron-mocha.patch

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
diff --git a/bin/electron-mocha b/bin/electron-mocha
2+
index 038b2a00322cfaf98824ff33729b917c80d12828..30ed87458181ae7b7efe2970726b2eedd25f2138 100755
3+
--- a/bin/electron-mocha
4+
+++ b/bin/electron-mocha
5+
@@ -35,7 +35,7 @@ function run (electron) {
6+
...process.argv.slice(2)
7+
]
8+
9+
- let child = spawn(electron, args)
10+
+ let child = spawn(electron, args, { shell: process.platform === 'win32' })
11+
12+
// stdio 'inherit' not work reliably in Renderer!
13+
child.stdout.pipe(process.stdout)
14+
diff --git a/lib/main.js b/lib/main.js
15+
index b8d0f8e80a86318d2a90fac3332514adda379ad9..0e1d55c3a996ddf0b5c8d98da8f04339da34788d 100644
16+
--- a/lib/main.js
17+
+++ b/lib/main.js
18+
@@ -54,7 +54,8 @@ app.on('quit', () => {
19+
detached: true,
20+
stdio: 'ignore',
21+
env: { ELECTRON_RUN_AS_NODE: 1 },
22+
- cwd: __dirname
23+
+ cwd: __dirname,
24+
+ shell: process.platform === 'win32'
25+
})
26+
child.unref()
27+
})

0 commit comments

Comments
 (0)