qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Manos Pitsidianakis <manos.pitsidianakis@linaro.org>
To: Junjie Mao <junjie.mao@intel.com>, qemu-devel@nongnu.org
Cc: "Paolo Bonzini" <pbonzini@redhat.com>,
	"Marc-André Lureau" <marcandre.lureau@redhat.com>,
	"Daniel P. Berrangé " <berrange@redhat.com>,
	"Thomas Huth" <thuth@redhat.com>,
	"Philippe Mathieu-Daudé " <philmd@linaro.org>,
	"Pierrick Bouvier" <pierrick.bouvier@linaro.org>,
	"Richard Henderson" <richard.henderson@linaro.org>,
	"Gustavo Romero" <gustavo.romero@linaro.org>,
	"Alex Benné e" <alex.bennee@linaro.org>,
	"Peter Maydell" <peter.maydell@linaro.org>,
	"Zhao Liu" <zhao1.liu@intel.com>
Subject: Re: [PATCH v8 7/8] rust: add utility procedural macro crate
Date: Mon, 26 Aug 2024 09:02:37 +0300	[thread overview]
Message-ID: <itagv.nihkv71gz0hp@linaro.org> (raw)
In-Reply-To: <b715130d-2673-4f3d-8189-4f2bda528fbf@intel.com>

Hello Junjie,

On Mon, 26 Aug 2024 08:15, Junjie Mao <junjie.mao@intel.com> wrote:
>On 8/23/2024 4:11 PM, Manos Pitsidianakis wrote:
>> This commit adds a helper crate library, qemu-api-macros for derive (and
>> other procedural) macros to be used along qemu-api.
>> 
>> It needs to be a separate library because in Rust, procedural macros, or
>> macros that can generate arbitrary code, need to be special separate
>> compilation units.
>> 
>> Only one macro is introduced in this patch, #[derive(Object)]. It
>> generates a constructor to register a QOM TypeInfo on init and it must
>> be used on types that implement qemu_api::definitions::ObjectImpl trait.
>> 
>> Signed-off-by: Manos Pitsidianakis <manos.pitsidianakis@linaro.org>
>> ---
>>   MAINTAINERS                            |   1 +
>>   rust/meson.build                       |   1 +
>>   rust/qemu-api-macros/Cargo.lock        |  47 +++++++
>>   rust/qemu-api-macros/Cargo.toml        |  25 ++++
>>   rust/qemu-api-macros/README.md         |   1 +
>>   rust/qemu-api-macros/meson.build       |  25 ++++
>>   rust/qemu-api-macros/src/cstr/mod.rs   |  55 ++++++++
>>   rust/qemu-api-macros/src/cstr/parse.rs | 225 +++++++++++++++++++++++++++++++++
>
>Since Rust 1.77.0 C-string literals are stabilized [1]. I don't think we need to 
>include this cstr crate as we require Rust >= 1.80.0.


Many thanks! I got the qemu-api-macros from my git stash, I tried to 
bundle cstr in a previous version before we had proper meson 
dependencies and I hadn't raised the Rust version. So I just forgot to 
remove these files (they are not even declared in lib.rs). Oops 🤦.

>
>[1] https://crates.io/crates/cstr
>
>>   rust/qemu-api-macros/src/lib.rs        |  43 +++++++
>>   rust/qemu-api/meson.build              |   3 +
>>   10 files changed, 426 insertions(+)
>> 
>[snip]
>> diff --git a/rust/qemu-api/meson.build b/rust/qemu-api/meson.build
>> index 85838d31b4..a0802ad858 100644
>> --- a/rust/qemu-api/meson.build
>> +++ b/rust/qemu-api/meson.build
>> @@ -13,6 +13,9 @@ _qemu_api_rs = static_library(
>>     rust_args: [
>>       '--cfg', 'MESON',
>>     ],
>> +  dependencies: [
>> +    qemu_api_macros,
>> +  ],
>>   )
>>   
>>   qemu_api = declare_dependency(
>> 
>
>qemu-api does not use macros provided by qemu-api-macros, but the later 
>generates code that uses types defined by the former. So to me qemu-api-macros 
>should depend on qemu-api, not vice versa.

It does generate code but it does not use those types, serde_derive for 
example does not depend on serde but serde depends on serde_derive 
(because it re-exports the macros in its API):

https://crates.io/crates/serde_derive/1.0.209/dependencies
https://crates.io/crates/serde/1.0.209/dependencies

Manos


  reply	other threads:[~2024-08-26  6:11 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-08-23  8:11 [PATCH v8 0/8] Add Rust build support, ARM PL011 device impl Manos Pitsidianakis
2024-08-23  8:11 ` [PATCH v8 1/8] Require meson version 1.5.0 Manos Pitsidianakis
2024-08-23  8:11 ` [PATCH v8 2/8] build-sys: Add rust feature option Manos Pitsidianakis
2024-08-23  8:11 ` [PATCH v8 3/8] configure, meson: detect Rust toolchain Manos Pitsidianakis
2024-08-23  8:11 ` [PATCH v8 4/8] rust: add bindgen step as a meson dependency Manos Pitsidianakis
2024-08-23  8:11 ` [PATCH v8 5/8] .gitattributes: add Rust diff and merge attributes Manos Pitsidianakis
2024-08-23  8:11 ` [PATCH v8 6/8] rust: add crate to expose bindings and interfaces Manos Pitsidianakis
2024-08-26  5:03   ` Junjie Mao
2024-08-26  6:12     ` Manos Pitsidianakis
2024-08-26  8:41       ` Junjie Mao
2024-08-26  5:31   ` Junjie Mao
2024-08-26  6:41     ` Manos Pitsidianakis
2024-08-26  7:45       ` Junjie Mao
2024-08-26  8:24       ` Thomas Huth
2024-08-26 11:29         ` Manos Pitsidianakis
2024-08-23  8:11 ` [PATCH v8 7/8] rust: add utility procedural macro crate Manos Pitsidianakis
2024-08-26  5:15   ` Junjie Mao
2024-08-26  6:02     ` Manos Pitsidianakis [this message]
2024-08-23  8:11 ` [PATCH v8 8/8] rust: add PL011 device model Manos Pitsidianakis

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=itagv.nihkv71gz0hp@linaro.org \
    --to=manos.pitsidianakis@linaro.org \
    --cc=alex.bennee@linaro.org \
    --cc=berrange@redhat.com \
    --cc=gustavo.romero@linaro.org \
    --cc=junjie.mao@intel.com \
    --cc=marcandre.lureau@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=peter.maydell@linaro.org \
    --cc=philmd@linaro.org \
    --cc=pierrick.bouvier@linaro.org \
    --cc=qemu-devel@nongnu.org \
    --cc=richard.henderson@linaro.org \
    --cc=thuth@redhat.com \
    --cc=zhao1.liu@intel.com \
    /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).