From 1ffc4b6233cf07bc3258704e3db5979bfcbb733e Mon Sep 17 00:00:00 2001 From: Sky Moore Date: Wed, 28 Jan 2026 13:12:51 +0000 Subject: [PATCH] fix(macos-app): patch SwiftPM Bundle.module accessor for app bundle compatibility --- scripts/package-mac-app.sh | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/scripts/package-mac-app.sh b/scripts/package-mac-app.sh index 48622efe1..730b5074f 100755 --- a/scripts/package-mac-app.sh +++ b/scripts/package-mac-app.sh @@ -128,6 +128,20 @@ cd "$ROOT_DIR/apps/macos" echo "🔨 Building $PRODUCT ($BUILD_CONFIG) [${BUILD_ARCHS[*]}]" for arch in "${BUILD_ARCHS[@]}"; do BUILD_PATH="$(build_path_for_arch "$arch")" + # First build to generate resource_bundle_accessor.swift files + swift build -c "$BUILD_CONFIG" --product "$PRODUCT" --build-path "$BUILD_PATH" --arch "$arch" -Xlinker -rpath -Xlinker @executable_path/../Frameworks || true + + # Patch SwiftPM-generated resource_bundle_accessor.swift files to use resourceURL + # instead of bundleURL (fixes Bundle.module lookup in .app bundles) + echo "🔧 Patching Bundle.module accessors for app bundle compatibility" + find "$BUILD_PATH" -name "resource_bundle_accessor.swift" -type f 2>/dev/null | while read -r accessor; do + if grep -q "Bundle.main.bundleURL.appendingPathComponent" "$accessor" 2>/dev/null; then + sed -i '' 's/Bundle\.main\.bundleURL\.appendingPathComponent/(Bundle.main.resourceURL ?? Bundle.main.bundleURL).appendingPathComponent/g' "$accessor" + echo " Patched: $accessor" + fi + done + + # Rebuild with patched accessors swift build -c "$BUILD_CONFIG" --product "$PRODUCT" --build-path "$BUILD_PATH" --arch "$arch" -Xlinker -rpath -Xlinker @executable_path/../Frameworks done @@ -252,6 +266,15 @@ else fi fi +echo "📦 Copying SwiftUIMath resources" +SWIFTUIMATH_BUNDLE="$(build_path_for_arch "$PRIMARY_ARCH")/$BUILD_CONFIG/swiftui-math_SwiftUIMath.bundle" +if [ -d "$SWIFTUIMATH_BUNDLE" ]; then + rm -rf "$APP_ROOT/Contents/Resources/$(basename "$SWIFTUIMATH_BUNDLE")" + cp -R "$SWIFTUIMATH_BUNDLE" "$APP_ROOT/Contents/Resources/" +else + echo "WARN: SwiftUIMath resource bundle not found at $SWIFTUIMATH_BUNDLE (continuing)" >&2 +fi + echo "⏹ Stopping any running Clawdbot" killall -q Clawdbot 2>/dev/null || true