iOS build fails
Describe the bug
cargo mobile init then building in XCode fails to build the Rust Code with error
library 'System' not found
The Rust dependencies do not finish building. Now when I add this line:
export LIBRARY_PATH="${DEVELOPER_SDK_DIR}/MacOSX.sdk/usr/lib:${LIBRARY_PATH:-}"
to the Build Rust Code build phase (from this tutorial; I assume compiling proc macros etc requires the MacOS SDK), all the dependencies build successfully, but the final linking fails with:
ld: building for 'iOS', but linking in dylib (/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/lib/libobjc.A.tbd) built for 'macOS macCatalyst zippered(macOS/Catalyst)'
Probably the XCode build environment is somehow messed up during the generation of the XCode project?
Steps To Reproduce
-
cargo mobile initon MacOS Somona - open and run the generated XCode project in XCode 15.3
Expected behavior XCode builds the project successfully out of the box.
Platform and Versions (please complete the following information):
Host OS: MacOS Sonoma 14.5
Target OS: aarch64 iOS
Rustc: 1.79.0
Ouput of cargo mobile doctor:
[✔] cargo-mobile v0.12.2
• Contains commits up to "Publish New Versions (#344)\n"
• Installed at "~/.cargo/.cargo-mobile2"
• macOS v14.5 (23F79)
• rustc v1.79.0 (129f3b996 2024-6-10)
[!] Apple developer tools
• Xcode v15.3
• Active developer dir: "/Applications/Xcode.app/Contents/Developer"
• ios-deploy v1.12.2
• XcodeGen v2.41.0
✗ xcode-rust-plugin plugin absent
✗ xcode-rust-plugin lang spec absent
✗ xcode-rust-plugin lang metadata absent
• xcode-rust-plugin is up-to-date
✗ Failed to check xcode-rust-plugin UUID status: Failed to lookup Xcode
UUID: command ["defaults", "read"] exited with code 1
• Development team: Gephyra OU (5M9G3KQ5FK)
[!] Android developer tools
✗ Have you installed the Android SDK? The ANDROID_HOME environment
variable isn't set, and is required: environment variable not found
/usr/local/bin/ios-deploy
[!] Connected devices
✗ Failed to get iOS device list: Failed to request device list from
ios-deploy: command ["ios-deploy", "--detect", "--timeout", "1",
"--json", "--no-wifi"] exited with code 253
Additional context Modifying the Build Rust Code build phase to this (essentially first building with LIBRARY_PATH=MacOS_SDK, which builds all dependencies but fails to link, then un-setting the LIBRARY_PATH to build with the iOS SDK, which succeeds in linking) somehow works, albeit with an error thrown and ignored in the middle:
export PATH=${PATH}:${HOME:?}/.cargo/bin
export MACOS_SDKROOT=$(xcrun --sdk macosx --show-sdk-path)
export OLD_LIBRARY_PATH=$LIBRARY_PATH
export LIBRARY_PATH="${MACOS_SDKROOT}/usr/lib:${SDKROOT}/usr/lib:${LIBRARY_PATH:-}"
cargo build --target aarch64-apple-ios || true
export LIBRARY_PATH=$OLD_LIBRARY_PATH
cargo build --target aarch64-apple-ios
cargo build --target x86_64-apple-ios
I also am unable to get this to build for ios.
$ cargo mobile doctor
[✔] cargo-mobile v0.17.2
• Contains commits up to "publish new versions (#389)\n"
• Installed at "~/.cargo/.cargo-mobile2"
• macOS v14.2.1 (23C71)
• rustc v1.78.0 (9b00956e5 2024-4-29)
[!] Apple developer tools
• Xcode v15.4
• Active developer dir: "/Applications/Xcode.app/Contents/Developer"
✗ Failed to check ios-deploy version: No such file or directory (os error 2)
• XcodeGen v2.42.0
✗ xcode-rust-plugin plugin absent
✗ xcode-rust-plugin lang spec absent
✗ xcode-rust-plugin lang metadata absent
• xcode-rust-plugin is up-to-date
✗ Failed to check xcode-rust-plugin UUID status: Failed to lookup Xcode UUID: command ["defaults", "read"] exited with code 1
• Development team: ************
[!] Android developer tools
✗ Have you installed the Android SDK? The `ANDROID_HOME` environment variable isn't set, and is required: environment variable not found
[✔] Connected devices
• ****’s Device of Ultimate Destiny (iPhone13,2)
I'm hitting this as well now. Is anyone knowledgable about this tool able to investigate / fix this issue? This seems to be affecting all / most templates (bevy, egui, etc).
❯ cargo mobile doctor
[✔] cargo-mobile v0.17.4
• Contains commits up to "feat: bevy templates upgrade to bevy 0.15 (#428)\n"
• Installed at "~/.cargo/.cargo-mobile2"
• macOS v14.6.1 (23G93)
• rustc v1.84.0 (9fc6b4312 2025-1-7)
[✔] Apple developer tools
• Xcode v15.2
• Active developer dir: "/Applications/Xcode.app/Contents/Developer"
• ios-deploy v1.12.2
• XcodeGen v2.42.0
✗ xcode-rust-plugin plugin absent
✗ xcode-rust-plugin lang spec absent
✗ xcode-rust-plugin lang metadata absent
• xcode-rust-plugin is up-to-date
✗ xcode-rust-plugin doesn't support Xcode UUID "EB2858C6-D4A9-4096-9AA3-BB5872AE7EF9"
Note if I just build the dylib via cargo it succeeds:
cargo build --target aarch64-apple-ios
So is it something up with the xcode wrapper project?
Ok figured out a simple solution to this. Open the xcode project and add the SystemConfiguration.framework.
running
cargo build --target aarch64-apple-ios
then adding the SystemConfiguration.framework made it work for me!
When running on ios the bottom 2/3 of the screen is just black however. I know remember seeing a comment about black bars on ios in some issue..
running
cargo build --target aarch64-apple-iosthen adding theSystemConfiguration.frameworkmade it work for me! When running on ios the bottom 2/3 of the screen is just black however. I know remember seeing a comment about black bars on ios in some issue..
Good to hear it worked for you. Note once you make that XCode mod for SystemConfiguration you can then just use the cargo mobile commands again to build, etc
cargo apple build
cargo apple run
I am also seeing the black/dead screen area on bottom. Something is up with egui/winit in my case. Another thing to investigate, but likely not related to cargo mobile itself.
To be fair, the wgpu, egui, and winit versions in that demo are super old. probably worth updating those as a first step.