Skip to content

Commit 9baee54

Browse files
committed
Issue#695 - Link liburing.a statically if present.
RocksDB enables IO_URING support by default and if the liburing dev files are present it creates a link dependency against liburing.a. Signed-off-by: Sunny Bains <[email protected]>
1 parent 72a6b68 commit 9baee54

File tree

1 file changed

+16
-12
lines changed

1 file changed

+16
-12
lines changed

librocksdb_sys/build.rs

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ extern crate bindgen;
1515
extern crate cc;
1616
extern crate cmake;
1717

18-
use cc::Build;
18+
use cc::{Build, Tool};
1919
use cmake::Config;
2020
use std::path::{Path, PathBuf};
2121
use std::{env, str};
@@ -79,24 +79,29 @@ fn main() {
7979
build.flag("-std=c++11");
8080
build.flag("-fno-rtti");
8181
}
82-
link_cpp(&mut build);
83-
build.warnings(false).compile("libcrocksdb.a");
84-
}
8582

86-
fn link_cpp(build: &mut Build) {
8783
let tool = build.get_compiler();
88-
let stdlib = if tool.is_like_gnu() {
89-
"libstdc++.a"
84+
85+
if tool.is_like_gnu() {
86+
link_lib("libstdc++.a", &tool);
87+
build.cpp_link_stdlib(None);
9088
} else if tool.is_like_clang() {
91-
"libc++.a"
89+
link_lib("libc++.a", &tool);
90+
build.cpp_link_stdlib(None);
9291
} else {
9392
// Don't link to c++ statically on windows.
94-
return;
9593
};
94+
95+
link_lib("liburing.a", &tool);
96+
97+
build.warnings(false).compile("libcrocksdb.a");
98+
}
99+
100+
fn link_lib(lib: &str, tool: &Tool) {
96101
let output = tool
97102
.to_command()
98103
.arg("--print-file-name")
99-
.arg(stdlib)
104+
.arg(lib)
100105
.output()
101106
.unwrap();
102107
if !output.status.success() || output.stdout.is_empty() {
@@ -111,7 +116,7 @@ fn link_cpp(build: &mut Build) {
111116
return;
112117
}
113118
// remove lib prefix and .a postfix.
114-
let libname = &stdlib[3..stdlib.len() - 2];
119+
let libname = &lib[3..lib.len() - 2];
115120
// optional static linking
116121
if cfg!(feature = "static_libcpp") {
117122
println!("cargo:rustc-link-lib=static={}", &libname);
@@ -122,7 +127,6 @@ fn link_cpp(build: &mut Build) {
122127
"cargo:rustc-link-search=native={}",
123128
path.parent().unwrap().display()
124129
);
125-
build.cpp_link_stdlib(None);
126130
}
127131

128132
fn build_rocksdb() -> Build {

0 commit comments

Comments
 (0)