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

Issue#695 - Link liburing.a statically if present. #724

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
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
28 changes: 16 additions & 12 deletions librocksdb_sys/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ extern crate bindgen;
extern crate cc;
extern crate cmake;

use cc::Build;
use cc::{Build, Tool};
use cmake::Config;
use std::path::{Path, PathBuf};
use std::{env, str};
Expand Down Expand Up @@ -79,24 +79,29 @@ fn main() {
build.flag("-std=c++11");
build.flag("-fno-rtti");
}
link_cpp(&mut build);
build.warnings(false).compile("libcrocksdb.a");
}

fn link_cpp(build: &mut Build) {
let tool = build.get_compiler();
let stdlib = if tool.is_like_gnu() {
"libstdc++.a"

if tool.is_like_gnu() {
link_lib("libstdc++.a", &tool);
build.cpp_link_stdlib(None);
} else if tool.is_like_clang() {
"libc++.a"
link_lib("libc++.a", &tool);
build.cpp_link_stdlib(None);
} else {
// Don't link to c++ statically on windows.
return;
};

link_lib("liburing.a", &tool);

build.warnings(false).compile("libcrocksdb.a");
}

fn link_lib(lib: &str, tool: &Tool) {
let output = tool
.to_command()
.arg("--print-file-name")
.arg(stdlib)
.arg(lib)
.output()
.unwrap();
if !output.status.success() || output.stdout.is_empty() {
Expand All @@ -111,7 +116,7 @@ fn link_cpp(build: &mut Build) {
return;
}
// remove lib prefix and .a postfix.
let libname = &stdlib[3..stdlib.len() - 2];
let libname = &lib[3..lib.len() - 2];
// optional static linking
if cfg!(feature = "static_libcpp") {
println!("cargo:rustc-link-lib=static={}", &libname);
Expand All @@ -122,7 +127,6 @@ fn link_cpp(build: &mut Build) {
"cargo:rustc-link-search=native={}",
path.parent().unwrap().display()
);
build.cpp_link_stdlib(None);
}

fn build_rocksdb() -> Build {
Expand Down