Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[feat] Build universal binaries for MacOS #3317

Closed
betamos opened this issue Feb 1, 2022 · 4 comments
Closed

[feat] Build universal binaries for MacOS #3317

betamos opened this issue Feb 1, 2022 · 4 comments

Comments

@betamos
Copy link
Contributor

betamos commented Feb 1, 2022

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.

@betamos betamos changed the title Build universal binaries for MacOS [feat] Build universal binaries for MacOS Feb 1, 2022
@nothingismagick
Copy link
Member

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
Copy link
Contributor Author

betamos commented Feb 1, 2022

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

(Obligatory thisisfine.gif)

Can you provide some more context?

@bluebreadhead
Copy link

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

@betamos
Copy link
Contributor Author

betamos commented Apr 22, 2023

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants