[pve-devel] [PATCH v3 proxmox-backup-qemu 2/3] return version via rust fn instead of header define

Stefan Reiter s.reiter at proxmox.com
Tue Nov 24 16:41:21 CET 2020


Otherwise the string gets included in the QEMU binary, not the library.

Suggested-by: Fabian Grünbichler <f.gruenbichler at proxmox.com>
Signed-off-by: Stefan Reiter <s.reiter at proxmox.com>
---

v3: added, applies as followup on top of already applied one

 Makefile      |  2 +-
 build.rs      |  6 +++---
 current-api.h |  7 +++++--
 src/lib.rs    | 13 +++++++++++++
 4 files changed, 22 insertions(+), 6 deletions(-)

diff --git a/Makefile b/Makefile
index f799124..e3a3420 100644
--- a/Makefile
+++ b/Makefile
@@ -20,7 +20,7 @@ endif
 all:
 ifneq ($(BUILD_MODE), skip)
 	cargo build $(CARGO_BUILD_ARGS)
-	diff -I 'PROXMOX_BACKUP_QEMU_VERSION' -up current-api.h proxmox-backup-qemu.h
+	diff -up current-api.h proxmox-backup-qemu.h
 endif
 
 # always re-create this dir
diff --git a/build.rs b/build.rs
index 274e935..6940d3f 100644
--- a/build.rs
+++ b/build.rs
@@ -12,8 +12,8 @@ fn main() {
         Some(ver) if !ver.is_empty() => ver,
         _ => "UNKNOWN",
     };
-    let version_define = format!(
-        "\n#define PROXMOX_BACKUP_QEMU_VERSION \"{} ({})\"",
+    let version_string = format!(
+        "{} ({})",
         crate_ver,
         git_ver,
     );
@@ -23,10 +23,10 @@ fn main() {
         .with_crate(&crate_dir)
         .with_header(header)
         .with_include_guard("PROXMOX_BACKUP_QEMU_H")
-        .with_after_include(version_define)
         .generate()
         .unwrap()
         .write_to_file("proxmox-backup-qemu.h");
 
     println!("cargo:rustc-cdylib-link-arg=-Wl,-soname,libproxmox_backup_qemu.so.0");
+    println!("cargo:rustc-env=PBS_LIB_VERSION={}", version_string);
 }
diff --git a/current-api.h b/current-api.h
index cc4d0c1..abe7e89 100644
--- a/current-api.h
+++ b/current-api.h
@@ -32,8 +32,6 @@
 #include <stdint.h>
 #include <stdlib.h>
 
-#define PROXMOX_BACKUP_QEMU_VERSION "0.7.1 (dbb900ce4f524af2b59c59727203633588f32804)"
-
 #define PROXMOX_BACKUP_DEFAULT_CHUNK_SIZE ((1024 * 1024) * 4)
 
 /**
@@ -183,6 +181,11 @@ ProxmoxBackupHandle *proxmox_backup_new(const char *repo,
                                         const char *fingerprint,
                                         char **error);
 
+/**
+ * Return a read-only pointer to a string containing the version of the library.
+ */
+const char *proxmox_backup_qemu_version(void);
+
 /**
  * Register a backup image (sync)
  */
diff --git a/src/lib.rs b/src/lib.rs
index 67c18fc..b755014 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -28,6 +28,19 @@ mod tools;
 
 pub const PROXMOX_BACKUP_DEFAULT_CHUNK_SIZE: u64 = 1024*1024*4;
 
+use lazy_static::lazy_static;
+lazy_static!{
+    static ref VERSION_CSTR: CString = {
+        CString::new(env!("PBS_LIB_VERSION")).unwrap()
+    };
+}
+
+/// Return a read-only pointer to a string containing the version of the library.
+#[no_mangle]
+pub extern "C" fn proxmox_backup_qemu_version() -> *const c_char {
+    VERSION_CSTR.as_ptr()
+}
+
 /// Free returned error messages
 ///
 /// All calls can return error messages, but they are allocated using
-- 
2.20.1






More information about the pve-devel mailing list