Cacao: Building macOS (and iOS) Apps in Rust | Ryan McGrath
7 min read
fairly easy
You can pry Objective-C out of my cold, dead hands.
Building native macOS apps outside the normal Apple ecosystem is sometimes a not-so-obvious task. The shifting ecosystem of AppKit, Catalyst, and SwiftUI - coupled with documentation that's sometimes non-existent, or spanning multiple operating system versions that each have their own nuance - makes it tricky to know just what you need to tie into.

One language that I've felt hasn't had a great solution to this yet is Rust. I've released an initial version of Cacao, which is my effort to enable building macOS (and iOS, see below) apps in Rust. This post showcases a bit of what Cacao is, how it works, and includes some opinions on GUI work sprinkled throughout.

History, Rust and Objective-C

I should clarify something before going any further. When I say that Rust hasn't had a great solution to this yet, I mean that there hasn't been an elegant way to build a macOS app in Rust. There is a litany of prior work though - some of which Cacao uses.

The objc crate by SSheldon has been around for years now, and does a very good job of providing a way to bridge Rust with Objective-C. Cacao relies on this heavily for bridging with the Apple side of things.

Delisa Mason wrote about building macOS apps in Rust as far as back as 2016, and the examples repository still holds up.

The core-foundation crate is often passed around as the "way" to build macOS apps in Rust. As far as I know, this was originally built to help Mozilla and Servo. It's a good crate, but I feel it's not as simple, and doesn't expose certain patterns that help make a macOS app feel "right".

fruity and objrs both attempt to offer better interop with the Objective-C side of things. Neither is used by Cacao, but I felt they're worth mentioning as they both are decent reading anyway.

Each of these are great works on their own, but none of them contribute to what I feel is a "native" macOS API style in Rust.

Feeling Native

So, let's define native.

When you build a macOS app in the standard,…
Read full article