--generate-cstr is a good idea and generally the right thing to do, but it is not available in Debian 12 and Ubuntu 22.04. Work around the absence.
Signed-off-by: Paolo Bonzini <pbonz...@redhat.com> --- meson.build | 4 +++- rust/hw/char/pl011/src/device.rs | 1 + rust/qemu-api/src/device_class.rs | 8 +++++++- 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/meson.build b/meson.build index 3b35fcb3feb..e08f226ee8a 100644 --- a/meson.build +++ b/meson.build @@ -3920,13 +3920,15 @@ common_all = static_library('common', dependencies: common_ss.all_dependencies()) if have_rust and have_system + # We would like to use --generate-cstr, but it is only available + # starting with bindgen 0.66.0. The oldest supported versions + # are in Ubuntu 22.04 (0.59.1) and Debian 12 (0.60.1). bindgen_args = [ '--disable-header-comment', '--raw-line', '// @generated', '--ctypes-prefix', 'std::os::raw', '--formatter', 'rustfmt', '--generate-block', - '--generate-cstr', '--impl-debug', '--merge-extern-blocks', '--no-doc-comments', diff --git a/rust/hw/char/pl011/src/device.rs b/rust/hw/char/pl011/src/device.rs index ca67d452e7e..ec82a2619f2 100644 --- a/rust/hw/char/pl011/src/device.rs +++ b/rust/hw/char/pl011/src/device.rs @@ -13,6 +13,7 @@ bindings::{self, *}, c_str, definitions::ObjectImpl, + device_class::TYPE_SYS_BUS_DEVICE, with_offsets, }; diff --git a/rust/qemu-api/src/device_class.rs b/rust/qemu-api/src/device_class.rs index d2535125c48..f4eec2f748a 100644 --- a/rust/qemu-api/src/device_class.rs +++ b/rust/qemu-api/src/device_class.rs @@ -2,7 +2,9 @@ // Author(s): Manos Pitsidianakis <manos.pitsidiana...@linaro.org> // SPDX-License-Identifier: GPL-2.0-or-later -use crate::bindings::Property; +use std::ffi::CStr; + +use crate::bindings::{self, Property}; #[macro_export] macro_rules! device_class_init { @@ -129,3 +131,7 @@ macro_rules! vm_state_description { }; } } + +// workaround until we can use --generate-cstr in bindgen. +pub const TYPE_SYS_BUS_DEVICE: &CStr = + unsafe { CStr::from_bytes_with_nul_unchecked(bindings::TYPE_SYS_BUS_DEVICE) }; -- 2.46.2