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
19bedb31
Commit
19bedb31
authored
Jul 22, 2016
by
Jay
Committed by
GitHub
Jul 22, 2016
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
support static link (#26)
parent
ebf9de0f
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
200 additions
and
0 deletions
+200
-0
Cargo.toml
librocksdb_sys/Cargo.toml
+1
-0
build.rs
librocksdb_sys/build.rs
+92
-0
build.sh
librocksdb_sys/build.sh
+107
-0
No files found.
librocksdb_sys/Cargo.toml
View file @
19bedb31
...
@@ -2,6 +2,7 @@
...
@@ -2,6 +2,7 @@
name
=
"librocksdb_sys"
name
=
"librocksdb_sys"
version
=
"0.1.0"
version
=
"0.1.0"
authors
=
[
"Jay Lee <busyjaylee@gmail.com>"
]
authors
=
[
"Jay Lee <busyjaylee@gmail.com>"
]
build
=
"build.rs"
[dependencies]
[dependencies]
libc
=
"0.1.8"
libc
=
"0.1.8"
...
...
librocksdb_sys/build.rs
0 → 100644
View file @
19bedb31
use
std
::
env
;
use
std
::
fs
;
use
std
::
path
::
PathBuf
;
use
std
::
process
::
Command
;
macro_rules!
t
{
(
$e:expr
)
=>
(
match
$e
{
Ok
(
n
)
=>
n
,
Err
(
e
)
=>
panic!
(
"
\n
{} failed with {}
\n
"
,
stringify!
(
$e
),
e
),
})
}
fn
main
()
{
let
want_static
=
env
::
var
(
"ROCKSDB_SYS_STATIC"
)
.map
(|
s
|
s
==
"1"
)
.unwrap_or
(
false
);
if
!
want_static
{
return
;
}
let
target
=
env
::
var
(
"TARGET"
)
.unwrap
();
if
!
target
.contains
(
"linux"
)
&&
!
target
.contains
(
"darwin"
)
{
// only linux and apple support static link right now
return
;
}
let
dst
=
PathBuf
::
from
(
env
::
var_os
(
"OUT_DIR"
)
.unwrap
());
let
build
=
dst
.join
(
"build"
);
t!
(
fs
::
create_dir_all
(
&
build
));
let
fest_dir
=
env
::
var
(
"CARGO_MANIFEST_DIR"
)
.unwrap
();
let
p
=
PathBuf
::
from
(
fest_dir
)
.join
(
"build.sh"
);
for
lib
in
&
[
"z"
,
"snappy"
,
"bz2"
,
"lz4"
,
"rocksdb"
]
{
let
lib_name
=
format!
(
"lib{}.a"
,
lib
);
let
src
=
build
.join
(
&
lib_name
);
let
dst
=
dst
.join
(
&
lib_name
);
if
dst
.exists
()
{
continue
;
}
if
!
src
.exists
()
{
let
mut
cmd
=
Command
::
new
(
p
.as_path
());
cmd
.current_dir
(
&
build
)
.args
(
&
[
format!
(
"compile_{}"
,
lib
)]);
if
*
lib
==
"rocksdb"
{
if
let
Some
(
s
)
=
env
::
var
(
"ROCKSDB_SYS_PORTABLE"
)
.ok
()
{
cmd
.env
(
"PORTABLE"
,
s
);
}
}
run
(
&
mut
cmd
);
}
if
let
Err
(
e
)
=
fs
::
rename
(
src
.as_path
(),
dst
.as_path
())
{
panic!
(
"failed to move {} to {}: {:?}"
,
src
.display
(),
dst
.display
(),
e
);
}
}
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=snappy"
);
println!
(
"cargo:rustc-link-search=native={}"
,
dst
.display
());
let
mut
cpp_linked
=
false
;
if
let
Ok
(
libs
)
=
env
::
var
(
"ROCKSDB_OTHER_STATIC"
)
{
for
lib
in
libs
.split
(
":"
)
{
if
lib
==
"stdc++"
{
cpp_linked
=
true
;
}
println!
(
"cargo:rustc-link-lib=static={}"
,
lib
);
}
if
let
Ok
(
pathes
)
=
env
::
var
(
"ROCKSDB_OTHER_STATIC_PATH"
)
{
for
p
in
pathes
.split
(
":"
)
{
println!
(
"cargo:rustc-link-search=native={}"
,
p
);
}
}
}
// TODO: find a reliable way to link stdc++ statically.
if
!
cpp_linked
{
println!
(
"cargo:rustc-link-lib=stdc++"
);
}
}
fn
run
(
cmd
:
&
mut
Command
)
{
println!
(
"running: {:?}"
,
cmd
);
let
status
=
match
cmd
.status
()
{
Ok
(
s
)
=>
s
,
Err
(
e
)
=>
panic!
(
"{:?} failed: {}"
,
cmd
,
e
),
};
if
!
status
.success
()
{
panic!
(
"{:?} failed: {}"
,
cmd
,
status
);
}
}
librocksdb_sys/build.sh
0 → 100755
View file @
19bedb31
#!/usr/bin/env bash
set
-e
function
panic
()
{
echo
$@
>
&2
exit
1
}
function
download
()
{
if
which wget &>/dev/null
;
then
wget
$1
-O
$2
elif
which curl &>/dev/null
;
then
curl
-L
$1
-o
$2
else
panic can
\'
t find wget and curl.
fi
if
which
md5sum
&>/dev/null
;
then
hash
=
`
md5sum
$2
|
cut
-d
' '
-f
1
`
elif
which openssl &>/dev/null
;
then
hash
=
`
openssl md5
-hex
$2
|
cut
-d
' '
-f
2
`
else
panic can
\'
t find
hash
tool.
fi
[[
"
$hash
"
==
"
$3
"
]]
||
panic
$2
:
hash
not correct, expect
$3
, got
$hash
}
function
compile_z
()
{
if
[[
-f
libz.a
]]
;
then
return
fi
rm
-rf
zlib-1.2.8
download http://zlib.net/zlib-1.2.8.tar.gz zlib-1.2.8.tar.gz 44d667c142d7cda120332623eab69f40
tar
xf zlib-1.2.8.tar.gz
cd
zlib-1.2.8
CFLAGS
=
'-fPIC'
./configure
--static
make
cp
libz.a ../
cd
..
}
function
compile_bz2
()
{
if
[[
-f
libbz2.a
]]
;
then
return
fi
rm
-rf
bzip2-1.0.6
download http://www.bzip.org/1.0.6/bzip2-1.0.6.tar.gz bzip2-1.0.6.tar.gz 00b516f4704d4a7cb50a1d97e6e8e15b
tar
xvzf bzip2-1.0.6.tar.gz
cd
bzip2-1.0.6
make
CFLAGS
=
'-fPIC -O2 -g -D_FILE_OFFSET_BITS=64'
cp
libbz2.a ../
cd
..
}
function
compile_snappy
()
{
if
[[
-f
libsnappy.a
]]
;
then
return
fi
rm
-rf
snappy-1.1.1
download http://pkgs.fedoraproject.org/repo/pkgs/snappy/snappy-1.1.1.tar.gz/8887e3b7253b22a31f5486bca3cbc1c2/snappy-1.1.1.tar.gz snappy-1.1.1.tar.gz 8887e3b7253b22a31f5486bca3cbc1c2
tar
xvzf snappy-1.1.1.tar.gz
cd
snappy-1.1.1
./configure
--with-pic
--enable-static
make
mv
.libs/libsnappy.a ../
cd
..
}
function
compile_lz4
()
{
if
[[
-f
liblz4.a
]]
;
then
return
fi
rm
-rf
lz4-r127
download https://github.com/Cyan4973/lz4/archive/r131.tar.gz lz4-r131.tar.gz 42b09fab42331da9d3fb33bd5c560de9
tar
xvzf lz4-r131.tar.gz
cd
lz4-r131/lib
make
CFLAGS
=
'-fPIC'
all
mv
liblz4.a ../../
cd
../..
}
function
compile_rocksdb
()
{
if
[[
-f
librocksdb.a
]]
;
then
return
fi
version
=
4.9.fb
echo
building rocksdb-
$version
rm
-rf
rocksdb-
$version
download https://github.com/facebook/rocksdb/archive/
$version
.tar.gz rocksdb-
$version
.tar.gz 75f00635d4dcf0200db54a9244ac5f1d
tar
xf rocksdb-
$version
.tar.gz
cd
rocksdb-
$version
EXTRA_CFLAGS
=
"-fPIC -I./zlib-1.2.8 -I./bzip2-1.0.6 -I./snappy-1.1.1 -I./lz4-r127/lib"
EXTRA_CXXFLAGS
=
"
$EXTRA_CFLAGS
"
make static_lib
mv
librocksdb.a ../
}
if
[[
$#
-ne
1
]]
;
then
panic
$0
[
compile_bz2|compile_z|compile_lz4|compile_rocksdb|compile_snappy]
fi
$1
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