feat(codegen): native Swift generator + iOS example over the C ABI#59
Draft
Ivansete-status wants to merge 3 commits into
Draft
feat(codegen): native Swift generator + iOS example over the C ABI#59Ivansete-status wants to merge 3 commits into
Ivansete-status wants to merge 3 commits into
Conversation
Ivansete-status
force-pushed
the
ffi-native-typed-returns
branch
from
May 31, 2026 14:38
9c15a8e to
1060340
Compare
Ivansete-status
force-pushed
the
ios-example
branch
from
May 31, 2026 14:38
f4031b4 to
8727272
Compare
A SwiftPM package wrapping the timer library's native ABI behind an idiomatic `TimerNode` Swift class. `build-xcframework.sh` cross-compiles the Nim library to a static MyTimer.xcframework with three slices — ios-arm64 (device), ios-arm64-simulator, and macos-arm64 — assembling the .xcframework by hand so it works without a functioning Simulator toolchain (CI-friendly). The wrapper bridges the async FFI-thread callback to a synchronous Swift API with a semaphore and reads the typed EchoResponse struct out of the callback. The macos-arm64 slice makes the wrapper testable on the host: `swift test` passes against it. Device/simulator slices are the real iOS deployment artifacts. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Ivansete-status
force-pushed
the
ffi-native-typed-returns
branch
from
May 31, 2026 16:38
1060340 to
c000a84
Compare
Ivansete-status
force-pushed
the
ios-example
branch
from
May 31, 2026 16:38
8727272 to
014e161
Compare
Ivansete-status
marked this pull request as draft
June 1, 2026 07:34
Adds ffi/codegen/swift.nim, wired into the targetLang dispatch and exposed as the `genbindings_swift` nimble task. It emits an idiomatic Swift wrapper over the native (zero-serialization) C ABI from c.nim — importing the C structs through the CMyTimer clang module and never touching CBOR. The one piece of real logic is callback-shape selection: ack / string / struct decoding is chosen per proc from FFIProcMeta.kind + returnTypeName, and struct returns are copied out inside the callback to honour the deep-free-after-callback ownership rule. A single struct param's fields are flattened into the Swift method signature; ctors keep argument labels. Procs needing seq/Option or multi-struct param marshaling are skipped with a logged notice rather than emitting broken Swift, so the wrapper always compiles. That marshaling, events, and async mapping are the next increments. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Regenerates Sources/MyTimer/MyTimer.swift via `nimble genbindings_swift` (replacing the hand-written wrapper) and points the tests at the derived MyTimerNode class. Proves the generator reproduces the validated create/version/echo path: build-xcframework.sh + `swift test` pass 2/2 on the macOS slice. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Collaborator
Author
|
Expanded scope: this PR now also adds the Swift generator that produces the wrapper, not just the hand-written example.
Validated: 🤖 Generated with Claude Code |
This was referenced Jun 13, 2026
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.
Adds an iOS example consuming the timer library's native (zero-serialization)
C ABI from Swift. Based on the native-FFI stack (#58) so it can use typed struct
returns.
What
examples/timer/ios/— a SwiftPM package with an idiomaticTimerNodeSwiftwrapper over the native ABI. Struct returns (
EchoResponse) come back as typedSwift values, read out of the C-POD inside the result callback.
build-xcframework.shcross-compiles the Nim library to a staticMyTimer.xcframeworkwith ios-arm64 (device), ios-arm64-simulator, andmacos-arm64 slices. The xcframework is assembled by hand (no
xcodebuild -create-xcframework), so it builds headless / in CI.Validation
CBOR symbols present).
swift testpasses(create / version / typed
echo/ a 200-iteration loop).🤖 Generated with Claude Code