]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
Add Samba versioning
authorDavid Mulder <dmulder@samba.org>
Tue, 30 Jul 2024 15:09:43 +0000 (09:09 -0600)
committerDavid Mulder <dmulder@samba.org>
Wed, 23 Oct 2024 14:21:33 +0000 (14:21 +0000)
Signed-off-by: David Mulder <dmulder@samba.org>
Reviewed-by: Alexander Bokovoy <ab@samba.org>
himmelblaud/Cargo.toml
himmelblaud/build.rs
himmelblaud/nss/Cargo.toml
himmelblaud/nss/build.rs [new file with mode: 0644]
himmelblaud/version/Cargo.toml [new file with mode: 0644]
himmelblaud/version/build.rs [new file with mode: 0644]
himmelblaud/version/include/includes.h [new file with mode: 0644]
himmelblaud/version/src/lib.rs [new file with mode: 0644]

index f51e21d1137ce7d8d98fdbc3e5d9ff4fce3b7363..6a5409487ef1547cecf2f675470d2beec109a873 100644 (file)
@@ -30,11 +30,14 @@ serde = "1.0.204"
 idmap = { workspace = true }
 libc = "0.2.155"
 
+[build-dependencies]
+version = { path = "version" }
+
 [workspace]
 members = [
   "chelps", "dbg", "idmap",
   "nss", "ntstatus_gen",
-  "param", "sock", "tdb",
+  "param", "sock", "tdb", "version",
 ]
 
 [workspace.dependencies]
index 1b5015098f38289652a284cdd0b2e92716e05ae1..5d1b869c9fb24f364cd10169d724497142b29241 100644 (file)
@@ -15,4 +15,20 @@ fn main() {
         );
     }
     println!("cargo:rerun-if-changed-env=TARGET");
+
+    if let Some(vers) = version::samba_version_string() {
+        println!("cargo:rustc-env=CARGO_PKG_VERSION={}", vers);
+    }
+    println!(
+        "cargo:rustc-env=CARGO_PKG_VERSION_MAJOR={}",
+        version::SAMBA_VERSION_MAJOR
+    );
+    println!(
+        "cargo:rustc-env=CARGO_PKG_VERSION_MINOR={}",
+        version::SAMBA_VERSION_MINOR
+    );
+    println!(
+        "cargo:rustc-env=CARGO_PKG_VERSION_PATCH={}",
+        version::SAMBA_VERSION_RELEASE
+    );
 }
index ecb0cda557fe6b7c20e2b580f83957ba1c6886c5..c182b27d51a773d3c97dac6806262b370bedd779 100644 (file)
@@ -16,3 +16,6 @@ libnss = "0.8.0"
 ntstatus_gen.workspace = true
 param = { workspace = true }
 sock = { workspace = true }
+
+[build-dependencies]
+version = { path = "../version" }
diff --git a/himmelblaud/nss/build.rs b/himmelblaud/nss/build.rs
new file mode 100644 (file)
index 0000000..4f5e414
--- /dev/null
@@ -0,0 +1,17 @@
+fn main() {
+    if let Some(vers) = version::samba_version_string() {
+        println!("cargo:rustc-env=CARGO_PKG_VERSION={}", vers);
+    }
+    println!(
+        "cargo:rustc-env=CARGO_PKG_VERSION_MAJOR={}",
+        version::SAMBA_VERSION_MAJOR
+    );
+    println!(
+        "cargo:rustc-env=CARGO_PKG_VERSION_MINOR={}",
+        version::SAMBA_VERSION_MINOR
+    );
+    println!(
+        "cargo:rustc-env=CARGO_PKG_VERSION_PATCH={}",
+        version::SAMBA_VERSION_RELEASE
+    );
+}
diff --git a/himmelblaud/version/Cargo.toml b/himmelblaud/version/Cargo.toml
new file mode 100644 (file)
index 0000000..c7e6aa8
--- /dev/null
@@ -0,0 +1,18 @@
+[package]
+name = "version"
+edition.workspace = true
+license.workspace = true
+homepage.workspace = true
+version.workspace = true
+
+[lib]
+name = "version"
+path = "src/lib.rs"
+
+[dependencies]
+chelps.workspace = true
+libc = "0.2.153"
+
+[build-dependencies]
+cc = "1.0.97"
+bindgen = "0.69.4"
diff --git a/himmelblaud/version/build.rs b/himmelblaud/version/build.rs
new file mode 100644 (file)
index 0000000..b426fd6
--- /dev/null
@@ -0,0 +1,29 @@
+use std::env;
+use std::path::{Path, PathBuf};
+
+fn main() {
+    cc::Build::new()
+        .file("../../source3/lib/version.c")
+        .include(Path::new("../../bin/default"))
+        .include(Path::new("./include")) // for the empty includes.h
+        .warnings(false)
+        .compile("version");
+
+    let bindings = bindgen::Builder::default()
+        .blocklist_function("qgcvt")
+        .blocklist_function("qgcvt_r")
+        .blocklist_function("qfcvt")
+        .blocklist_function("qfcvt_r")
+        .blocklist_function("qecvt")
+        .blocklist_function("qecvt_r")
+        .blocklist_function("strtold")
+        .header("../../bin/default/version.h")
+        .parse_callbacks(Box::new(bindgen::CargoCallbacks::new()))
+        .generate()
+        .expect("Unable to generate bindings");
+
+    let out_path = PathBuf::from(env::var("OUT_DIR").unwrap());
+    bindings
+        .write_to_file(out_path.join("bindings.rs"))
+        .expect("Couldn't write bindings!");
+}
diff --git a/himmelblaud/version/include/includes.h b/himmelblaud/version/include/includes.h
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/himmelblaud/version/src/lib.rs b/himmelblaud/version/src/lib.rs
new file mode 100644 (file)
index 0000000..d71a4aa
--- /dev/null
@@ -0,0 +1,40 @@
+/*
+   Unix SMB/CIFS implementation.
+   Samba Version functions
+
+   Copyright (C) David Mulder 2024
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 3 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.
+*/
+use std::str;
+
+include!(concat!(env!("OUT_DIR"), "/bindings.rs"));
+
+pub fn samba_version_string() -> Option<String> {
+    let null_trimmed_vers =
+        &SAMBA_VERSION_STRING[..SAMBA_VERSION_STRING.len() - 1];
+    match str::from_utf8(null_trimmed_vers) {
+        Ok(vers) => Some(vers.to_string()),
+        Err(_) => None,
+    }
+}
+
+pub fn samba_copyright_string() -> Option<String> {
+    let null_trimmed_copy =
+        &SAMBA_COPYRIGHT_STRING[..SAMBA_COPYRIGHT_STRING.len() - 1];
+    match str::from_utf8(null_trimmed_copy) {
+        Ok(copy) => Some(copy.to_string()),
+        Err(_) => None,
+    }
+}