14 releases (8 breaking)

0.10.0 Feb 25, 2025
0.9.0 Nov 23, 2024
0.8.0 May 24, 2024
0.7.1 Feb 14, 2024
0.2.0 Aug 2, 2021

#289 in Programming languages

Download history 1123/week @ 2024-11-20 2753/week @ 2024-11-27 2589/week @ 2024-12-04 4888/week @ 2024-12-11 5819/week @ 2024-12-18 3306/week @ 2024-12-25 4180/week @ 2025-01-01 8433/week @ 2025-01-08 3571/week @ 2025-01-15 2307/week @ 2025-01-22 1058/week @ 2025-01-29 565/week @ 2025-02-05 766/week @ 2025-02-12 1290/week @ 2025-02-19 421/week @ 2025-02-26 13/week @ 2025-03-05

2,566 downloads per month

MIT/Apache

1MB
21K SLoC

Rust 18K SLoC // 0.0% comments Jinja2 2.5K SLoC // 0.0% comments JavaScript 648 SLoC // 0.2% comments Dart 64 SLoC // 0.3% comments TypeScript 2 SLoC // 0.9% comments

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 languages through a plugin interface that makes it easy to add support for your favourite language. See 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.4.0"
diplomat-runtime = "0.4.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.

Dependencies

~5–13MB
~150K SLoC