miden_node_rocksdb_cxx_linkage_fix/
lib.rs1use std::env;
6
7pub fn configure() {
8 println!("cargo:rerun-if-env-changed=ROCKSDB_COMPILE");
9 println!("cargo:rerun-if-env-changed=ROCKSDB_LIB_DIR");
10 println!("cargo:rerun-if-env-changed=ROCKSDB_STATIC");
11 println!("cargo:rerun-if-env-changed=CXXSTDLIB");
12 let target = env::var("TARGET").unwrap_or_default();
13 if should_link_cpp_stdlib() {
14 link_cpp_stdlib(&target);
15 }
16}
17
18fn should_compile() -> bool {
19 if let Ok(v) = env::var("ROCKSDB_COMPILE") {
22 if v.to_lowercase() == "true" || v == "1" {
23 return true;
24 }
25 }
26 false
27}
28
29fn should_link_cpp_stdlib() -> bool {
30 if should_compile() {
31 return false;
32 }
33 env::var("ROCKSDB_STATIC").is_ok()
36 }
38
39fn link_cpp_stdlib(target: &str) {
40 if let Ok(stdlib) = env::var("CXXSTDLIB") {
43 println!("cargo:rustc-link-lib=dylib={stdlib}");
44 } else if target.contains("apple") || target.contains("freebsd") || target.contains("openbsd") {
45 println!("cargo:rustc-link-lib=dylib=c++");
46 } else if target.contains("linux") {
47 println!("cargo:rustc-link-lib=dylib=stdc++");
48 } else if target.contains("aix") {
49 println!("cargo:rustc-link-lib=dylib=c++");
50 println!("cargo:rustc-link-lib=dylib=c++abi");
51 }
52}