cd1ef98b27
外网 runner 的 git fetch 经 ali frps 隧道偶发超时(run#289/290 的 Checkout 卡死即此)。A 层加固: - deploy-client.yml 全部 actions/checkout 加 fetch-depth:1 —— 从拉全历史 降到一层,数据骤减,直接打掉 Checkout 步超时根因(外网/在家都受益)。 - build-libbox.sh sing-box clone(已 --depth 1)加 3 次重试 —— 另一大 fetch 抖了自动重来。 checkout 步显式重试(需替换 actions/checkout)暂缓,先看浅克隆后失败率; 仍高再上 checkout 重试 + frps 隧道调优(B)。 Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01FEVUXAbFT6bF1Qw27RHWoD
101 lines
5.2 KiB
Bash
101 lines
5.2 KiB
Bash
#!/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 需 ≥ 28,27 会链接失败)"
|
||
|
||
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}"
|
||
# 已是 --depth 1 浅克隆;外网 runner 经 ali frps 隧道 clone 偶发超时 → 重试 3 次。
|
||
_sb_ok=
|
||
for _try in 1 2 3; do
|
||
rm -rf "$WORK/sing-box"
|
||
if git clone --depth 1 --branch "$SINGBOX_VERSION" "$SINGBOX_GIT" "$WORK/sing-box"; then _sb_ok=1; break; fi
|
||
echo " sing-box clone 第 $_try 次失败(frps 抖动?),12s 后重试..."; sleep 12
|
||
done
|
||
[ -n "$_sb_ok" ] || { echo "✗ sing-box clone 重试耗尽($SINGBOX_GIT)"; exit 1; }
|
||
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
|