From: Marc-André Lureau <marcandre.lureau@redhat.com>
Use qapi-gen to generate low-level C FFI bindings for QAPI types,
include them to the build.
Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
---
Cargo.lock | 3 +++
qga/Cargo.toml | 3 +++
qga/lib.rs | 1 +
qga/meson.build | 11 +++++++++++
qga/qapi_ffi.rs | 8 ++++++++
5 files changed, 26 insertions(+)
create mode 100644 qga/qapi_ffi.rs
diff --git a/Cargo.lock b/Cargo.lock
index 2f5b202605..ad5bb47762 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -72,3 +72,6 @@ dependencies = [
[[package]]
name = "qga"
version = "0.1.0"
+dependencies = [
+ "common",
+]
diff --git a/qga/Cargo.toml b/qga/Cargo.toml
index a3bffd1fec..807acc947e 100644
--- a/qga/Cargo.toml
+++ b/qga/Cargo.toml
@@ -4,6 +4,9 @@ version = "0.1.0"
edition = "2018"
publish = false
+[dependencies]
+common = { path = "../rust/common" }
+
[lib]
path = "lib.rs"
crate-type = ["staticlib"]
diff --git a/qga/lib.rs b/qga/lib.rs
index e69de29bb2..17cf43a5e9 100644
--- a/qga/lib.rs
+++ b/qga/lib.rs
@@ -0,0 +1 @@
+mod qapi_ffi;
diff --git a/qga/meson.build b/qga/meson.build
index d272892ced..88d59bef0c 100644
--- a/qga/meson.build
+++ b/qga/meson.build
@@ -56,10 +56,21 @@ qga_ss = qga_ss.apply(config_host, strict: false)
qga_rs = declare_dependency()
if with_rust
+ qga_qapi_rs_outputs = [
+ 'qga-qapi-ffi-types.rs',
+ ]
+
+ qapi_gen_rs_files = custom_target('QGA QAPI Rust bindings',
+ output: qga_qapi_rs_outputs,
+ input: 'qapi-schema.json',
+ command: [ qapi_gen, '-r', '-o', 'qga', '-p', 'qga-', '@INPUT0@' ],
+ depend_files: qapi_gen_depends)
+
cargo_qga = custom_target('cargo-qga',
build_by_default: true,
output: ['libqga.args', 'libqga.a'],
build_always_stale: true,
+ depends: [qapi_gen_rs_files],
command: [cargo_wrapper,
meson.current_build_dir(),
meson.current_source_dir(),
diff --git a/qga/qapi_ffi.rs b/qga/qapi_ffi.rs
new file mode 100644
index 0000000000..1f4ade9318
--- /dev/null
+++ b/qga/qapi_ffi.rs
@@ -0,0 +1,8 @@
+#![allow(dead_code)]
+
+use common::libc;
+
+include!(concat!(
+ env!("MESON_BUILD_ROOT"),
+ "/qga/qga-qapi-ffi-types.rs"
+));
--
2.33.0.113.g6c40894d24