4 Commits

Author SHA1 Message Date
osmaczko
974d06d775
fix(nim-bindings): add all-endpoints test and fix installation_name ABI
Add nim-bindings/tests/test_all_endpoints.nim which imports bindings
directly and calls every FFI proc, forcing the linker to include all
symbols. This catches link-time and runtime issues that the pingpong
example missed because unused symbols were optimised out.

Running the new test revealed an ABI mismatch in installation_name:
the Rust function used an explicit out-parameter but ReprCString has
only flat fields, so Nim emits it as a C return value.

CI now runs nimble test next to nimble pingpong.
2026-02-28 13:17:30 +01:00
osmaczko
fa79b1c79c
chore(nim-bindings): replace dynlib dlopen with plain importc (#61)
* chore(nim-bindings): replace dynlib dlopen with plain importc

The dynlib pragma hard-coded a library path and resolved it via dlopen() at
runtime, preventing static linking and forcing a specific load-time path.
Using bare {.importc.} lets consumers choose: link liblibchat dynamically
at link time (--passL:-llibchat) or link it statically into their binary.

* Rust -> Nim ABI  (#62)

* Use correct build hook

* force sret like return from rust code for nim compatibility

* Fix target mismatch

* Update usages

* ci: add nim-bindings-test

* fix(nim-bindings): fix ABI mismatch in destroy_* FFI functions and add defer-based cleanup

Nim's C backend silently transforms large struct parameters (>16 bytes) into
pointer parameters when calling importc functions. The destroy_* functions were
declared taking T by value in Rust, but Nim always passed &T — causing Rust to
read garbage from the stack on x86-64 (SIGILL on CI) while accidentally working
on ARM64 macOS due to that ABI coincidentally also using pointers for large structs.

Fix by changing all destroy_* functions to take &mut T and using drop_in_place,
which is the correct idiom for dropping a value through a pointer.

On the Nim side, replace scattered manual destroy calls with defer, which
guarantees cleanup on all exit paths and prevents use-after-destroy bugs.

---------

Co-authored-by: Jazz Turner-Baggs <473256+jazzz@users.noreply.github.com>
2026-02-25 20:09:55 +01:00
Patryk Osmaczko
cd737ea058 fix: make ci checks pass 2026-02-10 19:45:00 +01:00
Aleksey
c5f9994c9e
feat: add ci checks
* base ci add

* Remove .DS_Store files

* Add .DS_Store to gitignore

* remove master & develop, kept only stable in matrix

Restrict CI workflow to only the main branch for pushes and pull requests.

* Update .github/workflows/ci.yml

Co-authored-by: osmaczko <33099791+osmaczko@users.noreply.github.com>

* Update .github/workflows/ci.yml

Co-authored-by: osmaczko <33099791+osmaczko@users.noreply.github.com>

---------

Co-authored-by: osmaczko <33099791+osmaczko@users.noreply.github.com>
2026-02-10 14:40:01 +01:00