Skip to content

clang_arg don't work when used to include the header file #2414

@try-agaaain

Description

@try-agaaain

I defined bindgen as follows:

     let wasm_bindings = bindgen::Builder::default()
         // The input header we would like to generate
         // bindings for.
         .header("../../wasm-runtime/include/bpf-api.h")
         .clang_arg("-I")
         .clang_arg("../../third_party/wasm-micro-runtime/core/iwasm/include/wasm_export.h")
         .clang_arg("-x")
         .clang_arg("c++")
         // Tell cargo to invalidate the built crate whenever any of the
         // included header files changed.
         .parse_callbacks(Box::new(bindgen::CargoCallbacks))
         // Finish the builder and generate the bindings.
         .generate()
         // Unwrap the Result and panic on failure.
         .expect("Unable to generate wasm-bpf bindings");

In the header file ../../wasm-runtime/include/bpf-api.h, you need to reference another header file ../../third_party/wasm-micro-runtime/core/iwasm/include /wasm_export.h, so I added this header file to the search path via clang_arg, but it didn't work.

The following error occurred in the terminal:

   --- stderr
   ../../wasm-runtime/include/bpf-api.h:16:10: fatal error: 'wasm_export.h' file not found
   thread 'main' panicked at 'Unable to generate wasm-bpf bindings: ClangDiagnostic("../../wasm-runtime/include/bpf-api.h:16:10: fatal error: 'wasm_export.h' file not found\n")', build.rs:43:10
   stack backtrace:
      0: rust_begin_unwind
                at /rustc/d5a82bbd26e1ad8b7401f6a718a9c57c96905483/library/std/src/panicking.rs:575:5
      1: core::panicking::panic_fmt
                at /rustc/d5a82bbd26e1ad8b7401f6a718a9c57c96905483/library/core/src/panicking.rs:64:14
      2: core::result::unwrap_failed
                at /rustc/d5a82bbd26e1ad8b7401f6a718a9c57c96905483/library/core/src/result.rs:1791:5
      3: core::result::Result<T,E>::expect
      4: build_script_build::main
      5: core::ops::function::FnOnce::call_once
   note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.
make: *** [Makefile:7: build] Error 101

I also tried defining BINDGEN_EXTRA_CLANG_ARGS="-I../../third_party/wasm-micro-runtime/core/iwasm/include/wasm_export.h", but that didn't work either.

I wonder know why doesn't clang_arg work? Any advice would be greatly appreciated. (I tried to find related issues, but it didn't solve my problem.)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions