Skip to content

Commit

Permalink
Add cross compilation
Browse files Browse the repository at this point in the history
  • Loading branch information
devraymondsh committed Apr 11, 2024
1 parent e4916a0 commit eb9b2f7
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 2 deletions.
11 changes: 10 additions & 1 deletion .github/workflows/linux-daily-check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,23 @@ jobs:
strategy:
matrix:
arch: [amd64, arm64]
include:
- arch: arm64
is_arm: true
steps:
- if: ${{ matrix.is_arm }}
uses: pguyot/arm-runner-action@v2
with:
base_image: raspios_lite_arm64:latest

- name: Update system
run: sudo apt-get update && sudo apt-get --yes upgrade

- name: Install Nodejs 21 repo
run: sudo apt-get install --yes ca-certificates curl gnupg && curl -sL https://deb.nodesource.com/setup_21.x | sudo bash - && sudo apt-get update

- name: Install building tools
run: sudo apt-get install --yes git python3 python3-pip gcc g++ make ninja-build nodejs sudo
run: sudo apt-get install --yes git python3 python3-pip gcc g++ make libz-dev linux-libc-dev ninja-build nodejs sudo

- name: Clone the repo
run: git clone https://github.com/devraymondsh/libnode-distributable
Expand All @@ -32,6 +40,7 @@ jobs:
env:
CC: "sccache gcc"
CXX: "sccache g++"
CROSS_COMPILE: false
ARCH: ${{ matrix.arch }}
SCCACHE_GHA_ENABLED: "true"
run: cd libnode-distributable && node index.js
Expand Down
8 changes: 8 additions & 0 deletions .github/workflows/macos-daily-check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@ jobs:
strategy:
matrix:
arch: [amd64, arm64]
include:
- arch: amd64
is_arm: false
- arch: arm64
is_arm: true
steps:
- name: Install building tools
run: brew install node python ninja nasm git
Expand All @@ -26,8 +31,11 @@ jobs:
env:
CC: "sccache cc"
CXX: "sccache c++"
CC_host: "sccache cc"
CXX_host: "sccache c++"
ARCH: ${{ matrix.arch }}
SCCACHE_GHA_ENABLED: "true"
CROSS_COMPILE: ${{ matrix.is_arm }}
run: cd libnode-distributable && node index.js

- name: Find the shared library
Expand Down
6 changes: 6 additions & 0 deletions .github/workflows/windows-daily-check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@ jobs:
strategy:
matrix:
arch: [amd64, amd64_arm64]
include:
- arch: amd64
is_arm: false
- arch: amd64_arm64
is_arm: true
steps:
- uses: ilammy/msvc-dev-cmd@v1
with:
Expand All @@ -37,6 +42,7 @@ jobs:
env:
ARCH: ${{ matrix.arch }}
SCCACHE_GHA_ENABLED: "true"
CROSS_COMPILE: ${{ matrix.is_arm }}
run: cd libnode-distributable ; node index.js

- name: Find the shared library
Expand Down
13 changes: 12 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@ import { spawn } from "node:child_process";
let CC = process.env.CC;
let CXX = process.env.CXX;
let ARCH = process.env.ARCH;
let CROSS_COMPILE = process.env.CROSS_COMPILE;
if (!CC) CC = "gcc";
if (!CXX) CXX = "g++";
if (!ARCH) ARCH = "amd64";
if (!CROSS_COMPILE) CROSS_COMPILE = false;

const coreCount = cpus().length;
const threadCount = coreCount * 2;
Expand Down Expand Up @@ -89,12 +91,21 @@ if (!syncFs.existsSync("node")) {
);
}

let extraArgs = [];
if (process.platform == "win32") {
await spawnAsync("vcbuild.bat", [arch, "dll"], "node");
} else {
if (arch === "arm64") {
extraArgs.push("--with-arm-float-abi");
extraArgs.push("hard");
extraArgs.push("--with-arm-fpu");
extraArgs.push("neon");
}
if (CROSS_COMPILE) extraArgs.push("--cross-compiling");

await spawnAsync(
"./configure",
["--ninja", "--shared", "--dest-cpu", arch, "--dest-os", os],
["--shared", "--dest-cpu", arch, "--dest-os", os, ...extraArgs],
"node"
);
await spawnAsync("make", [`-j${threadCount}`], "node");
Expand Down

0 comments on commit eb9b2f7

Please sign in to comment.