Skip to content

Instantly share code, notes, and snippets.

@ianthetechie
Created April 24, 2023 10:25
Show Gist options
  • Save ianthetechie/d87b7efc04870293b1b4ffb7a4e227b8 to your computer and use it in GitHub Desktop.
Save ianthetechie/d87b7efc04870293b1b4ffb7a4e227b8 to your computer and use it in GitHub Desktop.
A minimal zsh script that can be used by an Xcode External Build System target to build for iOS
#!/bin/zsh
# Clears environment variables set by Xcode by taking a whitelist approach.
# We only need our HOME and PATH, as well as the ACTION and CONFIGURATION set by Xcode
env -i HOME="$HOME" PATH="$PATH" ACTION="$ACTION" CONFIGURATION="$CONFIGURATION" \
/bin/zsh -l -c "$(cat <<-'END_OF_SCRIPT'
# Function to perform a clean build
clean_build() {
echo "Cleaning..."
cargo clean
}
# Function to perform a debug build
debug_build() {
echo "Building Debug..."
cargo build --lib --target x86_64-apple-ios
cargo build --lib --target aarch64-apple-ios
cargo build --lib --target aarch64-apple-ios-sim
}
# Function to perform a release build
release_build() {
echo "Building Release..."
cargo build --lib --release --target x86_64-apple-ios
cargo build --lib --release --target aarch64-apple-ios
cargo build --lib --release --target aarch64-apple-ios-sim
}
# Execute multiple actions based on Xcode build arguments
if [ "$ACTION" = "clean" ]; then
clean_build
elif [ "$CONFIGURATION" = "Debug" ]; then
debug_build
elif [ "$CONFIGURATION" = "Release" ]; then
release_build
else
echo "Unknown build action ($ACTION) or configuration ($CONFIGURATION)"
exit 1
fi
END_OF_SCRIPT
)"
@ianthetechie
Copy link
Author

See https://fosstodon.org/@ianthetechie/110253317456547643 for a thread on what I'm trying to accomplish and why I wrote this script.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment