Skip to content

Querying bindgen for LLVM version being used #2138

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Closed
ojeda opened this issue Dec 13, 2021 · 4 comments · Fixed by #2140
Closed

Querying bindgen for LLVM version being used #2138

ojeda opened this issue Dec 13, 2021 · 4 comments · Fixed by #2140

Comments

@ojeda
Copy link
Contributor

ojeda commented Dec 13, 2021

What is the preferred way to query bindgen about what is the LLVM / libclang version being effectively used/found?

One way is passing bindgen this header or similar:

#pragma message __clang_version__

But ideally, one could query the version with something like:

bindgen --version --verbose

which would print an extra line:

LLVM version: 13.0.0

like rustc does. Possibly with other extra information (e.g. the path to the library instead of just the version, whether it was set at runtime via CLANG_PATH...).

Apologies if I missed any obvious way in the documentation and/or existing issues.

@emilio
Copy link
Contributor

emilio commented Dec 17, 2021

I think we print it from a debug log, but of course that's not optimal, it's a fair request. One problematic thing is that --version is handled by clap, though maybe we can do it manually.

@emilio
Copy link
Contributor

emilio commented Dec 17, 2021

With #2140 we'd print:

bindgen 0.59.2
Clang version: clang version 13.0.0 (Fedora 13.0.0-5.fc36)

Would that work for you?

@ojeda
Copy link
Contributor Author

ojeda commented Dec 18, 2021

Yeah, that would be great!

@ojeda
Copy link
Contributor Author

ojeda commented Dec 18, 2021

A couple extra thoughts:

  • Will the output remain stable? I may fetch this line from a script to see if the Clang version is recent enough. It is fine if not -- it is very useful to debug a user's setup and one can use the __clang_version__ approach for scripts (we use a similar approach to get the C compiler version anyway; and given we are not using a recent bindgen, I will start with that), but I am wondering whether parsing --version --verbose from scripts is a possibility.

  • I am thinking whether to check if the Clang used by bindgen is the same as the one used to compile the C side of the project. For this, I guess checking the full version string is a quite good approximation already, but perhaps there is a better way, like a commit hash, or the version + the path to the library (e.g. the InstalledDir that clang --version prints). Any suggestion?

emilio added a commit that referenced this issue Feb 18, 2022
kulp pushed a commit to kulp/rust-bindgen that referenced this issue Jun 1, 2022
emilio added a commit that referenced this issue Jun 5, 2022
emilio added a commit that referenced this issue Jun 5, 2022
aatifsyed pushed a commit to aatifsyed/rust-bindgen that referenced this issue Sep 22, 2022
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
2 participants