build-mac.sh 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  1. #!/bin/bash
  2. # ============================================
  3. # Claude AI Installer macOS 构建脚本
  4. # Build script for macOS using Tauri
  5. # 此脚本作为 scripts/build.js 的简单入口
  6. # ============================================
  7. # 颜色定义
  8. RED='\033[0;31m'
  9. GREEN='\033[0;32m'
  10. YELLOW='\033[0;33m'
  11. BLUE='\033[0;34m'
  12. CYAN='\033[0;36m'
  13. NC='\033[0m' # No Color
  14. # 切换到脚本所在目录
  15. cd "$(dirname "$0")"
  16. # 显示帮助信息
  17. show_help() {
  18. echo ""
  19. echo " Claude AI Installer macOS 构建脚本 (Tauri)"
  20. echo ""
  21. echo " 用法:"
  22. echo " ./build-mac.sh [参数]"
  23. echo ""
  24. echo " 参数:"
  25. echo " --debug, -d 以调试模式构建"
  26. echo " --skip-frontend, -s 跳过前端构建"
  27. echo " --target, -t 指定目标架构 (aarch64 或 x86_64)"
  28. echo " --universal, -u 构建通用二进制 (同时支持 ARM 和 Intel)"
  29. echo " --help, -h 显示此帮助信息"
  30. echo ""
  31. echo " 示例:"
  32. echo " ./build-mac.sh 完整发布构建 (当前架构)"
  33. echo " ./build-mac.sh --debug 调试构建"
  34. echo " ./build-mac.sh -t aarch64 构建 Apple Silicon 版本"
  35. echo " ./build-mac.sh -t x86_64 构建 Intel 版本"
  36. echo " ./build-mac.sh --universal 构建通用二进制"
  37. echo ""
  38. echo " 输出 (发布模式):"
  39. echo " src-tauri/target/release/bundle/dmg/*.dmg (DMG 安装包)"
  40. echo " src-tauri/target/release/bundle/macos/*.app (应用程序)"
  41. echo " src-tauri/target/release/claude-ai-installer (可执行文件)"
  42. echo ""
  43. echo " 输出 (调试模式):"
  44. echo " src-tauri/target/debug/claude-ai-installer (调试版可执行文件)"
  45. echo ""
  46. echo " 前置要求:"
  47. echo " - Rust (https://rustup.rs/)"
  48. echo " - Node.js (https://nodejs.org/)"
  49. echo " - Xcode Command Line Tools"
  50. echo ""
  51. echo " 注意: 此脚本调用 scripts/build.js 执行实际构建"
  52. echo ""
  53. }
  54. # 检查是否请求帮助
  55. if [[ "$1" == "--help" || "$1" == "-h" ]]; then
  56. show_help
  57. exit 0
  58. fi
  59. echo ""
  60. echo " ========================================"
  61. echo " Claude AI Installer - macOS 构建"
  62. echo " 使用 Tauri 2.0"
  63. echo " ========================================"
  64. echo ""
  65. # 检查 Rust 是否安装
  66. if ! command -v rustc &> /dev/null; then
  67. echo -e " ${RED}✖${NC} 未找到 Rust,请先安装 Rust"
  68. echo -e " ${BLUE}ℹ${NC} 访问: https://rustup.rs/"
  69. exit 1
  70. fi
  71. # 显示 Rust 版本
  72. RUST_VERSION=$(rustc --version)
  73. echo -e " ${GREEN}✔${NC} Rust: $RUST_VERSION"
  74. # 检查 Node.js
  75. if ! command -v node &> /dev/null; then
  76. echo -e " ${RED}✖${NC} 未找到 Node.js,请先安装 Node.js"
  77. exit 1
  78. fi
  79. # 显示 Node.js 版本
  80. NODE_VERSION=$(node --version)
  81. echo -e " ${GREEN}✔${NC} Node.js: $NODE_VERSION"
  82. # 检查 Xcode Command Line Tools
  83. if ! xcode-select -p &> /dev/null; then
  84. echo -e " ${YELLOW}!${NC} 未找到 Xcode Command Line Tools"
  85. echo -e " ${BLUE}ℹ${NC} 安装: xcode-select --install"
  86. else
  87. echo -e " ${GREEN}✔${NC} Xcode Command Line Tools 已安装"
  88. fi
  89. # 显示当前架构
  90. ARCH=$(uname -m)
  91. echo -e " ${BLUE}ℹ${NC} 当前架构: $ARCH"
  92. # 设置 Tauri 签名密钥环境变量
  93. if [ -f ".keys/tauri-signing.key" ]; then
  94. echo -e " ${GREEN}✔${NC} 找到签名密钥"
  95. export TAURI_SIGNING_PRIVATE_KEY=$(cat .keys/tauri-signing.key)
  96. export TAURI_SIGNING_PRIVATE_KEY_PASSWORD=""
  97. else
  98. echo -e " ${YELLOW}!${NC} 未找到签名密钥 (.keys/tauri-signing.key)"
  99. echo -e " ${BLUE}ℹ${NC} 更新功能将不可用,构建将继续..."
  100. fi
  101. # 检查 node_modules
  102. if [ ! -d "node_modules" ]; then
  103. echo ""
  104. echo -e " ${YELLOW}!${NC} 未找到 node_modules,正在安装依赖..."
  105. npm install
  106. if [ $? -ne 0 ]; then
  107. echo -e " ${RED}✖${NC} 安装依赖失败"
  108. exit 1
  109. fi
  110. fi
  111. # 解析参数
  112. NODE_ARGS=""
  113. TARGET=""
  114. UNIVERSAL=false
  115. while [[ $# -gt 0 ]]; do
  116. case $1 in
  117. --debug|-d)
  118. NODE_ARGS="$NODE_ARGS --debug"
  119. shift
  120. ;;
  121. --skip-frontend|-s)
  122. NODE_ARGS="$NODE_ARGS --skip-frontend"
  123. shift
  124. ;;
  125. --target|-t)
  126. TARGET="$2"
  127. shift 2
  128. ;;
  129. --universal|-u)
  130. UNIVERSAL=true
  131. shift
  132. ;;
  133. *)
  134. shift
  135. ;;
  136. esac
  137. done
  138. # 处理目标架构
  139. if [ "$UNIVERSAL" = true ]; then
  140. NODE_ARGS="$NODE_ARGS --target universal-apple-darwin"
  141. echo -e " ${BLUE}ℹ${NC} 构建目标: 通用二进制 (ARM + Intel)"
  142. elif [ -n "$TARGET" ]; then
  143. case $TARGET in
  144. aarch64|arm64|arm)
  145. NODE_ARGS="$NODE_ARGS --target aarch64-apple-darwin"
  146. echo -e " ${BLUE}ℹ${NC} 构建目标: Apple Silicon (aarch64)"
  147. ;;
  148. x86_64|x64|intel)
  149. NODE_ARGS="$NODE_ARGS --target x86_64-apple-darwin"
  150. echo -e " ${BLUE}ℹ${NC} 构建目标: Intel (x86_64)"
  151. ;;
  152. *)
  153. echo -e " ${RED}✖${NC} 未知目标架构: $TARGET"
  154. echo -e " ${BLUE}ℹ${NC} 支持的架构: aarch64, x86_64"
  155. exit 1
  156. ;;
  157. esac
  158. fi
  159. echo ""
  160. echo -e " ${CYAN}▶ 调用 Node.js 构建脚本...${NC}"
  161. echo -e " ${BLUE}ℹ${NC} 执行: node scripts/build.js $NODE_ARGS"
  162. echo ""
  163. node scripts/build.js $NODE_ARGS
  164. BUILD_RESULT=$?
  165. if [ $BUILD_RESULT -ne 0 ]; then
  166. echo ""
  167. echo -e " ${RED}✖${NC} 构建失败!"
  168. echo ""
  169. exit 1
  170. fi
  171. echo ""