-
Notifications
You must be signed in to change notification settings - Fork 6
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
Conversation
README.md
Outdated
|
||
* `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`, |
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.
README.md
Outdated
|
||
* `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 comment
The reason will be displayed to describe this comment to others. Learn more.
This is not strictly correct. You don't use the bindgen rust_target
option, so the target by default is "the latest stable Rust version". However, as bindgen seems to almost never do compatible version bumps, this is likely to be true.
Still, this requirement sounds a bit suboptimal. I'll discuss it in a bit more detail in a follow-up comment.
build.rs
Outdated
|
||
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 comment
The 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 #[non_exhaustive]
would not help with unknown variants if a newer libftdi1 version returns them (it's still UB to have an enum with a value rustc
does not know about). We may want to look into the newtype
style of enums, it looks interesting.
src/lib.rs
Outdated
//! | ||
//! This wrapper is based on the rust-bindgen output for libftdi 1.2 | ||
//! This wrapper is based on the rust-bindgen output for libftdi 1.4 |
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 wrapper is not "based on", but generated with bindgen (the previous one, I believe, was manually edited after generation).
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 looked like it was manually edited, but I couldn't confirm or not. The options I passed to bindgen generated bindings that looked the closest to what's in the repo. Will fix.
Now to general comments. One change I consider a bit problematic is the new MSRV. I'm fine with bumping it to 1.31 for 2018 edition, but not to the very latest stable version. This question actually splits into two separate sub-questions. First, the Rust version required for generated code. In the current version with Second, the Rust version required for
Following the above, compile-time generation both introduces a dependency on
Could you check whether the bindings themselves actually differ, or only layout tests in them? If the bindings are not platform-dependent, I'd consider the following set of options:
Sounds good to me. |
Well, it's good you asked me to keep you in the loop, because I'm learning a lot today. :P
Will take a look and fix; didn't realize
Is it okay if the MSRV is different depending on whether we use pre-generated bindgen bindings or bindings generated at compile-time?
On my end, the My to-be-completed (oops!) comment discusses how to set up
Will check for ARM Linux and GNU Windows; I'm not in a position to check other bindings at present.
If the bindings actually differ, we can generate a set of bindings for each arch using the The proliferation of bindings that need to be regenerated during version bumps is one reason to prefer compile-time bindings. For instance, I'm going to have to get someone else to generate OS X bindings for me, because even w/ |
Yes, IMHO it's okay to say that old Rust versions require a workaround of using pre-generated bindings.
I've looked at the Another question that I'd like to look into but don't have time right now is how to make this crate work with cross-compiling. In theory for Linux-based systems this may require as little as falling back to |
Just checked: at least on ARM Linux vs Windows GNU, they are identical except for the layout tests, FWIW. |
Sorry, almost forgot about this one. Will merge in a day or two unless you want to introduce other changes. |
@tanriol I still need to apply your suggestions, but I've not been multitasking well the past few days. I'll try to get to this tonight. |
@tanriol Err, scratch that. I had a second wind tonight and managed to get my changes out the door :). |
@tanriol Friendly ping... this PR is ready I think if you have no other changes. |
Sorry, I've missed the push. Will take a look today or tomorrow. |
Looks good to me. It compiles in both modes, and it works (with a new example as I don't have the hardware for the previous example at hand). |
@cr1901 Anything else you think we should get in? |
I don't need anything else right now, but I'd like to comment on two future ideas:
|
You have an interesting configuration, but I'll probably make it work the other way around for
How do you intend to use this feature? Do you want to link to |
Btw, thank you in advance for dealing w/ my bikeshedding :P. Vendored Feature
My understanding so far is that you want a default-enabled feature- I'm calling it This leaves out the case where you want to link to the system libraries instead. Call this a hypothetical
Oh, oops. Right, there's no choice but to do that for Static Feature
Short version... I wanted to be able to deploy releases transitively depending on EDIT: Just kidding. See the
In light of the above, having a static link feature isn't important. |
How do you expect the product for (
A default-disabled feature. The default should be to use system libraries, at least if they are present.
Matches my understanding. There's one more complication with static linking, however, that I've just noticed. |
Yes, but in retrospect I guess this is pretty silly.
Ack.
Need to mull over the rest, but yes I agree to this. I'll see what others Rustaceans think... |
@tanriol In the interim, do you mind if I start hashing out the details of the |
@cr1901 Sure, go ahead! I don't remember the API at the moment, just that it was pretty minimal :-) |
Okay, it's PR-back-and-forth time!
I've modified
libftdi1-sys
so that the bindings are generated at compile time. This alleviates ABI issues that come with typedefs resulting in different-type sizes depending on compiler and architecture. If this is undesirable for you, my suggestion would be to keep this bindgen functionality in, and fallback to using pre-generated bindings (that will probably work) on a target basis.I've successfully generated bindings for ARMv7 Linux and x86_64 Windows 10 using GNU ABI Rust. If using the GNU ABI on Windows,
build.rs
will now attempt to locatelibftdi1.dll
usingpkg-config
;vcpkg
does not work with the GNU version of Rust on Windows.Changes in the API compared to the existing pre-generated bindings include:
libusb_
types, now seem to generate structs with dummyu8
fields instead of enums.timeval
type alias to the type in thelibc
crate.