Architecture
BridgeRust acts as a compile-time meta-layer on top of two robust ecosystems: PyO3 and napi-rs.
How it Works
Section titled “How it Works”When you compile a crate using BridgeRust:
- Macro Expansion: The
#[bridgerust::export]macro parses your Rust code. - Conditional Compilation: Based on enabled Cargo features (
pythonornodejs), it injects the appropriate attributes.- For
feature = "python", it adds#[pyo3::prelude::*]attributes. - For
feature = "nodejs", it adds#[napi_derive::napi]attributes.
- For
- Binding Generation:
- PyO3 generates C-compatible ABI wrappers for Python extensions.
- napi-rs generates N-API bindings for Node.js.
- Artifact Creation:
- For Python:
maturinbuilds a Python wheel (.whl). - For Node.js:
napi-cliorcargo buildproduces a.nodebinary.
- For Python:
Dependency Graph
Section titled “Dependency Graph”Your project depends on bridgerust, which re-exports:
pyo3napinapi-derive
This ensures version compatibility and simplifying dependency management. You don’t need to manually manage versions of PyO3 or NAPI unless you need advanced customizations.
CI/CD Pipeline
Section titled “CI/CD Pipeline”A typical BridgeRust project uses a CI pipeline that:
- Builds the Rust core.
- Runs
maturin buildto create Python wheels. - Runs
npm run build(vianapi build) to create Node.js artifacts. - Publishes to PyPI and NPM.