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

Make roxide compilable on windows with msvc cl #24

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
18 changes: 17 additions & 1 deletion roxide-librocksdb-sys/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -229,10 +229,11 @@ fn build_rocksdb() {
lib_sources.push("port/win/win_thread.cc");
}

config.flag(&cxx_standard());

if target.contains("msvc") {
config.flag("-EHsc");
} else {
config.flag(&cxx_standard());
// this was breaking the build on travis due to
// > 4mb of warnings emitted.
config.flag("-Wno-unused-parameter");
Expand Down Expand Up @@ -445,6 +446,9 @@ fn build_zstd() {
// Hide symbols from resulting library,
// so we can be used with another zstd-linking lib.
// See https://github.com/gyscos/zstd-rs/issues/58
// MSVC's cl.exe doesn't recognize this param and there doesn't seem to be an
// alternative.
#[cfg(not(windows))]
compiler.flag("-fvisibility=hidden");
compiler.define("ZSTDLIB_VISIBILITY", Some(""));
compiler.define("ZDICTLIB_VISIBILITY", Some(""));
Expand Down Expand Up @@ -516,6 +520,7 @@ fn try_to_find_and_link_lib(lib_name: &str) -> bool {
false
}

#[cfg(unix)]
fn cxx_standard() -> String {
env::var("ROCKSDB_CXX_STD").map_or("-std=c++17".to_owned(), |cxx_std| {
if !cxx_std.starts_with("-std=") {
Expand All @@ -526,6 +531,17 @@ fn cxx_standard() -> String {
})
}

#[cfg(windows)]
fn cxx_standard() -> String {
env::var("ROCKSDB_CXX_STD").map_or("-std:c++17".to_owned(), |cxx_std| {
if !cxx_std.starts_with("-std:") {
format!("-std:{}", cxx_std)
} else {
cxx_std
}
})
}

fn main() {
bindgen_rocksdb();

Expand Down
3 changes: 3 additions & 0 deletions roxide/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@ fn main() {
let mut config = cpp_build::Config::new();

// Rocks starting from 7.0 requires C++ 17
#[cfg(unix)]
config.flag("-std=c++17");
#[cfg(windows)]
config.flag("-std:c++17");

for include_path in include_paths {
config.include(&include_path);
Expand Down
2 changes: 1 addition & 1 deletion roxide/src/ffi_util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ pub(crate) unsafe fn path_from_char_ptr(path: *const libc::c_char) -> PathBuf {
// The RocksDB API on windows nonetheless produces single byte strings, so
// we need to convert to a String first, and convert that to an OsString
#[cfg(windows)]
let path_os_str: ffi::OsString = String::from_utf8_lossy(path_bytes).to_owned().into();
let path_os_str: ffi::OsString = String::from_utf8_lossy(path_bytes).to_string().into();

path_os_str.into()
}
Expand Down