自动生成 C(以及部分 C++)库的 Rust FFI 绑定。
bindgenbindgen 可以为 C(以及部分 C++)库自动生成 Rust FFI 绑定。
例如,给定 C 头文件 doggo.h:
typedef struct Doggo {
int many;
char wow;
} Doggo;
void eleven_out_of_ten_majestic_af(Doggo* pupper);bindgen 会生成 Rust FFI 代码,使你能够调用 doggo 库中的函数并使用其类型:
/* automatically generated by rust-bindgen 0.99.9 */
#[repr(C)]
pub struct Doggo {
pub many: ::std::os::raw::c_int,
pub wow: ::std::os::raw::c_char,
}
extern "C" {
pub fn eleven_out_of_ten_majestic_af(pupper: *mut Doggo);
}bindgen 最低支持的 Rust 版本为 1.71.0。
bindgen-cli 最低支持的 Rust 版本为 1.71.0。
目前尚未制定 MSRV 提升策略,因此任何版本发布时 MSRV 都可能提高。
MSRV 是可用于编译各个 crate 的最低 Rust 版本。不过,bindgen 和 bindgen-cli 可以生成兼容低于当前 MSRV 的 Rust 版本的绑定。
大多数情况下,bindgen-cli crate 的 MSRV 会比 bindgen 更新,因为 clap 等 crate 有此要求。
除了库 API 和 [可执行文件命令行 API][bindgen-cmdline] 之外,还可以通过环境变量来控制 bindgen。
最终用户应设置这些环境变量来修改 bindgen 的行为,而无需修改 bindgen 直接使用方的源代码。
BINDGEN_EXTRA_CLANG_ARGS:传递给 clang 的额外参数--sysroot=/path/to/sysroot-I"/path/with spaces"BINDGEN_EXTRA_CLANG_ARGS_<TARGET>:类似于 BINDGEN_EXTRA_CLANG_ARGS,
但用于设置传递给 clang 的按目标(per-target)参数。适用于设置系统头文件搜索
目录 Read the bindgen users guide here!
API reference documentation is on docs.rs
暂无开放 Issues,或尚未同步最近议题。