Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up

Automatically generates Rust FFI bindings to C (and some C++) libraries.

License

NotificationsYou must be signed in to change notification settings

rust-lang/rust-bindgen

Repository files navigation

crates.iodocs.rs

bindgen

bindgen automatically generates Rust FFI bindings to C (and some C++) libraries.

For example, given the C headerdoggo.h:

typedefstructDoggo {intmany;charwow;}Doggo;voideleven_out_of_ten_majestic_af(Doggo*pupper);

bindgen produces Rust FFI code allowing you to call into thedoggo library'sfunctions and use its types:

/* automatically generated by rust-bindgen 0.99.9 */#[repr(C)]pubstructDoggo{pubmany:::std::os::raw::c_int,pubwow:::std::os::raw::c_char,}extern"C"{pubfneleven_out_of_ten_majestic_af(pupper:*mutDoggo);}

Users Guide

📚 Read thebindgen users guide here! 📚

MSRV

Thebindgen minimum supported Rust version is1.70.0.

Thebindgen-cli minimum supported Rust version is1.70.0.

No MSRV bump policy has been established yet, so MSRV may increase in any release.

The MSRV is the minimum Rust version that can be used tocompile each crate. However,bindgen andbindgen-cli can generate bindings that are compatible with Rust versions below the current MSRV.

Most of the time, thebindgen-cli crate will have a more recent MSRV thanbindgen as crates such asclap require it.

API Reference

API reference documentation is on docs.rs

Environment Variables

In addition to thelibrary API andexecutable command-line API,bindgen can be controlled through environment variables.

End-users should set these environment variables to modifybindgen's behavior without modifying the source code of direct consumers ofbindgen.

  • BINDGEN_EXTRA_CLANG_ARGS: extra arguments to pass toclang
    • Arguments are whitespace-separated
    • Use shell-style quoting to pass through whitespace
    • Examples:
      • Specify alternate sysroot:--sysroot=/path/to/sysroot
      • Add include search path with spaces:-I"/path/with spaces"
  • BINDGEN_EXTRA_CLANG_ARGS_<TARGET>: similar toBINDGEN_EXTRA_CLANG_ARGS,but used to set per-target arguments to pass to clang. Useful to set system includedirectories in a target-specific way in cross-compilation environments with multiple targets.Has precedence overBINDGEN_EXTRA_CLANG_ARGS.

Additionally,bindgen useslibclang to parse C and C++ header files.To modify howbindgen searches forlibclang, see theclang-sys documentation.For more details on howbindgen useslibclang, see thebindgen users guide.

Releases

We don't follow a specific release calendar, but if you need a release pleasefile an issue requesting that (ping@emilio for increased effectiveness).

Contributing

SeeCONTRIBUTING.md for hacking onbindgen!


[8]ページ先頭

©2009-2025 Movatter.jp