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

ci: support Windows ARM #693

Draft
wants to merge 5 commits into
base: master
Choose a base branch
from
Draft
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
94 changes: 53 additions & 41 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jobs:
if: ${{ !contains(github.event.head_commit.message, '[skip ci]') }}
runs-on: ${{ matrix.os }}
# prettier-ignore
name: ${{ matrix.os }}-${{ matrix.node_arch }}-${{ matrix.dockerfile }}-${{ matrix.distro }}
name: ${{ matrix.os }}-${{ matrix.node_target_arch }}-${{ matrix.dockerfile }}-${{ matrix.distro }}
strategy:
fail-fast: false
matrix:
Expand All @@ -19,61 +19,79 @@ jobs:
- windows-2019
node_arch:
- x64
node_target_arch:
- x64
cpp_arch:
- x64
dockerfile:
- ""
distro:
- ""
native:
- true

vm:
- false
cross_compiling:
- false
include:
- os: windows-2019
node_arch: ia32
node_target_arch: ia32
cpp_arch: amd64_x86
native: true
vm: false
cross_compiling: true

# - os: windows-2022
# node_arch: x64
# arch: arm64
# cpp_arch: amd64_arm64
- os: windows-2022
node_arch: x64
node_target_arch: arm64
cpp_arch: amd64_arm64
vm: false
cross_compiling: true

- os: macos-13
node_arch: x64
node_target_arch: x64
cpp_arch: x64
native: true
vm: false
cross_compiling: false

- os: macos-14
node_arch: arm64
cpp_arch: amd64_arm64
native: true
node_target_arch: arm64
cpp_arch: arm64
vm: false
cross_compiling: false

# Musl Alpine
- os: ubuntu-24.04
dockerfile: docker/alpine.dockerfile
node_arch: x64
node_target_arch: x64
cpp_arch: x64
native: false
vm: true
cross_compiling: false

# Debian Arm
- os: ubuntu-24.04
node_arch: arm64
cpp_arch: amd64_arm64
distro: bookworm
native: false
node_arch: arm64
node_target_arch: arm64
cpp_arch: arm64
vm: true
cross_compiling: false

# Musl Alpine Arm
- os: ubuntu-24.04
node_arch: arm64
cpp_arch: amd64_arm64
distro: alpine_latest
native: false
node_arch: arm64
node_target_arch: arm64
cpp_arch: arm64
vm: true
cross_compiling: false

env:
npm_config_arch: ${{ matrix.node_arch }}
npm_config_target_arch: ${{ matrix.node_arch }}
npm_config_target_arch: ${{ matrix.node_target_arch }}
setup_node_arch: ${{ matrix.node_arch }}
cross_compiling: ${{ matrix.cross_compiling }}
steps:
- uses: actions/checkout@v4

Expand All @@ -96,8 +114,8 @@ jobs:
shell: bash

- name: Setup Cpp
if: ${{ matrix.native }}
uses: aminya/setup-cpp@v1
if: ${{ !matrix.vm }}
uses: aminya/setup-cpp@master
with:
vcvarsall: ${{ contains(matrix.os, 'windows') }}
cmake: true
Expand All @@ -112,44 +130,38 @@ jobs:
brew install gnutls autoconf automake libtool

- uses: pnpm/action-setup@v4
if: ${{ matrix.native }}
if: ${{ !matrix.vm }}
with:
version: 9

- name: Install Node 20
if: ${{ matrix.native }}
if: ${{ !matrix.vm }}
uses: actions/setup-node@v4
with:
node-version: 20
architecture: ${{ env.setup_node_arch }}

- name: Install and Build Native
if: ${{ matrix.native }}
if: ${{ !matrix.vm }}
run: pnpm install

- name: Build JavaScript
if: ${{ matrix.native }}
if: ${{ !matrix.vm }}
run: pnpm run build.js

- name: Install Node 10
if: ${{ matrix.native && matrix.os != 'macos-14' }}
if: ${{ !matrix.vm && matrix.os != 'macos-14' }}
uses: actions/setup-node@v4
with:
node-version: 10
architecture: ${{ env.setup_node_arch }}

- name: Build Native
if: ${{ matrix.native && matrix.node_arch != 'ia32' }}
run: npm run build.native

- name: Build Native Windows 32
if: ${{ matrix.os == 'windows-2019' && matrix.node_arch == 'ia32' }}
run:
node ./node_modules/@aminya/cmake-ts/build/main.js named-configs
windows-x86
- name: Build Node 10 Native
if: ${{ !matrix.vm }}
run: node ./script/install.js

- name: Use Node 20
if: ${{ matrix.native }}
if: ${{ !matrix.vm }}
uses: actions/setup-node@v4
with:
node-version: 20
Expand Down Expand Up @@ -201,11 +213,11 @@ jobs:
overwrite: true

- name: Lint
if: "${{ contains(matrix.os, 'ubuntu') && matrix.native }}"
if: "${{ !matrix.vm && contains(matrix.os, 'ubuntu') }}"
run: pnpm run lint-test

- name: Test
if: ${{ matrix.native }}
if: ${{ !matrix.vm }}
uses: nick-fields/retry@v3
with:
timeout_minutes: 5
Expand All @@ -216,7 +228,7 @@ jobs:
rm -rf ./tmp && mkdir -p ./tmp

- name: Test Electron Windows/MacOS
if: "${{ !contains(matrix.os, 'ubuntu') && matrix.native }}"
if: "${{ !matrix.vm && !contains(matrix.os, 'ubuntu') }}"
uses: nick-fields/retry@v3
with:
timeout_minutes: 5
Expand All @@ -226,7 +238,7 @@ jobs:
continue-on-error: true

- name: Test Electron Linux
if: "${{ contains(matrix.os, 'ubuntu') && matrix.native }}"
if: "${{ !matrix.vm && contains(matrix.os, 'ubuntu') }}"
uses: nick-fields/retry@v3
with:
timeout_minutes: 5
Expand Down
3 changes: 3 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,9 @@ if(WIN32)
elseif(NOT "$ENV{PROCESSOR_ARCHITEW6432}" STREQUAL "")
set(CMAKE_SYSTEM_PROCESSOR "$ENV{PROCESSOR_ARCHITEW6432}")
set(VCPKG_TARGET_TRIPLET "x86-windows-static")
elseif("$ENV{Platform}" STREQUAL "arm64")
set(CMAKE_SYSTEM_PROCESSOR "arm64")
set(VCPKG_TARGET_TRIPLET "arm64-windows-static")
else()
set(CMAKE_SYSTEM_PROCESSOR "$ENV{PROCESSOR_ARCHITECTURE}")
set(VCPKG_TARGET_TRIPLET "x64-windows-static")
Expand Down
9 changes: 8 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,13 @@
"runtime": "node",
"runtimeVersion": "12.22.12"
},
{
"name": "windows-arm64",
"os": "win32",
"arch": "arm64",
"runtime": "node",
"runtimeVersion": "12.22.12"
},
{
"name": "windows-x86",
"os": "win32",
Expand Down Expand Up @@ -250,4 +257,4 @@
],
"license": "MIT AND MPL-2.0",
"author": "Amin Yahyaabadi <aminyahyaabadi74@gmail.com>, Rolf Timmermans <rolf@zxcv.nl>"
}
}
16 changes: 15 additions & 1 deletion script/install.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,21 @@
)
const cmakeTsPath = require.resolve("@aminya/cmake-ts/build/main.js")

cp.execFileSync(process.execPath, [cmakeTsPath, "nativeonly"], {
// Default args
let args = ["nativeonly"]

if (process.arch !== process.env.npm_config_target_arch || process.env.cross_compiling === "true") {
// cross-compilation
if (process.platform === "win32") {
if (process.env.npm_config_target_arch === "ia32") {
args = ["named-configs", "windows-x86"]
} else if (process.env.npm_config_target_arch === "arm64") {
args = ["named-configs", "windows-arm64"]
}
}
}

cp.execFileSync(process.execPath, [cmakeTsPath, ...args], {
stdio: "inherit",
})
}
Expand All @@ -23,7 +37,7 @@
cmakeTs()
} else {
try {
require("../lib/load-addon.js")

Check warning on line 40 in script/install.js

View workflow job for this annotation

GitHub Actions / ubuntu-20.04-x64--

Imported module should be assigned
} catch (error) {
devWarn(error)
cmakeTs()
Expand Down
4 changes: 2 additions & 2 deletions src/socket.cc
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,7 @@ Napi::Value Socket::Bind(const Napi::CallbackInfo& info) {
if (run_ctx->error != 0) {
res.Reject(ErrnoException(
Env(), static_cast<int32_t>(run_ctx->error), run_ctx->address)
.Value());
.Value());
return;
}

Expand Down Expand Up @@ -491,7 +491,7 @@ Napi::Value Socket::Unbind(const Napi::CallbackInfo& info) {
if (run_ctx->error != 0) {
res.Reject(ErrnoException(
Env(), static_cast<int32_t>(run_ctx->error), run_ctx->address)
.Value());
.Value());
return;
}

Expand Down
Loading