2
votes

The rust toolchain currently does not allow you to create a dynamic library crate type (cdylib or dylib) for the target aarch64-apple-ios.

The reasoning I've seen on the Internet is that Apple doesn't allow dynamic libraries when uploading apps to the App Store.

However, my reading of TN2425 is that dynamic libraries are allowed, as long as they are embedded in the application as a framework. The technical note describes how to create a framework from a dynamic library.

My use case is that I am building a Rust library that makes numerous calls to the Objc system libraries provided by Apple. If I create a static library, Cargo/Rust will link in all the SDK and give me a very large static library that is tied to a specific SDK release.

Is there a way I can manually create a dynamic library from the intermediate files generated from the Rust toolchain? I could then sign it and embed it in my iOS app.

2
When you say "link in all the SDK", are you referring to the iOS system libraries? Because that is outright impossible, seeing as there are no static libraries floating around the iOS SDK.Siguza
I'm starting to feel really stupid. My dylib version was 3,051,444 bytes (~3Mb) and my static version was 20,281,120 bytes (~19Mb). I assumed it was because of linking in the SDK. However, then I found otool and size. The extra size is because of the Rust runtime, which I think is needed.Thomas O'Dell
Bhargav Rao, is it possible for your to re-instate my hidden answer? I've updated it to reflect what I learned during investigation, and still think it is the correct answer to the question as asked, namely: this is how you do it and btw it won't do you any good.Thomas O'Dell

2 Answers

1
votes

Yes, according to Rust Issue #73516, dynamic linking for iOS is already provided in the nightly toolchain for aarch64-apple-ios.

However, it won't do you much good. The extra size in the static library is from Rust runtimes, which you will need. You can look at what embedded Rust and Rust WASM coders do to reduce the size of the runtime portion.

-2
votes

For iOS you only need to make a static library (Apple does not allow 3rd party dynamic libraries on iOS), so fortunately you don't need to have any of Apple's proprietary frameworks for linking.

If you don't have any dependencies on C libraries it should be easier, because Rust itself knows how to cross-compile.