Straight to the point. Many build systems provide the ability to analyze the target platform by compiling small code chunks with the asking header or with a call to the asking function (eample: Release 0.47).
Is there in Rust any analogue of such a system and maybe someone is already writing or is going to write this?
If you have a config.h, that likely means the library in question is already using the GNU autotools, meaning that it is probably expected to be built by ./configure; make; make install. In particular, the configure script generates the correct config.h file which you can run bindgen on.
How about re-implementation part of GNU autotools on Rust to generate config.h like it doing meson in link at my original post?
For example pkg-config crate does not determine ncursesw include directory.
P.S. GNU autotools is already outdate solution and does not want to return back in 2021 year to bunch of Bash scripts for include directory searching as I say earley meson well complete with that issue better.
I usually generate my own minimal config.h, because most of the time most of these config files are full of useless junk that doesn't do anything.
Very often the C code doesn't even use these defines. Grep the codebase for them to make sure. They may be leftovers from older versions of the project, or even a copy-paste from build system's template that has no relevance for the project.
Even when some of the defines are technically used, they're often workarounds for prehistoric buggy C compilers and dead platforms that Rust never supported. It's fine to assume a compiler as modern as 1989, with support for 8-bit bytes, more than 64KB of RAM, and function prototypes.
You can approximate HAS_FOO_H headers without checking for the headers themselves just by target platform. Usually they're either Linux-only or available everywhere except Windows.
@kornel maybe you will make a crate in future with a well API of your solution, I just did not find anything except autocfg, but it was made for Rust, not for C. For example create cautocfg or if you allow I create this one?
If you want to make a crate for this, go ahead. Personally I haven't gone that far, because technically it's just a matter of writing a text file to OUT_DIR, but the details of each #define are very dependent on what each C project is doing, and they're all snowflakes.