aboutsummaryrefslogtreecommitdiff
path: root/meson.build
diff options
context:
space:
mode:
authorManos Pitsidianakis <manos.pitsidianakis@linaro.org>2024-10-03 16:28:46 +0300
committerPaolo Bonzini <pbonzini@redhat.com>2024-10-11 12:32:17 +0200
commit6fdc5bc173188f5e4942616b16d589500b874a15 (patch)
treeab2a3691286b9d463728100c45bddc5e7b271c4d /meson.build
parent1a6ef6ff624f0e485bf17210ad34d387a953b288 (diff)
downloadqemu-6fdc5bc173188f5e4942616b16d589500b874a15.zip
qemu-6fdc5bc173188f5e4942616b16d589500b874a15.tar.gz
qemu-6fdc5bc173188f5e4942616b16d589500b874a15.tar.bz2
rust: add bindgen step as a meson dependency
Add bindings_rs target for generating rust bindings to target-independent qemu C APIs. The bindings need be created before any rust crate that uses them is compiled. The bindings.rs file will end up in BUILDDIR/bindings.rs and have the same name as a target: ninja bindings.rs Signed-off-by: Paolo Bonzini <pbonzini@redhat.com> Signed-off-by: Manos Pitsidianakis <manos.pitsidianakis@linaro.org> Link: https://lore.kernel.org/r/1be89a27719049b7203eaf2eca8bbb75b33f18d4.1727961605.git.manos.pitsidianakis@linaro.org Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Diffstat (limited to 'meson.build')
-rw-r--r--meson.build68
1 files changed, 68 insertions, 0 deletions
diff --git a/meson.build b/meson.build
index f76f01f..b9a83df 100644
--- a/meson.build
+++ b/meson.build
@@ -3892,6 +3892,74 @@ common_all = static_library('common',
implicit_include_directories: false,
dependencies: common_ss.all_dependencies())
+if have_rust and have_system
+ rustc_args = run_command(
+ find_program('scripts/rust/rustc_args.py'),
+ '--config-headers', meson.project_build_root() / 'config-host.h',
+ capture : true,
+ check: true).stdout().strip().split()
+ rustc_args += ['-D', 'unsafe_op_in_unsafe_fn']
+ bindgen_args = [
+ '--disable-header-comment',
+ '--raw-line', '// @generated',
+ '--ctypes-prefix', 'core::ffi',
+ '--formatter', 'rustfmt',
+ '--generate-block',
+ '--generate-cstr',
+ '--impl-debug',
+ '--merge-extern-blocks',
+ '--no-doc-comments',
+ '--use-core',
+ '--with-derive-default',
+ '--no-size_t-is-usize',
+ '--no-layout-tests',
+ '--no-prepend-enum-name',
+ '--allowlist-file', meson.project_source_root() + '/include/.*',
+ '--allowlist-file', meson.project_source_root() + '/.*',
+ '--allowlist-file', meson.project_build_root() + '/.*'
+ ]
+ c_enums = [
+ 'DeviceCategory',
+ 'GpioPolarity',
+ 'MachineInitPhase',
+ 'MemoryDeviceInfoKind',
+ 'MigrationPolicy',
+ 'MigrationPriority',
+ 'QEMUChrEvent',
+ 'QEMUClockType',
+ 'device_endian',
+ 'module_init_type',
+ ]
+ foreach enum : c_enums
+ bindgen_args += ['--rustified-enum', enum]
+ endforeach
+ c_bitfields = [
+ 'ClockEvent',
+ 'VMStateFlags',
+ ]
+ foreach enum : c_bitfields
+ bindgen_args += ['--bitfield-enum', enum]
+ endforeach
+
+ # TODO: Remove this comment when the clang/libclang mismatch issue is solved.
+ #
+ # Rust bindings generation with `bindgen` might fail in some cases where the
+ # detected `libclang` does not match the expected `clang` version/target. In
+ # this case you must pass the path to `clang` and `libclang` to your build
+ # command invocation using the environment variables CLANG_PATH and
+ # LIBCLANG_PATH
+ bindings_rs = import('rust').bindgen(
+ input: 'rust/wrapper.h',
+ dependencies: common_ss.all_dependencies(),
+ output: 'bindings.rs',
+ include_directories: include_directories('.', 'include'),
+ bindgen_version: ['>=0.69.4'],
+ args: bindgen_args,
+ )
+ subdir('rust')
+endif
+
+
feature_to_c = find_program('scripts/feature_to_c.py')
if host_os == 'darwin'