cbindgen icon indicating copy to clipboard operation
cbindgen copied to clipboard

`with_parse_expand(...)` from build.rs seems to hang indefinetly

Open TomzBench opened this issue 2 years ago • 7 comments

I have a pretty simple project that uses macros. I try to expand them from inside my build.rs file and it seems to hang forever.

per my build script below... If I remove with_parse_expand(...) line then my project generates headers fine except I don't get the expansions in my header. If I add back the with_parse_expand(...) statement then my build never finishes. My repo is pretty minimal and perhaps it can be used to reproduce. : https://github.com/TomzBench/minicbor-c

Below is my build script:

use std::env;

fn main() {
    let crate_dir = env::var("CARGO_MANIFEST_DIR").unwrap();
    cbindgen::Builder::new()
        .with_crate(crate_dir)
        .with_parse_expand(&["minicbor-c"])
        .generate()
        .expect("Unable to generate bindings")
        .write_to_file("minicbor.h");
}

TomzBench avatar Dec 05 '22 21:12 TomzBench

Setting

        .with_language(cbindgen::Language::C)

may help

0xdeafbeef avatar Dec 07 '22 16:12 0xdeafbeef

my latest attempts had that in there. no help. Also, intermittently after killing the process, some cargo threads where stuck at 100% and i had to kill them.

TomzBench avatar Dec 07 '22 18:12 TomzBench

my latest attempts had that in there. no help. Also, intermittently after killing the process, some cargo threads where stuck at 100% and i had to kill them.

It's working with

cbindgen = "0.21.0"

so it's a regression

0xdeafbeef avatar Dec 07 '22 19:12 0xdeafbeef

yep - can confirm works with "0.21" for me also. Thanks.

TomzBench avatar Dec 07 '22 19:12 TomzBench

Can someone bisect this by any chance? Should be easy to identify the broken commit.

emilio avatar Dec 07 '22 22:12 emilio

Master version crashes with

Can someone bisect this by any chance? Should be easy to identify the broken commit.

❯ git bisect bad
aeb81934d1c4d3539cc426bbc46612b968adf653 is the first bad commit
commit aeb81934d1c4d3539cc426bbc46612b968adf653
Author: Vadim Petrochenkov <[email protected]>
Date:   Thu Mar 31 19:46:41 2022 +0300

    Avoid generating and writing bindings when called recursively

    from a build script.

 src/bindgen/bindings.rs | 17 +++++++++++++++++
 src/bindgen/library.rs  | 18 ++++++++++++++++++
 src/bindgen/parser.rs   |  7 -------
 3 files changed, 35 insertions(+), 7 deletions(-)

0xdeafbeef avatar Dec 07 '22 23:12 0xdeafbeef

Bisected from HEAD to 0.21 tag

0xdeafbeef avatar Dec 07 '22 23:12 0xdeafbeef