Cross-compiling a library (written in rust) inside linux to target ios devices

Has anyone tried to cross compile libraries (written in rust) inside Linux to target ios devices? What are the steps involved? I have tried to cross compile an android library (also written in rust) already and its running properly inside my android device. I'm thinking the process should be similar with ios. I have tried cctools-port but without success. Can anyone point me to the right direction in doing this. Thanks :slight_smile:

For iOS you only need to make a static library (Apple doesn't 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.

1 Like

Unless its a jailbroken device, am I right?

I guess. But then you'd need to have iOS frameworks that officially are only available in the SDK that ships with Xcode, and you'd need cross-linker capable of making appropriate dylib files. I suspect it'd be a lot of trouble to get that on Linux.

I have managed to build an ios toolchain using cctools-port. I configured my cargo config file by adding a aarch64-apple-ios target and point the linker to a clang binary inside the ios toolchain. But whenever i executed this command cargo build --target aarch64-apple-ios I got an error saying

error: failed to run rustc` to learn about target-specific information

Caused by:
process didn't exit successfully: /nix/store/yhm1ckck9c218b9ywfmhpmv239wkqrvf-sccache-0.2.11/bin/sccache rustc - --crate-name ___ --print=file-names --target aarch64-apple-ios --crate-type bin --crate-type rlib --crate-type dylib --crate-type cdylib --crate-type staticlib --crate-type proc-macro --print=sysroot --print=cfg (exit code: 1)
--- stderr
error: Error loading target specification: failed to get iphoneos SDK path: No such file or directory (os error 2)
= help: Use --print target-list for a list of built-in targets
Is there an option I could pass to cargo to point to the path of the iphonesdk?

It's no longer true that iOS doesn't allow 3rd-party dylibs. They needed it for Swift, so it has been allowed for ~4 years.

1 Like

anyone has any ideas regarding my last question?

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.