Skip to content

Commit 3803776

Browse files
committed
Rework how bindings are generated
It has been a few years since I have touched the xed-sys crate and advancements to the rust ecosystem have made some of the hacks we used to need obsolete. This commit reworks how and when bindings are generated. The new approach has two main advantages: - With no extra features enabled the build script doesn't even have to run bindgen at all. It can just use the bundled bindings directly. - We no longer have to maintain a separate c2rust translation of a subset of the functions exposed by XED. A new experimental feature in bindgen can now do this (mostly) automatically. I have also thrown in the enc2 feature that is in the process of being introduced by #65. We do end up needing bindgen when the enc2 feature is enabled as the generated bindings would be too large to submit to crates.io. (They are >40MB!). With that said, here's how things work now: 1. Bindings for the default featureset are generated in advance by running `./generate.sh`. XED's headers don't contain any platform-dependent code so this should remain portable to any platforms where XED is supported. 2. When the bindgen feature is enabled we ignore the bindings from step 1 and instead generate them in build.rs. With the new experimental --wrap-static-fns bindgen option we can drop the janky c2rust step that translates versions of these functions to rust so that they can be included. Instead bindgen generates an additional C file that declares a set of new functions that forward to the static functions, the generated bindings refer to these forwarding functions instead of the original ones.
1 parent 46ca346 commit 3803776

File tree

15 files changed

+25963
-2847
lines changed

15 files changed

+25963
-2847
lines changed

Cargo.toml

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,20 +8,29 @@ edition = "2018"
88
repository = "https://github.com/rust-xed/xed-sys"
99
readme = "README.md"
1010
keywords = ["xed", "intel", "x86", "x86_64"]
11-
categories = ["encoding", "external-ffi-bindings", "hardware-support", "parsing"]
11+
categories = ["encoding", "external-ffi-bindings", "hardware-support", "parsing", "no_std"]
1212

1313
[badges]
1414
appveyor = { repository = "rust-xed/xed-sys" }
1515
travis-ci = { repository = "rust-xed/xed-sys" }
1616

17+
[features]
18+
# Enable the enc2 module of XED.
19+
#
20+
# Note that this will somewhat dramatically slow down compilation of xed-sys.
21+
# The enc2 module involves a large amount of generated code and the resulting
22+
# bindgen definitions contain 40+MB of rust code.
23+
enc2 = ["bindgen"]
24+
25+
# Generate bindings with bindgen at build-time instead of using the
26+
# pregenerated bindings.
27+
#
28+
# This will be slower but is required for certain feature combinations.
29+
bindgen = ["dep:bindgen"]
30+
1731
[dependencies]
1832

1933
[build-dependencies]
20-
bindgen = "0.69"
34+
bindgen = { version = "0.69", optional = true, features = ["experimental"] }
35+
cc = "1.0"
2136
target-lexicon = "0.12"
22-
23-
[workspace]
24-
members = [
25-
".",
26-
"build-tools"
27-
]

build-tools/.gitignore

Lines changed: 0 additions & 1 deletion
This file was deleted.

build-tools/Cargo.toml

Lines changed: 0 additions & 15 deletions
This file was deleted.

build-tools/build-c2rust-bindings

Lines changed: 0 additions & 43 deletions
This file was deleted.

build-tools/src/bin/build-xed.rs

Lines changed: 0 additions & 97 deletions
This file was deleted.

build-tools/src/bin/remove-methods.rs

Lines changed: 0 additions & 42 deletions
This file was deleted.

build-tools/xed.c

Lines changed: 0 additions & 2 deletions
This file was deleted.

0 commit comments

Comments
 (0)