Skip to content

Instantly share code, notes, and snippets.

@TheSantacloud
Last active April 7, 2025 04:28
Show Gist options
  • Save TheSantacloud/0599ce563f3ed389a5ff5b5c1388f85c to your computer and use it in GitHub Desktop.
Save TheSantacloud/0599ce563f3ed389a5ff5b5c1388f85c to your computer and use it in GitHub Desktop.
Build script for SwiftUI applications to be built on MacOS
#!/bin/sh
set -e
# if build directory doesn't exist, build first
if [ ! -d ".build" ]; then
swift build
fi
#
# get executable target name
APP_NAME=$(swift package describe --type json | jq -r '.targets[] | select(.type == "executable") | .name')
DEV_APP_NAME="dev:$APP_NAME"
BUILD_DIR=".build/debug"
APP_BUNDLE="$BUILD_DIR/$DEV_APP_NAME.app"
# create app bundle structure
mkdir -p "$APP_BUNDLE/Contents/MacOS"
mkdir -p "$APP_BUNDLE/Contents/Resources"
# copy compiled binary into bundle
cp "$BUILD_DIR/$APP_NAME" "$APP_BUNDLE/Contents/MacOS/$DEV_APP_NAME"
# generate Info.plist
cat > "$APP_BUNDLE/Contents/Info.plist" <<EOF
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN"
"http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleName</key>
<string>$DEV_APP_NAME</string>
<key>CFBundleIdentifier</key>
<string>dev.example.$APP_NAME</string>
<key>CFBundleExecutable</key>
<string>$DEV_APP_NAME</string>
<key>CFBundlePackageType</key>
<string>APPL</string>
</dict>
</plist>
EOF
echo "App bundle created at $APP_BUNDLE"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment