Skip to content

Commit f318b63

Browse files
author
bors-servo
authored
Auto merge of #37 - emilio:v2, r=nox
Rewrite the core of the binding generator. TL;DR: The binding generator is a mess as of right now. At first it was funny (in a "this is challenging" sense) to improve on it, but this is not sustainable. The truth is that the current architecture of the binding generator is a huge pile of hacks, so these few days I've been working on rewriting it with a few goals. 1) Have the hacks as contained and identified as possible. They're sometimes needed because how clang exposes the AST, but ideally those hacks are well identified and don't interact randomly with each others. As an example, in the current bindgen when scanning the parameters of a function that references a struct clones all the struct information, then if the struct name changes (because we mangle it), everything breaks. 2) Support extending the bindgen output without having to deal with clang. The way I'm aiming to do this is separating completely the parsing stage from the code generation one, and providing a single id for each item the binding generator provides. 3) No more random mutation of the internal representation from anywhere. That means no more `Rc<RefCell<T>>`, no more random circular references, no more borrow_state... nothing. 4) No more deduplication of declarations before code generation. Current bindgen has a stage, called `tag_dup_decl`[1], that takes care of deduplicating declarations. That's completely buggy, and for C++ it's a complete mess, since we YOLO modify the world. I've managed to take rid of this using the clang canonical declaration, and the definition, to avoid scanning any type/item twice. 5) Code generation should not modify any internal data structure. It can lookup things, traverse whatever it needs, but not modifying randomly. 6) Each item should have a canonical name, and a single source of mangling logic, and that should be computed from the immutable state, at code generation. I've put a few canonical_name stuff in the code generation phase, but it's still not complete, and should change if I implement namespaces. Improvements pending until this can land: 1) Add support for missing core stuff, mainly generating functions (note that we parse the signatures for types correctly though), bitfields, generating C++ methods. 2) Add support for the necessary features that were added to work around some C++ pitfalls, like opaque types, etc... 3) Add support for the sugar that Manish added recently. 4) Optionally (and I guess this can land without it, because basically nobody uses it since it's so buggy), bring back namespace support. These are not completely trivial, but I think I can do them quite easily with the current architecture. I'm putting the current state of affairs here as a request for comments... Note that there are still a few smells I want to eventually re-redesign, like the ParseError::Recurse thing, but until that happens I'm way happier with this kind of architecture. I'm keeping the old `parser.rs` and `gen.rs` in tree just for reference while I code, but they will go away. [1]: https://github.com/Yamakaky/rust-bindgen/blob/master/src/gen.rs#L448
2 parents bbd6b2c + da69afd commit f318b63

File tree

143 files changed

+8221
-7088
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

143 files changed

+8221
-7088
lines changed

Cargo.toml

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,18 @@
11
[package]
2-
authors = ["Jyun-Yan You <[email protected]>"]
2+
authors = [
3+
"Jyun-Yan You <[email protected]>",
4+
"Emilio Cobos Álvarez <[email protected]>",
5+
"The Servo project developers",
6+
]
37
build = "build.rs"
48
description = "A binding generator for Rust"
5-
homepage = "https://github.com/crabtw/rust-bindgen"
9+
homepage = "https://github.com/servo/rust-bindgen"
610
keywords = ["bindings", "ffi", "code-generation"]
711
license = "BSD-3-Clause"
812
name = "bindgen"
913
readme = "README.md"
10-
repository = "https://github.com/crabtw/rust-bindgen"
11-
version = "0.16.0"
14+
repository = "https://github.com/servo/rust-bindgen"
15+
version = "0.17.0"
1216

1317
[[bin]]
1418
doc = false
@@ -19,23 +23,24 @@ quasi_codegen = "0.15"
1923

2024
[dependencies]
2125
clang-sys = "0.8.0"
22-
docopt = "0.6.82"
23-
libc = "0.2.*"
24-
log = "0.3.*"
26+
libc = "0.2"
27+
log = "0.3"
28+
env_logger = "0.3"
2529
rustc-serialize = "0.3.19"
26-
syntex_syntax = "0.38"
30+
syntex_syntax = "0.43"
31+
regex = "0.1"
2732

2833
[dependencies.aster]
2934
features = ["with-syntex"]
30-
version = "0.21.1"
35+
version = "0.26"
3136

3237
[dependencies.clippy]
3338
optional = true
3439
version = "*"
3540

3641
[dependencies.quasi]
3742
features = ["with-syntex"]
38-
version = "0.15"
43+
version = "0.19"
3944

4045
[features]
4146
llvm_stable = []

build.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,12 @@ mod codegen {
55

66
pub fn main() {
77
let out_dir = env::var_os("OUT_DIR").unwrap();
8-
let src = Path::new("src/gen.rs");
9-
let dst = Path::new(&out_dir).join("gen.rs");
8+
let src = Path::new("src/codegen/mod.rs");
9+
let dst = Path::new(&out_dir).join("codegen.rs");
1010

1111
quasi_codegen::expand(&src, &dst).unwrap();
12-
println!("cargo:rerun-if-changed=src/gen.rs");
12+
println!("cargo:rerun-if-changed=src/codegen/mod.rs");
13+
println!("cargo:rerun-if-changed=src/codegen/helpers.rs");
1314
}
1415
}
1516

0 commit comments

Comments
 (0)