跳到正文
灵动桌面框架
Esc
本栏目菜单

多平台打包

灵动桌面框架默认在本地打 Windows NSIS 安装包,macOS 与 Linux 安装包由仓库自带的 GitHub Actions 工作流(.github/workflows/release.yml)在对应系统上构建。

构建命令

pnpm tauri build
# 等价于 package.json 中的脚本
pnpm tauri:build

构建过程:

  1. 先执行 tauri.conf.json 的 build.beforeBuildCommand,即 pnpm build(tsc && vite build),前端产物输出到 dist/
  2. 再以 release profile 编译 Rust 并打包安装程序

src-tauri/Cargo.toml 的 release profile 以体积优先:opt-level = "z"、lto = true、codegen-units = 1、strip = true、panic = "abort"。

TIP

正式包使用 tauri.conf.json 的 productName(Agile Tauri)和 identifier(com.agilefr.tauri)。pnpm tauri:dev 会叠加 tauri.conf.dev.json,把它们换成 Agile Tauri (Dev) / com.agilefr.tauri.dev,开发版与正式版可同时运行、数据互不干扰。打包时不要带上 dev 配置。

支持的平台

平台格式构建方式
WindowsNSIS (_x64-setup.exe)本地 pnpm tauri build 默认产物;CI 用 --bundles nsis
macOS (Apple Silicon / Intel).app + DMGCI 在 macos-latest 上分别以 aarch64-apple-darwin、x86_64-apple-darwin 构建,--bundles app,dmg
LinuxDEB + AppImageCI 在 ubuntu-22.04 上构建,--bundles deb,appimage

bundle.targets 只配了 nsis,所以本地构建默认不出 MSI;需要其他格式时用 pnpm tauri build --bundles <格式> 临时指定,或修改 targets。

打包配置

src-tauri/tauri.conf.json 中的 bundle 段:

{
  "bundle": {
    "active": true,
    "targets": ["nsis"],
    "createUpdaterArtifacts": "v1Compatible",
    "icon": [
      "icons/32x32.png",
      "icons/128x128.png",
      "icons/128x128@2x.png",
      "icons/icon.icns",
      "icons/icon.ico"
    ],
    "windows": {
      "nsis": {
        "displayLanguageSelector": false,
        "languages": ["SimpChinese"]
      }
    },
    "macOS": {
      "hardenedRuntime": true,
      "entitlements": "./Entitlements.plist"
    }
  }
}
配置说明
targets: ["nsis"]本地默认只打 NSIS 安装包
createUpdaterArtifacts: "v1Compatible"同时生成自动更新所需的产物和 .sig 签名文件,详见 应用更新
windows.nsis安装界面固定为简体中文,不弹语言选择框
macOS.hardenedRuntime + entitlements开启硬化运行时,配合 src-tauri/Entitlements.plist(放行 WKWebView 的 JIT、网络访问等)用于 macOS 签名与公证

输出位置

本地构建产物位于 src-tauri/target/release/bundle/ 下,按格式分目录,例如 bundle/nsis/Agile Tauri_0.1.0_x64-setup.exe。指定 --target <三元组> 时路径为 src-tauri/target/<三元组>/release/bundle/。

CI 发布构建

推送 v*.*.* 格式的 tag 会触发 .github/workflows/release.yml:

  • 由 prepare job 生成构建矩阵,release job 用 tauri-apps/tauri-action@v0 在 Windows / macOS(两种架构)/ Linux 上并行构建
  • 产物上传到 GitHub Release 的草稿,不会自动发布;下载产物、生成 update.json、推送到 release 仓库由本地发布流程完成
  • 仓库变量 RELEASE_WINDOWS=skip 时矩阵不含 Windows(Windows 改为本地签名构建时使用),未设置或为其他值时包含 Windows
  • 推送 mobile-v*.*.* tag 只触发可选的 Android 构建 job,与桌面端互不影响

CI 用到的 Secrets:

Secret用途
TAURI_SIGNING_PRIVATE_KEY更新包签名私钥(生成 .sig);工作流中私钥密码固定传空字符串
APPLE_CERTIFICATE / APPLE_CERTIFICATE_PASSWORD / APPLE_SIGNING_IDENTITY / APPLE_ID / APPLE_PASSWORD / APPLE_TEAM_IDmacOS 代码签名与公证;缺失时 tauri-action 跳过签名,产出未签名的 mac 包(不报错)

注意事项

  • 首次构建需要下载 Rust 依赖,耗时较长
  • Windows 打包需要 NSIS 工具(Tauri 会自动下载)
  • macOS 打包建议在 macOS 系统上执行(CI 即在 macos-latest 上构建)
  • Linux 构建需要 libwebkit2gtk-4.1-dev、libayatana-appindicator3-dev、librsvg2-dev、patchelf、libxdo-dev 等系统依赖(见工作流的 Ubuntu 依赖安装步骤)
  • 发布前建议进行代码签名:macOS 走上面的 APPLE_* Secrets;Windows 签名为可选项,仓库附带 scripts/evsign-sign-ci.ps1 作为签名命令包装脚本,需自备签名服务凭据并自行接入构建配置