Comments (1)
Here is the build script I'm using on the rust-project side:
#!/bin/bash
set -e
# Make the script run in its own directory instead of the caller's directory.
cd "$(cd -P -- "$(dirname -- "$0")" && pwd -P)" || exit 1
XCODE_IOS_DIR="../ios"
RUST_LIB_DIR="$XCODE_IOS_DIR/rust-lib"
# The library name of the Cargo project
RUST_CRATE_NAME="my-rust-lib"
RUST_LIB_NAME="libmy_rust_lib_ios.a"
if [ ! -d "$XCODE_IOS_DIR" ]; then
echo "$XCODE_IOS_DIR does not exist."
fi
mkdir -p "./target/simulator-ios/release"
mkdir -p "./target/simulator-ios/debug"
# The directory for the source files
mkdir -p "$RUST_LIB_DIR/sources/$RUST_CRATE_NAME"
# The directory for the aarch64/arm64 lib
mkdir -p "$RUST_LIB_DIR/libs/arm64-ios"
# The directory for the simulator lib
mkdir -p "$RUST_LIB_DIR/libs/simulator-ios"
# The directory actually used by the compiler (XCode will use this directory)
mkdir -p "$RUST_LIB_DIR/libs/working-lib"
case "$1" in
"ci")
cargo build
;;
"debug")
cargo build --target aarch64-apple-ios
cargo build --target x86_64-apple-ios
cargo build --target aarch64-apple-ios-sim
lipo \
"./target/aarch64-apple-ios-sim/debug/$RUST_LIB_NAME" \
"./target/x86_64-apple-ios/debug/$RUST_LIB_NAME" -create -output \
"./target/simulator-ios/debug/$RUST_LIB_NAME"
cp "./target/aarch64-apple-ios/debug/$RUST_LIB_NAME" "$RUST_LIB_DIR/libs/arm64-ios/"
cp "./target/simulator-ios/debug/$RUST_LIB_NAME" "$RUST_LIB_DIR/libs/simulator-ios/"
cp -R "./generated/" "$RUST_LIB_DIR/sources/"
;;
"debug-arm64-only")
cargo build --target aarch64-apple-ios
cp "./target/aarch64-apple-ios/debug/$RUST_LIB_NAME" "$RUST_LIB_DIR/libs/arm64-ios/"
cp -R "./generated/" "$RUST_LIB_DIR/sources/"
;;
"release")
cargo build --release --target aarch64-apple-ios
cargo build --release --target x86_64-apple-ios
cargo build --release --target aarch64-apple-ios-sim
lipo \
"./target/aarch64-apple-ios-sim/release/$RUST_LIB_NAME" \
"./target/x86_64-apple-ios/release/$RUST_LIB_NAME" -create -output \
"./target/simulator-ios/release/$RUST_LIB_NAME"
cp "./target/aarch64-apple-ios/release/$RUST_LIB_NAME" "$RUST_LIB_DIR/libs/arm64-ios/"
cp "./target/simulator-ios/release/$RUST_LIB_NAME" "$RUST_LIB_DIR/libs/simulator-ios/"
cp -R "./generated/" "$RUST_LIB_DIR/sources/"
;;
"release-arm64-only")
cargo build --release --target aarch64-apple-ios
cp "./target/aarch64-apple-ios/release/$RUST_LIB_NAME" "$RUST_LIB_DIR/libs/arm64-ios/"
cp -R "./generated/" "$RUST_LIB_DIR/sources/"
;;
*)
echo "Must give option argument (debug | release)"
exit 1
;;
esac
On the XCode side I have this build phase script
echo "Copying the correct version of the iOS library for platform $PLATFORM_NAME and architectures $ARCHS"
mkdir -p "$PROJECT_DIR/rust-lib/libs/working-lib"
if [[ "$PLATFORM_NAME" = "iphonesimulator" ]]; then
cp "$PROJECT_DIR/rust-lib/libs/simulator-ios/libmy_rust_lib_ios.a" "$PROJECT_DIR/rust-lib/libs/working-lib/libmy_rust_lib_ios.a"
else
cp "$PROJECT_DIR/rust-lib/libs/arm64-ios/libmy_rust_lib_ios.a" "$PROJECT_DIR/rust-lib/libs/working-lib/libmy_rust_lib_ios.a"
fi
Using those two scripts, most of the other XCode + Cargo steps still make sense.
from swift-bridge.
Related Issues (20)
- swift-bridge-build should not emit errors and instead let rustc show errors emitted by the procedural macro HOT 2
- Problem with x86_64-apple-ios-simulator HOT 2
- Add RustVec.intoArray() HOT 1
- SwiftData struct for translating Swift's Data class HOT 1
- extern Swift declaration not public HOT 12
- Support Box<FnOnce> in extern "Rust" HOT 3
- Xcode reports "Multiple commands produce '...DerivedData...Build/Products/Debug/include/module.modulemap'" HOT 4
- Clippy finds clippy::unnecessary-cast
- Getting these errors in my project HOT 1
- Building for Release HOT 5
- #[swift_bridge::bridge] macro forces module to be private HOT 3
- warning: `extern` block uses type `RustString`, which is not FFI-safe HOT 4
- Book update: Xcode 15 (at least) requires a bridge in order to import into swift
- Can't seem to return refs of custom types HOT 11
- Cannot use two `#[swift_bridge(..)]` attributes on the same function
- Already_declared causes swift generation to never declare Class HOT 1
- Result returns translating incorrectly? HOT 3
- Is &Vec<T> supported? HOT 2
- Cannot for the life of me get Xcode + Cargo to work HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from swift-bridge.