From: "Alex Bennée" <alex.bennee@linaro.org>
To: Manos Pitsidianakis <manos.pitsidianakis@linaro.org>
Cc: qemu-devel@nongnu.org, "Stefan Hajnoczi" <stefanha@redhat.com>,
"Mads Ynddal" <mads@ynddal.dk>,
"Peter Maydell" <peter.maydell@linaro.org>,
"Daniel P. Berrangé" <berrange@redhat.com>,
"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>,
"Paolo Bonzini" <pbonzini@redhat.com>,
"John Snow" <jsnow@redhat.com>, "Cleber Rosa" <crosa@redhat.com>
Subject: Re: [RFC PATCH v3 2/5] rust: add bindgen step as a meson dependency
Date: Thu, 20 Jun 2024 13:32:25 +0100 [thread overview]
Message-ID: <8734p7dcbq.fsf@draig.linaro.org> (raw)
In-Reply-To: <6bf311a35e6d3bfa8b3bfd10d8f896a9e655fa30.1718827153.git.manos.pitsidianakis@linaro.org> (Manos Pitsidianakis's message of "Wed, 19 Jun 2024 23:13:59 +0300")
Manos Pitsidianakis <manos.pitsidianakis@linaro.org> writes:
> Add mechanism to generate rust hw targets that depend on a custom
> bindgen target for rust bindings to C.
>
> This way bindings will be created before the rust crate is compiled.
>
> The bindings will end up in BUILDDIR/{target}-generated.rs and have the same name
> as a target:
>
> ninja aarch64-softmmu-generated.rs
>
<snip>
> +
> +
> +rust_targets = {}
> +
> +cargo_wrapper = [
> + find_program(meson.global_source_root() / 'scripts/cargo_wrapper.py'),
> + '--config-headers', meson.project_build_root() / 'config-host.h',
> + '--meson-build-root', meson.project_build_root(),
> + '--meson-build-dir', meson.current_build_dir(),
> + '--meson-source-dir', meson.current_source_dir(),
> +]
I'm unclear what the difference between meson-build-root and
meson-build-dir is?
We also end up defining crate-dir and outdir. Aren't these all
derivable from whatever module we are building?
> +
> +if get_option('b_colorout') != 'never'
> + cargo_wrapper += ['--color', 'always']
> +endif
> +
> +if get_option('optimization') in ['0', '1', 'g']
> + rs_build_type = 'debug'
> +else
> + rs_build_type = 'release'
> +endif
> +
> +# Collect metadata for each (crate,qemu-target,compiler-target) combination.
> +# Rust meson targets cannot be defined a priori because they depend on bindgen
> +# generation that is created for each emulation target separately. Thus Rust
> +# meson targets will be defined for each target after the target-specific
> +# bindgen dependency is declared.
> +rust_hw_target_list = {}
> +
> +foreach rust_hw_target, rust_hws: rust_hw_target_list
> + foreach rust_hw_dev: rust_hws
> + output = meson.current_build_dir() / rust_target_triple / rs_build_type / rust_hw_dev['output']
> + crate_metadata = {
> + 'name': rust_hw_dev['name'],
> + 'output': [rust_hw_dev['output']],
> + 'output-path': output,
> + 'command': [cargo_wrapper,
> + '--crate-dir', meson.current_source_dir() / rust_hw_dev['dirname'],
> + '--profile', rs_build_type,
> + '--target-triple', rust_target_triple,
> + '--outdir', '@OUTDIR@',
> + 'build-lib'
> + ]
> + }
> + rust_targets += { rust_hw_target: [crate_metadata] }
> + endforeach
> +endforeach
> diff --git a/rust/wrapper.h b/rust/wrapper.h
> new file mode 100644
> index 0000000000..bcf808c8d7
> --- /dev/null
> +++ b/rust/wrapper.h
> @@ -0,0 +1,39 @@
> +/*
> + * QEMU System Emulator
> + *
> + * Copyright (c) 2003-2020 Fabrice Bellard
> + *
> + * Permission is hereby granted, free of charge, to any person obtaining a copy
> + * of this software and associated documentation files (the "Software"), to deal
> + * in the Software without restriction, including without limitation the rights
> + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
> + * copies of the Software, and to permit persons to whom the Software is
> + * furnished to do so, subject to the following conditions:
> + *
> + * The above copyright notice and this permission notice shall be included in
> + * all copies or substantial portions of the Software.
> + *
> + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
> + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
> + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
> + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
> + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
> + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
> + * THE SOFTWARE.
> + */
> +
> +#include "qemu/osdep.h"
> +#include "qemu/module.h"
> +#include "qemu-io.h"
> +#include "sysemu/sysemu.h"
> +#include "hw/sysbus.h"
> +#include "exec/memory.h"
> +#include "chardev/char-fe.h"
> +#include "hw/clock.h"
> +#include "hw/qdev-clock.h"
> +#include "hw/qdev-properties.h"
> +#include "hw/qdev-properties-system.h"
> +#include "hw/irq.h"
> +#include "qapi/error.h"
> +#include "migration/vmstate.h"
> +#include "chardev/char-serial.h"
> diff --git a/scripts/cargo_wrapper.py b/scripts/cargo_wrapper.py
> index 927336f80e..833e0e55f8 100644
> --- a/scripts/cargo_wrapper.py
> +++ b/scripts/cargo_wrapper.py
> @@ -111,6 +111,8 @@ def get_cargo_rustc(args: argparse.Namespace) -> tuple[Dict[str, Any], List[str]
>
> env = os.environ
> env["CARGO_ENCODED_RUSTFLAGS"] = cfg
> + env["MESON_BUILD_DIR"] = str(target_dir)
> + env["MESON_BUILD_ROOT"] = str(args.meson_build_root)
>
> return (env, cargo_cmd)
>
> @@ -234,6 +236,14 @@ def main() -> None:
> required=True,
> )
> parser.add_argument(
> + "--meson-build-root",
> + metavar="BUILD_ROOT",
> + help="meson.project_build_root()",
> + type=Path,
> + dest="meson_build_root",
> + required=True,
> + )
> + parser.add_argument(
> "--meson-source-dir",
> metavar="SOURCE_DIR",
> help="meson.current_source_dir()",
--
Alex Bennée
Virtualisation Tech Lead @ Linaro
next prev parent reply other threads:[~2024-06-20 12:33 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
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 [this message]
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=8734p7dcbq.fsf@draig.linaro.org \
--to=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=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=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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.