feat(ffi): use nim-ffi master (v0.2.0) — {.ffi.} macros + CBOR#75
Draft
Ivansete-status wants to merge 2 commits into
Draft
feat(ffi): use nim-ffi master (v0.2.0) — {.ffi.} macros + CBOR#75Ivansete-status wants to merge 2 commits into
Ivansete-status wants to merge 2 commits into
Conversation
Switch the C wrapper from the lower-level registerReqFFI + hand-written
exports to nim-ffi's declareLibrary/{.ffiCtor.}/{.ffi.}/{.ffiDtor.}
macros. This removes the per-op boilerplate (request structs, shared-mem
copy helpers, dispatch template) in favour of the framework's JSON
marshalling, and lets participantId be threaded in via config.
Consequences (intentional): C exports are now snake_case and parameters
travel as JSON, so the ABI changes and sds-go-bindings must be updated to
match. Two cases can't ride the JSON path: the retrieval-hint provider is
a C function pointer (kept hand-written, dispatched to set a worker-thread
threadvar) and the unwrap response has nested objects the framework's
serializer can't emit (returned as a hand-built JSON string).
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Port the {.ffi.} wrapper to nim-ffi 0.2.0 (master). 0.2.0 is a breaking
redesign over 0.1.4: events move to a per-context multi-listener registry
(sds_add_event_listener / sds_remove_event_listener) fired via {.ffiEvent.}
emitters, and request/response/event marshalling switches from JSON to CBOR.
- libsds.nim: typed {.ffiEvent.} payloads replace the JSON event modules;
CBOR handles nesting, so unwrap returns a typed response again. The
retrieval-hint provider (a C function pointer, not CBOR-encodable) passes
its address as a uint64 via a {.ffi.} method that stores it in a
worker-thread threadvar.
- pin nim-ffi to master HEAD by commit. The lock version is kept a clean
semver ("0.2.0") on purpose: nimble's `#`-prefixed special version in the
lock breaks `nimble setup -l` (an unquoted `#` truncates the git path),
so only vcsRevision carries the commit.
- add the new transitive dep cbor_serialization to the lock and nix/deps.nix.
- regenerate libsds.h for the CBOR/registry ABI.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Ivansete-status
marked this pull request as draft
June 12, 2026 15:13
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.
Moves libsds onto nim-ffi master (v0.2.0) using the high-level
{.ffi.}macros.Stacked on
use-ffi-macros, so this PR contains two commits:refactor(ffi): switch libsds fromregisterReqFFI+ hand-written exports todeclareLibrary/{.ffiCtor.}/{.ffi.}/{.ffiDtor.}.feat(ffi): port that to nim-ffi 0.2.0 (the breaking redesign).If
use-ffi-macros(#?) is merged first, rebase will drop commit 1.What changes (vs the v0.1.4 / registerReqFFI mainline)
{.ffi.}macros; exports are snake_case (sds_create,sds_wrap_outgoing_message, …). Seelibrary/libsds.h.sds_add_event_listener(ctx, eventName, cb, ud)/sds_remove_event_listener(ctx, id), fired from typed{.ffiEvent.}emitters. Wire names:message_ready,message_sent,missing_dependencies,periodic_sync,repair_ready.{ eventType, payload }.uint64address via a{.ffi.}method that stores it in a worker-thread threadvar.f96a5b15by commit; add new transitive depcbor_serialization; no Nim pin (stays 2.2.4).nimble.lock+nix/deps.nixupdated.Notes
nimble lock's#-prefixed special version breaksnimble setup -l(unquoted#truncates the git path), so the lockversionis kept a clean0.2.0and onlyvcsRevisioncarries the commit. Re-runningnimble lockre-introduces the#— re-clean that field if you do.sds-go-bindingsmust be updated to the snake_case + CBOR + event-listener model.Verification
nimble libsdsDynamicMacbuilds clean on Nim 2.2.4 against nim-ffi master.nimble test: 106/106 pass.🤖 Generated with Claude Code