RocksDB: Avoids modifying source code inside the build script

cargo publish does not like it.
pull/190/head
Tpt 3 years ago
parent 074ee466a3
commit 92a17e40df
  1. 36
      rocksdb-sys/api/build_version.cc
  2. 34
      rocksdb-sys/build.rs

@ -0,0 +1,36 @@
// Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.
#include <memory>
#include "rocksdb/version.h"
#include "util/string_util.h"
namespace ROCKSDB_NAMESPACE {
const std::unordered_map<std::string, std::string>& GetRocksBuildProperties() {
static std::unique_ptr<std::unordered_map<std::string, std::string>> props;
return *props;
}
std::string GetRocksVersionAsString(bool with_patch) {
std::string version = ToString(ROCKSDB_MAJOR) + "." + ToString(ROCKSDB_MINOR);
if (with_patch) {
return version + "." + ToString(ROCKSDB_PATCH);
} else {
return version;
}
}
std::string GetRocksBuildInfoAsString(const std::string& program, bool verbose) {
std::string info = program + " (RocksDB) " + GetRocksVersionAsString(true);
if (verbose) {
for (const auto& it : GetRocksBuildProperties()) {
info.append("\n ");
info.append(it.first);
info.append(": ");
info.append(it.second);
}
}
return info;
}
} // namespace ROCKSDB_NAMESPACE

@ -1,13 +1,10 @@
// Code from https://github.com/rust-rocksdb/rust-rocksdb/blob/eb2d302682418b361a80ad8f4dcf335ade60dcf5/librocksdb-sys/build.rs
// License: https://github.com/rust-rocksdb/rust-rocksdb/blob/master/LICENSE
use std::env;
use std::fs::File;
use std::io::Write;
use std::path::{Path, PathBuf};
use std::env::var;
use std::path::PathBuf;
fn link(name: &str, bundled: bool) {
use std::env::var;
let target = var("TARGET").unwrap();
let target: Vec<_> = target.split('-').collect();
if target.get(2) == Some(&"windows") {
@ -29,12 +26,12 @@ fn bindgen_rocksdb() {
.allowlist_var("rocksdb_.*")
.generate()
.expect("unable to generate rocksdb bindings")
.write_to_file(PathBuf::from(env::var("OUT_DIR").unwrap()).join("bindings.rs"))
.write_to_file(PathBuf::from(var("OUT_DIR").unwrap()).join("bindings.rs"))
.expect("unable to write rocksdb bindings");
}
fn build_rocksdb() {
let target = env::var("TARGET").unwrap();
let target = var("TARGET").unwrap();
let mut config = cc::Build::new();
config
@ -42,6 +39,7 @@ fn build_rocksdb() {
.include("rocksdb/include/")
.include("rocksdb/")
.file("api/c.cc")
.file("api/build_version.cc")
.define("NDEBUG", Some("1"))
.define("LZ4", Some("1"))
.include("lz4/lib/");
@ -62,7 +60,7 @@ fn build_rocksdb() {
// This is needed to enable hardware CRC32C. Technically, SSE 4.2 is
// only available since Intel Nehalem (about 2010) and AMD Bulldozer
// (about 2011).
let target_feature = env::var("CARGO_CFG_TARGET_FEATURE").unwrap();
let target_feature = var("CARGO_CFG_TARGET_FEATURE").unwrap();
let target_features: Vec<_> = target_feature.split(',').collect();
if target_features.contains(&"sse2") {
config.flag_if_supported("-msse2");
@ -148,29 +146,13 @@ fn build_rocksdb() {
config.flag("-std=c++11");
}
// version file
let build_version_cc_path = Path::new("rocksdb/util/build_version.cc");
if !build_version_cc_path.exists() {
let build_version_cc = include_str!("rocksdb/util/build_version.cc.in")
.replace("@GIT_SHA@", "")
.replace("@GIT_TAG@", "")
.replace("@GIT_MOD@", "0")
.replace("@GIT_DATE@", "")
.replace("@BUILD_DATE@", "");
File::create(build_version_cc_path)
.unwrap()
.write_all(build_version_cc.as_bytes())
.unwrap();
}
for file in lib_sources {
if file == "db/c.cc" {
if file == "db/c.cc" || file == "util/build_version.cc" {
continue;
}
let file = "rocksdb/".to_string() + file;
config.file(&file);
}
config.cpp(true);
config.compile("rocksdb");
}
@ -181,7 +163,7 @@ fn build_lz4() {
.file("lz4/lib/lz4frame.c")
.file("lz4/lib/lz4hc.c")
.file("lz4/lib/xxhash.c");
if env::var("TARGET").unwrap() == "i686-pc-windows-gnu" {
if var("TARGET").unwrap() == "i686-pc-windows-gnu" {
config.flag("-fno-tree-vectorize");
}
config.compile("lz4");

Loading…
Cancel
Save