tauri-apps / tauri

Build smaller, faster, and more secure desktop applications with a web frontend.
https://tauri.app
Apache License 2.0
82.34k stars 2.47k forks source link

[feat] Build universal binaries for MacOS #3317

Closed betamos closed 2 years ago

betamos commented 2 years ago

Describe the problem

By default, binaries are built for a single CPU architecture, either x86_64 or aarch64. MacOS supports Universal Binaries. that allow a single binary (and hence package & dmg) which contains both. This is recommended by Apple because it simplifies application distribution.

Describe the solution you'd like

I'd like to be able to build a universal dmg that can be distributed to any MacOS user, directly from tauri build.

I suggest adding a pseudo-target universal-darwin-macos for this purpose, which invokes the lipo command to combine two arch-specific binaries into a universal one. I've tried it out and it works for me.

Given such a feature, we also need a way to deal with external binaries:

Alternatives considered

Use an external build script

A custom build script would work, but it would require quite a bit of redundant and custom tooling. This is because the lipo invocation needs to happen between cargo build and dmg packaging.

Use cargo [blocked]

Cargo does not support universal binaries at this time.

Use cargo-lipo

cargo-lipo is a tool that uses lipo under the hood. Not investigated.

Use a Rust-lib instead of lipo

lipo is included in MacOS (perhaps with XCode?) but it may be harder to access it from Windows or Linux for cross-platform building. If that's hard to get lipo working, it may be worth looking into using a rust lib that does the same thing, to avoid external dependencies.

Additional context

It's an open question what exactly universal binaries mean for build systems. Should it be part of the arch triple (universal-darwin-macos) or should it be considered separate platform-specific config? I haven't seen best practices on this yet, feedback welcome.

nothingismagick commented 2 years ago

I would venture the guess that Apple prefers universal binaries not just because of Intel and Arm architectures, but also because of the subtle and sometimes massive differences between their M-series architectures. Nevertheless, this is a great topic and thankyou for filing the issue.

I almost feel like we need insight from the cargo engineering team here tbh.

betamos commented 2 years ago

the subtle and sometimes massive differences between their M-series architectures

(Obligatory thisisfine.gif)

Can you provide some more context?

bluebreadhead commented 1 year ago

@betamos how to mention this using .toml or config file?

betamos commented 1 year ago

Not sure what you mean by "mention". To my knowledge you can only manually set the target with the --target build flag. See https://tauri.app/v1/guides/building/macos/#binary-targets