rust: allow using build-root bindings.rs from cargo

Right now, using cargo with QEMU requires copying by hand the bindings.rs to the
source tree.  Instead, we can use an include file to escape the cage of cargo's
mandated source directory structure.

By running cargo within meson's "devenv" and adding a MESON_BUILD_ROOT
environment variable, it is easy for build.rs to find the file.  However, the
file must be symlinked into cargo's output directory for rust-analyzer to find
it.

Suggested-by: Junjie Mao <junjie.mao@hotmail.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
This commit is contained in:
Paolo Bonzini 2024-11-12 11:52:23 +01:00
parent 8c28667503
commit cb7ada5409
8 changed files with 63 additions and 35 deletions

View file

@ -0,0 +1,29 @@
// SPDX-License-Identifier: GPL-2.0-or-later
#![allow(
dead_code,
improper_ctypes_definitions,
improper_ctypes,
non_camel_case_types,
non_snake_case,
non_upper_case_globals,
unsafe_op_in_unsafe_fn,
clippy::missing_const_for_fn,
clippy::too_many_arguments,
clippy::approx_constant,
clippy::use_self,
clippy::useless_transmute,
clippy::missing_safety_doc
)]
#[cfg(MESON)]
include!("bindings.inc.rs");
#[cfg(not(MESON))]
include!(concat!(env!("OUT_DIR"), "/bindings.inc.rs"));
unsafe impl Send for Property {}
unsafe impl Sync for Property {}
unsafe impl Sync for TypeInfo {}
unsafe impl Sync for VMStateDescription {}
unsafe impl Sync for VMStateField {}
unsafe impl Sync for VMStateInfo {}

View file

@ -4,31 +4,9 @@
#![cfg_attr(not(MESON), doc = include_str!("../README.md"))]
#[allow(
dead_code,
improper_ctypes_definitions,
improper_ctypes,
non_camel_case_types,
non_snake_case,
non_upper_case_globals,
unsafe_op_in_unsafe_fn,
clippy::missing_const_for_fn,
clippy::too_many_arguments,
clippy::approx_constant,
clippy::use_self,
clippy::useless_transmute,
clippy::missing_safety_doc,
)]
#[rustfmt::skip]
pub mod bindings;
unsafe impl Send for bindings::Property {}
unsafe impl Sync for bindings::Property {}
unsafe impl Sync for bindings::TypeInfo {}
unsafe impl Sync for bindings::VMStateDescription {}
unsafe impl Sync for bindings::VMStateField {}
unsafe impl Sync for bindings::VMStateInfo {}
pub mod c_str;
pub mod definitions;
pub mod device_class;