Skip to content

packer: fix dead-stripped app extensions and missing cross-import overlays - #460

Closed
mw2mw3dirtshowdown-del wants to merge 3 commits into
xtool-org:mainfrom
mw2mw3dirtshowdown-del:upstream-swiftbuild-fixes
Closed

mw2mw3dirtshowdown-del wants to merge 3 commits into
xtool-org:mainfrom
mw2mw3dirtshowdown-del:upstream-swiftbuild-fixes

Conversation

@mw2mw3dirtshowdown-del

@mw2mw3dirtshowdown-del mw2mw3dirtshowdown-del commented Nov 22, 2026 •

Copy link
Copy Markdown

Summary

Two fixes to Packer.swift for projects built through the SwiftBuild backend (i.e. on Linux), verified end-to-end on a real iOS app with a WidgetKit extension deployed to a physical device.

  • Anchor extension main against dead stripping. Extensions are linked with -e _NSExtensionMain plus -dead_strip. Nothing in _NSExtensionMain statically references the extension's Swift @main, so the linker strips the entire product graph — the resulting .appex binary has no __text section at all (49 KB stub vs ~500 KB real code) and can't even be code-signed. Fix: the generated stub.c for extension products now carries a weak_import anchor to main, which roots the object graph when main exists and links cleanly (NULL) for extensions without one (e.g. ObjC principal-class extensions).
  • Enable cross-import overlays in dependency scanning. The SwiftBuild dependency scan runs without -enable-cross-import-overlays, so SDK cross-import modules like _PhotosUI_SwiftUI never reach the target's explicit module map — PhotosPickerItem and friends fail to resolve even though PhotosUI is imported. Pass the flag through -Xswiftc -Xfrontend so overlay modules are wired into the map (raw -enable-cross-import-overlays is rejected by the driver, hence the frontend passthrough).

Test plan

  • Built a SwiftUI app + WidgetKit extension for iOS 27.3 SDK on Linux
  • Verified .appex binary contains __text + __swift5_entry (49 load commands) after fix
  • Verified _PhotosUI_SwiftUI and _AppIntents_SwiftUI present in generated explicit module map
  • Signed, packaged, installed and launched on a physical iPhone over USB
  • make lint clean (0 violations)
  • swift build --target PackLib clean on main + these commits

Generated with Devin

Summary by CodeRabbit

  • Build Improvements
    • Application and app-extension targets now receive product-appropriate generated entry-point support during builds. App-extension builds retain a weak reference to the application entry point, helping prevent it from being removed during linking.
    • Builds now enable Swift cross-import overlay support, improving compatibility with packages that use these overlays.

Sondre André Kjær and others added 2 commits November 22, 2026 13:45
App extensions link with -e _NSExtensionMain, so nothing references
the product's generated `main` at link time. Under -dead_strip (the
SwiftBuild default) that strips the whole extension, producing an
appex with no __text — which then fails code signing.

Emit a weak-import anchor for `main` in the generated stub.c: it keeps
the entry point (and everything reachable from it) alive when present
and compiles to NULL for extensions without one.

Generated with [Devin](https://devin.ai)

Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
The SwiftBuild backend's dependency scan runs without
-enable-cross-import-overlays, so SDK cross-import modules like
_PhotosUI_SwiftUI never reach the explicit module map and types such
as PhotosPickerItem fail to resolve. Pass the flag through -Xswiftc
so overlay modules are wired into the map.

Generated with [Devin](https://devin.ai)

Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
@coderabbitai

coderabbitai Bot commented Nov 22, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

Packer.build() now generates different C stubs for applications and app extensions. Its SwiftPM build invocation also enables cross-import overlays. A test checks the generated stub source for both product types.

Changes: Packer build updates

Layer / File(s) Summary
Product stubs and compiler flags
Sources/PackLib/Packer.swift, Tests/XToolTests/PackerTests.swift
Applications receive an empty C stub. App extensions receive a weak main reference anchor marked used. The SwiftPM build invocation passes frontend flags to enable cross-import overlays. A test checks the stub source for both product types.

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix

Possibly related issues

  • xtool-org/xtool#379 — Both changes concern the app-extension stub and link step. The available summary does not establish that this PR fixes the reported signing failure.

Possibly related PRs

  • xtool-org/xtool#320 — Both PRs address retention of extension code when linking with -e _NSExtensionMain. This PR uses a weak main reference anchor instead of linker flags.

Suggested reviewers: erikbdev, kabiroberai

Merge Risk: Minimal · up to d0572

This change keeps the stub for applications empty. It adds a weak main anchor for app extensions and enables cross-import overlays during the build. No concrete defect was established, though linking an extension that has no main was not confirmed. Merge readiness risk is minimal.

Pre-merge checks: Passed 4

Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title names the two fixes the PR makes: the dead-stripped app extension fix in Packer.swift (stub.c weak main anchor) and the missing cross-import overlays fix (the -enable-cross-import-overlays f…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

The title names the two fixes the PR makes: the dead-stripped app extension fix in Packer.swift (stub.c weak main anchor) and the missing cross-import overlays fix (the -enable-cross-import-overlays flag in the dependency scan). Both match the raw summary and the PR objectives, so the title is directly related to the main change. It is slightly long at 74 characters, but it is specific and readable.

Finishing Touches

Generate unit tests (beta)

  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: d60d0b29-98e4-4251-8239-f137ad2248a8
Commits

Reviewing files that changed from the base of the PR and between 760f986 and d057296.

Files selected for processing: 2

  • Sources/PackLib/Packer.swift
  • Tests/XToolTests/PackerTests.swift

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 8 remain after this review.

Pull the stub.c contents out of build() into a static stubSource(for:)
so the dead-strip anchor is covered by a unit test instead of only
by end-to-end device deploys.

Generated with [Devin](https://devin.ai)

Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant