Skip to content

Commit

Permalink
rust: warn about bindgen versions 0.66.0 and 0.66.1
Browse files Browse the repository at this point in the history
`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: rust-lang/rust-bindgen#2567 [1]
Signed-off-by: Miguel Ojeda <ojeda@kernel.org>
  • Loading branch information
ojeda committed Jul 1, 2024
1 parent ebc3ef0 commit 726562c
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
8 changes: 8 additions & 0 deletions scripts/rust_is_available.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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.
#
Expand Down
7 changes: 7 additions & 0 deletions scripts/rust_is_available_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 },
Expand Down

0 comments on commit 726562c

Please sign in to comment.