From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by lists.proxmox.com (Postfix) with ESMTPS id C62D663388 for ; Tue, 24 Nov 2020 16:41:30 +0100 (CET) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id BC1A7FCEA for ; Tue, 24 Nov 2020 16:41:30 +0100 (CET) Received: from proxmox-new.maurer-it.com (proxmox-new.maurer-it.com [212.186.127.180]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by firstgate.proxmox.com (Proxmox) with ESMTPS id B6DF2FC00 for ; Tue, 24 Nov 2020 16:41:29 +0100 (CET) Received: from proxmox-new.maurer-it.com (localhost.localdomain [127.0.0.1]) by proxmox-new.maurer-it.com (Proxmox) with ESMTP id 7C98343A0C for ; Tue, 24 Nov 2020 16:41:29 +0100 (CET) From: Stefan Reiter To: pve-devel@lists.proxmox.com Date: Tue, 24 Nov 2020 16:41:21 +0100 Message-Id: <20201124154122.22202-3-s.reiter@proxmox.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20201124154122.22202-1-s.reiter@proxmox.com> References: <20201124154122.22202-1-s.reiter@proxmox.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-SPAM-LEVEL: Spam detection results: 0 AWL -0.035 Adjusted score from AWL reputation of From: address KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment RCVD_IN_DNSWL_MED -2.3 Sender listed at https://www.dnswl.org/, medium trust SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record URIBL_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to URIBL was blocked. See http://wiki.apache.org/spamassassin/DnsBlocklists#dnsbl-block for more information. [lib.rs, build.rs] Subject: [pve-devel] [PATCH v3 proxmox-backup-qemu 2/3] return version via rust fn instead of header define X-BeenThere: pve-devel@lists.proxmox.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Proxmox VE development discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 24 Nov 2020 15:41:30 -0000 Otherwise the string gets included in the QEMU binary, not the library. Suggested-by: Fabian Grünbichler Signed-off-by: Stefan Reiter --- 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 #include -#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