Files
ssw-platform/scripts/zig-cc-armv7.sh
T
admin 39201143c5 feat(armv7): 交叉编译 32 位 ARM 平台包,自建 pglite 引擎
上游 pglite-rs 只有 aarch64/x86_64 四架构引擎,没有 armv7 ⇒ 自建。
上游认 PGLITE_LIB_DIR,用它喂自建的 libpglite.a + pglite-runtime.tar。

构建链(amd64 容器 + arm-linux-gnueabihf 交叉工具链 + zig cc 链接):
- build-pglite-engine.sh / build-libpglite-cross.sh / relocate-runtime-cross.sh
- zig-cc-armv7.sh(改写 -Wl,/abs/path + 注入 armhf sysroot)
- build-armv7.sh(一键:引擎 → Rust 交叉编译 → arm/v7 容器冒烟)

三个坑(详见 docs/armv7-build.md):
- strip="symbols" 让 rustc 重建 native 静态库时破坏全局符号 ⇒ 交叉构建强制 strip=none
- PG configure 在 cross_compiling 时假定不支持 --export-dynamic ⇒ 强制 cache 变量
- 上游把 runtime 可移植化拆成独立脚本(RPATH + libpq + libz)⇒ 新增交叉版

release.sh 支持 --target <triple>:跳过宿主消费方编译自检改验架构,
rlib 走隔离目录,解包目录名带 target 后缀(多平台互不覆盖)。

实测(linux/arm/v7 容器):initdb、单用户模式、pglite 读写探针、
sspf-admin 启动 + 14255 条示例数据、登录接口、CurrentUser 菜单树全部通过;
从发布包 tar 解出的二进制端到端复测同样通过。
2026-11-12 20:17:26 +08:00

100 lines
3.0 KiB
Bash
Executable File
Raw 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.
#!/bin/sh
# zig-cc-armv7.sh —— cargo 交叉链接器包装器(zig cc → armv7-linux-gnueabihf)
#
# 🔴 为什么需要它(2026-11-12):
# rustc 传给链接器的原生静态库参数长这样(`-Wl,+whole-archive` 的展开):
# -Wl,--whole-archive -Wl,/abs/path/libpglite.a -Wl,--no-whole-archive
# `zig cc` 的参数解析器**不接受** `-Wl,` 后面直接跟一个路径
# (报 "unsupported linker arg: /abs/path/libpglite.a"),
# 但接受「裸路径」作为独立输入文件 ⇒ 这里把 `-Wl,/path` 还原成 `/path`。
# `--whole-archive` / `--no-whole-archive` 两个开关原样保留,语义不变。
#
# 用法(cargo 官方约定,无需改仓库 .cargo/config):
# export CARGO_TARGET_ARMV7_UNKNOWN_LINUX_GNUEABIHF_LINKER=<本脚本路径>
# export ZIG_SYSROOT=<armhf sysroot 目录> # 可选:提供 -lz 等系统库
set -eu
TARGET="${ZIG_TARGET:-arm-linux-gnueabihf}"
SYSROOT="${ZIG_SYSROOT:-}"
TMPARGS="$(mktemp)"
trap 'rm -f "${TMPARGS}"' EXIT
# 🔴 调试:ZIG_LOG=<文件> 时把改写后的完整参数落盘,便于排查链接失败
if [ -n "${ZIG_LOG:-}" ]; then
{
echo "=== zig-cc-armv7.sh 原始参数 ==="
printf '%s\n' "$@"
} > "${ZIG_LOG}" 2>/dev/null || true
fi
# 🔴 调试:把 rustc 实际传给链接器的 libpglite.a 副本留档(对比原件)
if [ -n "${ZIG_LOG:-}" ]; then
for a in "$@"; do
case "$a" in
*/libpglite.a)
cp "$a" "${ZIG_LOG}.libpglite.a" 2>/dev/null || true
;;
esac
done
fi
for a in "$@"; do
case "$a" in
-Wl,/*)
# "-Wl,/abs/path" ⇒ "/abs/path"(zig cc 认裸路径,不认 -Wl, 合并形式)
printf '%s\0' "${a#-Wl,}" >> "${TMPARGS}"
;;
*)
printf '%s\0' "${a}" >> "${TMPARGS}"
;;
esac
done
# 🔴 调试:把 rustc 实际传给链接器的 libpglite.a 副本留档(对比原件)
if [ -n "${ZIG_LOG:-}" ]; then
for a in "$@"; do
case "$a" in
*libpglite.a)
if [ -f "$a" ]; then
cp "$a" "${ZIG_LOG}.libpglite.a" 2>/dev/null || true
fi
;;
esac
done
fi
# 🔴 用 NUL 分隔重建参数,避免路径含空格时被拆开。
# POSIX sh 没有数组,用 set -- 逐个 append。
set --
while IFS= read -r -d '' line; do
set -- "$@" "${line}"
done < "${TMPARGS}"
# 🔴 zig 自带 libc 但**不带 zlib**(pglite-rs-sys 会链 -lz)
# ⇒ 指向自建的 armhf sysroot(里面有 libz.so + zlib.h + 交叉 libc 运行时)。
if [ -n "${SYSROOT}" ]; then
set -- -I "${SYSROOT}/include" -L "${SYSROOT}/lib" "$@"
fi
if [ -n "${ZIG_LOG:-}" ]; then
{
echo "=== 改写后参数 ==="
printf '%s\n' "$@"
echo "=== end ==="
} > "${ZIG_LOG}.final" 2>/dev/null || true
# 🔴 改写后的裸路径副本才是链接器真正吃进去的那份,单独留档
for a in "$@"; do
case "$a" in
*libpglite.a)
if [ -f "$a" ]; then
cp "$a" "${ZIG_LOG}.bare-libpglite.a" 2>/dev/null || true
fi
;;
esac
done
fi
exec zig cc -target "${TARGET}" "$@"