Skip to content

Commit

Permalink
Use quote instead of syntex for Rust code generation
Browse files Browse the repository at this point in the history
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 rust-lang#925
  • Loading branch information
fitzgen committed Aug 31, 2017
1 parent 749c538 commit 5e327da
Show file tree
Hide file tree
Showing 92 changed files with 11,103 additions and 8,840 deletions.
104 changes: 4 additions & 100 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 3 additions & 14 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -39,25 +39,18 @@ diff = "0.1"
clap = "2"
shlex = "0.1"

[build-dependencies]
quasi_codegen = "0.32"

[dependencies]
cexpr = "0.2"
cfg-if = "0.1.0"
# This kinda sucks: https://github.com/rust-lang/cargo/issues/1982
clap = "2"
clang-sys = { version = "0.19.0", features = ["runtime", "clang_3_9"] }
lazy_static = "0.2.1"
peeking_take_while = "0.1.2"
syntex_syntax = "0.58"
quote = "0.3.15"
regex = "0.2"
# This kinda sucks: https://github.com/rust-lang/cargo/issues/1982
clap = "2"
which = "1.0.2"

[dependencies.aster]
features = ["with-syntex"]
version = "0.41"

[dependencies.env_logger]
optional = true
version = "0.4"
Expand All @@ -66,10 +59,6 @@ version = "0.4"
optional = true
version = "0.3"

[dependencies.quasi]
features = ["with-syntex"]
version = "0.32"

[features]
default = ["logging"]
logging = ["env_logger", "log"]
Expand Down
13 changes: 2 additions & 11 deletions build.rs
Original file line number Diff line number Diff line change
@@ -1,20 +1,11 @@
mod codegen {
extern crate quasi_codegen;
mod target {
use std::env;
use std::fs::File;
use std::io::Write;
use std::path::{Path, PathBuf};

pub fn main() {
let out_dir = PathBuf::from(env::var("OUT_DIR").unwrap());
let src = Path::new("src/codegen/mod.rs");
let dst = Path::new(&out_dir).join("codegen.rs");

quasi_codegen::expand(&src, &dst).unwrap();
println!("cargo:rerun-if-changed=src/codegen/mod.rs");
println!("cargo:rerun-if-changed=src/codegen/error.rs");
println!("cargo:rerun-if-changed=src/codegen/helpers.rs");
println!("cargo:rerun-if-changed=src/codegen/struct_layout.rs");

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

fn main() {
codegen::main();
target::main();
testgen::main();
}
Loading

0 comments on commit 5e327da

Please sign in to comment.