diplomat

Experimental Rust tool for generating FFI definitions allowing many other languages to call Rust code

Latest version: 0.12.0 registry icon
Maintenance score
100
Safety score
100
Popularity score
80
Check your open source dependency risks. Get immediate insight about security, stability and licensing risks.
Security
  Vulnerabilities
Version Suggest Low Medium High Critical
0.12.0 0 0 0 0 0
0.11.0 0 0 0 0 0
0.10.0 0 0 0 0 0
0.9.0 0 0 0 0 0
0.8.0 0 0 0 0 0
0.7.0 0 0 0 0 0
0.6.0 0 0 0 0 0
0.5.2 0 0 0 0 0
0.5.1 0 0 0 0 0
0.5.0 0 0 0 0 0
0.4.2 0 0 0 0 0
0.4.1 0 0 0 0 0
0.4.0 0 0 0 0 0
0.3.0 0 0 0 0 0
0.2.0 0 0 0 0 0
0.1.0 0 0 0 0 0

Stability
Latest release:

0.12.0 - This version is safe to use because it has no known security vulnerabilities at this time. Find out if your coding project uses this component and get notified of any reported security vulnerabilities with Meterian-X Open Source Security Platform

Licensing

Maintain your licence declarations and avoid unwanted licences to protect your IP the way you intended.

Apache-2.0   -   Apache License 2.0

Not a wildcard

Not proprietary

OSI Compliant


MIT   -   MIT License

Not a wildcard

Not proprietary

OSI Compliant



Diplomat

Diplomat is an experimental Rust tool for generating FFI definitions allowing many other languages to call Rust code. With Diplomat, you can simply define Rust APIs to be exposed over FFI and get high-level C, C++, and JavaScript bindings automatically!

Diplomat supports generating bindings from Rust to:

  • C
  • C++
  • Dart
  • Javascript/Typescript
  • Kotlin (using JNA)
  • Python (using nanobind)

Diplomat supports languages through a plugin interface that makes it easy to add support for your favourite language. See the book to get started, and tool/src/{c, cpp, js} for examples of existing language plugins.

Installation

First, install the CLI tool for generating bindings:

$ cargo install diplomat-tool

Then, add the Diplomat macro and runtime as dependencies to your project:

diplomat = "0.10.0"
diplomat-runtime = "0.10.0"

Getting Started

Documentation on how to use Diplomat can be found in the book.

Architecture

See the design doc for more details.

Building and Testing

Simply run cargo build to build all the libraries and compile an example. To run unit tests, run cargo test.

Diplomat makes use of snapshot tests to check macro and code generation logic. When code generation logic changes and the snapshots need to be updated, run cargo insta review (run cargo install cargo-insta to get the tool) to view the changes and update the snapshots.

Javascript bindings for wasm32-unknown-unknown

The Javascript backend assumes that you are building WebAssembly on the C Spec ABI. This is not currently default for the wasm32-unknown-unknown target in the latest version of Rust, and so until the new WASM ABI is made stable, you have two options:

  1. Build using nightly Rust and enable the -Zwasm-c-abi=spec flag.
  2. Configure the JS backend to use legacy bindings. There is a WASM ABI config option for this, please read the guide on configuration in the book for more on how to configure.