virtio-bindings: use bindgen library from build.rs #327
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Since commit 3e51e2d ("virtio-bindings: regenerate with bindgen 0.70.1") there are compile-time alignment checks in virtio-bindings code. These checks are specific to the architecture where bindgen was run and they can break builds on other architectures.
Here is an example i686 build failure after upgrading from virtio-bindings 0.2.2 to 0.2.4:
https://koji.fedoraproject.org/koji/taskinfo?taskID=127997322
The bindgen User Guide recommends generating bindings from build.rs because it avoids portability issues and the need to maintain a copy of the bindings for each target:
https://rust-lang.github.io/rust-bindgen/library-usage.html
Introduce an import-linux-headers.sh script that copies required virtio headers from a Linux headers tree into include/. Do not distribute the full Linux headers tree because it is large and has falls under various software licenses that are not compatible with this crate's license.
Generate the actual bindings at compile-time in build.rs and then include!() the output from src/lib.rs.
You can verify that the generated bindings have not changed significantly for x86_64 by diffing them against the previous commit. For example:
The __u64 change is due to how <linux/types.h> defined __u64. We should avoid using that non-BSD licensed header. The result is equivalent now that the bindings are generated at compile-time.
Fixes: #326