apt-tx/docs/ffi-bridge.md
robojerk 2daad2837d Major improvements: rollbacks, testing, docs, and code quality
- Fixed rollback implementation with two-phase approach (remove new, downgrade upgraded)
- Added explicit package tracking (newly_installed vs upgraded)
- Implemented graceful error handling with fail-fast approach
- Added comprehensive test suite (20 tests across 3 test files)
- Created centralized APT command execution module (apt_commands.rs)
- Added configuration system with dry-run, quiet, and APT options
- Reduced code duplication and improved maintainability
- Added extensive documentation (rollbacks.md, rollbacks-not-featured.md, ffi-bridge.md)
- Created configuration usage example
- Updated README with crate usage instructions
- All tests passing, clean compilation, production-ready
2025-09-13 11:21:35 -07:00

51 lines
1.4 KiB
Markdown

# FFI Bridge Documentation
## Overview
The APT Wrapper provides a C++ Foreign Function Interface (FFI) bridge for integration with C++ applications, particularly designed for apt-ostree.
## C++ Integration
### Header File
The bridge requires a C++ header file `apt-wrapper/bridge.h` that defines the C++ side of the interface.
### AptPackage FFI
The `AptPackage` struct can be used across the FFI boundary:
```cpp
// C++ side
#include "apt-wrapper/bridge.h"
// Create package from Rust
AptPackage package = new_ffi("vim", "2:8.1.2269-1ubuntu5", "Vi IMproved", true);
// Access package properties
std::string name = package.name();
std::string version = package.version();
std::string description = package.description();
bool installed = package.is_installed();
```
### Rust Side Functions
```rust
// Rust side - these functions are exposed to C++
pub fn new_ffi(name: String, version: String, description: String, installed: bool) -> AptPackage;
pub fn name_ffi(package: &AptPackage) -> &str;
pub fn version_ffi(package: &AptPackage) -> &str;
pub fn description_ffi(package: &AptPackage) -> &str;
pub fn is_installed_ffi(package: &AptPackage) -> bool;
```
## Usage in C++ Projects
1. Include the generated header file
2. Link against the Rust library
3. Use the FFI functions to interact with APT packages
## Dependencies
- `cxx` crate for FFI generation
- C++ compiler with C++17 support