Files
clawpanel/build.sh
晴天 e62f270422 chore: 跨平台构建脚本 + CI/CD 改进 + 行尾规范
- 新增 .gitattributes 统一 LF 行尾,解决 Mac/Windows 协作 CRLF 问题
- 新增 build.ps1 Windows 本地构建脚本(支持 -Debug/-Clean 参数)
- 新增 build.sh macOS/Linux 本地构建脚本
- 新增 .windsurf/workflows/release.md 发版操作工作流
- release.yml: 将 Release Notes 更新抽为独立 job,彻底解决多 matrix job 竞争条件
- release.yml: 补充代码签名环境变量注释占位,开源后可直接配 Secrets 启用
- ci.yml: 增加 cargo fmt --check 和 cargo clippy -D warnings 质量门禁
- .gitignore: 补充 Windows 平台特有文件、内部报告、IDE 文件
- docs/index.html: 修正 openclaw 仓库 URL
- README.md: 修正 openclaw 仓库 URL
2026-03-04 12:17:48 +08:00

147 lines
5.3 KiB
Bash
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
# ClawPanel 本地构建脚本macOS / Linux
# 用法:
# ./build.sh — 构建当前平台安装包(默认)
# ./build.sh --debug — Debug 构建(快,不打包)
# ./build.sh --clean — 清理 Rust 编译缓存后构建
set -euo pipefail
DEBUG=false
CLEAN=false
for arg in "$@"; do
case "$arg" in
--debug) DEBUG=true ;;
--clean) CLEAN=true ;;
esac
done
RED='\033[0;31m'; GREEN='\033[0;32m'; CYAN='\033[0;36m'
MAGENTA='\033[0;35m'; GRAY='\033[0;90m'; RESET='\033[0m'
step() { echo -e "\n${CYAN}$1${RESET}"; }
ok() { echo -e " ${GREEN}$1${RESET}"; }
fail() { echo -e " ${RED}$1${RESET}"; exit 1; }
echo ""
echo -e " ${MAGENTA}ClawPanel 构建工具${RESET}"
echo -e " ${GRAY}─────────────────────────────────────${RESET}"
if [[ "$(uname)" == "Darwin" ]]; then
ARCH=$(uname -m)
if [[ "$ARCH" == "arm64" ]]; then
echo -e " ${GRAY}平台: macOS Apple Silicon (aarch64)${RESET}"
else
echo -e " ${GRAY}平台: macOS Intel (x86_64)${RESET}"
fi
else
echo -e " ${GRAY}平台: Linux x86_64${RESET}"
fi
echo -e " ${GRAY}跨平台构建 (其他平台) 请推送 tag 触发 GitHub Actions${RESET}"
echo ""
# ── 环境检测 ──────────────────────────────────────────────────────────────────
step "检查构建依赖"
if ! command -v node &>/dev/null; then
fail "未找到 Node.js请从 https://nodejs.org 安装 v18+"
fi
ok "Node.js $(node --version)"
if ! command -v cargo &>/dev/null; then
fail "未找到 Rust/Cargo请从 https://rustup.rs 安装"
fi
ok "Rust $(rustc --version)"
# macOS 额外检测
if [[ "$(uname)" == "Darwin" ]]; then
if ! command -v xcode-select &>/dev/null || ! xcode-select -p &>/dev/null 2>&1; then
echo -e " ${YELLOW}⚠ 未找到 Xcode Command Line Tools${RESET}"
echo -e " 运行: xcode-select --install"
fi
fi
# Linux 额外检测
if [[ "$(uname)" == "Linux" ]]; then
MISSING=()
for pkg in libwebkit2gtk-4.1-dev libssl-dev libgtk-3-dev; do
if ! dpkg -s "$pkg" &>/dev/null 2>&1; then
MISSING+=("$pkg")
fi
done
if [ ${#MISSING[@]} -gt 0 ]; then
echo -e " ${RED}✗ 缺少系统依赖: ${MISSING[*]}${RESET}"
echo -e " 运行: sudo apt-get install -y ${MISSING[*]} libayatana-appindicator3-dev librsvg2-dev patchelf"
exit 1
fi
fi
# ── 依赖安装 ──────────────────────────────────────────────────────────────────
step "安装前端依赖"
if [ ! -d "node_modules" ]; then
npm ci --silent
ok "依赖安装完成"
else
ok "依赖已存在,跳过"
fi
# ── 清理缓存 ──────────────────────────────────────────────────────────────────
if [ "$CLEAN" = true ]; then
step "清理 Rust 编译缓存"
(cd src-tauri && cargo clean)
ok "缓存已清理"
fi
# ── 构建 ──────────────────────────────────────────────────────────────────────
START_TIME=$(date +%s)
if [ "$DEBUG" = true ]; then
step "Debug 构建(不打包安装器)"
npm run tauri build -- --debug
else
step "Release 构建"
# macOS Apple Silicon: 同时构建 ARM64 + Intel Universal Binary可选
if [[ "$(uname)" == "Darwin" ]] && [[ "$(uname -m)" == "arm64" ]]; then
# 确保 Intel target 已安装
rustup target add x86_64-apple-darwin 2>/dev/null || true
echo -e " ${GRAY}构建 ARM64 版本...${RESET}"
npm run tauri build -- --target aarch64-apple-darwin
else
npm run tauri build
fi
fi
END_TIME=$(date +%s)
ELAPSED=$((END_TIME - START_TIME))
# ── 输出结果 ──────────────────────────────────────────────────────────────────
echo ""
echo -e " ${GREEN}✅ 构建成功!耗时 ${ELAPSED}s${RESET}"
echo -e " ${GRAY}─────────────────────────────────────${RESET}"
if [ "$DEBUG" = true ]; then
echo -e " 可执行文件: src-tauri/target/debug/clawpanel"
else
BUNDLE_DIR="src-tauri/target/release/bundle"
if [[ "$(uname)" == "Darwin" ]]; then
DMG=$(find "$BUNDLE_DIR/dmg" -name "*.dmg" 2>/dev/null | head -1)
APP=$(find "$BUNDLE_DIR/macos" -name "*.app" -maxdepth 1 2>/dev/null | head -1)
[ -n "$DMG" ] && echo -e " DMG: ${GRAY}$DMG${RESET}"
[ -n "$APP" ] && echo -e " APP: ${GRAY}$APP${RESET}"
else
APPIMAGE=$(find "$BUNDLE_DIR/appimage" -name "*.AppImage" 2>/dev/null | head -1)
DEB=$(find "$BUNDLE_DIR/deb" -name "*.deb" 2>/dev/null | head -1)
[ -n "$APPIMAGE" ] && echo -e " AppImage: ${GRAY}$APPIMAGE${RESET}"
[ -n "$DEB" ] && echo -e " DEB: ${GRAY}$DEB${RESET}"
fi
fi
echo ""
echo -e " ${GRAY}提示: 发布跨平台版本请推送 tag例如:${RESET}"
echo -e " ${GRAY} git tag v1.0.0 && git push origin v1.0.0${RESET}"
echo ""