New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support bindgen in recommended usage #2
Changes from 7 commits
c820c2c
b19ef77
563753d
9a0116b
3662ff0
0e937fa
e853165
84e4e70
006683a
7642e7b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
# `libftdi1-sys` | ||
`libftdi1-sys` is a crate providing Rust bindings to the C library | ||
[`libftdi1`](https://www.intra2net.com/en/developer/libftdi/index.php). | ||
|
||
## Prerequisites | ||
The libftdi1 bindings are generated at compile-time, per bindgen's | ||
[recommended usage](https://rust-lang.github.io/rust-bindgen/library-usage.html). | ||
|
||
* `libclang` must be installed and visible on your path. If you are using a | ||
`gcc`-toolchain and don't want to install the entirity of LLVM just for | ||
`libclang`, | ||
|
||
* `libftdi` version 1.4 (the most recent version as of 2017) is required. | ||
|
||
* The Minimum Supported Rust Version (MSRV) is stable `1.42`. However, older | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is not strictly correct. You don't use the bindgen Still, this requirement sounds a bit suboptimal. I'll discuss it in a bit more detail in a follow-up comment. |
||
versions may work and simply have not been tested. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,28 @@ | ||
#[cfg(not(windows))] | ||
fn main() { | ||
pkg_config::find_library("libftdi1").unwrap(); | ||
} | ||
use bindgen; | ||
use std::env; | ||
use std::path::PathBuf; | ||
|
||
#[cfg(windows)] | ||
fn main() { | ||
#[cfg(not(all(windows, target_env="msvc")))] | ||
pkg_config::Config::new().atleast_version("1.4").probe("libftdi1").unwrap(); | ||
#[cfg(all(windows, target_env="msvc"))] | ||
vcpkg::find_package("libftdi1").unwrap(); | ||
|
||
let bindings = bindgen::Builder::default() | ||
.header("wrapper.h") | ||
.default_enum_style(bindgen::EnumVariation::Rust{ non_exhaustive : true }) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There is an interesting problem here: according to the recent discussion in rust-lang/rust-bindgen#1554, this |
||
.rustfmt_bindings(true) | ||
.whitelist_function("ftdi_.*") | ||
.whitelist_type("ftdi_.*") | ||
.whitelist_type("libusb_.*") | ||
.blacklist_type("timeval") | ||
.blacklist_type("__.*") | ||
.raw_line("pub type timeval = libc::timeval;") | ||
.generate() | ||
.expect("Unable to generate bindings"); | ||
|
||
let out_path = PathBuf::from(env::var("OUT_DIR").unwrap()); | ||
bindings | ||
.write_to_file(out_path.join("bindings.rs")) | ||
.expect("Couldn't write bindings!"); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This phrase looks unfinished.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is, and I realized it was after I went to sleep for the night :P.