Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
R
rust-rocksdb
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
fangzongwu
rust-rocksdb
Commits
ab16db78
Commit
ab16db78
authored
Jul 11, 2017
by
Jay
Committed by
GitHub
Jul 11, 2017
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
adjust build (#94)
- always build crocksdb explicitly - fix linking on windows
parent
d593411a
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
58 additions
and
43 deletions
+58
-43
build.rs
librocksdb_sys/build.rs
+53
-38
build.sh
librocksdb_sys/build.sh
+3
-4
c.cc
librocksdb_sys/crocksdb/c.cc
+1
-1
c.h
librocksdb_sys/crocksdb/crocksdb/c.h
+0
-0
test_rocksdb_options.rs
tests/test_rocksdb_options.rs
+1
-0
No files found.
librocksdb_sys/build.rs
View file @
ab16db78
...
...
@@ -5,6 +5,8 @@ use std::{env, fs, str};
use
std
::
path
::
PathBuf
;
use
std
::
process
::
Command
;
use
gcc
::
Config
;
macro_rules!
t
{
(
$e:expr
)
=>
(
match
$e
{
Ok
(
n
)
=>
n
,
...
...
@@ -13,24 +15,40 @@ macro_rules! t {
}
fn
main
()
{
let
mut
cfg
=
build_rocksdb
();
cfg
.cpp
(
true
)
.file
(
"crocksdb/c.cc"
);
if
!
cfg!
(
target_os
=
"windows"
)
{
cfg
.flag
(
"-std=c++11"
);
}
cfg
.compile
(
"libcrocksdb.a"
);
println!
(
"cargo:rustc-link-lib=static=crocksdb"
);
}
fn
build_rocksdb
()
->
Config
{
let
mut
cfg
=
Config
::
new
();
if
!
cfg!
(
feature
=
"static-link"
)
{
gcc
::
Config
::
new
()
.cpp
(
true
)
.file
(
"crocksdb/c.cc"
)
.flag
(
"-std=c++11"
)
.flag
(
"-fPIC"
)
.flag
(
"-O2"
)
.compile
(
"libcrocksdb.a"
);
println!
(
"cargo:rustc-link-lib=static=crocksdb"
);
println!
(
"cargo:rustc-link-lib=rocksdb"
);
return
;
if
cfg!
(
target_os
=
"windows"
)
{
println!
(
"cargo:rustc-link-lib=rocksdb-shared"
);
}
else
{
println!
(
"cargo:rustc-link-lib=rocksdb"
);
}
return
cfg
;
}
println!
(
"cargo:rustc-link-lib=static=rocksdb"
);
println!
(
"cargo:rustc-link-lib=static=z"
);
println!
(
"cargo:rustc-link-lib=static=bz2"
);
println!
(
"cargo:rustc-link-lib=static=lz4"
);
println!
(
"cargo:rustc-link-lib=static=zstd"
);
println!
(
"cargo:rustc-link-lib=static=snappy"
);
if
!
cfg!
(
target_os
=
"linux"
)
&&
!
cfg!
(
target_os
=
"macos"
)
{
// only linux and apple support static link right now
return
;
// Compilation is not tested in other platform, so hopefully
// the static library is built already.
return
cfg
;
}
let
dst
=
PathBuf
::
from
(
env
::
var_os
(
"OUT_DIR"
)
.unwrap
());
...
...
@@ -39,8 +57,6 @@ fn main() {
let
fest_dir
=
env
::
var
(
"CARGO_MANIFEST_DIR"
)
.unwrap
();
let
p
=
PathBuf
::
from
(
fest_dir
.clone
())
.join
(
"build.sh"
);
let
crocksdb_path
=
PathBuf
::
from
(
fest_dir
)
.join
(
"crocksdb"
);
env
::
set_var
(
"CROCKSDB_PATH"
,
crocksdb_path
.to_str
()
.unwrap
());
for
lib
in
&
[
"z"
,
"snappy"
,
"bz2"
,
"lz4"
,
"zstd"
,
"rocksdb"
]
{
let
lib_name
=
format!
(
"lib{}.a"
,
lib
);
let
src
=
build
.join
(
&
lib_name
);
...
...
@@ -80,13 +96,8 @@ fn main() {
}
}
println!
(
"cargo:rustc-link-lib=static=rocksdb"
);
println!
(
"cargo:rustc-link-lib=static=z"
);
println!
(
"cargo:rustc-link-lib=static=bz2"
);
println!
(
"cargo:rustc-link-lib=static=lz4"
);
println!
(
"cargo:rustc-link-lib=static=zstd"
);
println!
(
"cargo:rustc-link-lib=static=snappy"
);
println!
(
"cargo:rustc-link-search=native={}"
,
dst
.display
());
cfg
.include
(
dst
.join
(
"build"
)
.join
(
"rocksdb"
)
.join
(
"include"
));
let
mut
cpp_linked
=
false
;
let
std_lib_name
=
if
cfg!
(
target_os
=
"linux"
)
{
...
...
@@ -108,25 +119,29 @@ fn main() {
}
}
}
if
!
cpp_linked
{
let
output
=
Command
::
new
(
p
.as_path
())
.args
(
&
[
"find_library"
,
std_lib_name
])
.output
()
.unwrap
();
if
output
.status
.success
()
&&
!
output
.stdout
.is_empty
()
{
if
let
Ok
(
path_str
)
=
str
::
from_utf8
(
&
output
.stdout
)
{
let
path
=
PathBuf
::
from
(
path_str
);
if
path
.is_absolute
()
{
println!
(
"cargo:rustc-link-lib=static=stdc++"
);
println!
(
"cargo:rustc-link-search=native={}"
,
path
.parent
()
.unwrap
()
.display
());
return
;
}
if
cpp_linked
{
cfg
.cpp_link_stdlib
(
None
);
return
cfg
;
}
let
output
=
Command
::
new
(
p
.as_path
())
.args
(
&
[
"find_library"
,
std_lib_name
])
.output
()
.unwrap
();
if
output
.status
.success
()
&&
!
output
.stdout
.is_empty
()
{
if
let
Ok
(
path_str
)
=
str
::
from_utf8
(
&
output
.stdout
)
{
let
path
=
PathBuf
::
from
(
path_str
);
if
path
.is_absolute
()
{
println!
(
"cargo:rustc-link-lib=static=stdc++"
);
println!
(
"cargo:rustc-link-search=native={}"
,
path
.parent
()
.unwrap
()
.display
());
cfg
.cpp_link_stdlib
(
None
);
return
cfg
;
}
}
println!
(
"failed to detect {}: {:?}, fallback to dynamic"
,
std_lib_name
,
output
);
println!
(
"cargo:rustc-link-lib={}"
,
&
short_std_lib_name
);
}
println!
(
"failed to detect {}: {:?}, fallback to dynamic"
,
std_lib_name
,
output
);
cfg
}
fn
run
(
cmd
:
&
mut
Command
)
{
...
...
librocksdb_sys/build.sh
View file @
ab16db78
...
...
@@ -127,13 +127,12 @@ function compile_rocksdb() {
version
=
v5.5.1
vernum
=
5.5.1
echo
building rocksdb-
$version
rm
-rf
rocksdb-
$vernum
rm
-rf
rocksdb
rocksdb
-
$vernum
download https://github.com/facebook/rocksdb/archive/
$version
.tar.gz rocksdb-
$version
.tar.gz d10fe596fe4c926ed3d68a8179f8edaa
tar
xf rocksdb-
$version
.tar.gz
wd
=
`
pwd
`
cd
rocksdb-
$vernum
cp
$CROCKSDB_PATH
/c.cc ./db/c.cc
cp
$CROCKSDB_PATH
/rocksdb/c.h ./include/rocksdb/c.h
mv
rocksdb-
$vernum
rocksdb
cd
rocksdb
export
EXTRA_CFLAGS
=
"-fPIC -I
${
wd
}
/zlib-1.2.11 -I
${
wd
}
/bzip2-1.0.6 -I
${
wd
}
/snappy-1.1.1 -I
${
wd
}
/lz4-r131/lib -I
${
wd
}
/zstd-1.2.0/lib"
export
EXTRA_CXXFLAGS
=
"-DZLIB -DBZIP2 -DSNAPPY -DLZ4 -DZSTD
$EXTRA_CFLAGS
"
make static_lib
-j
$con
...
...
librocksdb_sys/crocksdb/c.cc
View file @
ab16db78
...
...
@@ -7,7 +7,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. See the AUTHORS file for names of contributors.
#include "rocksdb/c.h"
#include "
c
rocksdb/c.h"
#include <stdlib.h>
#include "rocksdb/cache.h"
...
...
librocksdb_sys/crocksdb/rocksdb/c.h
→
librocksdb_sys/crocksdb/
c
rocksdb/c.h
View file @
ab16db78
File moved
tests/test_rocksdb_options.rs
View file @
ab16db78
...
...
@@ -148,6 +148,7 @@ fn test_set_wal_opt() {
drop
(
db
);
}
#[cfg(not(windows))]
#[test]
fn
test_sync_wal
()
{
let
path
=
TempDir
::
new
(
"_rust_rocksdb_test_sync_wal"
)
.expect
(
""
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment