| Crates.io | superffi |
| lib.rs | superffi |
| version | 0.1.2 |
| created_at | 2025-07-28 22:10:40.023994+00 |
| updated_at | 2025-07-29 11:17:19.76614+00 |
| description | Procedural macro for generating multi-language FFI bindings |
| homepage | |
| repository | https://github.com/deepbrainspace/superconfig |
| max_upload_size | |
| id | 1771640 |
| size | 56,014 |
SuperFFI is a procedural macro that automatically generates FFI bindings for multiple target languages from your Rust code. Write once, run everywhere.
snake_case naming)camelCase conversion)camelCase conversion)#[superffi] to your items[dependencies]
superffi = { version = "0.1", features = ["python", "nodejs", "wasm"] }
Features:
python - PyO3 bindings for Pythonnodejs - NAPI bindings for Node.jswasm - wasm-bindgen bindings for WebAssembly (browser + WASI)all - All target languagesuse superffi::superffi;
#[superffi]
pub struct Calculator {
pub value: f64,
}
#[superffi]
impl Calculator {
pub fn new(initial_value: f64) -> Self {
Self { value: initial_value }
}
pub fn add(&mut self, other: f64) {
self.value += other;
}
pub fn get_value(&self) -> f64 {
self.value
}
}
#[superffi]
pub fn fibonacci(n: u32) -> u64 {
match n {
0 => 0,
1 => 1,
_ => fibonacci(n - 1) + fibonacci(n - 2),
}
}
Apply #[superffi] to:
import your_library
calc = your_library.Calculator(10.0)
calc.add(5.0)
print(calc.get_value()) # 15.0
print(your_library.fibonacci(10)) # 55
const lib = require('./target/release/your_library.node');
const calc = new lib.Calculator(10.0);
calc.add(5.0);
console.log(calc.getValue()); // 15.0 (NAPI converts get_value → getValue)
console.log(lib.fibonacci(10)); // 55
import init, { Calculator, fibonacci } from './pkg/your_library.js';
await init();
const calc = new Calculator(10.0);
calc.add(5.0);
console.log(calc.getValue()); // 15.0 (SuperFFI converts get_value → getValue)
console.log(fibonacci(10)); // 55
After building your Rust library with the python feature:
import your_rust_library
# Create and use structs
calc = your_rust_library.Calculator(10.0)
calc.add(5.0)
calc.multiply(2.0)
print(calc.get_value()) # Output: 30.0
# Use standalone functions
result = your_rust_library.fibonacci(10)
print(result) # Output: 55
After building your Rust library with the nodejs feature:
const lib = require('./target/release/your_rust_library.node');
// Create and use structs
const calc = new lib.Calculator(10.0);
calc.add(5.0);
calc.multiply(2.0);
console.log(calc.getValue()); // Output: 30.0 (get_value → getValue)
// Use standalone functions
const result = lib.fibonacci(10);
console.log(result); // Output: 55
After building your Rust library with the wasm feature:
import init, { Calculator, fibonacci } from './pkg/your_rust_library.js';
async function run() {
await init();
// Create and use structs
const calc = new Calculator(10.0);
calc.add(5.0);
calc.multiply(2.0);
console.log(calc.getValue()); // Output: 30.0 (get_value → getValue)
// Use standalone functions
const result = fibonacci(10);
console.log(result); // Output: 55
}
run();
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() |
snake_case (Pythonic)camelCasecamelCase for JavaScript consistencyThis ensures your APIs feel natural in each target language while maintaining consistent functionality.
Add to your Cargo.toml:
[lib]
name = "your_rust_library"
crate-type = ["cdylib"]
[dependencies]
superffi = { version = "0.1", features = ["python"] }
pyo3 = { version = "0.25", features = ["extension-module"] }
Build command:
maturin develop # For development
maturin build --release # For production
Add to your package.json:
{
"napi": {
"name": "your-rust-library",
"triples": {
"defaults": true
}
}
}
Build command:
napi build --platform --release
Build command:
wasm-pack build --target web --out-dir pkg
bool, i8, i16, i32, i64, isizeu8, u16, u32, u64, usizef32, f64charStringVec<T> (where T is supported)Option<T> (where T is supported)HashMap<K, V> (limited support)#[superffi]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.
cargo testcargo run --example basicRun the test suite:
cargo test
cargo test --all-features
Test with specific features:
cargo test --features python
cargo test --features nodejs
cargo test --features wasm
This project is licensed under either of
at your option.
Happy coding! 🦀