qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] meson: check in main meson.build for native Rust compiler
@ 2024-10-14 14:36 Paolo Bonzini
  2024-10-14 14:38 ` Peter Maydell
  2024-10-14 16:04 ` Peter Maydell
  0 siblings, 2 replies; 5+ messages in thread
From: Paolo Bonzini @ 2024-10-14 14:36 UTC (permalink / raw)
  To: qemu-devel; +Cc: Peter Maydell

A working native Rust compiler is always needed in order to compile Rust
code, even when cross compiling, in order to build the procedural macros
that QEMU uses.

Right now, the check is done in rust/qemu-api-macros/meson.build, but this
has two disadvantages.  First, it makes the build fail when the Meson "rust"
option is set to "auto" (instead, Rust support should be disabled).  Second,
add_languages() is one of the few functions that are executed even by
"meson introspect", except that "meson introspect" executes both branches
of "if" statements!  Therefore, "meson introspect" tries to look for a
Rust compiler even if the option is disabled---and then fails because
the compiler is required by rust/qemu-api-macros/meson.build.  This is
visible for example if the compilation host has a stale
scripts/meson-buildoptions.sh and no rustc installed.

Both issues can be fixed by moving the check to the main meson.build,
together with the check for the cross compiler.

Reported-by: Peter Maydell <peter.maydell@linaro.org>
---
 meson.build                      | 3 ++-
 rust/qemu-api-macros/meson.build | 2 --
 2 files changed, 2 insertions(+), 3 deletions(-)

diff --git a/meson.build b/meson.build
index aecc381932d..c85f964bed4 100644
--- a/meson.build
+++ b/meson.build
@@ -71,7 +71,8 @@ if host_os == 'darwin' and \
   objc = meson.get_compiler('objc')
 endif
 have_rust = false
-if not get_option('rust').disabled() and add_languages('rust', required: get_option('rust'), native: false)
+if not get_option('rust').disabled() and add_languages('rust', required: get_option('rust'), native: false) \
+    and add_languages('rust', required: get_option('rust'), native: true)
   rustc = meson.get_compiler('rust')
   have_rust = true
   if rustc.version().version_compare('<1.80.0')
diff --git a/rust/qemu-api-macros/meson.build b/rust/qemu-api-macros/meson.build
index 48af91ed389..517b9a4d2d5 100644
--- a/rust/qemu-api-macros/meson.build
+++ b/rust/qemu-api-macros/meson.build
@@ -1,5 +1,3 @@
-add_languages('rust', required: true, native: true)
-
 quote_dep = dependency('quote-1-rs', native: true)
 syn_dep = dependency('syn-2-rs', native: true)
 proc_macro2_dep = dependency('proc-macro2-1-rs', native: true)
-- 
2.46.2



^ permalink raw reply related	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2024-10-14 16:05 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-10-14 14:36 [PATCH] meson: check in main meson.build for native Rust compiler Paolo Bonzini
2024-10-14 14:38 ` Peter Maydell
2024-10-14 14:40   ` Peter Maydell
2024-10-14 14:43     ` Paolo Bonzini
2024-10-14 16:04 ` Peter Maydell

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).