Skip to content

Commit 3db667d

Browse files
committed
Use quote instead of syntex for Rust code generation
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
1 parent bf2739b commit 3db667d

File tree

110 files changed

+11475
-8991
lines changed

Some content is hidden

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

110 files changed

+11475
-8991
lines changed

Cargo.lock

+4-100
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

+3-14
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

+2-11
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
}

0 commit comments

Comments
 (0)