Code Monkey home page Code Monkey logo

Comments (1)

bes avatar bes commented on August 18, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.