Skip to content

Add oxbitnet-ffi crate — C FFI bindings#9

Merged
m96-chan merged 4 commits into
mainfrom
feat/ffi
Feb 20, 2026
Merged

Add oxbitnet-ffi crate — C FFI bindings#9
m96-chan merged 4 commits into
mainfrom
feat/ffi

Conversation

@m96-chan

Copy link
Copy Markdown
Owner

Summary

  • Add oxbitnet-ffi crate (cdylib + staticlib) providing a stable C ABI for oxbitnet
  • Auto-generate oxbitnet.h via cbindgen at build time
  • 7 exported functions: oxbitnet_load, oxbitnet_free, oxbitnet_generate, oxbitnet_chat, oxbitnet_error_message, oxbitnet_default_generate_options, oxbitnet_default_load_options
  • Callback-based streaming with early cancellation (return non-zero)
  • Thread-local error handling, progress callbacks for loading
  • Minimal examples/chat.c to verify the FFI
  • Update top-level README with C/FFI quick start, API reference, and architecture tree

Shared foundation for #5 (Java/Android), #6 (Swift/iOS), #7 (C#), #8 (Haskell).

Test plan

  • cargo build -p oxbitnet-ffi compiles .so + .a
  • cargo clippy -p oxbitnet-ffi -- -D warnings passes clean
  • cbindgen generates oxbitnet.h with correct types (no double-prefix)
  • All 7 symbols exported (nm -D liboxbitnet_ffi.so)
  • Compile and run examples/chat.c against a real model (manual)

🤖 Generated with Claude Code

m96-chan and others added 2 commits February 21, 2026 05:06
…pport

Shared C ABI foundation for Java/Android (#5), Swift/iOS (#6), C# (#7),
and Haskell (#8) bindings. Exports load/free/generate/chat with callback-based
streaming, thread-local error handling, and auto-generated oxbitnet.h via cbindgen.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

if (rc != 0) {
const char *err = oxbitnet_error_message();
fprintf(stderr, "Generate error: %s\n", err ? err : "unknown error");

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMO replace logger?

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added oxbitnet_set_logger(callback, userdata, min_level) — routes internal tracing output through a C callback. The example now uses it instead of raw fprintf.

m96-chan and others added 2 commits February 21, 2026 05:41
Adds OxBitNetLogLevel enum, OxBitNetLogFn callback type, and
oxbitnet_set_logger(cb, userdata, min_level). Internal tracing events
are forwarded through the callback. Example updated to use the logger.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- Add OxBitNetLogLevel and OxBitNetLogFn to cbindgen export includes
- Use only "registry" feature for tracing-subscriber (env-filter unused)

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@m96-chan m96-chan merged commit af569cf into main Feb 20, 2026
@m96-chan m96-chan deleted the feat/ffi branch February 20, 2026 20:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant