11 releases (6 breaking)

0.7.0 Nov 15, 2023
0.5.2 Apr 28, 2023
0.5.0 Jan 17, 2023
0.4.2 Oct 28, 2022
0.1.0 Feb 22, 2021

#1955 in Development tools

Download history 408/week @ 2023-12-18 45/week @ 2023-12-25 429/week @ 2024-01-01 471/week @ 2024-01-08 484/week @ 2024-01-15 455/week @ 2024-01-22 574/week @ 2024-01-29 494/week @ 2024-02-05 834/week @ 2024-02-12 931/week @ 2024-02-19 724/week @ 2024-02-26 968/week @ 2024-03-04 782/week @ 2024-03-11 829/week @ 2024-03-18 634/week @ 2024-03-25 1000/week @ 2024-04-01

3,265 downloads per month
Used in 4 crates (via icu_capi)

MIT/Apache

300KB
6.5K SLoC

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

~0.5–1.1MB
~26K SLoC