qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Paolo Bonzini <pbonzini@redhat.com>
To: "Manos Pitsidianakis" <manos.pitsidianakis@linaro.org>,
	"Daniel P. Berrangé" <berrange@redhat.com>
Cc: qemu-devel <qemu-devel@nongnu.org>,
	"Stefan Hajnoczi" <stefanha@redhat.com>,
	"Mads Ynddal" <mads@ynddal.dk>,
	"Peter Maydell" <peter.maydell@linaro.org>,
	"Alex Benn é e" <alex.bennee@linaro.org>,
	"Marc-Andr é Lureau" <marcandre.lureau@redhat.com>,
	"Thomas Huth" <thuth@redhat.com>,
	"Markus Armbruster" <armbru@redhat.com>,
	"Philippe Mathieu-Daud é" <philmd@linaro.org>,
	"Zhao Liu" <zhao1.liu@intel.com>,
	"Gustavo Romero" <gustavo.romero@linaro.org>,
	"Pierrick Bouvier" <pierrick.bouvier@linaro.org>,
	rowan.hart@intel.com,
	"Richard Henderson" <richard.henderson@linaro.org>,
	"John Snow" <jsnow@redhat.com>, "Cleber Rosa" <crosa@redhat.com>
Subject: Re: [RFC PATCH v3 1/5] build-sys: Add rust feature option
Date: Wed, 26 Jun 2024 11:34:08 +0200	[thread overview]
Message-ID: <99c32ec8-f1c4-45f8-b19b-6487e1b6ec61@redhat.com> (raw)
In-Reply-To: <fnopq.orjfjqf36hxp@linaro.org>

On 6/25/24 23:47, Manos Pitsidianakis wrote:
> On Mon, 24 Jun 2024 20:14, Paolo Bonzini <pbonzini@redhat.com> wrote:
>> Yes, I agree. However, considering we haven't even checked the situation
>> with what language features are required by any idiomatic bindings vs the
>> 1.63 version that we need to support for Debian, I think it's a bit
>> premature to make it mandatory.
>>
> 
> FWIW, I just ran
> 
> `cargo msrv -- cargo check --target x86_64-unknown-linux-gnu`
> 
> And the result was `The MSRV is: 1.77.2`
> 
> and the most important issue was that the mem::offset_of! macro was 
> unstable till then.

I looked for a way to avoid it and the most promising is 
https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=10a22a9b8393abd7b541d8fc844bc0df

Basically, you replace

     pub struct Foo {
         foo: i32,
         bar: i32
     }

with

     with_offsets! {
         #[repr(C)]  // mandatory
         pub struct Foo {
             foo: i32,
             bar: i32,
         }
     }

The macro walks the struct twice, once to actually declare it and once 
to determine the offsets using mem::size_of and mem::align_of.  The 
result is something like

         #[repr(C)]  // mandatory
         pub struct Foo {
             foo: i32,
             bar: i32,
         }

         pub struct FooOffsets {
             foo: usize,
             bar: usize,
         }

         impl Foo {
             pub const offset_to: FooOffsets = FooOffsets {
                 foo: 0,
                 bar: 4,
             }
         }

(where 0 and 4 are actually the aforementioned computation based on 
size_of and align_of).

There are some limitations but the trick is really well done; the need 
for #[repr(C)] is not a problem for us (C<->Rust interoperability needs 
it anyway), and the implementation is fully "const".  And though it only 
works for structs that use "with_offsets!", and with just one level of 
fields, the implementation of offset_of is trivial:

     macro_rules! offset_of {
         ($Container:ty, $field:ident) => {
             <$Container>::offset_to.$field
         };
     }

Anyhow, this should _not_ be in the first version that is 
committed---which, as you remarked in the v2, should focus on working 
build system integration.  As long as we know it is doable, it can be 
left for later.

Paolo



  reply	other threads:[~2024-06-26  9:34 UTC|newest]

Thread overview: 44+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-06-19 20:13 [RFC PATCH v3 0/5] Implement ARM PL011 in Rust Manos Pitsidianakis
2024-06-19 20:13 ` [RFC PATCH v3 1/5] build-sys: Add rust feature option Manos Pitsidianakis
2024-06-20 13:21   ` Paolo Bonzini
2024-06-20 18:06     ` Manos Pitsidianakis
2024-06-20 19:44       ` Paolo Bonzini
2024-06-24  8:51     ` Zhao Liu
2024-06-24 16:35       ` Paolo Bonzini
2024-06-20 13:41   ` Alex Bennée
2024-06-20 18:14     ` Manos Pitsidianakis
2024-06-24 16:52   ` Daniel P. Berrangé
2024-06-24 17:14     ` Paolo Bonzini
2024-06-25 21:47       ` Manos Pitsidianakis
2024-06-26  9:34         ` Paolo Bonzini [this message]
2024-07-02 14:38     ` Manos Pitsidianakis
2024-07-02 15:23       ` Paolo Bonzini
2024-06-19 20:13 ` [RFC PATCH v3 2/5] rust: add bindgen step as a meson dependency Manos Pitsidianakis
2024-06-20 11:10   ` Alex Bennée
2024-06-20 12:34     ` Paolo Bonzini
2024-06-20 18:18       ` Manos Pitsidianakis
2024-06-20 12:32   ` Alex Bennée
2024-06-20 18:22     ` Manos Pitsidianakis
2024-06-24 19:52       ` Stefan Hajnoczi
2024-06-20 14:01   ` Richard Henderson
2024-06-20 18:36     ` Manos Pitsidianakis
2024-06-20 19:30       ` Richard Henderson
2024-06-24 10:12   ` Zhao Liu
2024-06-24 10:02     ` Manos Pitsidianakis
2024-06-25 16:00       ` Zhao Liu
2024-06-25 18:08         ` Manos Pitsidianakis
2024-06-27 23:47           ` Pierrick Bouvier
2024-06-28 19:12             ` Pierrick Bouvier
2024-06-28 21:50               ` Paolo Bonzini
2024-07-01 18:53                 ` Pierrick Bouvier
2024-06-29  8:06               ` Manos Pitsidianakis
2024-07-01 18:54                 ` Pierrick Bouvier
2024-07-02 12:25                   ` Manos Pitsidianakis
2024-07-02 16:07                     ` Pierrick Bouvier
2024-06-19 20:14 ` [RFC PATCH v3 3/5] rust: add PL011 device model Manos Pitsidianakis
2024-06-19 20:14 ` [RFC PATCH v3 4/5] DO NOT MERGE: add rustdoc build for gitlab pages Manos Pitsidianakis
2024-06-19 20:14 ` [RFC PATCH v3 5/5] DO NOT MERGE: replace TYPE_PL011 with x-pl011-rust in arm virt machine Manos Pitsidianakis
2024-06-25 16:18   ` Zhao Liu
2024-06-25 18:23     ` Manos Pitsidianakis
2024-06-25 19:15     ` Daniel P. Berrangé
2024-06-25 20:43       ` Peter Maydell

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=99c32ec8-f1c4-45f8-b19b-6487e1b6ec61@redhat.com \
    --to=pbonzini@redhat.com \
    --cc=alex.bennee@linaro.org \
    --cc=armbru@redhat.com \
    --cc=berrange@redhat.com \
    --cc=crosa@redhat.com \
    --cc=gustavo.romero@linaro.org \
    --cc=jsnow@redhat.com \
    --cc=mads@ynddal.dk \
    --cc=manos.pitsidianakis@linaro.org \
    --cc=marcandre.lureau@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=rowan.hart@intel.com \
    --cc=stefanha@redhat.com \
    --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).