跳到主要内容

macOS Bundle

用于macOS的Tauri应用程序是以应 用程序捆绑.app 文件)或苹果磁盘镜像(.dmg文件)的方式发布的。 Tauri CLI会自动将你的应用程序代码捆绑成这些格式,并提供选项对你的应用程序进行签名和公证。 请注意,.app.dmg捆绑文件只能在macOS上创建,因此交叉编译还不能工作。

备注

在 macOS 和 Linux 上的 GUI 应用程序不能继承您的 shell 配置文件的 $PATH (.bashrc, .bash_profile, .zshrc, etc). 请查看Tauri的 fix-path-env-rs crate 来解决这个问题。

要将 Tauri 应用程序编译并捆绑到一个可执行文件中,只需运行以下命令即可:

npm run tauri build

它将构建你的前端(如果已配置,请参阅 beforeBuildCommand),编译 Rust 二进制文件,收集所有外部二进制文件和资源,最后生成整齐的特定平台捆绑包和安装包。

Setting a Minimum System Version

The minimum version of the operating system required for a Tauri app to run on macOS is 10.13. 如果您需要支持较新的 macOS API,如 window.print 只支持 macOS 11.0 版本。只支持之后的版本的话,您可以更改 tauri.bundle.macOS.minimumSystem版本 This will in turn set the Info.plist LSMinimumSystemVersion property and the MACOSX_DEPLOYMENT_TARGET environment variable.

Binary Targets

You can compile your application targeting Apple Silicon, Intel-based Mac computers, or universal macOS binaries. By default, the CLI builds a binary targeting your machine's architecture. If you want to build for a different target you must first install the missing rust target for that target by running rustup target add aarch64-apple-darwin or rustup target add x86_64-apple-darwin, then you can build your app using the --target flag:

  • tauri build --target aarch64-apple-darwin: targets Apple silicon machines.
  • tauri build --target x86_64-apple-darwin: targets Intel-based machines.
  • tauri build --target universal-apple-darwin: produces a universal macOS binary that runs on both Apple silicon and Intel-based Macs.

While Apple silicon machines can run applications compiled for Intel-based Macs through a translation layer called Rosetta, this leads to a reduction in performance due to processor instruction translations. It is common practice to let the user choose the correct target when downloading the app, but you can also choose to distribute a Universal Binary. Universal Binaries include both aarch64 and x86_64 executables, giving you the best experience on both architectures. Note, however, that this increases your bundle size significantly.

Application Bundle Customization

The Tauri configuration file provides the following options to customize your application bundle:

信息

These options generate the application bundle Info.plist file. You can extend the generated file with your own Info.plist file stored in the Tauri folder (src-tauri by default). The CLI merges both .plist files in production, and the core layer embeds it in the binary during development.