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]
);
}
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
+ );
}
ntstatus_gen.workspace = true
param = { workspace = true }
sock = { workspace = true }
+
+[build-dependencies]
+version = { path = "../version" }
--- /dev/null
+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
+ );
+}
--- /dev/null
+[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"
--- /dev/null
+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!");
+}
--- /dev/null
+/*
+ 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,
+ }
+}