From cf3afd1b4ade3a39b1500c215c0bb2eae3d2e16b Mon Sep 17 00:00:00 2001 From: Ziyang Hu Date: Fri, 14 Oct 2022 13:24:20 +0800 Subject: [PATCH] windows linking --- cozorocks/build.rs | 31 ++++++++++++++++++++++--------- 1 file changed, 22 insertions(+), 9 deletions(-) diff --git a/cozorocks/build.rs b/cozorocks/build.rs index 453029fa..9e9b223a 100644 --- a/cozorocks/build.rs +++ b/cozorocks/build.rs @@ -35,19 +35,19 @@ fn main() { if target.contains("windows") { link("rpcrt4", false); link("shlwapi", false); - config.define("DWIN32", None); - config.define("OS_WIN", None); - config.define("_MBCS", None); - config.define("WIN64", None); - config.define("NOMINMAX", None); - config.define("ROCKSDB_WINDOWS_UTF8_FILENAMES", None); + builder.define("DWIN32", None); + builder.define("OS_WIN", None); + builder.define("_MBCS", None); + builder.define("WIN64", None); + builder.define("NOMINMAX", None); + builder.define("ROCKSDB_WINDOWS_UTF8_FILENAMES", None); if &target == "x86_64-pc-windows-gnu" { // Tell MinGW to create localtime_r wrapper of localtime_s function. - config.define("_POSIX_C_SOURCE", Some("1")); + builder.define("_POSIX_C_SOURCE", Some("1")); // Tell MinGW to use at least Windows Vista headers instead of the ones of Windows XP. // (This is minimum supported version of rocksdb) - config.define("_WIN32_WINNT", Some("_WIN32_WINNT_VISTA")); + builder.define("_WIN32_WINNT", Some("_WIN32_WINNT_VISTA")); } } @@ -55,7 +55,7 @@ fn main() { println!("cargo:rustc-link-lib=static=rocksdb"); println!("cargo:rustc-link-lib=static=zstd"); println!("cargo:rustc-link-lib=static=lz4"); - if cfg!(feature = "snappy") { + if cfg!(feature = "lib-uring") { println!("cargo:rustc-link-lib=static=uring"); } @@ -82,3 +82,16 @@ fn cxx_standard() -> String { } }) } + +fn link(name: &str, bundled: bool) { + use std::env::var; + let target = var("TARGET").unwrap(); + let target: Vec<_> = target.split('-').collect(); + if target.get(2) == Some(&"windows") { + println!("cargo:rustc-link-lib=dylib={}", name); + if bundled && target.get(3) == Some(&"gnu") { + let dir = var("CARGO_MANIFEST_DIR").unwrap(); + println!("cargo:rustc-link-search=native={}/{}", dir, target[0]); + } + } +} \ No newline at end of file