#!/bin/bash # Builds Mulberry for iOS on Linux: swift.org toolchain + iPhoneOS SDK, no Xcode. # Outputs build/Mulberry--iOS.ipa (TrollStore) and build/Mulberry--iOS-rootless.deb. # Signing uses a local ldid if present, otherwise ldid on the iPhone over SSH ($IPHONE). set -euo pipefail cd "$(dirname "$0")" VERSION=${VERSION:-1.0.0} BUILD=${BUILD:-$(date +%Y%m%d%H%M)} SWIFT=${SWIFT:-$HOME/.local/opt/swift/usr/bin} SDK=${SDK:-$HOME/.local/opt/dl/sdk18/iPhoneOS18.6.sdk} TARGET=arm64-apple-ios17.0 IPHONE=${IPHONE:-mobile@192.168.1.94} IPHONE_KEY=${IPHONE_KEY:-$HOME/.ssh/iphone_key} CONFIG=${CONFIG:-release} OUT=build APP=$OUT/Payload/Mulberry.app APPEX=$APP/PlugIns/MulberryWidgets.appex rm -rf "$OUT/Payload" "$OUT/deb" mkdir -p "$APPEX" "$OUT/obj" OPT=(-O -wmo) [ "$CONFIG" = debug ] && OPT=(-Onone -g) RES=${RES:-$HOME/.local/opt/swift-ios-res} # toolchain resources minus the Linux-only module maps common=(-target "$TARGET" -sdk "$SDK" -resource-dir "$RES" -swift-version 5 "${OPT[@]}" -Xcc -Wno-unused-command-line-argument) # Links on the phone; when the repacked SDK's stubs lack symbols, look them up on the device, patch, retry. link() { local log=$OUT/link.log if tools/phone-ld "$@" 2> "$log"; then return 0; fi if grep -q 'symbol(s) not found' "$log"; then echo " resolving missing SDK symbols on the device…" tools/resolve-undefined "$log" tools/phone-ld "$@" && return 0 fi cat "$log" >&2 return 1 } LD=link "$SWIFT/clang" -target "$TARGET" -isysroot "$SDK" -O2 -c Native/compat.c -o "$OUT/obj/compat.o" # FFmpeg for the extra formats, when Native/build-ffmpeg.sh has been run. ff=() fflibs=() if [ -f Native/ffmpeg/lib/libavformat.a ]; then "$SWIFT/clang" -target "$TARGET" -isysroot "$SDK" -O2 -INative/ffmpeg/include -c Native/ffdecode.c -o "$OUT/obj/ffdecode.o" ff=(-D MULBERRY_FFMPEG -import-objc-header Native/ffdecode.h) fflibs=("$OUT/obj/ffdecode.o" Native/ffmpeg/lib/libavformat.a Native/ffmpeg/lib/libavcodec.a Native/ffmpeg/lib/libswresample.a Native/ffmpeg/lib/libavutil.a -lz -lbz2 -liconv -framework AudioToolbox -framework CoreFoundation -framework CoreMedia -framework CoreVideo -framework Security -framework VideoToolbox) fi echo "== app" "$SWIFT/swiftc" "${common[@]}" "${ff[@]}" -module-name Mulberry -c -wmo -num-threads 0 \ $(find App Shared -name '*.swift' | sort) -o "$OUT/obj/Mulberry.o" $LD -dead_strip -o "$APP/Mulberry" "$OUT/obj/Mulberry.o" "$OUT/obj/compat.o" "${fflibs[@]}" echo "== widget extension" "$SWIFT/swiftc" "${common[@]}" -module-name MulberryWidgets -application-extension -c -wmo -num-threads 0 \ $(find Widget Shared -name '*.swift' | sort) -o "$OUT/obj/MulberryWidgets.o" $LD -dead_strip -application-extension -o "$APPEX/MulberryWidgets" "$OUT/obj/MulberryWidgets.o" "$OUT/obj/compat.o" echo "== bundle" sed -e "s/@VERSION@/$VERSION/" -e "s/@BUILD@/$BUILD/" Resources/Info.plist > "$APP/Info.plist" sed -e "s/@VERSION@/$VERSION/" -e "s/@BUILD@/$BUILD/" Resources/Widget-Info.plist > "$APPEX/Info.plist" cp Resources/AppIcon*.png "$APP/" printf 'APPL????' > "$APP/PkgInfo" echo "== sign" if command -v ldid >/dev/null; then ldid -Spackaging/widget.entitlements "$APPEX/MulberryWidgets" ldid -Spackaging/app.entitlements "$APP/Mulberry" else ssh_=(ssh -i "$IPHONE_KEY" -o BatchMode=yes -o ConnectTimeout=10 "$IPHONE") remote=/var/mobile/Documents/mulberry-sign "${ssh_[@]}" "rm -rf $remote && mkdir -p $remote" scp -i "$IPHONE_KEY" -q "$APP/Mulberry" "$APPEX/MulberryWidgets" packaging/app.entitlements packaging/widget.entitlements "$IPHONE:$remote/" "${ssh_[@]}" "cd $remote && ldid -Swidget.entitlements MulberryWidgets && ldid -Sapp.entitlements Mulberry" scp -i "$IPHONE_KEY" -q "$IPHONE:$remote/Mulberry" "$APP/Mulberry" scp -i "$IPHONE_KEY" -q "$IPHONE:$remote/MulberryWidgets" "$APPEX/MulberryWidgets" "${ssh_[@]}" "rm -rf $remote" fi echo "== ipa" rm -f "$OUT/Mulberry-$VERSION-iOS.ipa" (cd "$OUT" && zip -qry "Mulberry-$VERSION-iOS.ipa" Payload) echo "== deb (rootless)" D=$OUT/deb mkdir -p "$D/data/var/jb/Applications" "$D/control" cp -a "$APP" "$D/data/var/jb/Applications/" sed "s/@VERSION@/$VERSION/" packaging/control > "$D/control/control" cp packaging/postinst packaging/prerm "$D/control/" (cd "$D/control" && tar --owner=0 --group=0 -czf ../control.tar.gz .) (cd "$D/data" && tar --owner=0 --group=0 -cJf ../data.tar.xz .) echo "2.0" > "$D/debian-binary" rm -f "$OUT/Mulberry-$VERSION-iOS-rootless.deb" (cd "$D" && ar rc "../Mulberry-$VERSION-iOS-rootless.deb" debian-binary control.tar.gz data.tar.xz) ls -la "$OUT"/*.ipa "$OUT"/*.deb