Skip to content
Merged
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
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 5 additions & 4 deletions crates/proto/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ assert_matches = { workspace = true }
proptest = { version = "1.7" }

[build-dependencies]
fs-err = { workspace = true }
miden-node-proto-build = { features = ["internal"], workspace = true }
miette = { version = "7.6" }
tonic-prost-build = { workspace = true }
fs-err = { workspace = true }
miden-node-proto-build = { features = ["internal"], workspace = true }
miden-node-rocksdb-cxx-linkage-fix = { workspace = true }
miette = { version = "7.6" }
tonic-prost-build = { workspace = true }
2 changes: 2 additions & 0 deletions crates/proto/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ fn main() -> miette::Result<()> {
println!("cargo::rerun-if-changed=../../proto/proto");
println!("cargo::rerun-if-env-changed=BUILD_PROTO");

miden_node_rocksdb_cxx_linkage_fix::configure();

// Skip this build script in BUILD_PROTO environment variable is not set to `1`.
if env::var("BUILD_PROTO").unwrap_or("0".to_string()) == "0" {
return Ok(());
Expand Down
25 changes: 19 additions & 6 deletions crates/rocksdb-cxx-linkage-fix/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,29 @@ pub fn configure() {
}
}

fn should_link_cpp_stdlib() -> bool {
let rocksdb_compile = env::var("ROCKSDB_COMPILE").unwrap_or_default();
let rocksdb_compile_disabled = matches!(rocksdb_compile.as_str(), "0" | "false" | "FALSE");
let rocksdb_static = env::var("ROCKSDB_STATIC").is_ok();
let rocksdb_lib_dir_set = env::var("ROCKSDB_LIB_DIR").is_ok();
fn should_compile() -> bool {
// in sync with <https://github.com/rust-rocksdb/rust-rocksdb/blob/master/librocksdb-sys/build.rs#L348-L352>
if let Ok(v) = env::var("ROCKSDB_COMPILE") {
if v.to_lowercase() == "true" || v == "1" {
return true;
}
}
false
}

rocksdb_lib_dir_set || (rocksdb_static && rocksdb_compile_disabled)
fn should_link_cpp_stdlib() -> bool {
if should_compile() {
return false;
}
// the value doesn't matter
// <https://github.com/rust-rocksdb/rust-rocksdb/blob/master/librocksdb-sys/build.rs#L359>
env::var("ROCKSDB_STATIC").is_ok()
// `ROCKSDB_LIB_DIR` is not really discriminative, it only adds extra lookup dirs for the linker
}

fn link_cpp_stdlib(target: &str) {
// aligned with
// <https://github.com/rust-rocksdb/rust-rocksdb/blob/master/librocksdb-sys/build.rs#L399-L411>
if let Ok(stdlib) = env::var("CXXSTDLIB") {
println!("cargo:rustc-link-lib=dylib={stdlib}");
} else if target.contains("apple") || target.contains("freebsd") || target.contains("openbsd") {
Expand Down
Loading