Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Difficulty following the "Xcode + Cargo" example with Xcode 15.0 beta #231

Open
ghost opened this issue Jun 18, 2023 · 8 comments
Open

Difficulty following the "Xcode + Cargo" example with Xcode 15.0 beta #231

ghost opened this issue Jun 18, 2023 · 8 comments

Comments

@ghost
Copy link

ghost commented Jun 18, 2023

I followed it exactly, until the step "Pressing the Run button should now open up the iOS simulator with Xcode's default "Hello World" iOS app." where instead of the iOS simulator there are errors:

Screenshot 2023-06-18 at 20 58 29

This is on a Mac Mini M2 2023 running macOS 14.0 beta Sonoma.

@ghost
Copy link
Author

ghost commented Jun 18, 2023

Checked the build log (25916 lines long), noticed advice to run "rustup target add aarch64-apple-ios-sim", now there's only one error: "Sandbox: bash(18727) deny(1) file-read-data /Users/user/Desktop/code/ios-rust-analyzer/IosRustAnalyzer/build-rust.sh"

Copy and pasting the build script into the Build Phases > Run Script box (and changing Shell to /bin/bash), the build log contains the following:

error: failed to run custom build command for `ios-rust-analyzer v0.1.0 (/Users/user/Desktop/code/ios-rust-analyzer)`

Caused by:
process didn't exit successfully: /Users/user/Desktop/code/ios-rust-analyzer/target/debug/build/ios-rust-analyzer-d4c0ef4ad7b1cccf/build-script-build (exit status: 101)
--- stdout
cargo:rerun-if-changed=src/lib.rs
cargo:rerun-if-env-changed=CONFIGURATION

--- stderr
thread 'main' panicked at 'called Result::unwrap() on an Err value: Os { code: 1, kind: PermissionDenied, message: "Operation not permitted" }', /Users/user/.cargo/registry/src/index.crates.io-6f17d22bba15001f/swift-bridge-build-0.1.51/src/lib.rs:78:79
stack backtrace:
0: rust_begin_unwind
at /rustc/90c541806f23a127002de5b4038be731ba1458ca/library/std/src/panicking.rs:578:5
1: core::panicking::panic_fmt
at /rustc/90c541806f23a127002de5b4038be731ba1458ca/library/core/src/panicking.rs:67:14
2: core::result::unwrap_failed
at /rustc/90c541806f23a127002de5b4038be731ba1458ca/library/core/src/result.rs:1687:5
3: core::result::Result<T,E>::unwrap
at /rustc/90c541806f23a127002de5b4038be731ba1458ca/library/core/src/result.rs:1089:23
4: swift_bridge_build::GeneratedCode::write_all_concatenated
at /Users/user/.cargo/registry/src/index.crates.io-6f17d22bba15001f/swift-bridge-build-0.1.51/src/lib.rs:78:9
5: build_script_build::main
at ./build.rs:12:5
6: core::ops::function::FnOnce::call_once
at /rustc/90c541806f23a127002de5b4038be731ba1458ca/library/core/src/ops/function.rs:250:5
note: Some details are omitted, run with RUST_BACKTRACE=full for a verbose backtrace.
warning: build failed, waiting for other jobs to finish...
[ERROR cargo_lipo] Failed to build "ios-rust-analyzer" for "aarch64-apple-ios-sim": Executing ACTION="build"

Here is swift-bridge-build-0.1.51/src/lib.rs line 78 causing the error, in the GeneratedBuild impl:

std::fs::write(out.join(format!("{}.h", crate_name)), concatenated_c).unwrap();

..so somehow need to allowlist the build-swift-build program for writing files I guess?

@ghost
Copy link
Author

ghost commented Jun 18, 2023

Removing the Run Script step and running it manually, then trying to build the Xcode project gives the errors:

In /Users/user/Desktop/code/ios-rust-analyzer/target/universal/debug/libios_rust_analyzer.a(ios_rust_analyzer-0ef8df2bcd6643d0.qkrptas7sr7chi3.rcgu.o), building for iOS Simulator, but linking in object file built for iOS, file '/Users/user/Desktop/code/ios-rust-analyzer/target/universal/debug/libios_rust_analyzer.a' for architecture arm64

Linker command failed with exit code 1 (use -v to see invocation)

Changing line 30 of build-rust.sh to

TARGETS="aarch64-apple-ios-sim,x86_64-apple-ios"

and the simulator finally starts!

@chinedufn
Copy link
Owner

chinedufn commented Jun 18, 2023

Changing line 30 of build-rust.sh to TARGETS="aarch64-apple-ios-sim,x86_64-apple-ios"

Hmm, isn't this already the case in the guide

TARGETS="aarch64-apple-ios-sim,x86_64-apple-ios"

I'm not understanding what the problem was and what the fix was?

@ghost
Copy link
Author

ghost commented Jun 18, 2023

Oh, right, because I was running the build-rust.sh script manually as otherwise the swift-bridge-build GeneratedBuild code doesn't have write permission for some reason, and was forgetting to set PLATFORM_NAME.

The problem is the Run Script step fails on macOS 14.0 beta Sonoma, possibly because of increased privacy defaults.

@ghost
Copy link
Author

ghost commented Jun 18, 2023

Ok, followed the guide to the end now and it works, just wanted to report the build errors with the Run Script portion (included in my second post).

@chinedufn
Copy link
Owner

Got it. How did you fix the permissions issue?

@ghost
Copy link
Author

ghost commented Jun 19, 2023

I didn't, I ran the build-rust.sh script manually. I'm completely new to mac development and since the OS and IDE are both beta versions I put off trying to fix the permissions thing in favour of getting the example to run.

(And now I'm trying to build for rust targets aarch64-apple-ios-macabi and x86_64-apple-ios-macabi so I can compile for Mac Catalyst.)

@sax
Copy link

sax commented Mar 10, 2024

I'm not sure if this is related, but in XCode 15.3 I had to go into my project's Build Settings and configure: Build Option > User Script Sandboxing to No for both debug and release.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants