From 6d60d2f15d27f3e57549abe819f6e1fd4d874c8f Mon Sep 17 00:00:00 2001 From: Miguel Ojeda Date: Mon, 1 Jul 2024 20:36:17 +0200 Subject: [PATCH] rust: warn about `bindgen` versions 0.66.0 and 0.66.1 `bindgen` versions 0.66.0 and 0.66.1 panic due to C string literals with NUL characters [1]: panicked at .cargo/registry/src/index.crates.io-6f17d22bba15001f/bindgen-0.66.0/codegen/mod.rs:717:71: called `Result::unwrap()` on an `Err` value: FromBytesWithNulError { kind: InteriorNul(4) } Thus, in preparation for supporting several `bindgen` versions, add a version check to warn the user about it. We could make it an error, but 1) it is going to fail anyway later in the build, 2) we would disable `RUST` automatically, which is also painful, 3) someone could be using a patched `bindgen` at that version, 4) the interior NUL may go away in the headers (however unlikely). Thus just warn about it so that users know why it is failing. In addition, add a test for the new case. Link: https://github.com/rust-lang/rust-bindgen/pull/2567 [1] Signed-off-by: Miguel Ojeda Link: https://lore.kernel.org/r/20240701183625.665574-8-ojeda@kernel.org --- scripts/rust_is_available.sh | 8 ++++++++ scripts/rust_is_available_test.py | 7 +++++++ 2 files changed, 15 insertions(+) diff --git a/scripts/rust_is_available.sh b/scripts/rust_is_available.sh index 67cb900124cc9b..33bbd01ffe5115 100755 --- a/scripts/rust_is_available.sh +++ b/scripts/rust_is_available.sh @@ -165,6 +165,14 @@ if [ "$rust_bindings_generator_cversion" -gt "$rust_bindings_generator_min_cvers echo >&2 "***" warning=1 fi +if [ "$rust_bindings_generator_cversion" -eq 6600 ] || [ "$rust_bindings_generator_cversion" -eq 6601 ]; then + echo >&2 "***" + echo >&2 "*** Rust bindings generator '$BINDGEN' versions 0.66.0 and 0.66.1 may not" + echo >&2 "*** work due to a bug (https://github.com/rust-lang/rust-bindgen/pull/2567)." + echo >&2 "*** Your version: $rust_bindings_generator_version" + echo >&2 "***" + warning=1 +fi # Check that the `libclang` used by the Rust bindings generator is suitable. # diff --git a/scripts/rust_is_available_test.py b/scripts/rust_is_available_test.py index a255f79aafc2b1..2b887098c19d55 100755 --- a/scripts/rust_is_available_test.py +++ b/scripts/rust_is_available_test.py @@ -226,6 +226,13 @@ def test_bindgen_new_version(self): result = self.run_script(self.Expected.SUCCESS_WITH_WARNINGS, { "BINDGEN": bindgen }) self.assertIn(f"Rust bindings generator '{bindgen}' is too new. This may or may not work.", result.stderr) + def test_bindgen_bad_version_0_66_0_and_0_66_1(self): + for version in ("0.66.0", "0.66.1"): + with self.subTest(version=version): + bindgen = self.generate_bindgen_version(f"bindgen {version}") + result = self.run_script(self.Expected.SUCCESS_WITH_WARNINGS, { "BINDGEN": bindgen }) + self.assertIn(f"Rust bindings generator '{bindgen}' versions 0.66.0 and 0.66.1 may not", result.stderr) + def test_bindgen_libclang_failure(self): for env in ( { "LLVM_CONFIG_PATH": self.missing },