Commit 4c5c26548b for qemu.org
commit 4c5c26548b746e5866b2c00c353f43e6e322ad96
Author: Paolo Bonzini <pbonzini@redhat.com>
Date: Mon May 25 17:47:55 2026 +0200
rust: use meson automatic parsing of Cargo.toml
Finally, automatic parsing of Cargo.toml is also possible for QEMU's own
crates, not just for subprojects. This removes the need to list the
dependencies and language editions in both Cargo.toml and meson.build
files.
Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
diff --git a/meson.build b/meson.build
index 2593eb9762..3c6a82ab44 100644
--- a/meson.build
+++ b/meson.build
@@ -135,12 +135,7 @@ if have_rust
rustfmt = find_program('rustfmt', required: false)
- rustc_lint_args = run_command(rustc_args, '--lints',
- capture: true, check: true).stdout().strip().splitlines()
- if get_option('strict_rust_lints')
- rustc_lint_args += ['-Dwarnings', '-Funknown_lints']
- endif
-
+ rustc_lint_args = get_option('strict_rust_lints') ? ['-Dwarnings', '-Funknown_lints'] : []
add_project_arguments(rustc_lint_args + ['--cfg', 'MESON'],
native: false, language: 'rust')
add_project_arguments(rustc_lint_args + ['--cfg', 'MESON'],
diff --git a/rust/bindings/chardev-sys/meson.build b/rust/bindings/chardev-sys/meson.build
index 458075b806..7af5d74dd5 100644
--- a/rust/bindings/chardev-sys/meson.build
+++ b/rust/bindings/chardev-sys/meson.build
@@ -1,12 +1,9 @@
_bindgen_chardev_rs = rust.bindgen(
args: bindgen_args_common + bindgen_args_data['chardev-sys'].split(),
kwargs: bindgen_kwargs)
-_chardev_sys_rs = static_library(
- 'chardev_sys',
- structured_sources(['lib.rs', _bindgen_chardev_rs]),
- override_options: ['rust_std=2021', 'build.rust_std=2021'],
- rust_abi: 'rust',
- dependencies: [glib_sys_rs, common_rs, qom_sys_rs, util_sys_rs],
-)
+
+_chardev_sys_rs = cargo_ws.package('chardev-sys').library(
+ structured_sources(['lib.rs', _bindgen_chardev_rs]))
+cargo_ws.package('chardev-sys').override_dependency(declare_dependency(link_with: _chardev_sys_rs))
chardev_sys_rs = declare_dependency(link_with: [_chardev_sys_rs])
diff --git a/rust/bindings/hwcore-sys/meson.build b/rust/bindings/hwcore-sys/meson.build
index 3d51947b4a..6b8d218f69 100644
--- a/rust/bindings/hwcore-sys/meson.build
+++ b/rust/bindings/hwcore-sys/meson.build
@@ -1,12 +1,9 @@
_bindgen_hwcore_rs = rust.bindgen(
args: bindgen_args_common + bindgen_args_data['hwcore-sys'].split(),
kwargs: bindgen_kwargs)
-_hwcore_sys_rs = static_library(
- 'hwcore_sys',
- structured_sources(['lib.rs', _bindgen_hwcore_rs]),
- override_options: ['rust_std=2021', 'build.rust_std=2021'],
- rust_abi: 'rust',
- dependencies: [common_rs, glib_sys_rs, qom_sys_rs, util_sys_rs, migration_sys_rs, chardev_sys_rs],
-)
+
+_hwcore_sys_rs = cargo_ws.package('hwcore-sys').library(
+ structured_sources(['lib.rs', _bindgen_hwcore_rs]))
+cargo_ws.package('hwcore-sys').override_dependency(declare_dependency(link_with: _hwcore_sys_rs))
hwcore_sys_rs = declare_dependency(link_with: [_hwcore_sys_rs])
diff --git a/rust/bindings/migration-sys/meson.build b/rust/bindings/migration-sys/meson.build
index 9243acba30..91f2967c9b 100644
--- a/rust/bindings/migration-sys/meson.build
+++ b/rust/bindings/migration-sys/meson.build
@@ -1,12 +1,9 @@
_bindgen_migration_rs = rust.bindgen(
args: bindgen_args_common + bindgen_args_data['migration-sys'].split(),
kwargs: bindgen_kwargs)
-_migration_sys_rs = static_library(
- 'migration_sys',
- structured_sources(['lib.rs', _bindgen_migration_rs]),
- override_options: ['rust_std=2021', 'build.rust_std=2021'],
- rust_abi: 'rust',
- dependencies: [glib_sys_rs, common_rs, util_sys_rs],
-)
+
+_migration_sys_rs = cargo_ws.package('migration-sys').library(
+ structured_sources(['lib.rs', _bindgen_migration_rs]))
+cargo_ws.package('migration-sys').override_dependency(declare_dependency(link_with: _migration_sys_rs))
migration_sys_rs = declare_dependency(link_with: [_migration_sys_rs])
diff --git a/rust/bindings/qom-sys/meson.build b/rust/bindings/qom-sys/meson.build
index 8f8ae7d1bc..540e55eea8 100644
--- a/rust/bindings/qom-sys/meson.build
+++ b/rust/bindings/qom-sys/meson.build
@@ -1,12 +1,9 @@
_bindgen_qom_rs = rust.bindgen(
args: bindgen_args_common + bindgen_args_data['qom-sys'].split(),
kwargs: bindgen_kwargs)
-_qom_sys_rs = static_library(
- 'qom_sys',
- structured_sources(['lib.rs', _bindgen_qom_rs]),
- override_options: ['rust_std=2021', 'build.rust_std=2021'],
- rust_abi: 'rust',
- dependencies: [glib_sys_rs, util_sys_rs],
-)
+
+_qom_sys_rs = cargo_ws.package('qom-sys').library(
+ structured_sources(['lib.rs', _bindgen_qom_rs]))
+cargo_ws.package('qom-sys').override_dependency(declare_dependency(link_with: _qom_sys_rs))
qom_sys_rs = declare_dependency(link_with: [_qom_sys_rs])
diff --git a/rust/bindings/system-sys/meson.build b/rust/bindings/system-sys/meson.build
index aa5e880114..b1f4770499 100644
--- a/rust/bindings/system-sys/meson.build
+++ b/rust/bindings/system-sys/meson.build
@@ -1,12 +1,9 @@
_bindgen_system_rs = rust.bindgen(
args: bindgen_args_common + bindgen_args_data['system-sys'].split(),
kwargs: bindgen_kwargs)
-_system_sys_rs = static_library(
- 'system_sys',
- structured_sources(['lib.rs', _bindgen_system_rs]),
- override_options: ['rust_std=2021', 'build.rust_std=2021'],
- rust_abi: 'rust',
- dependencies: [common_rs, glib_sys_rs, hwcore_sys_rs, migration_sys_rs, qom_sys_rs, util_sys_rs],
-)
+
+_system_sys_rs = cargo_ws.package('system-sys').library(
+ structured_sources(['lib.rs', _bindgen_system_rs]))
+cargo_ws.package('system-sys').override_dependency(declare_dependency(link_with: _system_sys_rs))
system_sys_rs = declare_dependency(link_with: [_system_sys_rs])
diff --git a/rust/bindings/util-sys/meson.build b/rust/bindings/util-sys/meson.build
index c37f50a94b..5a9db6152e 100644
--- a/rust/bindings/util-sys/meson.build
+++ b/rust/bindings/util-sys/meson.build
@@ -1,12 +1,9 @@
_bindgen_util_rs = rust.bindgen(
args: bindgen_args_common + bindgen_args_data['util-sys'].split(),
kwargs: bindgen_kwargs)
-_util_sys_rs = static_library(
- 'util_sys',
- structured_sources(['lib.rs', _bindgen_util_rs]),
- override_options: ['rust_std=2021', 'build.rust_std=2021'],
- rust_abi: 'rust',
- dependencies: [glib_sys_rs],
-)
+
+_util_sys_rs = cargo_ws.package('util-sys').library(
+ structured_sources(['lib.rs', _bindgen_util_rs]))
+cargo_ws.package('util-sys').override_dependency(declare_dependency(link_with: _util_sys_rs))
util_sys_rs = declare_dependency(link_with: [_util_sys_rs])
diff --git a/rust/bits/meson.build b/rust/bits/meson.build
index c0094ffcf3..c64a17ba15 100644
--- a/rust/bits/meson.build
+++ b/rust/bits/meson.build
@@ -1,8 +1,5 @@
-_bits_rs = static_library(
- 'bits',
- 'src/lib.rs',
- dependencies: [qemu_macros],
-)
+_bits_rs = cargo_ws.package('bits').library()
+cargo_ws.package('bits').override_dependency(declare_dependency(link_with: _bits_rs))
bits_rs = declare_dependency(link_with: _bits_rs)
diff --git a/rust/bql/meson.build b/rust/bql/meson.build
index de295d2983..8bdc9b53a2 100644
--- a/rust/bql/meson.build
+++ b/rust/bql/meson.build
@@ -1,17 +1,10 @@
-_bql_cfg = run_command(rustc_args,
- '--config-headers', config_host_h, '--features', files('Cargo.toml'),
- capture: true, check: true).stdout().strip().splitlines()
-
+_bql_cfg = []
if get_option('debug_mutex')
_bql_cfg += ['--cfg', 'feature="debug_cell"']
endif
-_bql_rs = static_library(
- 'bql',
- 'src/lib.rs',
- rust_args: _bql_cfg,
- dependencies: [glib_sys_rs, util_sys_rs],
-)
+_bql_rs = cargo_ws.package('bql').library(rust_args: _bql_cfg)
+cargo_ws.package('bql').override_dependency(declare_dependency(link_with: _bql_rs))
bql_rs = declare_dependency(link_with: [_bql_rs],
dependencies: [qemuutil])
diff --git a/rust/chardev/meson.build b/rust/chardev/meson.build
index 7b267fd23a..f3462e9209 100644
--- a/rust/chardev/meson.build
+++ b/rust/chardev/meson.build
@@ -1,8 +1,4 @@
-_chardev_rs = static_library(
- 'chardev',
- 'src/lib.rs',
- link_with: [_bql_rs, _migration_rs, _qom_rs, _util_rs],
- dependencies: [glib_sys_rs, common_rs, qemu_macros, chardev_sys_rs],
-)
+_chardev_rs = cargo_ws.package('chardev').library()
+cargo_ws.package('chardev').override_dependency(declare_dependency(link_with: _chardev_rs))
chardev_rs = declare_dependency(link_with: [_chardev_rs], dependencies: [chardev, qemuutil])
diff --git a/rust/common/meson.build b/rust/common/meson.build
index 57091b18fc..43afe417dc 100644
--- a/rust/common/meson.build
+++ b/rust/common/meson.build
@@ -1,13 +1,9 @@
_common_cfg = run_command(rustc_args,
- '--config-headers', config_host_h, '--features', files('Cargo.toml'),
+ '--config-headers', config_host_h, files('Cargo.toml'),
capture: true, check: true).stdout().strip().splitlines()
-_common_rs = static_library(
- 'common',
- 'src/lib.rs',
- rust_args: _common_cfg,
- dependencies: [libc_rs, qemu_macros],
-)
+_common_rs = cargo_ws.package('common').library(rust_args: _common_cfg)
+cargo_ws.package('common').override_dependency(declare_dependency(link_with: _common_rs))
common_rs = declare_dependency(link_with: [_common_rs])
diff --git a/rust/hw/char/pl011/meson.build b/rust/hw/char/pl011/meson.build
index 1a1a09e508..92b7d375f7 100644
--- a/rust/hw/char/pl011/meson.build
+++ b/rust/hw/char/pl011/meson.build
@@ -8,8 +8,7 @@ _libpl011_bindings_inc_rs = rust.bindgen(
kwargs: bindgen_kwargs,
)
-_libpl011_rs = static_library(
- 'pl011',
+_libpl011_rs = cargo_ws.package('pl011').library(
structured_sources(
[
'src/lib.rs',
@@ -19,25 +18,6 @@ _libpl011_rs = static_library(
],
{'.' : _libpl011_bindings_inc_rs},
),
- override_options: ['rust_std=2021', 'build.rust_std=2021'],
- rust_abi: 'rust',
- link_with: [
- _util_rs,
- _migration_rs,
- _bql_rs,
- _qom_rs,
- _chardev_rs,
- _system_rs,
- _hwcore_rs,
- _trace_rs
- ],
- dependencies: [
- bilge_rs,
- bilge_impl_rs,
- bits_rs,
- common_rs,
- glib_sys_rs,
- ],
)
rust_devices_ss.add(when: 'CONFIG_X_PL011_RUST', if_true: [declare_dependency(
diff --git a/rust/hw/core/meson.build b/rust/hw/core/meson.build
index 6d1bfd4d20..da0f13d314 100644
--- a/rust/hw/core/meson.build
+++ b/rust/hw/core/meson.build
@@ -1,11 +1,5 @@
-_hwcore_rs = static_library(
- 'hwcore',
- 'src/lib.rs',
- override_options: ['rust_std=2021', 'build.rust_std=2021'],
- rust_abi: 'rust',
- link_with: [_bql_rs, _chardev_rs, _migration_rs, _qom_rs, _util_rs],
- dependencies: [glib_sys_rs, qemu_macros, common_rs, hwcore_sys_rs],
-)
+_hwcore_rs = cargo_ws.package('hwcore').library()
+cargo_ws.package('hwcore').override_dependency(declare_dependency(link_with: _hwcore_rs))
hwcore_rs = declare_dependency(link_with: [_hwcore_rs],
dependencies: [qom_rs, hwcore])
diff --git a/rust/hw/timer/hpet/meson.build b/rust/hw/timer/hpet/meson.build
index 3bb7ce2a6c..419e8f40b7 100644
--- a/rust/hw/timer/hpet/meson.build
+++ b/rust/hw/timer/hpet/meson.build
@@ -1,19 +1,4 @@
-_libhpet_rs = static_library(
- 'hpet',
- files('src/lib.rs'),
- override_options: ['rust_std=2021', 'build.rust_std=2021'],
- rust_abi: 'rust',
- link_with: [
- _util_rs,
- _migration_rs,
- _bql_rs,
- _qom_rs,
- _system_rs,
- _hwcore_rs,
- _trace_rs,
- ],
- dependencies: [common_rs],
-)
+_libhpet_rs = cargo_ws.package('hpet').library()
rust_devices_ss.add(when: 'CONFIG_X_HPET_RUST', if_true: [declare_dependency(
link_whole: [_libhpet_rs],
diff --git a/rust/meson.build b/rust/meson.build
index 1622a50a97..c0c4e52c1b 100644
--- a/rust/meson.build
+++ b/rust/meson.build
@@ -5,17 +5,6 @@ else
endif
cargo_ws = import('rust').workspace()
-anyhow_rs = cargo_ws.subproject('anyhow').dependency()
-bilge_rs = cargo_ws.subproject('bilge').dependency()
-bilge_impl_rs = cargo_ws.subproject('bilge-impl').dependency()
-foreign_rs = cargo_ws.subproject('foreign').dependency()
-glib_sys_rs = cargo_ws.subproject('glib-sys').dependency()
-libc_rs = cargo_ws.subproject('libc').dependency()
-probe_rs = cargo_ws.subproject('probe').dependency()
-quote_rs_native = cargo_ws.subproject('quote').dependency()
-syn_rs_native = cargo_ws.subproject('syn').dependency()
-proc_macro2_rs_native = cargo_ws.subproject('proc-macro2').dependency()
-attrs_rs_native = cargo_ws.subproject('attrs').dependency()
genrs = []
diff --git a/rust/migration/meson.build b/rust/migration/meson.build
index 9626689777..b9ba82989e 100644
--- a/rust/migration/meson.build
+++ b/rust/migration/meson.build
@@ -1,9 +1,5 @@
-_migration_rs = static_library(
- 'migration',
- 'src/lib.rs',
- link_with: [_util_rs, _bql_rs],
- dependencies: [common_rs, glib_sys_rs, qemu_macros, migration_sys_rs],
-)
+_migration_rs = cargo_ws.package('migration').library()
+cargo_ws.package('migration').override_dependency(declare_dependency(link_with: _migration_rs))
migration_rs = declare_dependency(link_with: [_migration_rs],
dependencies: [bql_rs, migration, qemuutil])
diff --git a/rust/qemu-macros/meson.build b/rust/qemu-macros/meson.build
index cdea5bf439..7b25ccefe3 100644
--- a/rust/qemu-macros/meson.build
+++ b/rust/qemu-macros/meson.build
@@ -1,13 +1,5 @@
-_qemu_macros_rs = rust.proc_macro(
- 'qemu_macros',
- files('src/lib.rs'),
- dependencies: [
- attrs_rs_native,
- proc_macro2_rs_native,
- quote_rs_native,
- syn_rs_native,
- ],
-)
+_qemu_macros_rs = cargo_ws.package('qemu_macros').proc_macro()
+cargo_ws.package('qemu_macros').override_dependency(declare_dependency(link_with: _qemu_macros_rs))
qemu_macros = declare_dependency(
link_with: _qemu_macros_rs,
diff --git a/rust/qom/meson.build b/rust/qom/meson.build
index 9865da280c..6736cfb24c 100644
--- a/rust/qom/meson.build
+++ b/rust/qom/meson.build
@@ -1,9 +1,5 @@
-_qom_rs = static_library(
- 'qom',
- 'src/lib.rs',
- link_with: [_bql_rs, _migration_rs],
- dependencies: [common_rs, glib_sys_rs, qemu_macros, qom_sys_rs],
-)
+_qom_rs = cargo_ws.package('qom').library()
+cargo_ws.package('qom').override_dependency(declare_dependency(link_with: _qom_rs))
qom_rs = declare_dependency(link_with: [_qom_rs], dependencies: [qemu_macros, qom, qemuutil])
diff --git a/rust/system/meson.build b/rust/system/meson.build
index 89c1f2b84d..b1edcd6bbe 100644
--- a/rust/system/meson.build
+++ b/rust/system/meson.build
@@ -1,9 +1,5 @@
-_system_rs = static_library(
- 'system',
- 'src/lib.rs',
- link_with: [_bql_rs, _hwcore_rs, _migration_rs, _qom_rs, _util_rs],
- dependencies: [glib_sys_rs, common_rs, qemu_macros, system_sys_rs],
-)
+_system_rs = cargo_ws.package('system').library()
+cargo_ws.package('system').override_dependency(declare_dependency(link_with: _system_rs))
system_rs = declare_dependency(link_with: [_system_rs],
dependencies: [hwcore])
diff --git a/rust/trace/meson.build b/rust/trace/meson.build
index 0071a49cf7..b049f73b54 100644
--- a/rust/trace/meson.build
+++ b/rust/trace/meson.build
@@ -7,11 +7,8 @@ lib_rs = configure_file(
'MESON_BUILD_ROOT': meson.project_build_root(),
})
-_trace_rs = static_library(
- 'trace', # Library name,
- lib_rs,
- trace_rs_targets, # List of generated `.rs` custom targets
- dependencies: [libc_rs, probe_rs],
-)
+_trace_rs = cargo_ws.package('trace').library(
+ structured_sources([lib_rs, trace_rs_targets]))
+cargo_ws.package('trace').override_dependency(declare_dependency(link_with: _trace_rs))
trace_rs = declare_dependency(link_with: _trace_rs)
diff --git a/rust/util/meson.build b/rust/util/meson.build
index 6d175ae0b0..704501b573 100644
--- a/rust/util/meson.build
+++ b/rust/util/meson.build
@@ -1,8 +1,5 @@
-_util_rs = static_library(
- 'util',
- 'src/lib.rs',
- dependencies: [anyhow_rs, libc_rs, foreign_rs, glib_sys_rs, common_rs, util_sys_rs],
-)
+_util_rs = cargo_ws.package('util').library()
+cargo_ws.package('util').override_dependency(declare_dependency(link_with: _util_rs))
util_rs = declare_dependency(link_with: [_util_rs], dependencies: [qemuutil, qom])