-
Notifications
You must be signed in to change notification settings - Fork 717
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
detect_include_paths
may use a different clang
#2682
Comments
detect_include_paths
introduces incorrect bindingsdetect_include_paths
may use a different clang
The big hazard is that this can override the search paths for builtins, which must be exactly matched between the clang compiler and library for very similar reasons as to why Rust stdlibs must be matched with the compiler. At minimum, they can cause spurious build failures that are hard to trace and understand. |
I ran into this when building servo / mozangle on ubuntu with both clang (clang-14) and clang-15 installed.
|
I've just now released Now, if runtime-loading of For example, if I'm hoping that in most cases this will result in the |
Nevermind, I've yanked I don't think there's any winning here, any change to the status quo w.r.t. Clang executable selection will probably just break someone else's builds. I think folks'll just need to use |
@KyleMayes Are you confident that a user forgetting to set |
* Don't prefix PATH with android toolchain: This is problematic, since it can cause Rust to select the NDK toolchain as a linker when compiling for the HOST target (e.g. compiling build-scripts). * Prefix target compiler and compiler flags variables with `TARGET_` so as not to influence compilation for HOST targets. * SET `CLANG_PATH` to avoid [bindgen servo#2682] [bindgen servo#2682]: rust-lang/rust-bindgen#2682 Signed-off-by: Jonathan Schwender <schwenderjonathan@gmail.com>
* Postfix PATH with android toolchain: We only need to edit path for the linker specified in the `.cargo/config.toml` to be found. Adding the NDK clang to the end of PATH is sufficient for that. Adding the NDK clang to the front can cause problems however, since it causes the NDK `clang` to be preferred over the system clang. This can cause problems on some systems, where compiling e.g. buildscripts for HOST subsequently fails. * Prefix target compiler and compiler flags variables with `TARGET_` so as not to influence compilation for HOST targets. * SET `CLANG_PATH` to avoid [bindgen servo#2682] [bindgen servo#2682]: rust-lang/rust-bindgen#2682 Signed-off-by: Jonathan Schwender <schwenderjonathan@gmail.com>
* Postfix PATH with android toolchain: We only need to edit path for the linker specified in the `.cargo/config.toml` to be found. Adding the NDK clang to the end of PATH is sufficient for that. Adding the NDK clang to the front can cause problems however, since it causes the NDK `clang` to be preferred over the system clang. This can cause problems on some systems, where compiling e.g. buildscripts for HOST subsequently fails. * Prefix target compiler and compiler flags variables with `TARGET_` so as not to influence compilation for HOST targets. * SET `CLANG_PATH` to avoid [bindgen servo#2682] [bindgen servo#2682]: rust-lang/rust-bindgen#2682 Signed-off-by: Jonathan Schwender <schwenderjonathan@gmail.com>
* Postfix PATH with android toolchain: We only need to edit path for the linker specified in the `.cargo/config.toml` to be found. Adding the NDK clang to the end of PATH is sufficient for that. Adding the NDK clang to the front can cause problems however, since it causes the NDK `clang` to be preferred over the system clang. This can cause problems on some systems, where compiling e.g. buildscripts for HOST subsequently fails. * Prefix target compiler and compiler flags variables with `TARGET_` so as not to influence compilation for HOST targets. * SET `CLANG_PATH` to avoid [bindgen #2682] [bindgen #2682]: rust-lang/rust-bindgen#2682 Signed-off-by: Jonathan Schwender <schwenderjonathan@gmail.com>
@KyleMayes Hmm. I appreciate the patch but I had to ship a lot more code than that to fix this problem: https://github.com/pgcentralfoundation/pgrx/pull/1325/files As clang-sys you may have an easier time making this correct than I did, or you may want to demand more stringent usage, either way. |
I have met the same issue when processing a header that uses I think it is reasonable to make
Version matching can be done by comparing the first line of This approach does not introduce additional search paths but only tries harder to use matched versions of One drawback of this approach is the performance overhead from multiple invocation to For the static linking case, we can directly call @KyleMayes How do you think of this approach? If that looks promising, I can look into the details and submit a PR to |
Any change to the existing logic for picking I already published a version of So while I understand the problem and want to fix it, I'd be making some people's lives a bit easier at the cost of making other people's a little more difficult. Maybe it's worth it in this case, but I'm lazy and suffer from status quo bias. |
But this only applies to the default logic. Adding a new API which e.g. is "give me a matching clang and libclang" or "give me the clang for this specific libclang" should not break any users, since it is a new opt-in API. |
The Probably Unnecessary PreludeMy understanding is that the original concern raised in this issue was that the bindings produced by Fixing that problem would require introducing a "breaking" change to the logic for selecting A Possible Path ForwardI am open to the idea of an alternate behavior for selecting Then, if the maintainers of I'll try to look into this further this week, but no promises (I'm going on vacation starting Friday 🏝️). |
@KyleMayes No, it actually would do more than that, it was just straight-up breaking builds. |
I understand that builds will be broken either way, but KyleMayes/clang-sys#181 (someone complaining about Very small numbers and not very scientific, I know, but my point is that I don't want to introduce changes that negatively affect people without feeling very confident that it's worth it. I'll try to think about this problem more, I'm coming around to the idea that |
@KyleMayes If you use incorrect headers and you don't break someone's build, the resulting compilation is incorrect, which means the bindings can be unsound. If you do break someone's build, then that's preferable to emitting unsound bindings. I reported this issue, and added a horrible hack to work around clang-sys's problems on my own end, because I received numerous reports of this being a problem with a framework I supported the tooling for, when the C codebase we were binding against added a new release that used more of clang's headers. Probably more than just six issues, at this point. They aren't coming here to give a thumbs up because the issue was so convoluted and tangled that they don't even understand why it started breaking. |
Sorry, I certainly didn't mean to dismiss your concerns! I hope I haven't come off as flippant. I am interested in fixing the problem, I'm just very conflict averse... This is very valuable feedback, and I think it provides a good motivation for fixing this issue even if it requires a bit of disruption to others. |
And I got direct reports from multiple other people, too, over other venues that aren't public. There's other issues opened against the pgrx repo that probably are related but I have no good evidence to believe one way or another. |
Now, consider this: Everyone that had an issue with the new version was on macOS. But the majority of people running their own databases in production... relevant, here, because the pgrx framework has to do with database extensions... does it on Linux. And the previous version, the one you reverted to, was breaking Linux builds. But I assure you, it was also breaking macOS before! So you seem to have implemented a fix that broke macOS but worked on Linux. If you actually in fact eliminated almost all problematic Linux builds, that was a strict improvement. You probably just needed to make your fix OS-aware, not to make a wholesale revert. |
Thats great to hear! Just to recap, bindgen uses
|
Bindgen often is deployed to build code using libclang's dynamic library, set by
LIBCLANG_PATH
. However, in bindgen, there is this code:rust-bindgen/bindgen/lib.rs
Lines 824 to 830 in 4f9fa49
This starts with the following check:
https://github.com/KyleMayes/clang-sys/blob/b7992e864eaa2c8cb5c014a52074b962f257e29b/src/support.rs#L59-L65
Unfortunately, this means rust-bindgen can easily wind up pulling a different clang than libclang, and it never consults
LIBCLANG_PATH
. If this is an intended hazard of thedetect_include_paths
function, then it should be documented appropriately. However, as it can easily cause subtly but hazardously incorrect bindings to be generated, it is likely not intended that this is the default.The text was updated successfully, but these errors were encountered: