#!/usr/bin/env bash12# based on https://github.com/mozilla/glean/blob/main/build-scripts/xc-universal-binary.sh34set -eux56PATH=$PATH:$HOME/.cargo/bin78PROFILE=debug9RELFLAG=10if [[ "$CONFIGURATION" != "Debug" ]]; then11PROFILE=release12RELFLAG=--release13fi1415set -euvx1617# add homebrew bin path, as it's the most commonly used package manager on macOS18# this is needed for cmake on apple arm processors as it's not available by default19export PATH="$PATH:/opt/homebrew/bin"2021# Make Cargo output cache files in Xcode's directories22export CARGO_TARGET_DIR="$DERIVED_FILE_DIR/cargo"2324# Xcode places `/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin`25# at the front of the path, with makes the build fail with `ld: library 'System' not found`, upstream issue:26# <https://github.com/rust-lang/rust/issues/80817>.27#28# Work around it by resetting the path, so that we use the system `cc`.29export PATH="/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:$PATH"3031IS_SIMULATOR=032if [ "${LLVM_TARGET_TRIPLE_SUFFIX-}" = "-simulator" ]; then33IS_SIMULATOR=134fi3536EXECUTABLES=37for arch in $ARCHS; do38case "$arch" in39x86_64)40if [ $IS_SIMULATOR -eq 0 ]; then41echo "Building for x86_64, but not a simulator build. What's going on?" >&242exit 243fi4445# Intel iOS simulator46export CFLAGS_x86_64_apple_ios="-target x86_64-apple-ios"47TARGET=x86_64-apple-ios48;;4950arm64)51if [ $IS_SIMULATOR -eq 0 ]; then52# Hardware iOS targets53TARGET=aarch64-apple-ios54else55# M1 iOS simulator56TARGET=aarch64-apple-ios-sim57fi58esac5960cargo build $RELFLAG --target $TARGET --bin bevy_mobile_example6162# Collect the executables63EXECUTABLES="$EXECUTABLES $DERIVED_FILE_DIR/cargo/$TARGET/$PROFILE/bevy_mobile_example"64done6566# Combine executables, and place them at the output path excepted by Xcode67lipo -create -output "$TARGET_BUILD_DIR/$EXECUTABLE_PATH" $EXECUTABLES686970