Skip to content

[feat] Build universal binaries for MacOS #3317

@betamos

Description

@betamos

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:

  • Either Tauri requires a universal binary be present at build-time
  • Or we find the arch-specific binaries and combine them at bundle-time (see below).

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.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions