From 35b34e8e42dee136eb39fb959c06020461b10c0b Mon Sep 17 00:00:00 2001 From: David Mulder Date: Thu, 8 Aug 2024 10:51:02 -0600 Subject: [PATCH] Add build config for proper TDB build linkage The tdb build needs to know whether Samba is building with TDB bundled or not, otherwise linking will fail. Signed-off-by: David Mulder Reviewed-by: Alexander Bokovoy --- rust/Cargo.toml | 3 ++- rust/config/Cargo.toml | 12 ++++++++++++ rust/config/additions.h | 4 ++++ rust/config/build.rs | 20 ++++++++++++++++++++ rust/config/src/lib.rs | 27 +++++++++++++++++++++++++++ rust/param/build.rs | 1 + rust/tdb/Cargo.toml | 1 + rust/tdb/build.rs | 6 +++++- 8 files changed, 72 insertions(+), 2 deletions(-) create mode 100644 rust/config/Cargo.toml create mode 100644 rust/config/additions.h create mode 100644 rust/config/build.rs create mode 100644 rust/config/src/lib.rs diff --git a/rust/Cargo.toml b/rust/Cargo.toml index 5c9e3107faa..91d0ccbd9c8 100644 --- a/rust/Cargo.toml +++ b/rust/Cargo.toml @@ -7,7 +7,7 @@ version = "4.21.0" [workspace] resolver = "2" members = [ - "chelps", "dbg", "himmelblaud", "idmap", + "chelps", "config", "dbg", "himmelblaud", "idmap", "nss", "ntstatus_gen", "pam", "param", "sock", "tdb", "version", ] @@ -21,3 +21,4 @@ ntstatus_gen = { path = "ntstatus_gen" } tdb = { path = "tdb" } idmap = { path = "idmap" } libc = "0.2.155" +config = { path = "config" } diff --git a/rust/config/Cargo.toml b/rust/config/Cargo.toml new file mode 100644 index 00000000000..e61ab953d2d --- /dev/null +++ b/rust/config/Cargo.toml @@ -0,0 +1,12 @@ +[package] +name = "config" +edition.workspace = true +license.workspace = true +homepage.workspace = true +version.workspace = true + +[dependencies] +libc.workspace = true + +[build-dependencies] +bindgen = "0.69.4" diff --git a/rust/config/additions.h b/rust/config/additions.h new file mode 100644 index 00000000000..c9561349028 --- /dev/null +++ b/rust/config/additions.h @@ -0,0 +1,4 @@ +#include "../../bin/default/include/config.h" +#ifndef USING_SYSTEM_TDB +#define USING_SYSTEM_TDB 0 +#endif diff --git a/rust/config/build.rs b/rust/config/build.rs new file mode 100644 index 00000000000..b1c1549dc70 --- /dev/null +++ b/rust/config/build.rs @@ -0,0 +1,20 @@ +use std::env; +use std::path::PathBuf; + +fn main() { + let header = "../../bin/default/include/config.h"; + println!("cargo:rerun-if-changed={}", header); + let additions_header = "./additions.h"; + println!("cargo:rerun-if-changed={}", additions_header); + + let bindings = bindgen::Builder::default() + .header(additions_header) + .header(header) + .generate() + .expect("Failed generating config 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/rust/config/src/lib.rs b/rust/config/src/lib.rs new file mode 100644 index 00000000000..be5724b695c --- /dev/null +++ b/rust/config/src/lib.rs @@ -0,0 +1,27 @@ +/* + Unix SMB/CIFS implementation. + + Samba config imported into Rust + + 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 . +*/ + +#![allow(non_upper_case_globals)] +#![allow(non_camel_case_types)] +#![allow(non_snake_case)] +#![allow(dead_code)] +#![allow(clippy::upper_case_acronyms)] +include!(concat!(env!("OUT_DIR"), "/bindings.rs")); diff --git a/rust/param/build.rs b/rust/param/build.rs index d2fa9df8753..8fe81e1091b 100644 --- a/rust/param/build.rs +++ b/rust/param/build.rs @@ -13,6 +13,7 @@ fn main() { .clang_arg("-Dbool=int") .clang_arg("-Doffset_t=loff_t") .clang_arg("-I../../bin/default") + .clang_arg("-I../../lib/talloc") .clang_arg("-includestdint.h") .header("../../lib/param/param.h") .header("../../lib/param/loadparm.h") diff --git a/rust/tdb/Cargo.toml b/rust/tdb/Cargo.toml index ef96e76c5e1..aad1c727d11 100644 --- a/rust/tdb/Cargo.toml +++ b/rust/tdb/Cargo.toml @@ -13,3 +13,4 @@ ntstatus_gen.workspace = true [build-dependencies] bindgen = "0.69.4" +config.workspace = true diff --git a/rust/tdb/build.rs b/rust/tdb/build.rs index 7a9923cf786..57ee90aa8d4 100644 --- a/rust/tdb/build.rs +++ b/rust/tdb/build.rs @@ -23,7 +23,11 @@ fn main() { let mut src_dir = PathBuf::from(env::var("CARGO_MANIFEST_DIR").unwrap()); src_dir.push("../../bin/default/lib/tdb"); - println!("cargo:rustc-link-lib=tdb"); + if config::USING_SYSTEM_TDB == 1 { + println!("cargo:rustc-link-lib=tdb"); + } else { + println!("cargo:rustc-link-lib=tdb-private-samba"); + } println!( "cargo:rustc-link-search=native={}", src_dir.to_str().unwrap() -- 2.47.3