You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am using cbindgen in a build script (build.rs) to generate a C header. I am building a static lib (using crate-type = ["staticlib"]) to be linked in a C project.
I had a problem where some types, defined in one of my dependency and which appear as function arguments are not exported in the header. Trying to debug the issue I compared the generated header with what the cbindgen CLI produces.
It seems that depending on how the header is generated (build script vs cli) the required types are exported or not.
I found this issue #127 where someone suggested to use cbindgen::Builder::with_parse_deps() and cbindgen::Builder::with_parse_include() but it did not solve my issue. It also links to this RFC issue rust-lang/rfcs#2771 saying that the symbols are not properly exported by Rust. But I don't understand how this could affect differently the CLI or the build script.
I made a small example to reproduce this. See https://github.com/nbigaouette/issue_with_cbindgen. In there I have a workspace with two crates, one is a rust dependency of the other. The CLI produces a header that is valid while the build script misses a type used in the API. Both are using the same configuration.
I've enabled logging (RUST_LOG=trace) for both runs. The build script reports the following:
2024-03-07T22:18:44Z INFO cbindgen::bindgen::parser] Take ffi::free_standing_function.
[2024-03-07T22:18:44Z WARN cbindgen::bindgen::ir::ty] Can't find TypeA. This usually means that this type was incompatible or not found.
Clearly it couldn't find TypeA...
The text was updated successfully, but these errors were encountered:
I am using
cbindgen
in a build script (build.rs
) to generate a C header. I am building a static lib (usingcrate-type = ["staticlib"]
) to be linked in a C project.I had a problem where some types, defined in one of my dependency and which appear as function arguments are not exported in the header. Trying to debug the issue I compared the generated header with what the
cbindgen
CLI produces.It seems that depending on how the header is generated (build script vs cli) the required types are exported or not.
I found this issue #127 where someone suggested to use
cbindgen::Builder::with_parse_deps()
andcbindgen::Builder::with_parse_include()
but it did not solve my issue. It also links to this RFC issue rust-lang/rfcs#2771 saying that the symbols are not properly exported by Rust. But I don't understand how this could affect differently the CLI or the build script.I made a small example to reproduce this. See https://github.com/nbigaouette/issue_with_cbindgen. In there I have a workspace with two crates, one is a rust dependency of the other. The CLI produces a header that is valid while the build script misses a type used in the API. Both are using the same configuration.
I've enabled logging (
RUST_LOG=trace
) for both runs. The build script reports the following:Clearly it couldn't find
TypeA
...The text was updated successfully, but these errors were encountered: