rust: do not generate GLib bindings
Subsystems (2)
cover rust: do not generate GLib bindings
Don't generate FFI for glib, rely on glib-sys crate. This makes it possible to limit Rust to the same minimum version as C code.
The disadvantage is that each bindings module needs to import from glib explicitly.
The extra lines in Cargo.lock are all build dependencies that are not used by Meson. They are only used for glib-sys's build.rs rules, when running e.g. "cargo check".
Marc-André Lureau (1):
rust: use glib-sys
subprojects: add glib-sys-rs
meson.build | 1 + include/hw/core/cpu.h | 2 +- rust/Cargo.lock | 182 ++++++++++++++++++ rust/Cargo.toml | 1 + rust/bql/Cargo.toml | 3 + rust/bql/meson.build | 1 + rust/bql/src/bindings.rs | 4 + rust/chardev/Cargo.toml | 1 + rust/chardev/meson.build | 2 +- rust/chardev/src/bindings.rs | 4 + rust/hw/char/pl011/Cargo.toml | 1 + rust/hw/char/pl011/meson.build | 1 + rust/hw/char/pl011/src/bindings.rs | 5 + rust/hw/core/Cargo.toml | 1 + rust/hw/core/meson.build | 2 +- rust/hw/core/src/bindings.rs | 3 + rust/meson.build | 2 + rust/migration/Cargo.toml | 1 + rust/migration/meson.build | 2 +- rust/migration/src/bindings.rs | 1 + rust/qom/Cargo.toml | 1 + rust/qom/meson.build | 2 +- rust/qom/src/bindings.rs | 2 + rust/system/Cargo.toml | 1 + rust/system/meson.build | 2 +- rust/system/src/bindings.rs | 4 + rust/util/Cargo.toml | 1 + rust/util/meson.build | 2 +- rust/util/src/bindings.rs | 2 + scripts/archive-source.sh | 1 + subprojects/.gitignore | 1 + subprojects/glib-sys-0.21-rs.wrap | 7 + .../packagefiles/glib-sys-0.21-rs/meson.build | 33 ++++ 33 files changed, 272 insertions(+), 7 deletions(-) create mode 100644 subprojects/glib-sys-0.21-rs.wrap create mode 100644 subprojects/packagefiles/glib-sys-0.21-rs/meson.build
Signature · 1 line
2.51.0
PATCH 1/2 subprojects: add glib-sys-rs
From: Marc-André Lureau <[email protected]>
Signed-off-by Marc-André Lureau <[email protected]>
Signed-off-by Paolo Bonzini <[email protected]>
--- rust/meson.build | 2 ++ scripts/archive-source.sh | 1 + subprojects/.gitignore | 1 + subprojects/glib-sys-0.21-rs.wrap | 7 ++++ .../packagefiles/glib-sys-0.21-rs/meson.build | 33 +++++++++++++++++++ 5 files changed, 44 insertions(+) create mode 100644 subprojects/glib-sys-0.21-rs.wrap create mode 100644 subprojects/packagefiles/glib-sys-0.21-rs/meson.build
rust/meson.build +2 -0
@@ -2,12 +2,14 @@ subproject('anyhow-1-rs', required: true) subproject('bilge-0.2-rs', required: true) subproject('bilge-impl-0.2-rs', required: true) subproject('foreign-0.3-rs', required: true) +subproject('glib-sys-0.21-rs', required: true) subproject('libc-0.2-rs', required: true) anyhow_rs = dependency('anyhow-1-rs') bilge_rs = dependency('bilge-0.2-rs') bilge_impl_rs = dependency('bilge-impl-0.2-rs') foreign_rs = dependency('foreign-0.3-rs') +glib_sys_rs = dependency('glib-sys-0.21-rs') libc_rs = dependency('libc-0.2-rs') subproject('proc-macro2-1-rs', required: true)
scripts/archive-source.sh +1 -0
@@ -36,6 +36,7 @@ subprojects=( bilge-impl-0.2-rs either-1-rs foreign-0.3-rs + glib-sys-0.21-rs itertools-0.11-rs keycodemapdb libc-0.2-rs
subprojects/.gitignore +1 -0
@@ -13,6 +13,7 @@ /bilge-impl-* /either-* /foreign-* +/glib-sys-* /itertools-* /libc-* /proc-macro-error-*
subprojects/glib-sys-0.21-rs.wrap new file +7 -0
@@ -0,0 +1,7 @@ +[wrap-file] +directory = glib-sys-0.21.2 +source_url = https://crates.io/api/v1/crates/glib-sys/0.21.2/download +source_filename = glib-sys-0.21.2.tar.gz +source_hash = d09d3d0fddf7239521674e57b0465dfbd844632fec54f059f7f56112e3f927e1 +#method = cargo +patch_directory = glib-sys-0.21-rs
subprojects/packagefiles/glib-sys-0.21-rs/meson.build new file +33 -0
@@ -0,0 +1,33 @@ +project('glib-sys-0.21-rs', 'rust', + meson_version: '>=1.5.0', + version: '0.21.2', + license: 'MIT', + default_options: []) + +subproject('libc-0.2-rs', required: true) +libc_rs = dependency('libc-0.2-rs') + +_glib_sys_rs = static_library( + 'glib_sys', + files('src/lib.rs'), + gnu_symbol_visibility: 'hidden', + override_options: ['rust_std=2021', 'build.rust_std=2021'], + rust_abi: 'rust', + rust_args: [ + '--cap-lints', 'allow', + '--cfg', 'feature="v2_66"', + '--cfg', 'feature="v2_64"', + '--cfg', 'feature="v2_62"', + '--cfg', 'feature="v2_60"', + '--cfg', 'feature="v2_58"', + ], + # should also link with glib; don't bother doing it here since all + # QEMU targets have it + dependencies: [libc_rs], +) + +glib_sys_dep = declare_dependency( + link_with: _glib_sys_rs, +) + +meson.override_dependency('glib-sys-0.21-rs', glib_sys_dep)
Signature · 1 line
2.51.0
PATCH 2/2 rust: use glib-sys
In reply to Paolo BonziniFrom: Marc-André Lureau <[email protected]>
Don't generate FFI for glib, rely on glib-sys crate.
Signed-off-by Marc-André Lureau <[email protected]>
Signed-off-by Paolo Bonzini <[email protected]>
--- meson.build | 1 + include/hw/core/cpu.h | 2 +- rust/Cargo.lock | 182 +++++++++++++++++++++++++++++ rust/Cargo.toml | 1 + rust/bql/Cargo.toml | 3 + rust/bql/meson.build | 1 + rust/bql/src/bindings.rs | 4 + rust/chardev/Cargo.toml | 1 + rust/chardev/meson.build | 2 +- rust/chardev/src/bindings.rs | 4 + rust/hw/char/pl011/Cargo.toml | 1 + rust/hw/char/pl011/meson.build | 1 + rust/hw/char/pl011/src/bindings.rs | 5 + rust/hw/core/Cargo.toml | 1 + rust/hw/core/meson.build | 2 +- rust/hw/core/src/bindings.rs | 3 + rust/migration/Cargo.toml | 1 + rust/migration/meson.build | 2 +- rust/migration/src/bindings.rs | 1 + rust/qom/Cargo.toml | 1 + rust/qom/meson.build | 2 +- rust/qom/src/bindings.rs | 2 + rust/system/Cargo.toml | 1 + rust/system/meson.build | 2 +- rust/system/src/bindings.rs | 4 + rust/util/Cargo.toml | 1 + rust/util/meson.build | 2 +- rust/util/src/bindings.rs | 2 + 28 files changed, 228 insertions(+), 7 deletions(-)
meson.build +1 -0
@@ -4239,6 +4239,7 @@ if have_rust '--no-prepend-enum-name', '--allowlist-file', meson.project_source_root() + '/include/.*', '--allowlist-file', meson.project_build_root() + '/.*', + '--blocklist-file', glib_pc.get_variable('includedir') + '/glib-2.0/.*', ] if not rustfmt.found() if bindgen.version().version_compare('<0.65.0')
include/hw/core/cpu.h +1 -1
@@ -169,7 +169,7 @@ struct CPUClass {vaddr (*gdb_adjust_breakpoint)(CPUState *cpu,vaddr addr);const char *gdb_core_xml_file; -const gchar * (*gdb_arch_name)(CPUState *cpu); +const char * (*gdb_arch_name)(CPUState *cpu);const char * (*gdb_get_core_xml_file)(CPUState *cpu);void (*disas_set_info)(CPUState *cpu,disassemble_info *info);
rust/Cargo.lock +182 -0
279 lines not on this page · raw message
rust/Cargo.toml +1 -0
@@ -29,6 +29,7 @@ authors = ["The QEMU Project Developers <[email protected]>"] anyhow = "~1.0" foreign = "~0.3.1" libc = "0.2.162" +glib-sys = { version = "0.21.2", features = ["v2_66"] } [workspace.lints.rust] unexpected_cfgs = { level = "deny", check-cfg = ['cfg(MESON)'] }
rust/bql/Cargo.toml +3 -0
@@ -12,6 +12,9 @@ license.workspace = true repository.workspace = true rust-version.workspace = true +[dependencies] +glib-sys.workspace = true + [features] default = ["debug_cell"] debug_cell = []
rust/bql/meson.build +1 -0
@@ -37,6 +37,7 @@ _bql_rs = static_library( override_options: ['rust_std=2021', 'build.rust_std=2021'], rust_abi: 'rust', rust_args: _bql_cfg, + dependencies: [glib_sys_rs], ) bql_rs = declare_dependency(link_with: [_bql_rs],
rust/bql/src/bindings.rs +4 -0
@@ -18,6 +18,10 @@ clippy::too_many_arguments )] +use glib_sys::{ + guint,GArray ,GHashTable ,GHashTableIter ,GList ,GPollFD ,GPtrArray ,GQueue ,GSList ,GSource , +}; +#[cfg( MESON )] include! ("bindings.inc.rs" );
rust/chardev/Cargo.toml +1 -0
@@ -13,6 +13,7 @@ repository.workspace = true rust-version.workspace = true [dependencies] +glib-sys = { workspace = true } common = { path = "../common" } bql = { path = "../bql" } migration = { path = "../migration" }
rust/chardev/meson.build +1 -1
@@ -36,7 +36,7 @@ _chardev_rs = static_library( override_options: ['rust_std=2021', 'build.rust_std=2021'], rust_abi: 'rust', link_with: [_bql_rs, _migration_rs, _qom_rs, _util_rs], - dependencies: [common_rs, qemu_macros], + dependencies: [glib_sys_rs, common_rs, qemu_macros], ) chardev_rs = declare_dependency(link_with: [_chardev_rs], dependencies: [chardev, qemuutil])
rust/chardev/src/bindings.rs +4 -0
@@ -19,6 +19,10 @@ )]use common::Zeroable ; +use glib_sys::{ + gboolean, guint,GArray ,GHashTable ,GHashTableIter ,GIOCondition ,GList ,GMainContext , +GPollFD ,GPtrArray ,GQueue ,GSList ,GSource ,GSourceFunc , +};#[cfg( MESON )] include! ("bindings.inc.rs" );
rust/hw/char/pl011/Cargo.toml +1 -0
@@ -13,6 +13,7 @@ repository.workspace = true rust-version.workspace = true [dependencies] +glib-sys.workspace = true bilge = { version = "0.2.0" } bilge-impl = { version = "0.2.0" } bits = { path = "../../../bits" }
rust/hw/char/pl011/meson.build +1 -0
@@ -33,6 +33,7 @@ _libpl011_rs = static_library( bilge_impl_rs, bits_rs, common_rs, + glib_sys_rs, util_rs, migration_rs, bql_rs,
rust/hw/char/pl011/src/bindings.rs +5 -0
@@ -20,6 +20,11 @@//! `bindgen`-generated declarations. +use glib_sys::{ + gboolean, guint,GArray ,GByteArray ,GHashTable ,GHashTableIter ,GIOCondition ,GList , +GMainContext ,GPollFD ,GPtrArray ,GQueue ,GSList ,GSource ,GSourceFunc ,GString , +}; +#[cfg( MESON )] include! ("bindings.inc.rs" );
rust/hw/core/Cargo.toml +1 -0
@@ -13,6 +13,7 @@ repository.workspace = true rust-version.workspace = true [dependencies] +glib-sys.workspace = true qemu_macros = { path = "../../qemu-macros" } common = { path = "../../common" } bql = { path = "../../bql" }
rust/hw/core/meson.build +1 -1
@@ -59,7 +59,7 @@ _hwcore_rs = static_library( override_options: ['rust_std=2021', 'build.rust_std=2021'], rust_abi: 'rust', link_with: [_bql_rs, _chardev_rs, _migration_rs, _qom_rs, _system_rs, _util_rs], - dependencies: [qemu_macros, common_rs], + dependencies: [glib_sys_rs, qemu_macros, common_rs], ) hwcore_rs = declare_dependency(link_with: [_hwcore_rs],
rust/hw/core/src/bindings.rs +3 -0
@@ -20,6 +20,9 @@use chardev::bindings::Chardev ;use common::Zeroable ; +use glib_sys::{ +GArray ,GByteArray ,GHashTable ,GHashTableIter ,GList ,GPtrArray ,GQueue ,GSList ,GString , +};use migration::bindings::VMStateDescription ;use qom::bindings::ObjectClass ;use system::bindings::MemoryRegion ;
rust/migration/Cargo.toml +1 -0
@@ -17,6 +17,7 @@ bql = { path = "../bql" } common = { path = "../common" } qemu_macros = { path = "../qemu-macros" } util = { path = "../util" } +glib-sys.workspace = true [lints] workspace = true
rust/migration/meson.build +1 -1
@@ -39,7 +39,7 @@ _migration_rs = static_library( override_options: ['rust_std=2021', 'build.rust_std=2021'], rust_abi: 'rust', link_with: [_util_rs, _bql_rs], - dependencies: [common_rs, qemu_macros], + dependencies: [common_rs, glib_sys_rs, qemu_macros], ) migration_rs = declare_dependency(link_with: [_migration_rs],
rust/migration/src/bindings.rs +1 -0
@@ -19,6 +19,7 @@ )]use common::Zeroable ; +use glib_sys::{GHashTable ,GHashTableIter ,GList ,GPtrArray ,GQueue ,GSList };#[cfg( MESON )] include! ("bindings.inc.rs" );
rust/qom/Cargo.toml +1 -0
@@ -18,6 +18,7 @@ bql = { path = "../bql" } migration = { path = "../migration" } qemu_macros = { path = "../qemu-macros" } util = { path = "../util" } +glib-sys.workspace = true [lints] workspace = true
rust/qom/meson.build +1 -1
@@ -29,7 +29,7 @@ _qom_rs = static_library( override_options: ['rust_std=2021', 'build.rust_std=2021'], rust_abi: 'rust', link_with: [_bql_rs, _migration_rs], - dependencies: [common_rs, qemu_macros], + dependencies: [common_rs, glib_sys_rs, qemu_macros], ) qom_rs = declare_dependency(link_with: [_qom_rs], dependencies: [qemu_macros, qom])
rust/qom/src/bindings.rs +2 -0
@@ -18,6 +18,8 @@ clippy::too_many_arguments )] +use glib_sys::{GHashTable ,GHashTableIter ,GList ,GPtrArray ,GQueue ,GSList }; +#[cfg( MESON )] include! ("bindings.inc.rs" );
rust/system/Cargo.toml +1 -0
@@ -16,6 +16,7 @@ rust-version.workspace = true common = { path = "../common" } qom = { path = "../qom" } util = { path = "../util" } +glib-sys.workspace = true [lints] workspace = true
rust/system/meson.build +1 -1
@@ -36,7 +36,7 @@ _system_rs = static_library( override_options: ['rust_std=2021', 'build.rust_std=2021'], rust_abi: 'rust', link_with: [_bql_rs, _migration_rs, _qom_rs, _util_rs], - dependencies: [common_rs, qemu_macros], + dependencies: [glib_sys_rs, common_rs, qemu_macros], ) system_rs = declare_dependency(link_with: [_system_rs],
rust/system/src/bindings.rs +4 -0
@@ -19,6 +19,10 @@ )]use common::Zeroable ; +use glib_sys::{ + guint,GArray ,GByteArray ,GHashTable ,GHashTableIter ,GList ,GPollFD ,GPtrArray ,GQueue , +GSList ,GString , +};#[cfg( MESON )] include! ("bindings.inc.rs" );
rust/util/Cargo.toml +1 -0
@@ -15,6 +15,7 @@ rust-version.workspace = true [dependencies] anyhow = { workspace = true } foreign = { workspace = true } +glib-sys = { workspace = true } libc = { workspace = true } common = { path = "../common" }
rust/util/meson.build +1 -1
@@ -40,7 +40,7 @@ _util_rs = static_library( ), override_options: ['rust_std=2021', 'build.rust_std=2021'], rust_abi: 'rust', - dependencies: [anyhow_rs, libc_rs, foreign_rs, common_rs, qom, qemuutil], + dependencies: [anyhow_rs, libc_rs, foreign_rs, glib_sys_rs, common_rs, qom, qemuutil], ) util_rs = declare_dependency(link_with: [_util_rs], dependencies: [qemuutil, qom])
rust/util/src/bindings.rs +2 -0
@@ -18,6 +18,8 @@ clippy::too_many_arguments )] +use glib_sys::{guint,GList ,GPollFD ,GQueue ,GSList ,GString }; +#[cfg( MESON )] include! ("bindings.inc.rs" );
Signature · 1 line
2.51.0