Skip to content

Commit bcc978b

Browse files
committed
Add cross compilation
1 parent e4916a0 commit bcc978b

File tree

5 files changed

+122
-67
lines changed

5 files changed

+122
-67
lines changed
Lines changed: 34 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: Linux daily check
1+
name: Linux
22

33
on:
44
schedule:
@@ -7,34 +7,50 @@ on:
77

88
jobs:
99
update:
10-
name: Linux daily check
1110
runs-on: ubuntu-latest
1211
strategy:
1312
matrix:
1413
arch: [amd64, arm64]
14+
include:
15+
- arch: arm64
16+
is_arm: true
17+
container:
18+
image: ubuntu:devel
1519
steps:
16-
- name: Update system
17-
run: sudo apt-get update && sudo apt-get --yes upgrade
20+
- uses: actions/checkout@v4
1821

19-
- name: Install Nodejs 21 repo
20-
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
22+
- name: Setup ccache
23+
uses: actions/cache@v4
24+
with:
25+
path: .ccache
26+
save-always: true
27+
key: ${{ github.workflow }}-${{ matrix.arch }}
2128

2229
- name: Install building tools
23-
run: sudo apt-get install --yes git python3 python3-pip gcc g++ make ninja-build nodejs sudo
24-
25-
- name: Clone the repo
26-
run: git clone https://github.com/devraymondsh/libnode-distributable
27-
28-
- name: Run sccache-cache
29-
uses: mozilla-actions/[email protected]
30+
run: |
31+
apt-get install --yes ca-certificates curl gnupg && curl -sL https://deb.nodesource.com/setup_21.x | bash -
32+
apt-get update
33+
apt-get install --yes git nodejs python3 python3-pip gcc g++ make nasm ccache linux-libc-dev linux-libc-dev-arm64-cross binutils-aarch64-linux-gnu gcc-aarch64-linux-gnu g++-aarch64-linux-gnu
3034
3135
- name: Run the script
3236
env:
33-
CC: "sccache gcc"
34-
CXX: "sccache g++"
3537
ARCH: ${{ matrix.arch }}
36-
SCCACHE_GHA_ENABLED: "true"
37-
run: cd libnode-distributable && node index.js
38+
CC: "${{ matrix.is_arm && 'aarch64-linux-gnu-gcc' || 'gcc' }}"
39+
CXX: "${{ matrix.is_arm && 'aarch64-linux-gnu-g++' || 'g++' }}"
40+
# We don't want these variables to be set for AMD64.
41+
CC_host: "${{ matrix.is_arm && 'gcc' || null }}"
42+
CXX_host: "${{ matrix.is_arm && 'g++' || null }}"
43+
AS: "${{ matrix.is_arm && 'aarch64-linux-gnu-as' || null }}"
44+
LD: "${{ matrix.is_arm && 'aarch64-linux-gnu-ld' || null }}"
45+
RANLIB: "${{ matrix.is_arm && 'aarch64-linux-gnu-ranlib' || null }}"
46+
run: |
47+
export CCACHE_COMPRESS="true"
48+
export CCACHE_BASEDIR="$GITHUB_WORKSPACE"
49+
export CCACHE_DIR="$CCACHE_BASEDIR/.ccache"
50+
export PATH="/usr/lib/ccache:/usr/local/opt/ccache/libexec:$PATH"
51+
mkdir -p "$CCACHE_DIR"
52+
53+
node index.js
3854
3955
- name: Find the shared library
40-
run: find libnode-distributable/node -name libnode.so\* -not -name '*.TOC' -not -name '*.toc' -exec ls {} \;
56+
run: ls node/out/Release
Lines changed: 38 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: Macos daily check
1+
name: Macos
22

33
on:
44
schedule:
@@ -7,28 +7,53 @@ on:
77

88
jobs:
99
update:
10-
name: Macos daily check
11-
runs-on: macos-latest
1210
strategy:
1311
matrix:
1412
arch: [amd64, arm64]
13+
include:
14+
- arch: arm64
15+
os: macos-14
16+
is_arm: true
17+
- arch: amd64
18+
os: macos-13
19+
runs-on: ${{ matrix.os }}
1520
steps:
21+
- uses: actions/checkout@v4
22+
23+
- name: Setup ccache
24+
uses: actions/cache@v4
25+
with:
26+
path: .ccache
27+
save-always: true
28+
key: ${{ github.workflow }}-${{ matrix.arch }}
29+
1630
- name: Install building tools
17-
run: brew install node python ninja nasm git
31+
run: |
32+
sudo chown -R $(whoami) $(brew --prefix)/*
1833
19-
- name: Clone the repo
20-
run: git clone https://github.com/devraymondsh/libnode-distributable
34+
# homebrew fails to update python 3.9.1 to 3.9.1.1 due to unlinking failure
35+
sudo rm -f /usr/local/bin/2to3 || true
36+
# homebrew fails to update python from 3.9 to 3.10 due to another unlinking failure
37+
sudo rm -f /usr/local/bin/idle3 || true
38+
sudo rm -f /usr/local/bin/pydoc3 || true
39+
sudo rm -f /usr/local/bin/python3 || true
40+
sudo rm -f /usr/local/bin/python3-config || true
2141
22-
- name: Run sccache-cache
23-
uses: mozilla-actions/[email protected]
42+
brew install git node ninja nasm ccache
2443
2544
- name: Run the script
2645
env:
27-
CC: "sccache cc"
28-
CXX: "sccache c++"
46+
CC: "gcc"
47+
CXX: "g++"
2948
ARCH: ${{ matrix.arch }}
30-
SCCACHE_GHA_ENABLED: "true"
31-
run: cd libnode-distributable && node index.js
49+
run: |
50+
export CCACHE_COMPRESS="true"
51+
export CCACHE_BASEDIR="$GITHUB_WORKSPACE"
52+
export CCACHE_DIR="$CCACHE_BASEDIR/.ccache"
53+
export PATH="/usr/lib/ccache:/usr/local/opt/ccache/libexec:$PATH"
54+
mkdir -p "$CCACHE_DIR"
55+
56+
node index.js
3257
3358
- name: Find the shared library
34-
run: find libnode-distributable/node -name libnode.so\* -not -name '*.TOC' -not -name '*.toc' -exec ls {} \;
59+
run: ls node/out/Release
Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: Windows daily check
1+
name: Windows
22

33
on:
44
schedule:
@@ -7,37 +7,39 @@ on:
77

88
jobs:
99
update:
10-
name: Windows daily check
10+
name: Windows
1111
runs-on: windows-latest
1212
strategy:
1313
matrix:
1414
arch: [amd64, amd64_arm64]
1515
steps:
16+
- uses: actions/checkout@v4
17+
18+
- run: |
19+
"$([Environment]::OSVersion.VersionString) $(('x86', 'x64')[[Environment]::Is64BitOperatingSystem])"
20+
# - name: Setup ccache
21+
# uses: actions/cache@v4
22+
# with:
23+
# key: ${{ github.workflow }}-${{ matrix.arch }}
24+
# path: C:\.ccache
25+
1626
- uses: ilammy/msvc-dev-cmd@v1
1727
with:
1828
arch: ${{ matrix.arch }}
1929

2030
- uses: MinoruSekine/setup-scoop@v3
2131
with:
22-
buckets: extras
2332
update_path: true
2433
run_as_admin: true
2534
scoop_update: true
2635

2736
- name: Install building tools
28-
run: scoop install nodejs python ninja nasm git
29-
30-
- name: Clone the repo
31-
run: git clone https://github.com/devraymondsh/libnode-distributable
32-
33-
- name: Run sccache-cache
34-
uses: mozilla-actions/[email protected]
37+
run: scoop install git nodejs python ninja nasm
3538

3639
- name: Run the script
3740
env:
3841
ARCH: ${{ matrix.arch }}
39-
SCCACHE_GHA_ENABLED: "true"
40-
run: cd libnode-distributable ; node index.js
42+
run: node index.js
4143

4244
- name: Find the shared library
43-
run: dir libnode-distributable\node\out\Release\libnode.dll
45+
run: dir node\out\Release\node.lib

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
node
1+
node
2+
.ccache

index.js

Lines changed: 33 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -3,29 +3,26 @@ import { cpus } from "node:os";
33
import fs from "node:fs/promises";
44
import { spawn } from "node:child_process";
55

6-
let CC = process.env.CC;
7-
let CXX = process.env.CXX;
8-
let ARCH = process.env.ARCH;
9-
if (!CC) CC = "gcc";
10-
if (!CXX) CXX = "g++";
11-
if (!ARCH) ARCH = "amd64";
6+
let OS = process.env.OS;
7+
const ARCH = process.env.ARCH == "amd64" ? "x64" : "arm64";
128

139
const coreCount = cpus().length;
1410
const threadCount = coreCount * 2;
15-
const arch = ARCH == "amd64" ? "x64" : "arm64";
16-
let os;
11+
let current_os;
1712
switch (process.platform) {
1813
case "darwin":
19-
os = "mac";
14+
current_os = "mac";
2015
break;
2116
case "win32":
22-
os = "win";
17+
current_os = "win";
2318
break;
2419
default:
25-
os = "linux";
20+
current_os = "linux";
2621
break;
2722
}
2823

24+
if (!OS) OS = current_os;
25+
2926
const nodejsGithubRepo = "https://github.com/nodejs/node";
3027
const removeTheVCharacter = (str) => str.replace("v", "");
3128

@@ -55,11 +52,11 @@ const isANewerVersion = (oldVer, newVer) => {
5552
return false;
5653
};
5754

58-
const spawnAsync = (program, args, cwd) =>
55+
const spawnAsync = (program, args) =>
5956
new Promise((resolve, reject) => {
60-
console.log([program, ...args].join(" "));
57+
console.log("Running:", [program, ...args].join(" "));
6158

62-
const child = spawn(program, args, cwd ? { cwd } : {});
59+
const child = spawn(program, args, {});
6360

6461
child.stdout.on("data", (chunk) => console.log(chunk.toString()));
6562
child.stderr.on("data", (chunk) => console.error(chunk.toString()));
@@ -85,17 +82,31 @@ if (!syncFs.existsSync("node")) {
8582
`v${latestNodeVersion}`,
8683
"--depth=1",
8784
],
88-
undefined
85+
undefined,
86+
{}
8987
);
9088
}
9189

90+
process.chdir("node");
91+
92+
let extraArgs = [];
9293
if (process.platform == "win32") {
93-
await spawnAsync("vcbuild.bat", [arch, "dll"], "node");
94+
await spawnAsync(".\\vcbuild.bat", [ARCH, "dll", "openssl-no-asm"]);
9495
} else {
95-
await spawnAsync(
96-
"./configure",
97-
["--ninja", "--shared", "--dest-cpu", arch, "--dest-os", os],
98-
"node"
99-
);
100-
await spawnAsync("make", [`-j${threadCount}`], "node");
96+
if (ARCH === "arm64") {
97+
extraArgs.push("--with-arm-float-abi");
98+
extraArgs.push("hard");
99+
extraArgs.push("--with-arm-fpu");
100+
extraArgs.push("neon");
101+
}
102+
103+
await spawnAsync("./configure", [
104+
"--shared",
105+
"--dest-cpu",
106+
ARCH,
107+
"--dest-os",
108+
OS,
109+
...extraArgs,
110+
]);
111+
await spawnAsync("make", [`-j${threadCount}`]);
101112
}

0 commit comments

Comments
 (0)