Re: [PATCH] rust: warn when using libclang >=19.1 with bindgen <0.70
From: Tamir Duberstein
Date: Wed Oct 30 2024 - 10:14:29 EST
On Wed, Oct 30, 2024 at 9:41 AM Alice Ryhl <aliceryhl@xxxxxxxxxx> wrote:
>
> When testing a clang upgrade with Rust Binder, I encountered a build
> failure caused by bindgen not translating some symbols related to
> tracepoints. This was caused by commit 2e770edd8ce1 ("[libclang] Compute
> the right spelling location") changing the behavior of a function
> exposed by libclang. Bindgen fixed the regression in commit 600f63895f73
> ("Use clang_getFileLocation instead of clang_getSpellingLocation").
>
> However, the regression fix is only available in bindgen versions 0.70.0
> or later. This means that when older bindgen versions are used with new
> versions of libclang, bindgen may do the wrong thing, which could lead
> to a build failure.
>
> I encountered the bug with some header files related to tracepoints, but
> it could also cause build failures in other circumstances. Thus, always
> emit a warning when using an old bindgen with a new libclang so that
> other people do not have to spend time chasing down the same bug as me.
>
> If you encounter this warning, it is recommended that you upgrade
> bindgen to 0.70 or later.
>
> Signed-off-by: Alice Ryhl <aliceryhl@xxxxxxxxxx>
> ---
> scripts/rust_is_available.sh | 12 ++++++++++++
Might be time to rename this script - in another patch of course.
> 1 file changed, 12 insertions(+)
>
> diff --git a/scripts/rust_is_available.sh b/scripts/rust_is_available.sh
> index 5262c56dd674..30695612a0d7 100755
> --- a/scripts/rust_is_available.sh
> +++ b/scripts/rust_is_available.sh
> @@ -225,6 +225,18 @@ if [ "$bindgen_libclang_cversion" -lt "$bindgen_libclang_min_cversion" ]; then
> exit 1
> fi
>
> +if [ "$bindgen_libclang_cversion" -ge 190100 ] && [ "$rust_bindings_generator_cversion" -lt 7000 ]; then
> + echo >&2 "***"
> + echo >&2 "*** You're using libclang version 19.1+ together with a version of the"
> + echo >&2 "*** Rust bindings generator '$BINDGEN' from before version 0.70. This"
Maybe `version >= 19.1` and `version < 0.70` would be clearer than
`version 19.1+` and `before version 0.70` respectively.
> + echo >&2 "*** combination has a known bug that may lead to build failures."
> + echo >&2 "*** (https://github.com/rust-lang/rust-bindgen/pull/2824)"
> + echo >&2 "*** Your bindgen version: $rust_bindings_generator_version"
> + echo >&2 "*** Your libclang version: $bindgen_libclang_version"
> + echo >&2 "***"
> + warning=1
> +fi
> +
> # If the C compiler is Clang, then we can also check whether its version
> # matches the `libclang` version used by the Rust bindings generator.
> #
>
> ---
> base-commit: 81983758430957d9a5cb3333fe324fd70cf63e7e
> change-id: 20241030-bindgen-libclang-warn-cebf97ea3506
>
> Best regards,
> --
> Alice Ryhl <aliceryhl@xxxxxxxxxx>
>
>
Reviewed-by: Tamir Duberstein <tamird@xxxxxxxxx>