Files
admin e95b37ca51 build(armv7): 收编 glibc26 引擎,产物绑定 GLIBC 2.18
- 引擎默认目录改为 dist/pglite-engine-armv7-glibc26(TDS 侧按
  docs/armv7-glibc-compat.md 重编,pqcomm.o/noblock_srv.o 不再引用 fcntl64)。
- sysroot 换成 zlib-only(上游完整 sysroot 的 libc 是 2.36 ⇒ 产物又绑 GLIBC_2.34+)。
- zig-cc-armv7.sh 增补:丢弃 rustc 的 --target / -target(zig 不认 unknown OS 名)、
  注入 explicit_bzero/getrandom 兼容 shim(glibc 2.25 才有)、target 降到 2.26。
- release.sh 清理指向其它引擎的 build script 实例与 rlib,并绕过 sccache
  (rustc 指纹不含 native 静态库内容 ⇒ 换引擎会命中旧缓存 ⇒ undefined fcntl64)。

影响:armv7 产物 GLIBC 需求降到 ≤2.18,ZYNQ(2.26)/海光(2.28) 可启动;
x86_64 本机构建路径不变。
2026-11-13 12:42:00 +08:00

119 lines
4.4 KiB
Bash
Executable File
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.
#!/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` 两个开关原样保留,语义不变。
#
# 🔴 2026-11-13 增补的三项(都是实测踩出来的):
# 1. **丢弃 rustc 传入的 --target= / -target <triple>**
# rustc 固定传 `--target=arm-unknown-linux-gnueabihf`,但 zig 的 target
# 解析器不认 `unknown` 这个 OS 名 ⇒ 合并后报
# "version '.2.26' in target triple 'arm-unknown-linux-gnueabihf.2.26' is invalid"。
# ⇒ 只保留本脚本自己的 `-target`。
# 2. **注入 glibc 兼容 shim(放在所有 .a 之后)**
# · explicit_bzero(glibc 2.25+)—— PostgreSQL 17 与 Rust std 都要用
# · getrandom (glibc 2.25+)—— Rust std 的 RandomState 播种哈希用
# ⚠️ 即使是**弱引用**,链接器也会把它写进 .gnu.version_r
# ⇒ 动态链接器启动即报 "version `GLIBC_2.25' not found"。
# ⚠️ 这两个 shim **不能**放进 libpglite.a:rustc 在 --whole-archive 场景
# 会重打包归档,对这类「只被 undefined 引用」的成员处理不确定
# (时有时无);且若库内已有,再注入会 duplicate symbol 链接失败。
# 用法:export ZIG_COMPAT_DIR=<引擎目录>/compat
# 3. **sysroot 必须是 zlib-only**
# 不要用上游那个含完整 Debian 12 armhf 的 sysroot:它的 libc.so.6 是
# glibc 2.36,`-L` 会把链接器引到 2.36 ⇒ 产物又绑 GLIBC_2.34+。
#
# 用法(cargo 官方约定,无需改仓库 .cargo/config):
# export CARGO_TARGET_ARMV7_UNKNOWN_LINUX_GNUEABIHF_LINKER=<本脚本路径>
# export ZIG_SYSROOT=<zlib-only armhf sysroot>
# export ZIG_COMPAT_DIR=<引擎目录>/compat
set -eu
TARGET="${ZIG_TARGET:-arm-linux-gnueabihf.2.26}"
SYSROOT="${ZIG_SYSROOT:-}"
COMPAT_DIR="${ZIG_COMPAT_DIR:-}"
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
# 🔴 用 NUL 分隔重建参数,避免路径含空格时被拆开。
# POSIX sh 没有数组,用 set -- 逐个 append。
# ⚠️ -target 是两参数形式(-target <triple>)⇒ 命中时要连下一个参数一起丢。
SKIP=0
for a in "$@"; do
if [ "${SKIP}" = "1" ]; then
SKIP=0
continue
fi
case "$a" in
--target=*)
# rustc 的 target 覆盖项 —— 丢弃(zig 不认 unknown OS)
;;
-target)
# zig cc 的 "-target <triple>" —— 丢弃两者,只保留本脚本的 TARGET
SKIP=1
;;
-Wl,/*)
# "-Wl,/abs/path" ⇒ "/abs/path"(zig cc 认裸路径,不认 -Wl, 合并形式)
printf '%s\0' "${a#-Wl,}" >> "${TMPARGS}"
;;
*)
printf '%s\0' "$a" >> "${TMPARGS}"
;;
esac
done
set --
while IFS= read -r -d '' line; do
set -- "$@" "${line}"
done < "${TMPARGS}"
# 🔴 zig 自带 libc 但**不带 zlib**(pglite-rs-sys 会链 -lz)
# ⇒ 指向 zlib-only armhf sysroot。
if [ -n "${SYSROOT}" ]; then
set -- -I "${SYSROOT}/include" -L "${SYSROOT}/lib" "$@"
fi
# 🔴 glibc 兼容 shim —— 必须放在所有 .a 之后(强符号优先于 libc.so.6)
if [ -n "${COMPAT_DIR}" ] && [ -d "${COMPAT_DIR}" ]; then
for obj in "${COMPAT_DIR}"/*.o; do
if [ -f "${obj}" ]; then
set -- "$@" "${obj}"
fi
done
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}" "$@"