Files
tdc-rs/scripts/check-platform-package.sh
T
admin 400d883e1a feat(p6): 平台改为预编译 rlib 接入,依赖全部来自包内闭包
- 新增 scripts/fetch-platform.sh:读 .sspf-version 解包 vendor/ + 生成 .cargo/config.toml(rustflags + rustdocflags),只校工具链 channel
- Cargo.toml 的 [dependencies]/[dev-dependencies] 清空:17 个 crate 全部 --extern 自平台闭包
- release profile lto 由 thin 改 false(平台 rlib bitcode-free,开 LTO 找不到 __bitcode)
- tower-http 不在闭包 ⇒ 自研 platform::static_files(ServeDir 等价,含 Range 206)与 platform::cors(permissive 等价)
- reqwest 与 extern tokio 双 runtime 必 panic(no reactor running)⇒ 自研 platform::http(HTTP/1.1 明文)
- tests/auth_flow 的 reqwest 调用改用 lib 客户端;tds_biz 的头白名单补 connection
- 新增尺子 check-platform-package.sh:依赖单一来源 + 真编一次证明平台闭包零重编
- 验收:cargo test 306 passed / 七把尺子 + 新尺子全绿;dev 构建 2.5s 只编本仓
2026-11-05 13:01:27 +08:00

114 lines
5.2 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
# 平台包接入自检(**P6 新增尺子**):证明「依赖全部来自预编译 rlib 闭包」这件事没漂。
#
# 判据(任一红即失败):
# 1. `.sspf-version` 与 `vendor/sspf-v<版本>/` 对得上,且包结构完整(`lib/` 存在);
# 2. `.cargo/config.toml` 已生成,里面**每一个** `--extern` / `-L` 指向的路径真实存在;
# 3. 工具链与包内 `rust-toolchain.toml` 的 channel **一字不差**(rlib ABI 前提);
# 4. `Cargo.toml` 的 `[dependencies]` / `[dev-dependencies]` **必须为空**
# —— 重新声明 `axum` / `tokio` / `serde` 会编出第二份 ⇒ 把业务 `Router` 交给
# `sspf::Finish` 时 `E0308 mismatched types`(已实测);
# 5. 真的编一次(touch 本仓源码触发重编):构建输出里**不得**出现
# `Compiling sspf` / `Compiling axum` / `Compiling tokio` / `Compiling serde*`
# ⇒ 「平台闭包零重编」是端到端可验的,不是文档承诺。
set -uo pipefail
ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
cd "$ROOT"
FAIL=0
pass() { printf ' ✅ %s\n' "$1"; }
fail() { printf ' ❌ %s\n' "$1"; FAIL=$((FAIL + 1)); }
echo "── 1. 版本与包结构 ─────────────────────────────"
if [ ! -f .sspf-version ]; then
fail ".sspf-version 缺失(先跑 scripts/fetch-platform.sh)"
VERSION=""
else
VERSION="$(tr -d '[:space:]' < .sspf-version)"
pass ".sspf-version = ${VERSION}"
fi
VENDOR="$ROOT/vendor/sspf-v${VERSION}"
if [ -n "$VERSION" ] && [ -d "$VENDOR/lib" ] && [ -f "$VENDOR/rust-toolchain.toml" ]; then
pass "vendor/sspf-v${VERSION}/ 结构完整(lib/ + rust-toolchain.toml)"
else
fail "vendor/sspf-v${VERSION}/ 不完整 ⇒ 跑 bash scripts/fetch-platform.sh"
fi
echo "── 2. .cargo/config.toml ───────────────────────"
CFG="$ROOT/.cargo/config.toml"
if [ ! -f "$CFG" ]; then
fail ".cargo/config.toml 缺失 ⇒ 跑 bash scripts/fetch-platform.sh"
else
pass ".cargo/config.toml 存在"
# 抽出所有 `k=v` / `dependency=...` 形式的路径,逐个判存在
MISSING=0
while IFS= read -r p; do
[ -n "$p" ] || continue
if [ ! -e "$p" ]; then
fail "配置里的路径不存在: ${p}"
MISSING=1
fi
done < <(grep -oE '(dependency=|=)[^",]+' "$CFG" | sed 's/^dependency=//; s/^=//' | grep '^/' || true)
[ "$MISSING" -eq 0 ] && pass "配置里所有绝对路径都存在"
# extern 必须覆盖跨边界的那 7 个 crate(少了任何一个,跨 `sspf` 边界传参就 E0308)
for c in sspf axum tokio serde serde_json http bytes; do
if grep -q "\"--extern\", \"${c}=" "$CFG"; then
:
else
fail "缺少 --extern ${c}(跨边界类型必须与平台同一实例)"
fi
done
pass "跨边界 7 个 crate 均已 --extern"
fi
echo "── 3. 工具链一致 ───────────────────────────────"
if [ -n "$VERSION" ] && [ -f "$VENDOR/rust-toolchain.toml" ]; then
WANT="$(grep -oE 'channel = "[^"]+"' "$VENDOR/rust-toolchain.toml" | grep -oE '[0-9]+\.[0-9]+\.[0-9]+')"
HAVE="$(rustc --version 2>/dev/null | awk '{print $2}')"
LOCAL="$(grep -oE 'channel = "[^"]+"' "$ROOT/rust-toolchain.toml" 2>/dev/null | grep -oE '[0-9]+\.[0-9]+\.[0-9]+')"
if [ "$WANT" = "$HAVE" ] && [ "$WANT" = "$LOCAL" ]; then
pass "rustc ${HAVE} == 包内 channel == 本仓 rust-toolchain.toml"
else
fail "工具链不一致:包内 ${WANT} / 本仓 ${LOCAL} / 实际 ${HAVE}(rlib ABI 会不匹配)"
fi
fi
echo "── 4. Cargo.toml 不许声明依赖 ─────────────────"
# 取 `[dependencies]` 与 `[dev-dependencies]` 段的有效行(去掉注释与空行)
for section in dependencies dev-dependencies; do
BAD="$(awk -v s="[$section]" '
$0 == s { inside = 1; next }
/^\[/ { inside = 0 }
inside {
line = $0
sub(/#.*/, "", line)
gsub(/[[:space:]]/, "", line)
if (line != "") print line
}' Cargo.toml)"
if [ -z "$BAD" ]; then
pass "[${section}] 为空(依赖全部来自平台包)"
else
fail "[${section}] 出现依赖声明: ${BAD}"
fi
done
echo "── 5. 平台闭包零重编(真编一次)───────────────"
touch src/lib.rs
BUILD="$(cargo build 2>&1)"
if printf '%s' "$BUILD" | grep -qE '^ *Compiling (sspf|sspf_|ssw_platform|axum|tokio|serde|serde_json|http|bytes|tower|pglite|hyper)'; then
fail "构建时重编了平台闭包(应只编本仓):"
printf '%s\n' "$BUILD" | grep -E '^ *Compiling' | sed 's/^/ /'
else
pass "构建只编本仓(平台 rlib 直链,零重编)"
fi
echo "────────────────────────────────────────────────"
if [ "$FAIL" -eq 0 ]; then
echo "平台包接入自检通过 ✅(预编译 rlib / 零重编 / 依赖单一来源)"
exit 0
fi
echo "平台包接入自检失败 ❌(${FAIL} 处)"
exit 1