Skip to content

Add C/C++ FFI interface for native integration#14

Open
muk2 wants to merge 1 commit intomainfrom
feature/ffi-interface
Open

Add C/C++ FFI interface for native integration#14
muk2 wants to merge 1 commit intomainfrom
feature/ffi-interface

Conversation

@muk2
Copy link
Owner

@muk2 muk2 commented Jan 27, 2026

Summary

This PR adds a stable C-compatible FFI layer that enables C/C++ applications to integrate feedtui as a library, addressing issue #12.

Features Added:

  • Lifecycle APIs:

    • feedtui_init(config_path) - Initialize with config file
    • feedtui_init_with_config(toml_string) - Initialize with inline config
    • feedtui_run(handle) - Run the TUI (blocks until quit)
    • feedtui_shutdown(handle) - Clean shutdown and resource cleanup
  • Utility Functions:

    • feedtui_get_last_error(handle) - Get detailed error messages
    • feedtui_version() - Get library version
    • feedtui_has_feature(name) - Check compile-time features
  • Build Artifacts (with --features ffi):

    • libfeedtui.so / libfeedtui.dylib / feedtui.dll (shared)
    • libfeedtui.a / feedtui.lib (static)
    • include/feedtui.h (C header)

Documentation:

  • Comprehensive guide: docs/FFI.md
  • Build instructions for Linux, macOS, Windows
  • CMake integration example

Examples:

  • examples/cpp/main.cpp - Full C++ example with argument parsing
  • examples/cpp/simple.c - Minimal C example
  • examples/cpp/Makefile - Build system for examples

Key Design Decisions:

  • Opaque handles prevent memory corruption across FFI boundary
  • Panic-safe wrappers using catch_unwind
  • Feature-gated with ffi flag (no overhead when not used)
  • Thread-safety notes in documentation

Usage:

# Build library
cargo build --release --features ffi

# C++ example
cd examples/cpp
make
make run

Test plan

  • Build library with cargo build --release --features ffi
  • Verify shared library is created in target/release/
  • Build C++ example with make in examples/cpp/
  • Run example and verify TUI launches
  • Press 'q' to quit and verify clean shutdown
  • Test with custom config file
  • Test error handling with invalid config

Closes #12


Generated with Claude Code

This adds a stable C-compatible FFI layer that enables C/C++ applications
to integrate feedtui as a library.

Features:
- Lifecycle APIs: feedtui_init, feedtui_run, feedtui_shutdown
- Config from file path or inline TOML string
- Error handling with last_error retrieval
- Version and feature queries
- Opaque handles for safe memory management

Build artifacts:
- libfeedtui.so/.dylib/.dll (shared library)
- libfeedtui.a/.lib (static library)
- feedtui.h (C header)

Documentation:
- Comprehensive FFI guide in docs/FFI.md
- C and C++ examples in examples/cpp/
- Makefile for building examples

Usage:
  cargo build --release --features ffi

Closes #12

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@claude
Copy link

claude bot commented Jan 27, 2026

Code review

No issues found. Checked for bugs and CLAUDE.md compliance.

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.

Add C/C++ FFI Interface to Enable Native Integration of feedtui

1 participant