SuperFFI - Multi-Language FFI Binding Generator
SuperFFI is a procedural macro that automatically generates FFI bindings for multiple target languages from your Rust code. Write once, run everywhere.
Features
- Python bindings via PyO3 (preserves
snake_casenaming) - Node.js bindings via NAPI-RS (automatic
camelCaseconversion) - WebAssembly bindings via wasm-bindgen (automatic
camelCaseconversion) - Automatic naming conversion for consistent JavaScript APIs
- Zero-cost abstractions - only generates code for enabled features
- Simple annotation - just add
#[superffi]to your items
Installation
[]
= { = "0.1", = ["python", "nodejs", "wasm"] }
Features:
python- PyO3 bindings for Pythonnodejs- NAPI bindings for Node.jswasm- wasm-bindgen bindings for WebAssembly (browser + WASI)all- All target languages
Quick Start
use superffi;
Usage
Apply #[superffi] to:
- Structs → generates class/object bindings
- Impl blocks → generates method bindings
- Functions → generates standalone function bindings
Language Usage Examples
Python
=
# 15.0
# 55
Node.js
const lib = require;
const calc = ;
calc.;
console.log; // 15.0 (NAPI converts get_value → getValue)
console.log; // 55
WebAssembly (Browser + WASI)
import init from './pkg/your_library.js';
await ;
const calc = ;
calc.;
console.log; // 15.0 (SuperFFI converts get_value → getValue)
console.log; // 55
🎯 Language-Specific Usage
Python
After building your Rust library with the python feature:
# Create and use structs
=
# Output: 30.0
# Use standalone functions
=
# Output: 55
Node.js
After building your Rust library with the nodejs feature:
const lib = require;
// Create and use structs
const calc = ;
calc.;
calc.;
console.log; // Output: 30.0 (get_value → getValue)
// Use standalone functions
const result = lib.;
console.log; // Output: 55
WebAssembly
After building your Rust library with the wasm feature:
import init from './pkg/your_rust_library.js';
;
🔄 Automatic Naming Convention
SuperFFI automatically handles naming conventions for different target languages:
| Rust Function | Python | Node.js | WebAssembly |
|---|---|---|---|
get_value() |
get_value() |
getValue() |
getValue() |
set_debug() |
set_debug() |
setDebug() |
setDebug() |
with_file() |
with_file() |
withFile() |
withFile() |
extract_json() |
extract_json() |
extractJson() |
extractJson() |
- Python: Preserves
snake_case(Pythonic) - Node.js: NAPI automatically converts to
camelCase - WebAssembly: SuperFFI converts to
camelCasefor JavaScript consistency
This ensures your APIs feel natural in each target language while maintaining consistent functionality.
🏗️ Build Configuration
For Python (PyO3)
Add to your Cargo.toml:
[]
= "your_rust_library"
= ["cdylib"]
[]
= { = "0.1", = ["python"] }
= { = "0.25", = ["extension-module"] }
Build command:
For Node.js (NAPI)
Add to your package.json:
Build command:
For WebAssembly
Build command:
⚠️ Limitations
- Async functions: Not currently supported across all target languages
- Complex generics: May not translate directly to all target languages
- Advanced lifetimes: Rust-specific lifetime annotations may not be supported
- Trait objects: Not directly supported; use concrete types instead
- Custom derives: May conflict with generated bindings
🛠️ Supported Types
Primitive Types
bool,i8,i16,i32,i64,isizeu8,u16,u32,u64,usizef32,f64char
Standard Library Types
StringVec<T>(where T is supported)Option<T>(where T is supported)HashMap<K, V>(limited support)
Custom Types
- Structs annotated with
#[superffi] - Enums (limited support, varies by target language)
🤝 Contributing
Contributions are welcome! Please feel free to submit a Pull Request. For major changes, please open an issue first to discuss what you would like to change.
Development Setup
- Clone the repository
- Install Rust nightly (required for proc-macro development)
- Run tests:
cargo test - Run examples:
cargo run --example basic
Testing
Run the test suite:
Test with specific features:
📄 License
This project is licensed under either of
- Apache License, Version 2.0, (LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0)
- MIT license (LICENSE-MIT or http://opensource.org/licenses/MIT)
at your option.
🙏 Acknowledgments
- PyO3 for Python FFI
- NAPI-RS for Node.js FFI
- wasm-bindgen for WebAssembly FFI
- The Rust community for excellent procedural macro resources
Happy coding! 🦀