Skip to content

Commit f580d61

Browse files
brndnmtthwsovr
authored andcommitted
Fix C++ linking (rust-rocksdb#981)
* Fix C++ linking Hard-coding the C++ library linking is bad practice, and instead this crate needs to follow the practices as described under https://docs.rs/cc/1.2.14/cc/index.html#c-support. Without doing so, this crate will not compile on when using libc++ instead of libstdc++. This change will keep the existing behaviour, while allowing downstream consumers of this crate to override the C++ library with the `CXXSTDLIB` which is respected by the cc crate.
1 parent 8698f51 commit f580d61

1 file changed

Lines changed: 5 additions & 8 deletions

File tree

librocksdb-sys/build.rs

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,11 @@ fn build_rocksdb() {
275275

276276
config.cpp(true);
277277
config.flag_if_supported("-std=c++17");
278+
if target.contains("linux") {
279+
config.cpp_link_stdlib("stdc++");
280+
} else if !target.contains("windows") {
281+
config.cpp_link_stdlib("c++");
282+
}
278283
config.compile("librocksdb.a");
279284
}
280285

@@ -370,14 +375,6 @@ fn main() {
370375
println!("cargo:rerun-if-changed=rocksdb/");
371376
fail_on_empty_directory("rocksdb");
372377
build_rocksdb();
373-
} else {
374-
let target = env::var("TARGET").unwrap();
375-
// according to https://github.com/alexcrichton/cc-rs/blob/master/src/lib.rs#L2189
376-
if target.contains("apple") || target.contains("freebsd") || target.contains("openbsd") {
377-
println!("cargo:rustc-link-lib=dylib=c++");
378-
} else if target.contains("linux") {
379-
println!("cargo:rustc-link-lib=dylib=stdc++");
380-
}
381378
}
382379
if cfg!(feature = "snappy") && !try_to_find_and_link_lib("SNAPPY") {
383380
println!("cargo:rerun-if-changed=snappy/");

0 commit comments

Comments
 (0)