Skip to content

Commit 6d38f17

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

File tree

3 files changed

+39
-44
lines changed

3 files changed

+39
-44
lines changed

.github/workflows/CI.yml

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -10,56 +10,60 @@ 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
- ""
2629
native:
2730
- true
28-
2931
include:
32+
# Windows x86
3033
- os: windows-2019
3134
node_arch: ia32
35+
target_arch: ia32
3236
cpp_arch: amd64_x86
3337
native: true
3438

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

45+
# MacOS Arm64
4546
- os: macos-14
4647
node_arch: arm64
48+
target_arch: arm64
4749
cpp_arch: amd64_arm64
4850
native: true
4951

50-
# Ubuntu x64
52+
# Ubuntu 20.04 x64
5153
- os: ubuntu-24.04
5254
distro: ubuntu
5355
platform: linux/amd64
5456
node_arch: x64
57+
target_arch: x64
5558
cpp_arch: x64
5659
native: false
5760

58-
# Ubuntu Arm
61+
# Ubuntu 20.04 Arm64
5962
- os: ubuntu-24.04-arm
6063
distro: ubuntu
6164
platform: linux/arm64
6265
node_arch: arm64
66+
target_arch: arm64
6367
cpp_arch: arm64
6468
native: false
6569

@@ -68,6 +72,7 @@ jobs:
6872
distro: alpine
6973
platform: linux/amd64
7074
node_arch: x64
75+
target_arch: x64
7176
cpp_arch: x64
7277
native: false
7378

@@ -76,12 +81,13 @@ jobs:
7681
distro: alpine
7782
platform: linux/arm64
7883
node_arch: arm64
84+
target_arch: arm64
7985
cpp_arch: arm64
8086
native: false
8187

8288
env:
8389
npm_config_arch: ${{ matrix.node_arch }}
84-
npm_config_target_arch: ${{ matrix.node_arch }}
90+
npm_config_target_arch: ${{ matrix.target_arch }}
8591
setup_node_arch: ${{ matrix.node_arch }}
8692
steps:
8793
- uses: actions/checkout@v4
@@ -146,14 +152,9 @@ jobs:
146152
architecture: ${{ env.setup_node_arch }}
147153

148154
- name: Build Native
149-
if: ${{ matrix.native && matrix.node_arch != 'ia32' }}
155+
if: ${{ matrix.native }}
150156
run: npm run build.native
151157

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-
157158
- name: Use Node 20
158159
if: ${{ matrix.native }}
159160
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)