From: Paolo Bonzini <pbonzini@redhat.com>
To: qemu-devel@nongnu.org
Cc: qemu-rust@nongnu.org, armbru@redhat.com, marcandre.lureau@redhat.com
Subject: [PATCH 13/14] rust/util: build QAPI types
Date: Wed, 1 Oct 2025 10:00:50 +0200 [thread overview]
Message-ID: <20251001080051.1043944-14-pbonzini@redhat.com> (raw)
In-Reply-To: <20251001075005.1041833-1-pbonzini@redhat.com>
From: Marc-André Lureau <marcandre.lureau@redhat.com>
Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
rust/util/wrapper.h | 1 +
qapi/meson.build | 6 ++++++
rust/Cargo.lock | 1 +
rust/util/Cargo.toml | 1 +
rust/util/meson.build | 18 +++++++++++++++++-
rust/util/src/qobject/mod.rs | 9 +++++++++
6 files changed, 35 insertions(+), 1 deletion(-)
diff --git a/rust/util/wrapper.h b/rust/util/wrapper.h
index 0907dd59142..c88820a5e5b 100644
--- a/rust/util/wrapper.h
+++ b/rust/util/wrapper.h
@@ -37,3 +37,4 @@ typedef enum memory_order {
#include "qobject/qobject.h"
#include "qobject/qlist.h"
#include "qobject/qdict.h"
+#include "qobject/qjson.h"
diff --git a/qapi/meson.build b/qapi/meson.build
index ca6b61a608d..5d4b55b47f8 100644
--- a/qapi/meson.build
+++ b/qapi/meson.build
@@ -129,3 +129,9 @@ foreach output : qapi_outputs
util_ss.add(qapi_files[i])
i = i + 1
endforeach
+
+qapi_rs_files = custom_target('QAPI Rust',
+ output: 'qapi-types.rs',
+ input: [ files('qapi-schema.json') ],
+ command: [ qapi_gen, '-o', 'qapi', '-b', '@INPUT0@', '-B', 'qapi.backend.QAPIRsBackend' ],
+ depend_files: [ qapi_inputs, qapi_gen_depends ])
diff --git a/rust/Cargo.lock b/rust/Cargo.lock
index c1075e11d6c..991533d92c1 100644
--- a/rust/Cargo.lock
+++ b/rust/Cargo.lock
@@ -447,6 +447,7 @@ dependencies = [
"glib-sys",
"libc",
"serde",
+ "serde_derive",
]
[[package]]
diff --git a/rust/util/Cargo.toml b/rust/util/Cargo.toml
index 554004816eb..9f6c52c5acd 100644
--- a/rust/util/Cargo.toml
+++ b/rust/util/Cargo.toml
@@ -18,6 +18,7 @@ foreign = { workspace = true }
glib-sys = { workspace = true }
libc = { workspace = true }
serde = { workspace = true }
+serde_derive = { workspace = true }
common = { path = "../common" }
[lints]
diff --git a/rust/util/meson.build b/rust/util/meson.build
index 45366d03786..a2d0e6ded0d 100644
--- a/rust/util/meson.build
+++ b/rust/util/meson.build
@@ -50,7 +50,7 @@ _util_rs = static_library(
dependencies: [anyhow_rs, libc_rs, foreign_rs, glib_sys_rs, common_rs, serde_rs, qom, qemuutil],
)
-util_rs = declare_dependency(link_with: [_util_rs], dependencies: [qemuutil, qom])
+util_rs = declare_dependency(link_with: [_util_rs], dependencies: [])
rust.test('rust-util-tests', _util_rs,
dependencies: [qemuutil, qom],
@@ -64,3 +64,19 @@ rust.doctest('rust-util-rs-doctests',
dependencies: util_rs,
suite: ['doc', 'rust']
)
+
+_qapi_cfg = run_command(rustc_args,
+ '--no-strict-cfg',
+ '--config-headers', config_host_h,
+ capture: true, check: true).stdout().strip().splitlines()
+
+_qapi_rs = static_library(
+ 'qapi',
+ qapi_rs_files,
+ rust_args: _qapi_cfg,
+ override_options: ['rust_std=2021', 'build.rust_std=2021'],
+ rust_abi: 'rust',
+ dependencies: [common_rs, util_rs, serde_rs],
+)
+
+qapi_rs = declare_dependency(link_with: [_qapi_rs])
diff --git a/rust/util/src/qobject/mod.rs b/rust/util/src/qobject/mod.rs
index b6e86f11a64..f2618c86473 100644
--- a/rust/util/src/qobject/mod.rs
+++ b/rust/util/src/qobject/mod.rs
@@ -13,6 +13,7 @@
mod serializer;
use core::fmt::{self, Debug, Display};
+use foreign::prelude::*;
use std::{
cell::UnsafeCell,
ffi::{c_char, CString},
@@ -104,6 +105,14 @@ fn refcnt(&self) -> &AtomicUsize {
let qobj = self.0.get();
unsafe { AtomicUsize::from_ptr(addr_of_mut!((*qobj).base.refcnt)) }
}
+
+ pub fn to_json(&self) -> String {
+ let qobj = self.0.get();
+ unsafe {
+ let json = bindings::qobject_to_json(qobj);
+ glib_sys::g_string_free(json, glib_sys::GFALSE).into_native()
+ }
+ }
}
impl From<()> for QObject {
--
2.51.0
next prev parent reply other threads:[~2025-10-01 8:03 UTC|newest]
Thread overview: 34+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-10-01 7:49 [PATCH 00/11] rust: migration: add high-level migration wrappers Paolo Bonzini
2025-10-01 7:52 ` [PATCH 01/11] rust: bql: add BqlRefCell::get_mut() Paolo Bonzini
2025-10-13 8:49 ` Zhao Liu
2025-10-01 7:52 ` [PATCH 02/11] rust: migration: do not pass raw pointer to VMStateDescription::fields Paolo Bonzini
2025-10-13 8:20 ` Zhao Liu
2025-10-01 7:52 ` [PATCH 03/11] rust: migration: do not store raw pointers into VMStateSubsectionsWrapper Paolo Bonzini
2025-10-13 8:46 ` Zhao Liu
2025-10-01 7:52 ` [PATCH 04/11] rust: migration: validate termination of subsection arrays Paolo Bonzini
2025-10-13 8:46 ` Zhao Liu
2025-10-01 7:52 ` [PATCH 05/11] rust: migration: extract vmstate_fields_ref Paolo Bonzini
2025-10-13 8:55 ` Zhao Liu
2025-10-01 7:52 ` [PATCH 06/11] rust: move VMState from bql to migration Paolo Bonzini
2025-10-13 8:57 ` Zhao Liu
2025-10-01 7:52 ` [PATCH 07/11] rust: migration: add high-level migration wrappers Paolo Bonzini
2025-10-01 7:52 ` [PATCH 08/11] rust: qemu-macros: add ToMigrationState derive macro Paolo Bonzini
2025-10-01 7:52 ` [PATCH 09/11] timer: constify some functions Paolo Bonzini
2025-10-01 7:52 ` [PATCH 10/11] rust: migration: implement ToMigrationState for Timer Paolo Bonzini
2025-10-01 7:52 ` [PATCH 11/11] rust: migration: implement ToMigrationState as part of impl_vmstate_bitsized Paolo Bonzini
2025-10-01 8:00 ` [PATCH preview 00/14] rust: QObject and QAPI bindings Paolo Bonzini
2025-10-01 8:00 ` [PATCH 01/14] qobject: make refcount atomic Paolo Bonzini
2025-10-13 7:51 ` Zhao Liu
2025-10-01 8:00 ` [PATCH 02/14] rust: add basic QObject bindings Paolo Bonzini
2025-10-01 8:00 ` [PATCH 03/14] subprojects: add serde Paolo Bonzini
2025-10-01 8:00 ` [PATCH 04/14] rust: add Serialize implementation for QObject Paolo Bonzini
2025-10-01 8:00 ` [PATCH 05/14] rust: add Serializer (to_qobject) " Paolo Bonzini
2025-10-01 8:00 ` [PATCH 06/14] rust: add Deserialize " Paolo Bonzini
2025-10-01 8:00 ` [PATCH 07/14] rust: add Deserializer (from_qobject) " Paolo Bonzini
2025-10-01 8:00 ` [PATCH 08/14] rust/qobject: add Display/Debug Paolo Bonzini
2025-10-01 8:00 ` [PATCH 09/14] scripts/qapi: add QAPISchemaIfCond.rsgen() Paolo Bonzini
2025-10-01 8:00 ` [PATCH 10/14] scripts/qapi: generate high-level Rust bindings Paolo Bonzini
2025-10-01 8:00 ` [PATCH 11/14] scripts/qapi: strip trailing whitespaces Paolo Bonzini
2025-10-01 8:00 ` [PATCH 12/14] scripts/rustc_args: add --no-strict-cfg Paolo Bonzini
2025-10-01 8:00 ` Paolo Bonzini [this message]
2025-10-01 8:00 ` [PATCH 14/14] rust: start qapi tests Paolo Bonzini
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20251001080051.1043944-14-pbonzini@redhat.com \
--to=pbonzini@redhat.com \
--cc=armbru@redhat.com \
--cc=marcandre.lureau@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=qemu-rust@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).