This example codebase demonstrates using cargo-lipo tool & some scripts to ensure proper universal library building & ability to make an XCFramework out of them as well.
This might be useful if you're not directly including the library in your main Xcode project, say producing a downloadable binary for others. XCFramework fills the need for this. If you want to build from source, you can also just look at the framework project & mylib/build-platform.sh
- Don't open the project yet...
- Run
./make-xcf.sh
to build the RustTest.xcframework - Open RustTestApp.xcodeproj
- Build & run on sim or iOS device
- Implement a macOS framework & test app
- Implement an iOS framework & test app
I left out Mac Catalyst because that target is fairly immature sounding for Rust. It requires a lot more work to get going.
- Apple doesn't support universal libraries with more than 1 platform in it, hence some of the issues coming up with Carthage etc & M1 recently. It only happened to work until M1 complicated things.
- To aid this I whipped together a script at mylib/build-platform.sh that can build a rust staticlib crate by platform, this may be an area to explore a PR to cargo-lipo in future even.
- For those wanting to produce a shareable pre-built binary framework, I also made make-xcf.sh which builds & archives each destination & then combines them all, this can be tweaked to do a full Apple platform framework if your library supports it. This example includes Rust which complicates things beyond macOS & iOS.