fix(macos-app): patch SwiftPM Bundle.module accessor for app bundle#3337
Open
skymoore wants to merge 2 commits intoopenclaw:mainfrom
Open
fix(macos-app): patch SwiftPM Bundle.module accessor for app bundle#3337skymoore wants to merge 2 commits intoopenclaw:mainfrom
skymoore wants to merge 2 commits intoopenclaw:mainfrom
Conversation
Contributor
Additional Comments (1)
Because the first build is Prompt To Fix With AIThis is a comment left during a code review.
Path: scripts/package-mac-app.sh
Line: 132:132
Comment:
[P0] Ignoring the first `swift build` failure can silently leave accessors unpatched and produce a broken app.
Because the first build is `... || true`, if generation fails (missing deps, wrong toolchain, transient SwiftPM error), the patch loop will find nothing and the second build will run anyway; you’ll only find out later at runtime. Consider removing `|| true` or explicitly failing if no `resource_bundle_accessor.swift` files were found/patched for the target.
How can I resolve this? If you propose a fix, please make it concise. |
bfc1ccb to
f92900f
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
fix(macos-app): patch SwiftPM Bundle.module accessor for app bundle compatibility
Problem
SwiftPM's auto-generated resource_bundle_accessor.swift files use Bundle.main.bundleURL.appendingPathComponent(...) to locate package resource bundles. This resolves to .app/Package_Target.bundle at the app root.
However:
• macOS app bundles put resources in .app/Contents/Resources/
• Code signing prohibits arbitrary files/symlinks at the app root
• This causes EXC_BREAKPOINT crashes when packages like Textual try Bundle.module.url(forResource:) (e.g., prism-bundle.js for syntax highlighting)
Crash trace:
Thread 0 Crashed:
0 libswiftCore.dylib _assertionFailure
1 Clawdbot closure #1 in variable initialization expression of static NSBundle.module
2 Clawdbot CodeTokenizer.init()
Solution
After the first swift build (which generates accessors), patch all resource_bundle_accessor.swift files:
• Falls back to resourceURL first (correct for .app/Contents/Resources/), then bundleURL (development builds)
• Rebuilds with patched accessors
• No upstream changes needed
Changes
• scripts/package-mac-app.sh: Add double-build + sed patching step
• Works for all arches, all packages (Textual, SwiftUIMath, ClawdbotKit, etc.)
• Minimal overhead (~1-2s rebuild)
Testing
Before/After
Development (swift run)
• Before: ✅
• After: ✅
Packaged .app
• Before: 💥 Crash on startup
• After: ✅ Launches + full functionality
Codesign
• Before: ✅
• After: ✅
Fixes #1709 (#1709) (Textual/CodeTokenizer crash).
Closes: #1709
Type: Fix
Scope: macos-app, swiftpm
Greptile Overview
Greptile Summary
This PR updates
scripts/package-mac-app.shto patch SwiftPM-generatedresource_bundle_accessor.swiftfiles soBundle.moduleresolves resources viaBundle.main.resourceURLinside a signed.appbundle (instead ofbundleURLat the app root). The script now performs an initialswift buildper-arch to generate accessors, rewrites the accessor code viased, then rebuilds and continues packaging by copying resource bundles (including adding SwiftUIMath’s bundle) intoMoltbot.app/Contents/Resources.Confidence Score: 3/5
swift build ... || truecan let the script proceed without actually generating/patching accessors, making failures harder to diagnose and potentially reintroducing the crash at runtime.(2/5) Greptile learns from your feedback when you react with thumbs up/down!
Context used:
dashboard- CLAUDE.md (source)dashboard- AGENTS.md (source)