Skip to content

Commit

Permalink
fix: detect cross-compilation in the install script
Browse files Browse the repository at this point in the history
  • Loading branch information
aminya committed Jan 12, 2025
1 parent cce4323 commit ea1d4df
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 34 deletions.
63 changes: 33 additions & 30 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,62 +27,71 @@ jobs:
- ""
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
node_target_arch: arm64
cpp_arch: amd64_arm64
native: true
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
node_target_arch: arm64
cpp_arch: arm64
native: true
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
distro: bookworm
node_arch: arm64
node_target_arch: arm64
cpp_arch: arm64
native: false
vm: true
cross_compiling: false

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

env:
npm_config_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 @@ -105,7 +114,7 @@ jobs:
shell: bash

- name: Setup Cpp
if: ${{ matrix.native }}
if: ${{ !matrix.vm }}
uses: aminya/setup-cpp@master
with:
vcvarsall: ${{ contains(matrix.os, 'windows') }}
Expand All @@ -121,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 @@ -210,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 @@ -225,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 @@ -235,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
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 <[email protected]>, Rolf Timmermans <[email protected]>"
}
}
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 @@ function cmakeTs() {
)
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 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

0 comments on commit ea1d4df

Please sign in to comment.