Skip to content

Commit 1526d43

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

3 files changed

Lines changed: 37 additions & 44 deletions

File tree

.github/workflows/CI.yml

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,14 @@ 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:
@@ -25,41 +26,42 @@ jobs:
2526
- ""
2627
native:
2728
- true
28-
2929
include:
30+
# Windows x86
3031
- os: windows-2019
3132
node_arch: ia32
33+
target_arch: ia32
3234
cpp_arch: amd64_x86
3335
native: true
3436

35-
# - os: windows-2022
36-
# node_arch: x64
37-
# arch: arm64
38-
# cpp_arch: amd64_arm64
39-
40-
- os: macos-13
37+
# Windows Arm64
38+
- os: windows-2022
4139
node_arch: x64
42-
cpp_arch: x64
43-
native: true
40+
target_arch: arm64
41+
cpp_arch: amd64_arm64
4442

43+
# MacOS Arm64
4544
- os: macos-14
4645
node_arch: arm64
46+
target_arch: arm64
4747
cpp_arch: amd64_arm64
4848
native: true
4949

50-
# Ubuntu x64
50+
# Ubuntu 20.04 x64
5151
- os: ubuntu-24.04
5252
distro: ubuntu
5353
platform: linux/amd64
5454
node_arch: x64
55+
target_arch: x64
5556
cpp_arch: x64
5657
native: false
5758

58-
# Ubuntu Arm
59+
# Ubuntu 20.04 Arm64
5960
- os: ubuntu-24.04-arm
6061
distro: ubuntu
6162
platform: linux/arm64
6263
node_arch: arm64
64+
target_arch: arm64
6365
cpp_arch: arm64
6466
native: false
6567

@@ -68,6 +70,7 @@ jobs:
6870
distro: alpine
6971
platform: linux/amd64
7072
node_arch: x64
73+
target_arch: x64
7174
cpp_arch: x64
7275
native: false
7376

@@ -76,12 +79,13 @@ jobs:
7679
distro: alpine
7780
platform: linux/arm64
7881
node_arch: arm64
82+
target_arch: arm64
7983
cpp_arch: arm64
8084
native: false
8185

8286
env:
8387
npm_config_arch: ${{ matrix.node_arch }}
84-
npm_config_target_arch: ${{ matrix.node_arch }}
88+
npm_config_target_arch: ${{ matrix.target_arch }}
8589
setup_node_arch: ${{ matrix.node_arch }}
8690
steps:
8791
- uses: actions/checkout@v4
@@ -146,14 +150,9 @@ jobs:
146150
architecture: ${{ env.setup_node_arch }}
147151

148152
- name: Build Native
149-
if: ${{ matrix.native && matrix.node_arch != 'ia32' }}
153+
if: ${{ matrix.native }}
150154
run: npm run build.native
151155

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-
157156
- name: Use Node 20
158157
if: ${{ matrix.native }}
159158
uses: actions/setup-node@v4

CMakeLists.txt

Lines changed: 18 additions & 10 deletions
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

script/install.js

Lines changed: 1 addition & 15 deletions
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)