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

Xcode fails to inherit PATH and therefore fails to find nix-installed cargo #151

Closed
n8henrie opened this issue Nov 1, 2023 · 2 comments
Closed

Comments

@n8henrie
Copy link

n8henrie commented Nov 1, 2023

I've successfully run cargo build --package shared && cargo build --package shared_types and opened the project in xcode.

In Xcode, attempting to build gives multiple errors, the first of which is:

RuleScriptExecution /Users/n8henrie/git/crux/examples/counter/iOS/generated/shared.swift /Users/n8henrie/git/crux/examples/counter/iOS/generated/sharedFFI.h /Users/n8henrie/git/crux/examples/counter/shared/src/shared.udl normal undefined_arch (in target 'CounterApp' from project 'CounterApp')
    cd /Users/n8henrie/git/crux/examples/counter/iOS
    /bin/sh -c \#\!/bin/bash'
'set\ -e'
''
'\#\ Skip\ during\ indexing\ phase\ in\ XCode\ 13+'
'if\ \[\ \"\$ACTION\"\ \=\=\ \"indexbuild\"\ \]\;\ then'
'\ \ echo\ \"Not\ building\ \*.udl\ files\ during\ indexing.\"'
'\ \ exit\ 0'
'fi'
''
'\#\ Skip\ for\ preview\ builds'
'if\ \[\ \"\$ENABLE_PREVIEWS\"\ \=\ \"YES\"\ \]\;\ then'
'\ \ echo\ \"Not\ building\ \*.udl\ files\ during\ preview\ builds.\"'
'\ \ exit\ 0'
'fi'
''
'cd\ \"\$\{INPUT_FILE_DIR\}/..\"'
'\"\$\{BUILD_DIR\}/debug/uniffi-bindgen\"\ generate\ \"src/\$\{INPUT_FILE_NAME\}\"\ --language\ swift\ --out-dir\ \"\$\{PROJECT_DIR\}/generated\"'
'

/bin/sh: line 16: /Users/n8henrie/Library/Developer/Xcode/DerivedData/CounterApp-fwwrdheqxdkprxbqjomnsznablpm/Build/Products/debug/uniffi-bindgen: No such file or directory
Command RuleScriptExecution failed with a nonzero exit code

Looking through a few other errors, I suspect this may be because I'm using a nix-installed cargo:

$ type -p cargo
/run/current-system/sw/bin/cargo

If the xcode build scripts are trying to call cargo commands, my recollection is that xcode won't necessarily have cargo in its path; some people also search for a rustup-installed cargo at ~/.cargo/bin or a brew-installed cargo at /opt/homebrew/bin (or /usr/local), but there are other possibilities.

Maybe related: #83

@StuartHarris
Copy link
Member

Hey thank you for submitting this! And apologies for slow response.

We use Mozilla's uniffi to help with the bindings generation. To help with version matching, we build the tool as a binary within the shared crate (see https://github.com/redbadger/crux/blob/master/examples/counter/shared/src/bin/uniffi-bindgen.rs), and your script seems to be failing because it can't find this uniffi executable (rather than the cargo executable). I'm not too familiar with nix, but it may be that you need to edit the script to point to the built uniffi binary.

Hope this helps, but LMK if you're still struggling.
Thanks

@n8henrie
Copy link
Author

Problem 1: cargo-xcode's build script uses a fixed PATH that won't work with alternative cargo install locations: https://gitlab.com/kornelski/cargo-xcode/-/blob/f202f751790b1e36571a0fe48a85ad35a3541ead/src/xcodebuild.sh#L2. Slight annoyance, easy fix.
Problem 2: It did not like using a faster linker (link-arg=-fuse-ld=lld), also an easy fix

With these two small fixes the iOS project builds and runs.

Because these will only affect a fairly niche set of users I don't think any code changes on crux's side are indicated, hopefully this issue will help if others run into similar issues. Will update the title for better searchability.

Thanks for a cool project!

@n8henrie n8henrie changed the title Unable to build counter example for iOS Xcode fails to inherit PATH and therefore fails to find nix-installed cargo Nov 16, 2023
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