#!/usr/bin/env bash set -euo pipefail export PATH="/opt/homebrew/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:$PATH:$HOME/.cargo/bin" export RUSTC="$(rustup which --toolchain stable rustc)" export RUSTDOC="$(rustup which --toolchain stable rustdoc)" export CARGO_TARGET_DIR="$DERIVED_FILE_DIR/cargo" export CARGO_PROFILE_RELEASE_DEBUG="${CARGO_PROFILE_RELEASE_DEBUG:-1}" if [[ "$CONFIGURATION" == "Debug" ]]; then profile=debug else profile=release fi if [[ "${LLVM_TARGET_TRIPLE_SUFFIX:-}" == "-simulator" ]]; then separator=$'\x1f' entitlement_flags="-Clink-arg=-Wl,-sectcreate,__TEXT,__entitlements,$LD_ENTITLEMENTS_SECTION" entitlement_flags+="$separator-Clink-arg=-Wl,-sectcreate,__TEXT,__ents_der,$LD_ENTITLEMENTS_SECTION_DER" export CARGO_ENCODED_RUSTFLAGS="${CARGO_ENCODED_RUSTFLAGS:+$CARGO_ENCODED_RUSTFLAGS$separator}$entitlement_flags" fi executables=() for arch in $ARCHS; do if [[ "$arch" == "arm64" && "${LLVM_TARGET_TRIPLE_SUFFIX:-}" == "-simulator" ]]; then target=aarch64-apple-ios-sim elif [[ "$arch" == "arm64" ]]; then target=aarch64-apple-ios elif [[ "$arch" == "x86_64" ]]; then target=x86_64-apple-ios else echo "Unsupported iOS architecture: $arch" >&2 exit 1 fi if [[ "$profile" == "debug" ]]; then rustup run stable cargo build --locked --target "$target" --bin "$1" else rustup run stable cargo build --locked --release --target "$target" --bin "$1" fi executables+=("$CARGO_TARGET_DIR/$target/$profile/$1") done lipo -create -output "$TARGET_BUILD_DIR/$EXECUTABLE_PATH" "${executables[@]}" if [[ -n "${DWARF_DSYM_FOLDER_PATH:-}" && -n "${DWARF_DSYM_FILE_NAME:-}" ]]; then dsymutil "$TARGET_BUILD_DIR/$EXECUTABLE_PATH" -o "$DWARF_DSYM_FOLDER_PATH/$DWARF_DSYM_FILE_NAME" fi