How to organize interdependent sys crates?

How do inter-dependent sys crates get setup and consumed ? What are its best practices ? Any references to sys crates to look into that have similar situation as the following ?

Context:

  • I have a system package (libfoo/foo.h + libfoo.so) and (libbar/libbar.h + libbar.so). foo.h consumes types from bar.h (foo.h includes bar.h) .
  • I want to use bindgen to generate the CFFI bindings to both libfoo.so and libbar.so using bindgen as 2 separate sys crates.

Questions:

  • Is there a way in bindgen to prevent types included from other headers from being codegened ?
  • How do I exclude the system types(types in stdlib.h etc) from being codegened ?
  • How can I instruct bindgen to prevent codegen of included types (foo.h including bar.h but bar.h has a separate sys crate, stdlib.h etc) ?
  • Do I just add the libbar-sys crate as a dependency to libfoo-sys crate ?

What I tried:
I tried using the allow list feature of bindgen but I am dealing with legacy components that dont follow a std naming convention or use prefixes.

Yes, make two sys crates and make one depend on another.

Bindgen can filter by regex. Add filters for functions and statics too.

Crates that set links property in Cargo.toml can set variables that will be visible to other crates. You can export location of the .h files and other things discovered by the sys crate to other sys crates.

https://doc.rust-lang.org/cargo/reference/build-script-examples.html#using-another-sys-crate

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.