I'm attempting my first binding to a C library and had a few questions. Rather than breaking them into smaller posts, I thought I'd keep them in a single thread.
First, what is the point of bundling dependencies as both a sys crate, and as a higher-level API crate? Is it for versioning of the lower-level library separately from the Rust API? Are there reasons why you might just bundle them into a single crate?
Next, when I run the tests for my generated binding, I get one failure:
failures:
---- bindgen_test_layout_max_align_t stdout ----
thread 'bindgen_test_layout_max_align_t' panicked at 'assertion failed: `(left == right)` (left: `24`, right: `32`): Size of: max_align_t', /home/nolan/Projects/speech-dispatcher-rs/speech-dispatcher-sys/target/debug/build/speech-dispatcher-sys-6b2956e71593ee84/out/speech-dispatcher.rs:1098
How do I fix this? What code do I even show that would help you help me to fix this? I'd expect that bindgen generates tests that succeed, or that it at least tells me how to fix failing tests.
I have lower-level code that looks like this:
pub enum SPDConnectionMode { SPD_MODE_SINGLE = 0, SPD_MODE_THREADED = 1, }
I want to wrap it into a Rust API that looks like:
enum Mode {
Single = 0,
Threaded = 1,
}
...
// Mode will be passed to a wrapped FFI call as an SPDConnectionMode.
pub fn open(&self, client_name: String, connection_name: String, user_name: String, mode: Mode) -> Connection {
First, is there a way to get the struct values directly so I'm not hard-coding them in? Referring to them from code gives a type mismatch, since what I'm getting is the struct type and not its lower-level values. What I want to do is:
enum Mode {
Single = SPDConnectionMode::SPD_MODE_SINGLE,
Threaded = SPDConnectionMode::SPD_MODE_THREADED,
}
Similarly, calling the wrapped function doesn't work. I suppose I could use pattern matching, but in this case the values align exactly, and I wish I could give the Rust API friendlier names while linking directly to the wrapped values somehow.
Thanks.