-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
merge #2: bindgen, Windows, bump to 1.4, Rust 2018
- support bindgen for on-the-fly bindings generation, - stop using enums to avoid UB on possible unknown values, - bump libftdi1 version to 1.4, - add Windows support
- Loading branch information
Showing
6 changed files
with
1,057 additions
and
572 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
# `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 | ||
By default, 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`, you can use the following procedure (using a Debian-based | ||
ARM system as an example): | ||
|
||
``` | ||
sudo apt-get install libclang-dev | ||
export LIBCLANG_PATH=/usr/lib/llvm-7/lib | ||
export C_INCLUDE_PATH=/usr/lib/gcc/arm-linux-gnueabihf/8/include | ||
cargo build | ||
``` | ||
|
||
* `libftdi` version 1.4 (the most recent version as of 2017) is required. | ||
|
||
### MSRV | ||
The Minimum Supported Rust Version (MSRV) is stable `1.34` when default | ||
features are enabled (i.e. generating bindings at compile-time). If support for | ||
older Rust versions is required, the pre-generated bindings | ||
(down to `1.31`, Rust 2018) must be used instead. | ||
|
||
## Pre-Generated Bindings | ||
`libftdi1-sys` provides some bindings generated ahead-of-time from `bindgen` | ||
as a fallback for users lacking `libclang`, requiring Rust 2018 support, or | ||
otherwise. To use these pre-generated bindings, add the following to your | ||
`Cargo.toml`: | ||
|
||
``` | ||
[dependencies.libftdi1-sys] | ||
default-features="false" | ||
``` | ||
|
||
## Features | ||
* `bindgen`: Generate bindings to `libftdi` at compile time. | ||
Enabled by default. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,42 @@ | ||
#[cfg(not(windows))] | ||
fn main() { | ||
pkg_config::find_library("libftdi1").unwrap(); | ||
cfg_if::cfg_if! { | ||
if #[cfg(feature = "bindgen")] { | ||
use bindgen; | ||
|
||
use std::env; | ||
use std::path::PathBuf; | ||
} | ||
} | ||
|
||
#[cfg(windows)] | ||
fn main() { | ||
vcpkg::find_package("libftdi1").unwrap(); | ||
cfg_if::cfg_if! { | ||
if #[cfg(all(windows, target_env="msvc"))] { | ||
vcpkg::find_package("libftdi1").unwrap(); | ||
} else { | ||
pkg_config::Config::new().atleast_version("1.4").probe("libftdi1").unwrap(); | ||
} | ||
} | ||
|
||
cfg_if::cfg_if! { | ||
if #[cfg(feature = "bindgen")] { | ||
let bindings = bindgen::Builder::default() | ||
.header("wrapper.h") | ||
.default_enum_style(bindgen::EnumVariation::NewType{ is_bitfield : false }) | ||
.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!"); | ||
} else { | ||
// Anything not depending on bindgen feature goes here. | ||
} | ||
} | ||
} |
Oops, something went wrong.