Repository navigation
feat(swift-interop): generate and link thunks in app builds (4/7) - #521
Draft
NathanWalker wants to merge 4 commits into
Draft
NathanWalker wants to merge 4 commits into
NathanWalker wants to merge 4 commits into
Conversation
|
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 was referenced Oct 21, 2026
Draft
Draft
NathanWalker
marked this pull request as ready for review
October 21, 2026 13:50
NathanWalker
force-pushed
the
swift-interop/4-app-builds
branch
from
October 21, 2026 14:47
0cb1e1b to
91839dc
Compare
NathanWalker
force-pushed
the
swift-interop/3-modules-protocols
branch
from
October 21, 2026 14:47
b951726 to
39dac9d
Compare
NathanWalker
marked this pull request as draft
October 21, 2026 16:33
SwiftInteropBenchmarks.js times matched operations through the Objective-C/C metadata path and through Swift thunks: - a function; - class and instance methods; - a string round trip; - object construction; - a property read. It writes the results to Documents/swift-bench.txt and asserts nothing. The fixture gains the Swift counterparts. The benchmarks showed instance calls and property accesses copying their member group on every call to filter a generic family's overloads by receiver. Groups now record whether they mix owners, and only those are filtered. With that, the Swift path matches or beats the Objective-C path in a Debug simulator build (docs/swift-interop.md has the numbers).
Apps list the Swift modules JavaScript uses in NS_SWIFT_MODULES, in App_Resources/iOS/build.xcconfig. SDK modules, SwiftPM packages and the app's own module are all supported. At link time, nsld.sh (iOS and visionOS templates) runs the new build-step-swift-interop.py for each architecture, next to the Objective-C metadata step: - it extracts the modules' symbol graphs from the build products and the SDK; - it generates and verifies them as one unit; - it compiles the thunks to an object; - it hands nsld the object and a -u flag per register symbol to link. The script ships beside build-step-metadata-generator.py, so the CLI needs no change. Checked against Xcode-shaped environments: the SwiftDemo/SwiftDemoKit modules and WeatherKit each produce an object that exports its register symbols. A full `ns build` against a packed runtime has not been run yet.
The app build step now passes the app's header search paths to symbol graph extraction and to the thunk compile, so clang modules from plugin sources resolve. One example is @nativescript/core's NativeScriptEmbedder, which an app's Swift module imports. Relative search paths are resolved against SRCROOT, since the step runs from the metadata generator's folder. Validated with an app: the app's own Swift module plus WeatherKit, built through `ns build ios` with the packed runtime. Debug and Release simulator builds both pass a startup check of every ns:swift feature.
The app build step keys the generated object on a hash of the extracted symbol graphs, the generator binary, the step itself, and the generator and compiler command lines. A relink with the same key reuses the previous object instead of regenerating, verifying and recompiling, so an unchanged module costs only its symbol graph extraction.
NathanWalker
force-pushed
the
swift-interop/4-app-builds
branch
from
October 21, 2026 16:44
91839dc to
e76a9ec
Compare
NathanWalker
force-pushed
the
swift-interop/3-modules-protocols
branch
from
October 21, 2026 16:44
39dac9d to
83c8aff
Compare
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.
Summary
Swift interop stack — review bottom-up; each PR shows only its own commits. Merge in order; after a squash merge, rebase the next branch onto
main. Design discussion: RFC NativeScript/rfcs#57..d.tsns:swiftcoreApps get thunks for the Swift modules they name, and a benchmark compares the Swift path with the Objective-C one.
The CLI needs no change.
TestRunner/app/tests/SwiftInteropBenchmarks.jsadds benchmarks of the same API through both paths.Evidence
After: a real app (its own module, WeatherKit, a local SwiftPM package) builds through
ns build iosand importsns:swiftin Debug and Release. App-level plugin modules and relative paths resolve. An unchanged module reuses its thunk object on relink.Merge Danger
Door: two-way
Blast Radius: app builds
nsld.shchanges in the iOS and visionOS templates but does nothing unlessNS_SWIFT_MODULESis set, so apps without it link exactly as before.