build-mac.sh 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. #!/usr/bin/env bash
  2. set -euo pipefail
  3. cd "$(dirname "$0")/.."
  4. if [ "$(uname -s)" != "Darwin" ]; then
  5. echo "此脚本需要在 macOS 上运行。"
  6. exit 1
  7. fi
  8. for tool in node npm cargo; do
  9. if ! command -v "$tool" >/dev/null 2>&1; then
  10. echo "缺少 $tool,请先安装 Node.js 20+ 和 Rust (https://rustup.rs)。"
  11. exit 1
  12. fi
  13. done
  14. if [ ! -d node_modules ]; then
  15. echo "==> 安装前端/CLI 依赖"
  16. npm ci
  17. fi
  18. echo "==> 准备 luatos-cli sidecar(universal)"
  19. CLI_SRC="../luatools-mac/resources/bin/luatos-cli"
  20. for triple in aarch64-apple-darwin x86_64-apple-darwin; do
  21. target="src-tauri/binaries/luatos-cli-$triple"
  22. if [ ! -f "$target" ]; then
  23. if [ -f "$CLI_SRC" ]; then
  24. cp "$CLI_SRC" "$target"
  25. chmod +x "$target"
  26. else
  27. echo "缺少 $target,请先把 luatos-cli 放到 src-tauri/binaries/。"
  28. exit 1
  29. fi
  30. fi
  31. done
  32. if [ "${UNIVERSAL:-0}" = "1" ]; then
  33. echo "==> 补齐 Rust 双架构 target"
  34. rustup target add aarch64-apple-darwin x86_64-apple-darwin >/dev/null 2>&1 || true
  35. echo "==> 构建 universal .app / .dmg"
  36. npm run build:mac:universal
  37. OUT="src-tauri/target/universal-apple-darwin/release/bundle"
  38. else
  39. echo "==> 构建 arm64 .app / .dmg"
  40. npm run build:mac
  41. OUT="src-tauri/target/aarch64-apple-darwin/release/bundle"
  42. fi
  43. echo
  44. echo "完成。产物:"
  45. ls -lh "$OUT"/dmg/*.dmg "$OUT"/macos/*.app 2>/dev/null || true
  46. echo
  47. echo "未签名构建首次运行如被 Gatekeeper 拦截:"
  48. echo ' xattr -cr "/Applications/LuatOS Flasher.app"'