rust-bindgen icon indicating copy to clipboard operation
rust-bindgen copied to clipboard

Generating bindings is extremely slow

Open wspl opened this issue 1 year ago • 1 comments

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?

wspl avatar Jul 28 '22 08:07 wspl

Hard to say without a test-case, but cargo check shouldn't re-run the build.rs file if their inputs haven't changed.

emilio avatar Jul 28 '22 09:07 emilio

@wspl do you have a minimal test case for this behavior?

pvdrz avatar Oct 12 '22 16:10 pvdrz

Closed due to lack of answer

pvdrz avatar Nov 11 '22 16:11 pvdrz

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 avatar Jan 12 '23 07:01 tom-anders

@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?

amanjeev avatar Jan 13 '23 17:01 amanjeev

even if it is a bug, this sounds more like a cargo issue than a bindgen one

pvdrz avatar Jan 16 '23 19:01 pvdrz