From e4c28a2d576c651e65da36ef009dd5ceafe74189 Mon Sep 17 00:00:00 2001 From: David Mulder Date: Tue, 30 Jul 2024 09:09:43 -0600 Subject: [PATCH] Add Samba versioning Signed-off-by: David Mulder Reviewed-by: Alexander Bokovoy --- himmelblaud/Cargo.toml | 5 +++- himmelblaud/build.rs | 16 +++++++++++ himmelblaud/nss/Cargo.toml | 3 ++ himmelblaud/nss/build.rs | 17 +++++++++++ himmelblaud/version/Cargo.toml | 18 ++++++++++++ himmelblaud/version/build.rs | 29 +++++++++++++++++++ himmelblaud/version/include/includes.h | 0 himmelblaud/version/src/lib.rs | 40 ++++++++++++++++++++++++++ 8 files changed, 127 insertions(+), 1 deletion(-) create mode 100644 himmelblaud/nss/build.rs create mode 100644 himmelblaud/version/Cargo.toml create mode 100644 himmelblaud/version/build.rs create mode 100644 himmelblaud/version/include/includes.h create mode 100644 himmelblaud/version/src/lib.rs diff --git a/himmelblaud/Cargo.toml b/himmelblaud/Cargo.toml index f51e21d1137..6a5409487ef 100644 --- a/himmelblaud/Cargo.toml +++ b/himmelblaud/Cargo.toml @@ -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] diff --git a/himmelblaud/build.rs b/himmelblaud/build.rs index 1b5015098f3..5d1b869c9fb 100644 --- a/himmelblaud/build.rs +++ b/himmelblaud/build.rs @@ -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 + ); } diff --git a/himmelblaud/nss/Cargo.toml b/himmelblaud/nss/Cargo.toml index ecb0cda557f..c182b27d51a 100644 --- a/himmelblaud/nss/Cargo.toml +++ b/himmelblaud/nss/Cargo.toml @@ -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 index 00000000000..4f5e414bf9a --- /dev/null +++ b/himmelblaud/nss/build.rs @@ -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 index 00000000000..c7e6aa8ff7c --- /dev/null +++ b/himmelblaud/version/Cargo.toml @@ -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 index 00000000000..b426fd6c222 --- /dev/null +++ b/himmelblaud/version/build.rs @@ -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 index 00000000000..e69de29bb2d diff --git a/himmelblaud/version/src/lib.rs b/himmelblaud/version/src/lib.rs new file mode 100644 index 00000000000..d71a4aae641 --- /dev/null +++ b/himmelblaud/version/src/lib.rs @@ -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 . +*/ +use std::str; + +include!(concat!(env!("OUT_DIR"), "/bindings.rs")); + +pub fn samba_version_string() -> Option { + 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 { + 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, + } +} -- 2.47.3