ralfbiedert / interoptopus
The polyglot bindings generator for your library (C#, C, Python, …) 🐙
AI Architecture Analysis
This repository is indexed by RepoMind. By analyzing ralfbiedert/interoptopus in our AI interface, you can instantly generate complete architecture diagrams, visualize control flows, and perform automated security audits across the entire codebase.
Our Agentic Context Augmented Generation (Agentic CAG) engine loads full source files into context on-demand, avoiding the fragmentation of traditional RAG systems. Ask questions about the architecture, dependencies, or specific features to see it in action.
Repository Overview (README excerpt)
Crawler view[![crates.io-badge]][crates.io-url] [![docs.rs-badge]][docs.rs-url] ![license-badge] [![rust-version-badge]][rust-version-url] [![rust-build-badge]][rust-build-url] Interoptopus 🐙 The polyglot bindings generator for your library. Write a robust library in Rust, easily access it from your second-favorite language: • Design a single / in Rust, consume it from anywhere. • Get features (e.g., classes, strings) in languages that have them. • Painless workflow, no external tooling required. • Easy to support more languages, backends fully decoupled from main project. We strive to make our generated bindings _zero cost_. They should be as idiomatic as you could have reasonably written them yourself, but never magic or hiding the interface you actually wanted to expose. Code you write ... ... Interoptopus generates | Language | Crate | Sample Output 1 | Status | |----------|-----------------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------|--------| | C# | [**interoptopus_csharp**][interoptopus_csharp] | [Interop.cs][interop-cs] | ✅ | | C | [**interoptopus_c**][interoptopus_c] | - | ⏯️ | | Python | [**interoptopus_cpython**][interoptopus_cpython] | - | ⏯️ | | Other | Write your own backend 2 | - | ✅ Tier 1 target. Active maintenance and production use. Full support of all features. ⏯️ Tier 2 target. Currently suspended, contributors wanted! 1 For the [reference project][reference-project]. 2 Add basic support for a new language in just a few hours. [No pull request needed][new-backends]. Getting Started 🍼 If you want to ... • **get started** see the [**hello world**][hello-world], • **productify your project**, see the [**real project layout**][real-project-layout], • **understand what's possible**, see the [**reference project**][reference-project], • **support a new language**, [**copy the C backend**][backend-c]. Supported Rust Constructs See the [**reference project**][reference-project] for an overview: • [functions][ref-functions] (freestanding functions and delegates) • [types][ref-types] (composites, enums, opaques, references, ...) • [constants][ref-constants] ( primitive constants; results of const evaluation) • [patterns][ref-patterns] (ASCII pointers, options, slices, ...) • [services][ref-services] (turn to classes in C# and Python, and async methods) Performance 🏁 Generated low-level bindings are _zero cost_ w.r.t. hand-crafted bindings for that language. That said, even hand-crafted bindings encounter some target-specific overhead at the FFI boundary (e.g., marshalling, pinning, and safety checks). For C# that cost is often nanoseconds, for Python it can be microseconds. For a quick overview, this table lists some common round trip times in _ns / call_: | Construct | C# | |----------------------------------------|------------------| | | 3 | | | 4 | | | 14 | | | 477 1 | | | 21 | | | 20 | | | 52 | | | 361 2 | 1 First time delegate creation and pinning is expensive in C# (100's of ns). We recommend you retain the delegate instead for >20x faster calls, [see for example here][csharp-callbacks]. 2 Preliminary numbers for full round trip to tokio and back. Although async calls have some intrinsic overhead (e.g., spawning a new is ~100ns), some of that overhead appears to be a benchmarking effect when spin-waiting for a newly spawned task. In essence, if your application benefits from async this overhead is negligible, but simple getters or setters shouldn't needlessly be made async. Feature Flags Gated behind **feature flags**, these enable: • - Proc macros such as . • - Serde attributes on internal types. • - Invoke [log][log-crate] on FFI errors. • - Convenience support for async services via Tokio. Changelog • **v0.16** - Total rewrite: better architecture,safety, diagnostics. • **v0.15** - Massive cleanup, bugfix, UX overhaul (+syn2). • **v0.14** - Better inventory UX. • **v0.13** - Python backend uses now. Also see our [upgrade instructions][upgrade-instructions]. FAQ • [FAQ and Safety Guides][faq]. Contributing PRs are very welcome! • Submit small bug fixes directly. Major changes should be issues first. • New features or patterns must be materialized in the reference project and accompanied by at least an C# interop test. [crates.io-badge]: https://img.shields.io/crates/v/interoptopus.svg [crates.io-url]: https://crates.io/crates/interoptopus [license-badge]: https://img.shields.io/badge/license-MIT-blue.svg [docs.rs-badge]: https://docs.rs/interoptopus/badge.svg [docs.rs-url]: https://docs.rs/interoptopus/ [rust-version-badge]: https://img.shields.io/badge/rust-1.94%2B-blue.svg?maxAge=3600 [rust-version-url]: https://github.com/ralfbiedert/interoptopus [rust-build-badge]: https://github.com/ralfbiedert/interoptopus/actions/workflows/rust.yml/badge.svg [rust-build-url]: https://github.com/ralfbiedert/interoptopus/actions/workflows/rust.yml [interoptopus_csharp]: https://crates.io/crates/interoptopus_csharp [interoptopus_c]: https://crates.io/crates/interoptopus_backend_c [interoptopus_cpython]: https://crates.io/crates/interoptopus_backend_cpython [interop-cs]: https://github.com/ralfbiedert/interoptopus/blob/master/tests/tests/csharp_reference_project/Interop.cs [reference-project]: https://github.com/ralfbiedert/interoptopus/tree/master/crates/reference_project/src [new-backends]: https://github.com/ralfbiedert/interoptopus/blob/master/FAQ.md#new-backends [hello-world]: https://github.com/ralfbiedert/interoptopus/tree/master/examples/hello_world [real-project-layout]: https://github.com/ralfbiedert/interoptopus/tree/master/examples/real_project_layout [backend-c]: https://github.com/ralfbiedert/interoptopus/tree/master/crates/backend_c [ref-functions]: https://github.com/ralfbiedert/interoptopus/tree/master/crates/reference_project/src/functions [ref-types]: https://github.com/ralfbiedert/interoptopus/…