Electric-Coin-Company / zcash-swift-wallet-sdk

iOS light client Framework proof-of-concept
MIT License
37 stars 33 forks source link

M1 fixes (#309) #316

Closed dh-ecc closed 2 years ago

dh-ecc commented 2 years ago

[Addressing #309]

This is the absolute bare minimum diff to get the pod integration working for M1 machines, which can be demonstrated in this repo by pod installing in the Example/ZcashLightClientSample/ directory and running on simulator.

In doing so we remove some rust build dependencies, but (at the time of writing) can only build on the rust nightly toolchain, so we add this as a dependency.

Caveats / Known issues

The following commands should be sufficient to test this working and should work on both intel and m1 macs. It assumes you have working rustup and pod commands, try running it in a /tmp/ folder 😄

rustup toolchain add nightly
rustup +nightly target add \
x86_64-apple-ios \
aarch64-apple-ios \
aarch64-apple-ios-sim
git clone git@github.com:dh-ecc/ZcashLightClientKit.git
cd ZcashLightClientKit
git checkout m1-fixes
cd Example/ZcashLightClientSample
pod install
SIMULATOR_ID="$(xcrun simctl list devices available 'iPhone' | grep -E -o -i '([0-9a-f]{8}-([0-9a-f]{4}-){3}[0-9a-f]{12})' | head -n 1)"
xcodebuild \
-workspace ZcashLightClientSample.xcworkspace \
-scheme ZcashLightClientSample \
-destination "id=$SIMULATOR_ID" \
clean \
build

The build command is a very fancy way of saying "build it for an iOS Simulator on my machine" without having to assume an OS version or device that the host might have 😅, Some inspiration from https://nshipster.com/simctl/ . Would be much nicer if it was possibe to something like-destination "generic/platform=iOS Simulator" but as far as I know this is not possible... please let me know if there is!

Author

Reviewer

pacu commented 2 years ago

Travis CI Build is failing with

=== BUILD TARGET ZcashLightClientKit OF PROJECT Pods WITH CONFIGURATION Debug ===
Building Rust backend
platform name
iphonesimulator
fix 'permission denied issue'
cargo +nightly build --manifest-path /Users/travis/build/zcash/ZcashLightClientKit/Example/ZcashLightClientSample/Pods/../../../Cargo.toml --target x86_64-apple-ios --release
export LIBRARY_PATH="/Applications/Xcode-12.5.1.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/lib:"
error: toolchain 'nightly-x86_64-apple-darwin' is not installed
/Users/travis/build/zcash/ZcashLightClientKit/Example/ZcashLightClientSample/Pods/../../../Scripts/build_librustzcash_xcode.sh: line 44: persist_environment: command not found
clean up existing artifacts: rm -f /Users/travis/build/zcash/ZcashLightClientKit/Example/ZcashLightClientSample/Pods/../../../ZcashLightClientKit/zcashlc/libzcashlc.a
clean up sdk lib path: rm -f /Users/travis/build/zcash/ZcashLightClientKit/Example/ZcashLightClientSample/Pods/../../../lib/libzcashlc.a
copying artifacts: cp -f /Users/travis/build/zcash/ZcashLightClientKit/Example/ZcashLightClientSample/Pods/../../../target/x86_64-apple-ios/release/libzcashlc.a /Users/travis/build/zcash/ZcashLightClientKit/Example/ZcashLightClientSample/Pods/../../../ZcashLightClientKit/zcashlc/libzcashlc.a
cp: /Users/travis/build/zcash/ZcashLightClientKit/Example/ZcashLightClientSample/Pods/../../../target/x86_64-apple-ios/release/libzcashlc.a: No such file or directory
copying artifacts: cp -f /Users/travis/build/zcash/ZcashLightClientKit/Example/ZcashLightClientSample/Pods/../../../target/x86_64-apple-ios/release/libzcashlc.a /Users/travis/build/zcash/ZcashLightClientKit/Example/ZcashLightClientSample/Pods/../../../lib/libzcashlc.a
cp: /Users/travis/build/zcash/ZcashLightClientKit/Example/ZcashLightClientSample/Pods/../../../target/x86_64-apple-ios/release/libzcashlc.a: No such file or directory
** BUILD FAILED **
/Users/travis/.travis/functions: line 607:  4158 Terminated: 15          travis_jigger "${!}" "${timeout}" "${cmd[@]}"
The command "travis_wait 60 xcodebuild -quiet -UseModernBuildSystem=NO -workspace ./Example/ZcashLightClientSample/ZcashLightClientSample.xcworkspace -scheme ZcashLightClientSample -destination platform\=iOS\ Simulator,OS\=14.5,name\=iPhone\ 8 build" exited with 65.
pacu commented 2 years ago

Bitrise CI is failing with this error

▸ Running script '[CP-User] Build generate constants and build librustzcash'
❌  error: toolchain 'nightly-x86_64-apple-darwin' is not installed
Last lines of the Xcode's build log:
cp: /Users/vagrant/git/Example/ZcashLightClientSample/Pods/../../../target/x86_64-apple-ios/release/libzcashlc.a: No such file or directory
copying artifacts: cp -f /Users/vagrant/git/Example/ZcashLightClientSample/Pods/../../../target/x86_64-apple-ios/release/libzcashlc.a /Users/vagrant/git/Example/ZcashLightClientSample/Pods/../../../lib/libzcashlc.a
cp: /Users/vagrant/git/Example/ZcashLightClientSample/Pods/../../../target/x86_64-apple-ios/release/libzcashlc.a: No such file or directory
** BUILD FAILED **
The following build commands failed:
    PhaseScriptExecution [CP-User]\ Build\ generate\ constants\ and\ build\ librustzcash /Users/vagrant/Library/Developer/Xcode/DerivedData/ZcashLightClientSample-bgjqxuwsktfenyabttyfngigqezy/Build/Intermediates.noindex/Pods.build/Release-iphonesimulator/ZcashLightClientKit.build/Script-C9462958FFCBCF2AA9566CCBDC027C0C.sh
(1 failure)
You can find the last couple of lines of Xcode's build log above, but the full log is also available in the raw-xcodebuild-output.log
The log file is stored in $BITRISE_DEPLOY_DIR, and its full path is available in the $BITRISE_XCODE_RAW_RESULT_TEXT_PATH environment variable
(value: /Users/vagrant/deploy/raw-xcodebuild-output.log)
Build failed, error: exit status 65
dh-ecc commented 2 years ago

[@pacu]

Travis CI Build is failing with [...]

I'll get onto this now 👍 Need to update the rust environment setup.

[@pacu]

Bitrise CI is failing with this error

I might need your help to update some pre build steps for setting up the rust environment, should be basically the same as the update to the travis script.

pacu commented 2 years ago

Bitrise is failing with

Running script '[CP-User] Build generate constants and build librustzcash'
    Patch `jubjub v0.7.0 (https://github.com/zkcrypto/jubjub.git?rev=96ab4162b83303378eae32a326b54d88b75bffc2#96ab4162)` was not used in the crate graph.
❌  error: could not compile `cfg-if` due to previous error
    build failed, waiting for other jobs to finish...
❌  error: build failed
Last lines of the Xcode's build log:
copying artifacts: cp -f /Users/vagrant/git/Example/ZcashLightClientSample/Pods/../../../target/x86_64-apple-ios/release/libzcashlc.a /Users/vagrant/git/Example/ZcashLightClientSample/Pods/../../../lib/libzcashlc.a
+ cp -f /Users/vagrant/git/Example/ZcashLightClientSample/Pods/../../../target/x86_64-apple-ios/release/libzcashlc.a /Users/vagrant/git/Example/ZcashLightClientSample/Pods/../../../lib/libzcashlc.a
cp: /Users/vagrant/git/Example/ZcashLightClientSample/Pods/../../../target/x86_64-apple-ios/release/libzcashlc.a: No such file or directory
** BUILD FAILED **
dh-ecc commented 2 years ago

@pacu Bitrise is failing because it is building in Release configuration which builds all available platform architectures, since it's for simulator it will need to have an x86_64 and arm64 slice.

To sort this I reintroduced cargo-lipo 😅, this will be temporary since we'll remove all of the rust tooling in the near future.

Would you be able to add a cargo install cargo-lipo to the bitrise setup? (again 😓 sorry)