Files
wangjia ee16cd3266
Deploy Client / build-windows (push) Successful in 1m46s
Deploy Client / build-android (push) Failing after 22m36s
Deploy Client / release-deploy (push) Has been skipped
Deploy Client / build-macos (push) Failing after 3m40s
Deploy Client / build-ios (push) Failing after 1m16s
ci(android): libbox 从 NAS gitea 镜像取 sing-box 源码,绕开 github 不可达
build-android 失败根因:build-libbox.sh 第一步 git clone github.com/SagerNet/
sing-box,而 mac runner(经 pangolin 隧道)连不上 github(SSL_ERROR_SYSCALL,
exit 128)。windows 成功是因为它从 NAS 镜像取 sing-box.exe、不碰 github。

修:build-libbox.sh clone 改用 $SINGBOX_GIT(默认仍 github,本地开发不受影响);
deploy-client.yml 的 build-android 设 SINGBOX_GIT=http://127.0.0.1:13000/wangjia/
sing-box.git,经 runner 的 gitea relay 取 NAS 上的 sing-box 镜像(已用 gitea
migrate 从 github 拉好,含 v1.13.13)。与 windows 的 DESKTOP_BIN_MIRROR 同思路,
CI 不再依赖 github。

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-07-26 08:24:03 +08:00

94 lines
4.9 KiB
Bash
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/usr/bin/env bash
# build-libbox.sh — 把 sing-box 编成嵌入式核心库(方案B / docs/vpn-core-embedding.md)
#
# 产物:
# apple → Libbox.xcframework (macOS System Extension / iOS Packet Tunnel 链接)
# android→ Libbox.aar (VpnService 集成)
#
# 关键:用 sagernet 的 gomobile **fork**(非上游 golang.org/x/mobile)。
# sing-box 版本必须与节点对齐(当前节点 1.13.13)。
#
# 前置:
# - Go(PATH 中);gomobile/gobind 由本脚本自动 go install 到 $(go env GOPATH)/bin 并加 PATH。
# - Android 还需 Android NDK ≥ 28(未设 ANDROID_NDK_HOME 则自动挑 SDK 里最高版)。
# NDK 27 会因 cronet-go 预编译库链接失败(unknown relocation 315)。JDK 17 用于 bind 末段 javac。
#
# 产物自动部署到工程引用位置(均 gitignore,故每次重建或换 worktree 都要重跑):
# apple → client/macos/Frameworks/Libbox.xcframework + client/ios/Frameworks/Libbox.xcframework
# android→ app/kernel/dist/android/libbox.aar(包名 io.nekohasekai.libbox,build.gradle 读这里)
#
# 用法:
# bash scripts/build-libbox.sh apple macos # 只编 macOS(快)
# bash scripts/build-libbox.sh apple # 全 Apple(ios+sim+tvos+macos,慢)
# bash scripts/build-libbox.sh android # Android aar(需 NDK ≥ 28)
# SINGBOX_VERSION=v1.13.13 WORK=/tmp/x bash scripts/build-libbox.sh apple macos
set -euo pipefail
SINGBOX_VERSION="${SINGBOX_VERSION:-v1.13.13}" # 与节点 sing-box 对齐
TARGET="${1:-apple}" # apple | android
PLATFORM="${2:-}" # macos | ios | "" (全 Apple)
WORK="${WORK:-/tmp/pangolin-libbox}"
REPO_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
command -v go >/dev/null || { echo "✗ 需要 Go"; exit 1; }
# ── Android: 选 NDK ─────────────────────────────────────────────────────────
# ⚠️ 官方 build_libbox 会拉 cronet-go(Tailscale 依赖),其预编译 libcronet.a 含新版
# 重定位类型,NDK 27 的 lld 链接报 "unknown relocation (315)" 而失败。**必须 NDK ≥ 28。**
# 未显式设 ANDROID_NDK_HOME 时,自动从 SDK 挑最高版本 NDK。
if [ "$TARGET" = "android" ] && [ -z "${ANDROID_NDK_HOME:-}" ]; then
SDK="${ANDROID_HOME:-${ANDROID_SDK_ROOT:-$HOME/Library/Android/sdk}}"
if [ -d "$SDK/ndk" ]; then
NDK_PICK="$(ls -d "$SDK"/ndk/*/ 2>/dev/null | sort | tail -1)"
[ -n "$NDK_PICK" ] && export ANDROID_NDK_HOME="${NDK_PICK%/}" ANDROID_HOME="$SDK"
fi
fi
[ "$TARGET" = "android" ] && echo " NDK = ${ANDROID_NDK_HOME:-<未找到!gomobile 会失败>}android 需 ≥ 2827 会链接失败)"
echo "==> [1/3] 安装 sagernet/gomobile fork v0.1.12(非上游)"
go install github.com/sagernet/gomobile/cmd/gomobile@v0.1.12
go install github.com/sagernet/gomobile/cmd/gobind@v0.1.12
export PATH="$PATH:$(go env GOPATH)/bin"
gomobile init
echo "==> [2/3] 拉 sing-box $SINGBOX_VERSION 源码"
mkdir -p "$WORK"
rm -rf "$WORK/sing-box"
# sing-box 源码:默认 github,CI 里国内 runner 连不上 github → 经 SINGBOX_GIT 指向
# NAS gitea 镜像(wangjia/sing-box,gitea migrate 自 github)。见 deploy-client.yml。
SINGBOX_GIT="${SINGBOX_GIT:-https://github.com/SagerNet/sing-box.git}"
git clone --depth 1 --branch "$SINGBOX_VERSION" "$SINGBOX_GIT" "$WORK/sing-box"
cd "$WORK/sing-box"
echo "==> [3/3] 用官方 build_libbox 编核心库"
if [ "$TARGET" = "apple" ]; then
if [ -n "$PLATFORM" ]; then
go run ./cmd/internal/build_libbox -target apple -platform "$PLATFORM"
else
go run ./cmd/internal/build_libbox -target apple
fi
echo "✅ 产物: $WORK/sing-box/Libbox.xcframework"
# 按 PLATFORM 部署到工程引用位置(均 gitignore)。⚠️ 只编某一平台时,产出的 xcframework
# 只含该平台 slice,**不能**覆盖到另一平台的 Frameworks(否则那端 build 缺 slice)。
# 空(全 Apple)→ macos + ios 都放;macos→只 macos;ios→只 ios。
case "$PLATFORM" in
macos) fws=("$REPO_ROOT/client/macos/Frameworks") ;;
ios) fws=("$REPO_ROOT/client/ios/Frameworks") ;;
*) fws=("$REPO_ROOT/client/macos/Frameworks" "$REPO_ROOT/client/ios/Frameworks") ;;
esac
for fw in "${fws[@]}"; do
mkdir -p "$fw"
rm -rf "$fw/Libbox.xcframework"
cp -R "$WORK/sing-box/Libbox.xcframework" "$fw/"
echo " → 已部署 $fw/Libbox.xcframework"
done
else
go run ./cmd/internal/build_libbox -target android
echo "✅ 产物: $WORK/sing-box/Libbox.aar"
# 部署到 build.gradle 引用位置(app/kernel/dist/android/libbox.aar,gitignore)。
# ⚠️ 注意大小写/文件名:gradle 读的是小写 libbox.aar。
mkdir -p "$REPO_ROOT/app/kernel/dist/android"
cp "$WORK/sing-box/Libbox.aar" "$REPO_ROOT/app/kernel/dist/android/libbox.aar"
echo " → 已部署 $REPO_ROOT/app/kernel/dist/android/libbox.aar(包名 io.nekohasekai.libbox"
fi