Skip to contentSkip to conversation

meson: check in main meson.build for native Rust compiler

PATCH In review Paolo Bonzini 2 participants 5 messages Oct 14, 2024

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 meson: check in main meson.build for native Rust compiler

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.

---
 meson.build                      | 3 ++-
 rust/qemu-api-macros/meson.build | 2 --
 2 files changed, 2 insertions(+), 3 deletions(-)
meson.build +2 -1
index aecc381932d..c85f964bed4 100644
@@ -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')
rust/qemu-api-macros/meson.build +0 -2
index 48af91ed389..517b9a4d2d5 100644
@@ -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)
Signature · 1 line
2.46.2
#1 lore raw
Quoted 16 lines · Paolo Bonzini

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.

Quoted 8 lines

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

---
 meson.build                      | 3 ++-
 rust/qemu-api-macros/meson.build | 2 --
 2 files changed, 2 insertions(+), 3 deletions(-)

Missing Signed-off-by: line ?

Quoted 26 lines
meson.build +2 -1
index aecc381932d..c85f964bed4 100644
@@ -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')
rust/qemu-api-macros/meson.build +0 -3
index 48af91ed389..517b9a4d2d5 100644
@@ -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)
--
Quoted 1 line

2.46.

thanks
-- PMM

#2 lore raw
Quoted 21 lines · Peter Maydell
Quoted 19 lines · Paolo Bonzini

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.

Quoted 7 lines
Quoted 5 lines
---
 meson.build                      | 3 ++-
 rust/qemu-api-macros/meson.build | 2 --
 2 files changed, 2 insertions(+), 3 deletions(-)

Missing Signed-off-by: line ?

Oh, and is there any better order in which to apply this patch and your other fix, or does it not matter?

-- PMM

#3 lore raw
Quoted 23 lines · Peter Maydell
Quoted 21 lines · Peter Maydell
Quoted 19 lines · Paolo Bonzini

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.

Quoted 7 lines
Quoted 7 lines
Quoted 5 lines
---
 meson.build                      | 3 ++-
 rust/qemu-api-macros/meson.build | 2 --
 2 files changed, 2 insertions(+), 3 deletions(-)

Missing Signed-off-by: line ?

Ugh, yes (my OpenBSD VM does not have the usual git hooks :)).

Quoted 2 lines

Oh, and is there any better order in which to apply this patch and your other fix, or does it not matter?

It's not super important but I guess this one could go first, since it affects non-incremental builds (as in CI) as well.

Paolo

#4 lore raw
In reply to Paolo Bonzini
Quoted 16 lines · Paolo Bonzini

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.

Quoted 5 lines

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

---

Applied directly to git, thanks.

-- PMM