]> git.proxmox.com Git - proxmox-backup.git/commitdiff
use build.rs to pass REPOID to rustc-env
authorDietmar Maurer <dietmar@proxmox.com>
Thu, 6 May 2021 11:00:03 +0000 (13:00 +0200)
committerDietmar Maurer <dietmar@proxmox.com>
Fri, 7 May 2021 08:11:39 +0000 (10:11 +0200)
Cargo.toml
build.rs [new file with mode: 0644]
src/api2/version.rs

index be6c7da9eb368ff03ce613f7700ab11cebfaa72e..246b8e07c182a2d5ea54d6093f5aaf363417cc39 100644 (file)
@@ -15,6 +15,7 @@ edition = "2018"
 license = "AGPL-3"
 description = "Proxmox Backup"
 homepage = "https://www.proxmox.com"
+build = "build.rs"
 
 exclude = [ "build", "debian", "tests/catar_data/test_symlink/symlink1"]
 
diff --git a/build.rs b/build.rs
new file mode 100644 (file)
index 0000000..754966b
--- /dev/null
+++ b/build.rs
@@ -0,0 +1,24 @@
+// build.rs
+use std::env;
+use std::process::Command;
+
+fn main() {
+    let repoid = match env::var("REPOID") {
+        Ok(repoid) => repoid,
+        Err(_) => {
+            match Command::new("git")
+                .args(&["rev-parse", "HEAD"])
+                .output()
+            {
+                Ok(output) => {
+                    String::from_utf8(output.stdout).unwrap()
+                }
+                Err(err) => {
+                    panic!("git rev-parse failed: {}", err);
+                }
+            }
+        }
+    };
+
+    println!("cargo:rustc-env=REPOID={}", repoid);
+}
index ca156402ff5fec3e0477251d0c7a6c476b81ee3b..d18d0cf40c1d79cd3d80a336b7245c66bcb00231 100644 (file)
@@ -13,7 +13,7 @@ pub const PROXMOX_PKG_VERSION: &str =
         env!("CARGO_PKG_VERSION_MINOR"),
     );
 pub const PROXMOX_PKG_RELEASE: &str = env!("CARGO_PKG_VERSION_PATCH");
-pub const PROXMOX_PKG_REPOID: &str = env!("CARGO_PKG_REPOSITORY");
+pub const PROXMOX_PKG_REPOID: &str = env!("REPOID");
 
 fn get_version(
     _param: Value,