[RFC PATCH 09/11] rust: build: add "make clippy", "make rustfmt"

Paolo Bonzini posted 11 patches 2 weeks, 1 day ago
There is a newer version of this series
[RFC PATCH 09/11] rust: build: add "make clippy", "make rustfmt"
Posted by Paolo Bonzini 2 weeks, 1 day ago
Abstract common invocations of "cargo", that do not require copying
the generated bindgen file or setting up MESON_BUILD_ROOT.

In the future these could also do completely without cargo and invoke
the underlying programs directly.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
 rust/meson.build       | 14 ++++++++++++++
 rust/qemu-api/build.rs |  8 ++++++--
 2 files changed, 20 insertions(+), 2 deletions(-)

diff --git a/rust/meson.build b/rust/meson.build
index def77389cdd..6fa0fd54527 100644
--- a/rust/meson.build
+++ b/rust/meson.build
@@ -2,3 +2,17 @@ subdir('qemu-api-macros')
 subdir('qemu-api')
 
 subdir('hw')
+
+cargo = find_program('cargo')
+
+run_target('clippy',
+  command: [config_host['MESON'], 'devenv',
+            '--workdir', '@CURRENT_SOURCE_DIR@',
+            cargo, 'clippy', '--tests'],
+  depends: bindings_rs)
+
+run_target('rustfmt',
+  command: [config_host['MESON'], 'devenv',
+            '--workdir', '@CURRENT_SOURCE_DIR@',
+            cargo, 'fmt'],
+  depends: bindings_rs)
diff --git a/rust/qemu-api/build.rs b/rust/qemu-api/build.rs
index e4eab718553..d7b6d76828b 100644
--- a/rust/qemu-api/build.rs
+++ b/rust/qemu-api/build.rs
@@ -15,8 +15,12 @@ fn main() {
     let file = format!("{}/bindings.rs.inc", path);
     if !Path::new(&file).exists() {
         panic!(concat!(
-            "No generated C bindings found! If you want to run `cargo`, start a subshell\n",
-            "with `meson devenv`, or point MESON_BUILD_ROOT to the top of the build tree."
+            "\n",
+            "    No generated C bindings found! To run clippy or rustfmt, you can use\n",
+            "    `make clippy` or `make rustfmt`.\n",
+            "\n",
+            "    For other uses of `cargo`, start a subshell with `meson devenv`, or\n",
+            "    point MESON_BUILD_ROOT to the top of the build tree."
         ));
     }
 
-- 
2.47.0
Re: [RFC PATCH 09/11] rust: build: add "make clippy", "make rustfmt"
Posted by Junjie Mao 1 week, 3 days ago
Paolo Bonzini <pbonzini@redhat.com> writes:

> Abstract common invocations of "cargo", that do not require copying
> the generated bindgen file or setting up MESON_BUILD_ROOT.
>
> In the future these could also do completely without cargo and invoke
> the underlying programs directly.
>
> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>

Reviewed-by: Junjie Mao <junjie.mao@hotmail.com>

--
Best Regards
Junjie Mao