Skip to content

Commit 0cce026

Browse files
committed
Add tool to read a Rust crate and generate C-compatible wrappers
In general, it maps: * Traits to a struct with a void* and a list of function pointers, emulating what the compiler will do for a dyn trait anyway, * Structs as a struct with a single opaque pointer to the underlying type. While this is a bit less effecient than just a direct pointer, it neatly lets us expose in the public interface the concept of ownership by passing either a pointer to the struct-containing-a-pointer or the struct itself. * Unit enums as enums with each type copied over and conversion functions, * Non-unit enums the same way as structs.
1 parent 8f23cf4 commit 0cce026

File tree

3 files changed

+1923
-0
lines changed

3 files changed

+1923
-0
lines changed

c-bindings-gen/Cargo.toml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
[package]
2+
name = "c-bindings-gen"
3+
version = "0.0.1"
4+
authors = ["Matt Corallo"]
5+
edition = "2018"
6+
7+
[dependencies]
8+
syn = { version = "1", features = ["full", "extra-traits"] }
9+
proc-macro2 = "1"
10+
11+
# We're not in the workspace as we're just a binary code generator:
12+
[workspace]

0 commit comments

Comments
 (0)