Skip to content

Commit 66719be

Browse files
committed
perf: 优化交叉编译
1 parent f5173fa commit 66719be

5 files changed

Lines changed: 355 additions & 135 deletions

File tree

conf/config.json

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@
88
"loongarch64": {
99
"version": "0.65.1",
1010
"template": "https://github.com/msojocs/nwjs-loongarch/releases/download/v0.65.2/nwjs-sdk-v0.65.2-linux-loong64.tar.gz"
11+
},
12+
"arm64": {
13+
"version": "0.55.0",
14+
"template": "https://github.com/LeonardLaszlo/nw.js-armv7-binaries/releases/download/nw55-arm64_2021-12-05/nw55-arm64_2021-12-05.tar.gz"
1115
}
1216
},
1317
"nw2node": {
@@ -59,11 +63,15 @@
5963
"loongarch64": {
6064
"version": "18.20.4",
6165
"template": "https://github.com/loong64/node/releases/download/v${version}/node-v${version}-linux-loong64.tar.gz"
66+
},
67+
"arm64": {
68+
"version": "16.13.1",
69+
"template": "https://npmmirror.com/mirrors/node/v${version}/node-v${version}-linux-arm64.tar.gz"
6270
}
6371
}
6472
},
6573
"compiler": {
66-
"version": "0.1.6",
74+
"version": "0.1.7",
6775
"template": "https://github.com/msojocs/wx-compiler/releases/download/v${version}"
6876
},
6977
"devtools": {
Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
#!/bin/bash
2+
# 为 x86_64 → arm64 交叉编译准备工具链与 sysroot
3+
set -ex
4+
5+
root_dir=$(cd "$(dirname "$0")/../.." && pwd -P)
6+
7+
# ────────────────────────────────────────────
8+
# 1. 检查系统交叉编译工具链
9+
# ────────────────────────────────────────────
10+
if ! command -v aarch64-linux-gnu-gcc &>/dev/null; then
11+
echo "错误:未找到 aarch64-linux-gnu-gcc。" >&2
12+
echo "请先安装:sudo apt install gcc-aarch64-linux-gnu g++-aarch64-linux-gnu" >&2
13+
exit 1
14+
fi
15+
16+
# ────────────────────────────────────────────
17+
# 2. 下载 sysroot(Debian bookworm arm64 包)
18+
# ────────────────────────────────────────────
19+
SYSROOT="$root_dir/cache/cross-tools-arm64/target"
20+
mkdir -p "$SYSROOT"
21+
mkdir -p "$root_dir/cache/pkg"
22+
cd "$root_dir/cache/pkg"
23+
24+
BASE_DEBIAN="http://ftp.kr.debian.org/debian"
25+
SUITE="bookworm"
26+
COMPONENT="main"
27+
DEB_ARCH="arm64"
28+
29+
function _index_path {
30+
local suite=$1
31+
local arch=$2
32+
echo "$root_dir/cache/pkg/Packages-debian-${suite}-${arch}.xz"
33+
}
34+
35+
function _download_index {
36+
local suite=$1
37+
local arch=$2
38+
local index_path=$(_index_path "$suite" "$arch")
39+
local index_url="$BASE_DEBIAN/dists/$suite/$COMPONENT/binary-$arch/Packages.xz"
40+
if [ ! -f "$index_path" ]; then
41+
wget -c "$index_url" -O "$index_path"
42+
fi
43+
}
44+
45+
function _find_filename_in_index {
46+
local pkg_name=$1
47+
local index_path=$2
48+
if [ ! -f "$index_path" ]; then
49+
return 1
50+
fi
51+
xzcat "$index_path" | awk -v pkg="$pkg_name" '
52+
$1=="Package:" {p=$2}
53+
$1=="Filename:" && p==pkg {print $2; exit}
54+
'
55+
}
56+
57+
function _resolve_pkg_url {
58+
local pkg_name=$1
59+
local filename=""
60+
61+
# 先查 arm64
62+
_download_index "$SUITE" "$DEB_ARCH"
63+
filename=$(_find_filename_in_index "$pkg_name" "$(_index_path "$SUITE" "$DEB_ARCH")")
64+
if [ -n "$filename" ]; then
65+
echo "$BASE_DEBIAN/$filename"
66+
return 0
67+
fi
68+
69+
# 再查 arch-independent(all)
70+
_download_index "$SUITE" "all"
71+
filename=$(_find_filename_in_index "$pkg_name" "$(_index_path "$SUITE" "all")")
72+
if [ -n "$filename" ]; then
73+
echo "$BASE_DEBIAN/$filename"
74+
return 0
75+
fi
76+
77+
return 1
78+
}
79+
80+
function install_pkg {
81+
local pkg_name=$1
82+
local pkg_url
83+
pkg_url=$(_resolve_pkg_url "$pkg_name")
84+
if [ -z "$pkg_url" ]; then
85+
echo "Failed to resolve package URL for $pkg_name" >&2
86+
exit 1
87+
fi
88+
local pkg_file
89+
pkg_file=$(basename "$pkg_url")
90+
if [ ! -f "$pkg_file" ]; then
91+
wget -c "$pkg_url" -O "$pkg_file"
92+
fi
93+
dpkg -x "$pkg_file" "$SYSROOT"
94+
}
95+
96+
install_pkg libx11-dev
97+
install_pkg libxkbfile-dev
98+
install_pkg x11proto-dev
99+
install_pkg libx11-6
100+
install_pkg libxkbfile1
101+
install_pkg libkrb5-dev
102+
install_pkg krb5-multidev
103+
install_pkg openssl
104+
install_pkg libssl-dev
105+
install_pkg libssh2-1-dev
106+
install_pkg libssh2-1
107+
install_pkg zlib1g
108+
install_pkg comerr-dev
109+
install_pkg libkrb5-3
110+
install_pkg libk5crypto3
111+
install_pkg libgssapi-krb5-2
112+
install_pkg libcom-err2
113+
114+
# ────────────────────────────────────────────
115+
# 3. 安装 node-gyp 头文件
116+
# ────────────────────────────────────────────
117+
node-gyp install
118+
119+
# ────────────────────────────────────────────
120+
# 4. 修复 krb5-config(输出正确的 arm64 链接参数)
121+
# ────────────────────────────────────────────
122+
mkdir -p "$SYSROOT/usr/bin"
123+
echo 'echo "-L/usr/lib/aarch64-linux-gnu/mit-krb5 -Wl,-Bsymbolic-functions -Wl,-z,relro -lgssapi_krb5 -lkrb5 -lk5crypto -lcom_err"' \
124+
> "$SYSROOT/usr/bin/krb5-config"
125+
chmod +x "$SYSROOT/usr/bin/krb5-config"

tools/parse-config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ for (let i = 0; i < args.length; i++) {
4646
i++;
4747
if (i < args.length) {
4848
if (args[i - 1] === '--arch') {
49-
if (args[i] === 'x64' || args[i] === 'loongarch64') {
49+
if (args[i] === 'x64' || args[i] === 'loongarch64' || args[i] === 'arm64') {
5050
configArg.arch = args[i];
5151
} else {
5252
console.error(`Invalid value for option --arch: ${args[i]}`);

0 commit comments

Comments
 (0)