Skip to content

Commit b13f076

Browse files
author
bors-servo
authored
Auto merge of #940 - fitzgen:no-syntex, r=emilio
No more syntex There are a few commits in this PR, but the big one is the commit that goes `syntex` -> `quote` for code generation. I've included a copy of its commit message below. I tried to verify that it works with the stylo build still, but there were some issues, and then I checked with master, and that wasn't working either. So now I'm C-Reducing the failures on master and figured that this is at least ready for feedback in the meantime. r? @emilio ---------------------------- The `syntex` crate is unmaintained. It is slow to build, and additionally it requires that we pre-process `src/codegen/mod.rs` before we build the `bindgen` crate. The `quote` crate provides similar quasi-quoting functionality, is maintained, and builds faster. It doesn't have a typed API or builders, however; it only deals with tokens. Before this commit: ``` $ cargo clean; cargo build <snip> Finished dev [unoptimized + debuginfo] target(s) in 98.75 secs ``` After this commit: ``` $ cargo clean; cargo build <snip> Finished dev [unoptimized + debuginfo] target(s) in 46.26 secs ``` Build time is cut in half! But what about run time? Before this commit: ``` Generated Stylo bindings in: Duration { secs: 3, nanos: 521105668 } ``` After this commit: ``` Generated Stylo bindings in: Duration { secs: 3, nanos: 548797242 } ``` So it appears to be about 20ms slower at generating Stylo bindings, but I suspect this is well within the noise. Finally, this also lets us remove that nasty `mem::transmute` inside `bindgen::ir::BindgenContext::gen` that was used for the old `syntex` context. Now `BindgenContext` doesn't have a lifetime parameter either. This should make it easier to revisit doing our analyses in parallel with `rayon`, since that context was one of the things that made it hard for `BindgenContext` to implement `Sync`. Fixes #925
2 parents dcd8385 + 46f74c1 commit b13f076

File tree

120 files changed

+11718
-9042
lines changed

Some content is hidden

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

120 files changed

+11718
-9042
lines changed

CONTRIBUTING.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,14 @@ There is also the `./bindgen-integration` crate, which uses `bindgen` to
8888
generate bindings to some C++ code, and then uses the bindings, asserting that
8989
values are what we expect them to be both on the Rust and C++ side.
9090

91+
The generated and expected bindings are run through `rustfmt` before they are
92+
compared. Make sure you have `rustfmt` up to date:
93+
94+
```
95+
$ rustup update nightly
96+
$ rustup run nightly cargo install -f rustfmt-nightly
97+
```
98+
9199
### Testing Bindings Generation
92100

93101
To regenerate bindings from the corpus of test headers in `tests/headers` and

Cargo.lock

Lines changed: 4 additions & 100 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -39,25 +39,18 @@ diff = "0.1"
3939
clap = "2"
4040
shlex = "0.1"
4141

42-
[build-dependencies]
43-
quasi_codegen = "0.32"
44-
4542
[dependencies]
4643
cexpr = "0.2"
4744
cfg-if = "0.1.0"
45+
# This kinda sucks: https://github.com/rust-lang/cargo/issues/1982
46+
clap = "2"
4847
clang-sys = { version = "0.19.0", features = ["runtime", "clang_3_9"] }
4948
lazy_static = "0.2.1"
5049
peeking_take_while = "0.1.2"
51-
syntex_syntax = "0.58"
50+
quote = "0.3.15"
5251
regex = "0.2"
53-
# This kinda sucks: https://github.com/rust-lang/cargo/issues/1982
54-
clap = "2"
5552
which = "1.0.2"
5653

57-
[dependencies.aster]
58-
features = ["with-syntex"]
59-
version = "0.41"
60-
6154
[dependencies.env_logger]
6255
optional = true
6356
version = "0.4"
@@ -66,10 +59,6 @@ version = "0.4"
6659
optional = true
6760
version = "0.3"
6861

69-
[dependencies.quasi]
70-
features = ["with-syntex"]
71-
version = "0.32"
72-
7362
[features]
7463
default = ["logging"]
7564
logging = ["env_logger", "log"]

build.rs

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,11 @@
1-
mod codegen {
2-
extern crate quasi_codegen;
1+
mod target {
32
use std::env;
43
use std::fs::File;
54
use std::io::Write;
65
use std::path::{Path, PathBuf};
76

87
pub fn main() {
98
let out_dir = PathBuf::from(env::var("OUT_DIR").unwrap());
10-
let src = Path::new("src/codegen/mod.rs");
11-
let dst = Path::new(&out_dir).join("codegen.rs");
12-
13-
quasi_codegen::expand(&src, &dst).unwrap();
14-
println!("cargo:rerun-if-changed=src/codegen/mod.rs");
15-
println!("cargo:rerun-if-changed=src/codegen/error.rs");
16-
println!("cargo:rerun-if-changed=src/codegen/helpers.rs");
17-
println!("cargo:rerun-if-changed=src/codegen/struct_layout.rs");
189

1910
let mut dst = File::create(Path::new(&out_dir).join("host-target.txt"))
2011
.unwrap();
@@ -77,6 +68,6 @@ mod testgen {
7768
}
7869

7970
fn main() {
80-
codegen::main();
71+
target::main();
8172
testgen::main();
8273
}

ci/script.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@ export RUST_BACKTRACE=1
1111

1212
case "$BINDGEN_JOB" in
1313
"test")
14+
# Need rustfmt to compare the test expectations.
15+
rustup update nightly
16+
rustup run nightly cargo install -f rustfmt-nightly
17+
1418
cargo test $BINDGEN_PROFILE --features "$BINDGEN_FEATURES"
1519
./ci/assert-no-diff.sh
1620
;;

0 commit comments

Comments
 (0)