Files
ssw-mpc/tools/release-build.sh
T
admin 2606062761 feat(release): 发布构建三目标二进制 + 可复现的发布脚本
- tools/release-build.sh:一次产出 x86_64-linux-gnu / armv7-linux-gnueabihf /
  x86_64-apple-darwin 三个宿主版 mpc 二进制,落 dist/ 并出 SHA256SUMS
- crates/mpc-chain: 新增 vendored feature(默认关闭),发布构建把 OpenSSL
  从源码编进二进制 ⇒ 产物自包含,不依赖目标机 libssl 版本
- crates/mpc-cli: 透出 vendored feature 作为发布构建入口
- .gitignore: 忽略 dist/(发布物走 Release 上传,不进仓)

踩坑与结论(写进脚本头,勿删):
- sccache 不能包住 zig:cargo-zigbuild 把 CC 设成「sccache …/zigcc-*.sh」,
  sccache 不认 ⇒ vendored OpenSSL 每个 .c 都编不过。交叉编译必须
  --config 'build.rustc-wrapper=""' 把 sccache 关掉(mac 原生是 clang,不受影响)
2026-11-10 14:03:21 +08:00

112 lines
3.3 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.
#!/usr/bin/env bash
# 发布构建:一次产出三个目标的主机版二进制(`mpc` 单二进制)。
#
# 目标(宿主形态 = 默认 control-plane,含 hostd + chain + OpenSSL):
# x86_64-unknown-linux-gnu linux x86_64
# armv7-unknown-linux-gnueabihf linux arm 32 位
# x86_64-apple-darwin mac x86_64
#
# 用法:
# tools/release-build.sh # 只构建,产物落在 dist/
# tools/release-build.sh --tag v0.0.1 # 构建 + 打 tag(不推送)
# tools/release-build.sh --tag v0.0.1 --push # 构建 + 打 tag + 推 tag
#
# ★ 两条踩过的坑(别删):
# ① sccache 不能包住 zig:cargo-zigbuild 会把 CC 设成
# 「sccache …/zigcc-xxx.sh」,sccache 不认这个编译器 ⇒
# vendored OpenSSL 的每一个 .c 都编不过,报
# 「Compiler not supported / SCCACHE_START_SERVER=1 can't be used with other commands」。
# ⇒ 交叉编译必须 --config 'build.rustc-wrapper=""' 把 sccache 关掉。
# (mac 原生目标是 clang,sccache 认,所以本机原生构建不受影响。)
# ② OpenSSL 必须 vendored:动态链到目标机的 libssl,
# 换个发行版版本对不上就直接起不来 ⇒ 静态编进去,产物自包含。
#
# 依赖:cargo-zigbuild(cargo install cargo-zigbuild)、zig、armv7 的 rust-std
# (rustup target add armv7-unknown-linux-gnueabihf)。
set -euo pipefail
ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
cd "${ROOT}"
TAG=""
PUSH=0
for arg in "$@"; do
case "${arg}" in
--tag)
shift
TAG="${1:-}"
;;
--push)
PUSH=1
;;
*)
echo "未知参数:${arg}" >&2
exit 2
;;
esac
shift
done
DIST="${ROOT}/dist"
TARGETS="x86_64-unknown-linux-gnu armv7-unknown-linux-gnueabihf x86_64-apple-darwin"
# ★ vendored OpenSSL + 关掉 sccache(见文件头【坑①】)
export OPENSSL_STATIC=1
ZIGBUILD_FLAGS=(--release -p mpc-cli --features vendored --config 'build.rustc-wrapper=""')
mkdir -p "${DIST}"
echo "=== 构建目标 ==="
for t in ${TARGETS}; do
echo "--- ${t}"
if [ "${t}" = "x86_64-apple-darwin" ]; then
# mac 原生:zig 不参与,编译器是本机 clang
cargo build --target "${t}" "${ZIGBUILD_FLAGS[@]}"
else
cargo zigbuild --target "${t}" "${ZIGBUILD_FLAGS[@]}"
fi
cp "target/${t}/release/mpc" "${DIST}/mpc-${t}"
chmod +x "${DIST}/mpc-${t}"
echo " -> ${DIST}/mpc-${t}"
done
echo
echo "=== 产物校验 ==="
for t in ${TARGETS}; do
f="${DIST}/mpc-${t}"
echo "--- ${t}"
file "${f}"
done
echo
echo "=== sha256 ==="
if command -v sha256sum >/dev/null 2>&1; then
(cd "${DIST}" && sha256sum mpc-*)
else
(cd "${DIST}" && shasum -a 256 mpc-*)
fi | tee "${DIST}/SHA256SUMS"
if [ -z "${TAG}" ]; then
echo
echo "未指定 --tag,构建结束。"
exit 0
fi
echo
echo "=== 打 tag:${TAG} ==="
if git rev-parse "${TAG}" >/dev/null 2>&1; then
echo "tag 已存在:${TAG}(不重复创建)"
else
git tag -a "${TAG}" -m "release ${TAG}"
echo "已创建 tag ${TAG}"
fi
if [ "${PUSH}" -eq 1 ]; then
echo "=== 推送 tag:${TAG} ==="
git push origin "${TAG}"
echo "已推送 ${TAG}"
else
echo "(未加 --push,不推送远程)"
fi