Repository navigation
feat(ios): embed dynamic SwiftPM products with embed - #6169
Draft
edusperoni wants to merge 1 commit into
Draft
edusperoni wants to merge 1 commit into
edusperoni wants to merge 1 commit into
Conversation
A Swift package product declared `.library(type: .dynamic)` was linked into the target's Frameworks phase but never copied into the app bundle. Debug simulator builds still ran because Xcode adds an absolute LC_RPATH to the build directory's PackageFrameworks folder; device and archive builds crashed in dyld at launch with "Library not loaded: @rpath/<Product>.framework/<Product>". Xcode records a dynamic package product added through "Frameworks, Libraries, and Embedded Content" twice: once in the Frameworks phase and once in the "Embed Frameworks" copy phase with CodeSignOnCopy. The CLI only ever wrote the first entry. `IosSPMPackageBase` gains `embed?: string[]`, the subset of `libs` to copy into the bundle. For each, the pbxproj service writes a second PBXBuildFile for the same productRef into the target's own "Embed Frameworks" copy phase (dstSubfolderSpec 10), creating the phase when the target has none. Entries are keyed on productRef so re-applying on every prepare stays idempotent. An embed entry that is not in `libs` is warned about and skipped. The option is opt-in: the CLI cannot tell a static product from a dynamic one without parsing Package.swift, and embedding a static product's placeholder breaks the build. The existing post-build architecture strip already walks the bundle's Frameworks folder, so embedded package frameworks get the same treatment as plugin frameworks.
|
Important Draft PR not reviewedDraft PRs are not automatically reviewed by default.
To automatically review draft PRs, update your CodeRabbit configuration: reviews:
auto_review:
drafts: true
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. Comment |
This branch has not been deployed
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.
PR Checklist
What is the current behavior?
Declare a Swift package product as dynamic and reference it from
nativescript.config.ts:The app builds, links, and launches on the simulator. On a device or from an archive it crashes in dyld at launch:
@rpath/MyProduct.framework.app/Frameworksns build ios(Debug, simulator)LC_RPATHtoplatforms/ios/build/…/PackageFrameworksns build ios --release --for-device@executable_path/Frameworksand@loader_path/FrameworksonlyThe framework is built (with its dSYM) and simply never copied into the bundle.
Cause.
SPMPbxprojService.addPackageToTargetwires a product into theXCSwiftPackageProductDependency, aPBXBuildFilewithproductRef, and the target'sPBXFrameworksBuildPhase. Nothing adds it to the "Embed Frameworks"PBXCopyFilesBuildPhase(dstSubfolderSpec = 10). When a package product is added through Xcode's own "Frameworks, Libraries, and Embedded Content" UI, Xcode emits the sameproductReftwice: once in the Frameworks phase, and once in the Embed Frameworks copy phase withsettings = { ATTRIBUTES = (CodeSignOnCopy, ); }. That second entry is what the CLI was missing. Xcode does not infer it from the link phase alone, as the Release build above shows.Verified on
nativescript@9.1.0-next.2026-08-19with Xcode 26.3.What is the new behavior?
IosSPMPackageBasegains an opt-inembed:For each product in
embed,addPackageToTargetnow:dstSubfolderSpec = 10), creating one when the target has none, the same way the link phase is resolved from the target's ownbuildPhasesrather than any target's;PBXBuildFilefor the sameproductRefwithsettings = { ATTRIBUTES = (CodeSignOnCopy, ); }and comment<Product> in Embed Frameworks;files, keyed onproductRefso re-applying on every prepare stays idempotent.An
embedentry that is not inlibsis warned about and skipped, matching how the missing-Frameworks-phase case is reported.What the service writes for an embedded product:
Why opt-in. The CLI cannot tell a static product from a dynamic one without parsing
Package.swift, and embedding a static product's placeholder breaks the build.Nothing else changes.
internal/strip-dynamic-framework-architectures.shalready walks$FRAMEWORKS_FOLDER_PATH, so embedded package frameworks get the same architecture strip and re-sign as plugin.xcframeworks.Docs follow-up (docs.nativescript.org)
The SPM section should say that:
.library(type: .dynamic)products needembed, or they fail in dyld at launch on devices;.library(...)without a type is static and ends up inside the app executable. A Release archive strips the executable's symbol table, so C functions reached from JS by name must then be listed forstrip -sviaSTRIPFLAGSinbuild.xcconfig, or shipped as a dynamic product withembed.Tests
test/services/ios/spm-pbxproj-service.ts:productRef, the latter withCodeSignOnCopy; a linked-only product gets no embed entry;embedentry missing fromlibswarns and is skipped.