I have a project that depends on a crate where a header file is generated with cbindgen. How can I get the path to this header file? I have external tools that need to include it.
I am using git dependencies in cargo. I can find the header file in two places:
In cargo's global package registry/cache (for me it's ~/.local/share/cargo/git/checkouts/<my_repo>-<some_hash>/<commit_sha>/...)
In the main project's target directory (if I use the OUT_DIR environment variable in the dependency's build script, it puts it in target/debug/build/<the_crate>-<some_hash>/out/include/header.h)
Is there any way I can get programmatic access to the header? I do not know how the hashes are generated, and even if I did I feel it's a hack to try to get the path to the files that way.
Is there another environment variable I can use to tell cbindgen to put the file somewhere else accessible?
Edit: I know I can use the extra_bindings option in cbindgen, but that puts all bindings in the same header, which is not desired.
It looks like --message-format=json will output all generated paths. It's a definitely a firehose of information, but I think it will get me what I need.
The following gives me the OUT_DIR of my dependency:
If a package defines unmangled symbols, it makes sense to set the package.links key. If a package sets this key, the buildscript can println cargo::metadata={KEY}={VAL} to make the environment variable DEP_{LINKS}_{KEY}={VAL} available to downstream crates.
I'm running Cargo with an external tool. It needs to find the native build artifacts of a crate and its dependencies. If I understand correctly, the package.links key will only propagate to downstream crates, not external tools.
My apologies, I should have been more clear regarding Cargo's invocation.
Cargo writes buildscript output to a file in the target directory. You should scan the target for any such files and parse out any directives that way.