| 1 | #!/bin/bash |
| 2 | set -euo pipefail |
| 3 | mobile_dir="$(cd "$(dirname "$0")" && pwd)" |
| 4 | cd "$mobile_dir" |
| 5 | case "${1:-}" in |
| 6 | android|ios) platform="$1" ;; |
| 7 | android-release) platform=android ;; |
| 8 | ios-ipa|ios-ipa-basic) |
| 9 | platform=ios |
| 10 | if [[ $# != 2 || ! $2 =~ ^[A-Z0-9]{10}$ ]]; then |
| 11 | echo "Usage: mobile/build.sh $1 TEAM_ID (10 uppercase letters or digits)" >&2 |
| 12 | exit 2 |
| 13 | fi |
| 14 | ;; |
| 15 | *) echo "Usage: mobile/build.sh android | android-release | ios | ios-ipa TEAM_ID | ios-ipa-basic TEAM_ID" >&2; exit 2 ;; |
| 16 | esac |
| 17 | if [[ "$platform" == ios ]]; then |
| 18 | |
| 19 | xcrun --sdk iphoneos --show-sdk-path >/dev/null |
| 20 | fi |
| 21 | mkdir -p .build/bin ".build/$platform" |
| 22 | node build-ui.mjs |
| 23 | if [[ "$platform" == android ]]; then bash android/fetch-webkit.sh "$mobile_dir/.build/android"; fi |
| 24 | bash scripts/licenses.sh |
| 25 | ( |
| 26 | cd bindings |
| 27 | go build -o ../.build/bin/gomobile golang.org/x/mobile/cmd/gomobile |
| 28 | go build -o ../.build/bin/gobind golang.org/x/mobile/cmd/gobind |
| 29 | ) |
| 30 | export PATH="$mobile_dir/.build/bin:$PATH" |
| 31 | if [[ -n "${JAVA_HOME:-}" ]]; then export PATH="$JAVA_HOME/bin:$PATH"; fi |
| 32 | if [[ "$platform" == ios ]]; then |
| 33 | brand=".build/ios/Assets.xcassets/CageMark.imageset" |
| 34 | mkdir -p "$brand" |
| 35 | cp ../ui/src/logo.png "$brand/mark.png" |
| 36 | printf '%s\n' '{"images":[{"filename":"mark.png","idiom":"universal"}],"info":{"author":"xcode","version":1}}' > "$brand/Contents.json" |
| 37 | devices=".build/ios/Assets.xcassets/PairDevices.imageset" |
| 38 | mkdir -p "$devices" |
| 39 | cp assets/pair-devices.png "$devices/devices.png" |
| 40 | sed 's/mark.png/devices.png/' "$brand/Contents.json" > "$devices/Contents.json" |
| 41 | icon=".build/ios/Assets.xcassets/AppIcon.appiconset" |
| 42 | mkdir -p "$icon" |
| 43 | printf '%s\n' '{"info":{"author":"xcode","version":1}}' > ".build/ios/Assets.xcassets/Contents.json" |
| 44 | cp ios/AppIcon.json "$icon/Contents.json" |
| 45 | sips -z 1024 1024 ../ui/src/logo.png --out "$icon/Cage.png" >/dev/null |
| 46 | |
| 47 | |
| 48 | (cd bindings && gomobile bind -target="ios/arm64,iossimulator/$(go env GOHOSTARCH)" -iosversion=17.0 -o "$mobile_dir/.build/ios/Cagemobile.xcframework" .) |
| 49 | if [[ "$1" == ios-ipa* ]]; then |
| 50 | scheme=CageMobile |
| 51 | if [[ "$1" == ios-ipa-basic ]]; then scheme=CageMobileBasic; fi |
| 52 | output=$(mktemp -d "$mobile_dir/.build/ios/device-XXXXXXXX") |
| 53 | xcodebuild -project ios/CageMobile.xcodeproj -scheme "$scheme" -configuration Release \ |
| 54 | -destination 'generic/platform=iOS' -archivePath "$output/CageMobile.xcarchive" \ |
| 55 | DEVELOPMENT_TEAM="$2" archive |
| 56 | xcodebuild -exportArchive -archivePath "$output/CageMobile.xcarchive" \ |
| 57 | -exportOptionsPlist ios/DebuggingExport.plist -exportPath "$output/export" |
| 58 | ipa="$output/export/$scheme.ipa" |
| 59 | |
| 60 | ditto -x -k "$ipa" "$output/check" |
| 61 | app="$output/check/Payload/$scheme.app" |
| 62 | test -s "$app/embedded.mobileprovision" |
| 63 | codesign --verify --deep --strict "$app" |
| 64 | rm -r "$output/check" |
| 65 | printf 'Cage iPhone development IPA: %s\n' "$ipa" |
| 66 | else |
| 67 | xcodebuild -project ios/CageMobile.xcodeproj -target CageMobile -sdk iphoneos -configuration Debug \ |
| 68 | CODE_SIGNING_ALLOWED=NO SYMROOT="$mobile_dir/.build/ios/products" OBJROOT="$mobile_dir/.build/ios/obj" build |
| 69 | fi |
| 70 | else |
| 71 | : "${ANDROID_HOME:?Set ANDROID_HOME to the Android SDK directory}" |
| 72 | (cd bindings && gomobile bind -target=android/arm64 -androidapi=26 \ |
| 73 | -ldflags='-extldflags=-Wl,-z,max-page-size=16384,-z,common-page-size=16384' \ |
| 74 | -o "$mobile_dir/.build/android/Cagemobile.aar" .) |
| 75 | if [[ "$1" == android-release ]]; then |
| 76 | bash android/package.sh --release |
| 77 | else |
| 78 | bash android/package.sh |
| 79 | fi |
| 80 | fi |