-
Notifications
You must be signed in to change notification settings - Fork 1.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
modules/rust: allow customizing env vars on bindgen #13631
Conversation
6bf14e5
to
f717a72
Compare
You can already pass additional arguments to clang using the rust.bindgen(input : 'in.h', output : 'out.rs', c_args : '-DEXPOSE_API') Looking at the build scripts for sys-clang, it appears only the clang binary can be changed at runtime using If the concern is a clang/libclang mismatch, we should solve that, but in general this seems like the primary use of this would be to do something that can already be done, without any benefit over the current mechanism. |
Bindgen is configurable through environment variables on how it searches for clang and what extra arguments it passes to the compiler. The former is the only way to change which clang or libclang bindgen will use, which is useful to work around the issue that bindgen uses clang and libclang of different versions on systems with multiple version of the compiler installed. Add an env keyword argument to bindgen() of the rust module to allow customizing the environment variables when invoking bindgen. The argument has the same type as env of custom_target(). Signed-off-by: Junjie Mao <junjie.mao@hotmail.com>
Yes, the current
In addition to those that appears in
I agree that tweaking
+1 for solving the mismatch. The author of
The full conversation can be found in rust-lang/rust-bindgen#2682. |
An alternative to avoid rust-lang/rust-bindgen#2682 can be that bindgen() accepts a |
Sigh, that's a frustrating set of problems to have. Short of being able to change bindgen/sys-libclang to have an interface for this; my preference would be to either expose a specific field for this, or to just silently handle this internally with some sort of heuristic such that:
I'd really prefer a solution where the end user doesn't need to do anything special to get correct, reliable results, if at all possible. |
Got your point and thanks for the suggestions. I'll also check if this can be fixed by always finding clang/libclang of the same version in the sys-clang crate. If that doesn't work, I'll submit something following your recommendations. |
Thanks! I really appreciate this work. We haven't run into this in Mesa yet, but I'm sure we will given enough time :/ |
Agreed with this. Note however that this should be the host machine's compiler. Even better: bindgen could have a
I don't think this is possible, unfortunately. While it is easy to go from clang to libclang, there's no good way to do the opposite.
I think this would be the same as step 2, effectively |
and point LIBCLANG_PATH to that. So it does probably have a dependency on #13134. |
Close this PR. It is clear that allowing arbitrary environment variables for bindgen is not a proper direction to go at the moment. The author of clang-sys crate is considering adding a feature to enforce |
Bindgen is configurable through environment variables on how it searches for clang and what extra arguments it passes to the compiler. The former is the only way to change which clang or libclang bindgen will use, which is useful to work around the issue that bindgen uses clang and libclang of different versions on systems with multiple version of the compiler installed.
Add an env keyword argument to bindgen() of the rust module to allow customizing the environment variables when invoking bindgen. The argument has the same type as env of custom_target().