rust-bindgen
rust-bindgen copied to clipboard
Generating bindings is extremely slow
The performance of my hardware device is not the bottleneck:
CPU: i9 12900k
MEM: 64GB DDR4-3200
Input C/C++ Header
// only 4 functions and 1 type are declared,
// also includes a larger project
Bindgen Invocation
let mut builder = bindgen::Builder::default()
.clang_args() // same arguments as rust-cc, but rust-cc compiles very fast.
.new_type_alias(".*")
.opaque_type("my_types_.*") // the only type I declared
.allowlist_recursively(false);
.header(header) // just my simple code
.allowlist_file(header) // just my simple code
builder.generate()
Actual Results
I use rust-analyzer to develop rust project. But due to the slowness of rust-bindgen, my intellisense is almost broken (every time I saving the code triggers a cargo check
and intellisense becomes temporarily unavailable)
Is there a caching mechanism so that it doesn't generate every time, or to improve its speed?
Hard to say without a test-case, but cargo check
shouldn't re-run the build.rs
file if their inputs haven't changed.
@wspl do you have a minimal test case for this behavior?
Closed due to lack of answer
For future reference, for me this happened because I had a line like println!("cargo:rerun-if-changed=does_not_exist.h");
that referred to a non-existing file (due to a typo). For some reason this causes cargo check
to rerun the build even if nothing actually changed. Kinda sounds like a bug...?
@tom-anders thank you and that does sound like a bug to me. Could you please open a new issue with the minimal reproducible example?
even if it is a bug, this sounds more like a cargo issue than a bindgen one