Unverified Commit 6ead62ca authored by yiwu-arbug's avatar yiwu-arbug Committed by GitHub

Avoid build require system zlib (#303)

`register_dep("Z")` correctly set the include path for zlib, but fail to set the path to libz.a. RocksDB cmake script expect libz.a be place under ${DEP_Z_ROOT}/lib, but libz-sys place it under ${DEP_Z_ROOT}/build. Fixed it.

Also added a test to make sure possible compression types are all linked.
Signed-off-by: 's avatarYi Wu <yiwu@pingcap.com>
parent 9246b9c5
......@@ -77,12 +77,6 @@ fn link_cpp(build: &mut Build) {
fn build_rocksdb() -> Build {
let target = env::var("TARGET").expect("TARGET was not set");
let mut build = Build::new();
for e in env::vars() {
println!("{:?}", e);
}
let mut cfg = Config::new("rocksdb");
if cfg!(feature = "jemalloc") && NO_JEMALLOC_TARGETS.iter().all(|i| !target.contains(i)) {
cfg.register_dep("JEMALLOC").define("WITH_JEMALLOC", "ON");
......@@ -93,6 +87,16 @@ fn build_rocksdb() -> Build {
if cfg!(feature = "sse") {
cfg.define("FORCE_SSE42", "ON");
}
// RocksDB cmake script expect libz.a being under ${DEP_Z_ROOT}/lib, but libz-sys crate put it
// under ${DEP_Z_ROOT}/build. Append the path to CMAKE_PREFIX_PATH to get around it.
env::set_var("CMAKE_PREFIX_PATH", {
let zlib_path = format!("{}/build", env::var("DEP_Z_ROOT").unwrap());
if let Ok(prefix_path) = env::var("CMAKE_PREFIX_PATH") {
format!("{};{}", prefix_path, zlib_path)
} else {
zlib_path
}
});
let dst = cfg
.define("WITH_GFLAGS", "OFF")
.register_dep("Z")
......@@ -106,8 +110,10 @@ fn build_rocksdb() -> Build {
.register_dep("SNAPPY")
.define("WITH_SNAPPY", "ON")
.build_target("rocksdb")
.very_verbose(true)
.build();
let build_dir = format!("{}/build", dst.display());
let mut build = Build::new();
if cfg!(target_os = "windows") {
let profile = match &*env::var("PROFILE").unwrap_or("debug".to_owned()) {
"bench" | "release" => "Release",
......
extern crate cc;
extern crate cmake;
use std::env;
fn main() {
// RocksDB cmake script expect libz.a being under ${DEP_Z_ROOT}/lib, but libz-sys crate put it
// under ${DEP_Z_ROOT}/build. Append the path to CMAKE_PREFIX_PATH to get around it.
env::set_var("CMAKE_PREFIX_PATH", {
let zlib_path = format!("{}/build", env::var("DEP_Z_ROOT").unwrap());
if let Ok(prefix_path) = env::var("CMAKE_PREFIX_PATH") {
format!("{};{}", prefix_path, zlib_path)
} else {
zlib_path
}
});
let cur_dir = std::env::current_dir().unwrap();
let mut cfg = cmake::Config::new("titan");
if cfg!(feature = "portable") {
......@@ -25,6 +37,7 @@ fn main() {
.register_dep("SNAPPY")
.define("WITH_SNAPPY", "ON")
.build_target("titan")
.very_verbose(true)
.build();
println!("cargo:rustc-link-search=native={}/build", dst.display());
println!("cargo:rustc-link-lib=static=titan");
......
......@@ -7,6 +7,7 @@ extern crate tempdir;
mod test_column_family;
mod test_compact_range;
mod test_compaction_filter;
mod test_compression;
mod test_delete_files_in_range;
mod test_delete_range;
mod test_encryption;
......
// Copyright 2018 PingCAP, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// See the License for the specific language governing permissions and
// limitations under the License.
use rocksdb::{ColumnFamilyOptions, DBCompressionType, DBOptions, DB};
use tempdir::TempDir;
#[test]
// Make sure all compression types are supported.
fn test_compression() {
let path = TempDir::new("_rust_rocksdb_test_metadata").unwrap();
let compression_types = [
DBCompressionType::Snappy,
DBCompressionType::Zlib,
DBCompressionType::Bz2,
DBCompressionType::Lz4,
DBCompressionType::Lz4hc,
DBCompressionType::Zstd,
];
for compression_type in compression_types.iter() {
let mut opts = DBOptions::new();
opts.create_if_missing(true);
let mut cf_opts = ColumnFamilyOptions::new();
cf_opts.compression(*compression_type);
// DB open will fail if compression type is not supported.
DB::open_cf(
opts,
path.path().to_str().unwrap(),
vec![("default", cf_opts)],
)
.unwrap();
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment