Commit 349b4f5c authored by Ryan Hunt's avatar Ryan Hunt
Browse files

Update README and add some examples

parent 0a37a486
......@@ -2,15 +2,26 @@
This project can be used to generate C bindings for Rust code. It is currently being developed to support creating bindings for [WebRender](https://github.com/servo/webrender/).
## Features
* Builds bindings for a crate, its mods, its dependent crates, and their mods
* Only the necessary types for exposed functions are given bindings
* Can specify directives for controlling some aspects of binding
* Generic structs can be exposed using `type IntFoo = Foo<i32>;`
## Use
`cbindgen crate/ crate/bindings.h`
## Examples
See `examples/` for some examples of rust source that can be handled.
## How it works
1. All the structs, enums, type aliases, and functions that are representable in C are gathered
2. A dependency graph is built using the extern "C" functions as roots
* This removes unneeded types from the bindings and sorts the structs that depend on each other
* This removes unneeded types from the bindings and sorts the structs that depend on each other
3. Some code generation is done to specialize generics that are specified as type aliases
3. The items are printed in dependency order in C syntax
......
enum Opaque {
Foo(i32),
Bar
}
#[repr(u32)]
enum A {
x = 0,
y = 2,
z,
w = 5,
}
#[repr(u16)]
enum B {
x = 0,
y = 2,
z,
w = 5,
}
#[repr(u8)]
enum C {
x = 0,
y = 2,
z,
w = 5,
}
#[no_mangle]
extern "C" fn root(x: *mut Opaque, y: A, z: B, w: C)
{
}
struct Opaque {
x: i32,
y: f32,
}
#[repr(C)]
struct Normal {
x: i32,
y: f32,
}
#[repr(C)]
struct Tuple(i32, f32);
/// cbindgen:field-names=[x, y]
#[repr(C)]
struct TupleNamed(i32, f32);
#[no_mangle]
extern "C" fn root(x: *mut Opaque, y: Normal, z: Tuple, w: TupleNamed)
{
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment