Target `aarch64-apple-ios` does not support these `cdylib` crate type?

Hi Guys,
I have a project that I cross compile to Android and iOS dynamic (cdylib).

For Android I package the libs into a JNI wrapped AAR and that works great .
For iOS I package the generated dylib's into a universal framework and works great for simulators and real devices.
However as of recent whenever I try to compile the library for targets aarch64-apple-ios or x86_64-apple-ios using a command:
cargo build -p my_project --target aarch64-apple-ios --release
i get an error:
error: cannot produce cdylib for 'sifir-ios v0.1.0 (/MyProject)' as the target aarch64-apple-ios does not support these crate types
Which is totally new and use to work fine.

Note: That i can compile a static lib (.a) fine but the problem with the static lib vs dynamic lib are sizes , a universal static lib is around ~88megs, while the universal dylib is ~9megs! Which is huge difference for mobile context.

Did something change recently ? Any pointers to why this is happening all of a sudden ? Would really appreciate any pointers
I'm on:
rustc 1.49.0 (e1884a8e3 2020-12-29)
targets installed:
x86_64-apple-darwin (installed)
x86_64-apple-ios (installed)
aarch64-apple-ios (installed)
and a link to the project if it helps:

1 Like

For a long time iOS did not allow any non-Apple dynamic libraries, so Rust/Cargo didn't bother supporting them for iOS.

BTW, you're not saving any disk space by using cdylib.

Size of the .a file is mostly meaningless, don't pay attention to it. Your "small" cdylib is basically made from the same .a file too. It's a bunch of unlinked object files. The linker (and LTO optimizer) will only pick parts of it that it needs, just like it does when making cdylib.

1 Like

Thank you very much for that clarification.
To be honest I never checked the final app size when using .dylib / .a , I will do that and if it's true then all the better ! Thanks again!

Hi,
I am having the same issue; iOS does definitely allow dynamic libraries now (they have to be packaged into a framework, as @Zmiller said, but they work). Is there any way to work around this limitation?

It was shortly allowed, but then reverted in Revert "Allow dynamic linking for iOS/tvOS targets." by francesca64 · Pull Request #77716 · rust-lang/rust · GitHub as it turned out to not actually work.