Skip to content

Commit 8fb3518

Browse files
committed
feat: add cross-compiling Windows arm via cmake-ts v1
1 parent 2a8f826 commit 8fb3518

File tree

5 files changed

+56
-69
lines changed

5 files changed

+56
-69
lines changed

.github/workflows/CI.yml

+31-38
Original file line numberDiff line numberDiff line change
@@ -10,78 +10,76 @@ jobs:
1010
if: ${{ !contains(github.event.head_commit.message, '[skip build]') }}
1111
runs-on: ${{ matrix.os }}
1212
# prettier-ignore
13-
name: ${{ matrix.os }}-${{ matrix.node_arch }}-${{ matrix.distro }}-${{ matrix.platform }}
13+
name: ${{ matrix.os }} ${{ matrix.target_arch }} ${{ matrix.distro }} ${{ matrix.platform }}
1414
strategy:
1515
fail-fast: false
1616
matrix:
1717
os:
1818
- ubuntu-24.04
1919
- windows-2019
20+
- macos-13
2021
node_arch:
2122
- x64
2223
cpp_arch:
2324
- x64
25+
target_arch:
26+
- x64
2427
distro:
2528
- ""
26-
native:
27-
- true
28-
2929
include:
30+
# Windows x86
3031
- os: windows-2019
3132
node_arch: ia32
33+
target_arch: ia32
3234
cpp_arch: amd64_x86
33-
native: true
34-
35-
# - os: windows-2022
36-
# node_arch: x64
37-
# arch: arm64
38-
# cpp_arch: amd64_arm64
3935

40-
- os: macos-13
36+
# Windows Arm64
37+
- os: windows-2022
4138
node_arch: x64
42-
cpp_arch: x64
43-
native: true
39+
target_arch: arm64
40+
cpp_arch: amd64_arm64
4441

42+
# MacOS Arm64
4543
- os: macos-14
4644
node_arch: arm64
45+
target_arch: arm64
4746
cpp_arch: amd64_arm64
48-
native: true
4947

50-
# Ubuntu x64
48+
# Ubuntu 20.04 x64
5149
- os: ubuntu-24.04
5250
distro: ubuntu
5351
platform: linux/amd64
5452
node_arch: x64
53+
target_arch: x64
5554
cpp_arch: x64
56-
native: false
5755

58-
# Ubuntu Arm
56+
# Ubuntu 20.04 Arm64
5957
- os: ubuntu-24.04-arm
6058
distro: ubuntu
6159
platform: linux/arm64
6260
node_arch: arm64
61+
target_arch: arm64
6362
cpp_arch: arm64
64-
native: false
6563

6664
# Musl Alpine
6765
- os: ubuntu-24.04
6866
distro: alpine
6967
platform: linux/amd64
7068
node_arch: x64
69+
target_arch: x64
7170
cpp_arch: x64
72-
native: false
7371

7472
# Musl Alpine Arm
7573
- os: ubuntu-24.04-arm
7674
distro: alpine
7775
platform: linux/arm64
7876
node_arch: arm64
77+
target_arch: arm64
7978
cpp_arch: arm64
80-
native: false
8179

8280
env:
8381
npm_config_arch: ${{ matrix.node_arch }}
84-
npm_config_target_arch: ${{ matrix.node_arch }}
82+
npm_config_target_arch: ${{ matrix.target_arch }}
8583
setup_node_arch: ${{ matrix.node_arch }}
8684
steps:
8785
- uses: actions/checkout@v4
@@ -105,7 +103,7 @@ jobs:
105103
shell: bash
106104

107105
- name: Setup Cpp
108-
if: ${{ matrix.native }}
106+
if: ${{ ! matrix.distro }}
109107
uses: aminya/setup-cpp@v1
110108
with:
111109
vcvarsall: ${{ contains(matrix.os, 'windows') }}
@@ -121,41 +119,36 @@ jobs:
121119
brew install gnutls autoconf automake libtool
122120
123121
- uses: pnpm/action-setup@v4
124-
if: ${{ matrix.native }}
122+
if: ${{ ! matrix.distro }}
125123

126124
- name: Install Node 20
127-
if: ${{ matrix.native }}
125+
if: ${{ ! matrix.distro }}
128126
uses: actions/setup-node@v4
129127
with:
130128
node-version: 20
131129
architecture: ${{ env.setup_node_arch }}
132130

133131
- name: Install and Build Native
134-
if: ${{ matrix.native }}
132+
if: ${{ ! matrix.distro }}
135133
run: pnpm install
136134

137135
- name: Build JavaScript
138-
if: ${{ matrix.native }}
136+
if: ${{ ! matrix.distro }}
139137
run: pnpm run build.js
140138

141139
- name: Install Node 12
142-
if: ${{ matrix.native && matrix.os != 'macos-14' }}
140+
if: ${{ !matrix.distro && matrix.os != 'macos-14' }}
143141
uses: actions/setup-node@v4
144142
with:
145143
node-version: 12
146144
architecture: ${{ env.setup_node_arch }}
147145

148146
- name: Build Native
149-
if: ${{ matrix.native && matrix.node_arch != 'ia32' }}
147+
if: ${{ ! matrix.distro }}
150148
run: npm run build.native
151149

152-
- name: Build Native Windows 32
153-
if: ${{ matrix.os == 'windows-2019' && matrix.node_arch == 'ia32' }}
154-
run:
155-
node --enable-source-maps ./node_modules/cmake-ts/build/main.js build --config win32-ia32-release
156-
157150
- name: Use Node 20
158-
if: ${{ matrix.native }}
151+
if: ${{ ! matrix.distro }}
159152
uses: actions/setup-node@v4
160153
with:
161154
node-version: 20
@@ -190,11 +183,11 @@ jobs:
190183
overwrite: true
191184

192185
- name: Lint
193-
if: "${{ contains(matrix.os, 'ubuntu') && matrix.native }}"
186+
if: "${{ contains(matrix.os, 'ubuntu') && !matrix.distro }}"
194187
run: pnpm run lint-test
195188

196189
- name: Test
197-
if: ${{ matrix.native }}
190+
if: ${{ ! matrix.distro }}
198191
uses: nick-fields/retry@v3
199192
with:
200193
timeout_minutes: 5
@@ -205,7 +198,7 @@ jobs:
205198
rm -rf ./tmp && mkdir -p ./tmp
206199
207200
- name: Test Electron Windows/MacOS
208-
if: "${{ !contains(matrix.os, 'ubuntu') && matrix.native }}"
201+
if: "${{ !contains(matrix.os, 'ubuntu') && !matrix.distro }}"
209202
uses: nick-fields/retry@v3
210203
with:
211204
timeout_minutes: 5
@@ -215,7 +208,7 @@ jobs:
215208
continue-on-error: true
216209

217210
- name: Test Electron Linux
218-
if: "${{ contains(matrix.os, 'ubuntu') && matrix.native }}"
211+
if: "${{ contains(matrix.os, 'ubuntu') && !matrix.distro }}"
219212
uses: nick-fields/retry@v3
220213
with:
221214
timeout_minutes: 5

CMakeLists.txt

+18-10
Original file line numberDiff line numberDiff line change
@@ -65,18 +65,26 @@ endif()
6565

6666
# target system on Windows (for cross-compiling x86) and static linking runtimes
6767
if(WIN32)
68-
if("$ENV{Platform}" STREQUAL "x86")
69-
set(CMAKE_SYSTEM_PROCESSOR "x86")
70-
set(VCPKG_TARGET_TRIPLET "x86-windows-static")
71-
elseif(NOT "$ENV{PROCESSOR_ARCHITEW6432}" STREQUAL "")
72-
set(CMAKE_SYSTEM_PROCESSOR "$ENV{PROCESSOR_ARCHITEW6432}")
73-
set(VCPKG_TARGET_TRIPLET "x86-windows-static")
74-
elseif("$ENV{Platform}" STREQUAL "arm64")
75-
set(CMAKE_SYSTEM_PROCESSOR "arm64")
68+
if("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "")
69+
if("$ENV{Platform}" STREQUAL "x86")
70+
set(CMAKE_SYSTEM_PROCESSOR "x86")
71+
elseif(NOT "$ENV{PROCESSOR_ARCHITEW6432}" STREQUAL "")
72+
set(CMAKE_SYSTEM_PROCESSOR "$ENV{PROCESSOR_ARCHITEW6432}")
73+
else()
74+
set(CMAKE_SYSTEM_PROCESSOR "$ENV{PROCESSOR_ARCHITECTURE}")
75+
endif()
76+
endif()
77+
78+
string(TOLOWER "${CMAKE_SYSTEM_PROCESSOR}" CMAKE_SYSTEM_PROCESSOR_LOWER)
79+
80+
if("${CMAKE_SYSTEM_PROCESSOR_LOWER}" STREQUAL "amd64" OR "${CMAKE_SYSTEM_PROCESSOR_LOWER}" STREQUAL "x64")
81+
set(VCPKG_TARGET_TRIPLET "x64-windows-static")
82+
elseif("${CMAKE_SYSTEM_PROCESSOR_LOWER}" STREQUAL "arm64" OR "${CMAKE_SYSTEM_PROCESSOR_LOWER}" STREQUAL "aarch64")
7683
set(VCPKG_TARGET_TRIPLET "arm64-windows-static")
84+
elseif("${CMAKE_SYSTEM_PROCESSOR_LOWER}" STREQUAL "x86")
85+
set(VCPKG_TARGET_TRIPLET "x86-windows-static")
7786
else()
78-
set(CMAKE_SYSTEM_PROCESSOR "$ENV{PROCESSOR_ARCHITECTURE}")
79-
set(VCPKG_TARGET_TRIPLET "x64-windows-static")
87+
message(STATUS "Not setting VCPKG_TARGET_TRIPLET for ${CMAKE_SYSTEM_PROCESSOR}")
8088
endif()
8189

8290
# Avoid loading of project_optinos/WindowsToolchain

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
},
2020
"homepage": "http://zeromq.github.io/zeromq.js/",
2121
"dependencies": {
22-
"cmake-ts": "1.0.0",
22+
"cmake-ts": "1.0.1",
2323
"node-addon-api": "^8.3.0"
2424
},
2525
"devDependencies": {

pnpm-lock.yaml

+5-5
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

script/install.js

+1-15
Original file line numberDiff line numberDiff line change
@@ -15,21 +15,7 @@ function cmakeTs() {
1515
)
1616
}
1717

18-
// Default args
19-
let args = ["nativeonly"]
20-
21-
if (process.arch !== process.env.npm_config_target_arch || process.env.cross_compiling === "true") {
22-
// cross-compilation
23-
if (process.platform === "win32") {
24-
if (process.env.npm_config_target_arch === "ia32") {
25-
args = ["named-configs", "windows-x86"]
26-
} else if (process.env.npm_config_target_arch === "arm64") {
27-
args = ["named-configs", "windows-arm64"]
28-
}
29-
}
30-
}
31-
32-
cp.execFileSync(process.execPath, [cmakeTsPath, ...args], {
18+
cp.execFileSync(process.execPath, [cmakeTsPath, "build"], {
3319
stdio: "inherit",
3420
})
3521
}

0 commit comments

Comments
 (0)