Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optionally de-bundle libmdbx #2

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 41 additions & 26 deletions mdbx-sys/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,32 +51,7 @@ impl ParseCallbacks for Callbacks {
}
}

fn main() {
let mut mdbx = PathBuf::from(&env::var("CARGO_MANIFEST_DIR").unwrap());
mdbx.push("libmdbx");

let out_path = PathBuf::from(env::var("OUT_DIR").unwrap());

let bindings = bindgen::Builder::default()
.header(mdbx.join("mdbx.h").to_string_lossy())
.allowlist_var("^(MDBX|mdbx)_.*")
.allowlist_type("^(MDBX|mdbx)_.*")
.allowlist_function("^(MDBX|mdbx)_.*")
.size_t_is_usize(true)
.ctypes_prefix("::libc")
.parse_callbacks(Box::new(Callbacks))
.layout_tests(false)
.prepend_enum_name(false)
.generate_comments(false)
.disable_header_comment()
.formatter(Formatter::None)
.generate()
.expect("Unable to generate bindings");

bindings
.write_to_file(out_path.join("bindings.rs"))
.expect("Couldn't write bindings!");

fn build_mdbx() {
let mut mdbx = PathBuf::from(&env::var("CARGO_MANIFEST_DIR").unwrap());
mdbx.push("libmdbx");

Expand Down Expand Up @@ -117,3 +92,43 @@ fn main() {
.compile("libmdbx.a");
}
}

fn main() {
let mut mdbx = PathBuf::from(&env::var("CARGO_MANIFEST_DIR").unwrap());
mdbx.push("libmdbx");

let out_path = PathBuf::from(env::var("OUT_DIR").unwrap());

let bindings = bindgen::Builder::default()
.header(mdbx.join("mdbx.h").to_string_lossy())
.allowlist_var("^(MDBX|mdbx)_.*")
.allowlist_type("^(MDBX|mdbx)_.*")
.allowlist_function("^(MDBX|mdbx)_.*")
.size_t_is_usize(true)
.ctypes_prefix("::libc")
.parse_callbacks(Box::new(Callbacks))
.layout_tests(false)
.prepend_enum_name(false)
.generate_comments(false)
.disable_header_comment()
.formatter(Formatter::None)
.generate()
.expect("Unable to generate bindings");

bindings
.write_to_file(out_path.join("bindings.rs"))
.expect("Couldn't write bindings!");

println!("cargo::rerun-if-env-changed=LIBMDBX_NO_VENDOR");
let no_vendor = env::var("LIBMDBX_NO_VENDOR").map_or(false, |x| x != "0");

if no_vendor {
println!("cargo:rustc-link-lib=mdbx");
if cfg!(windows) {
println!(r"cargo:rustc-link-lib=ntdll");
println!(r"cargo:rustc-link-search=C:\windows\system32");
}
} else {
build_mdbx();
}
}