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
6c32ab80
Commit
6c32ab80
authored
Oct 26, 2016
by
Jay
Committed by
GitHub
Oct 26, 2016
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
use feature to control static link (#52)
parent
9e6db6fc
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
45 additions
and
22 deletions
+45
-22
Cargo.toml
Cargo.toml
+4
-2
Cargo.toml
librocksdb_sys/Cargo.toml
+7
-0
build.rs
librocksdb_sys/build.rs
+29
-15
build.sh
librocksdb_sys/build.sh
+5
-5
No files found.
Cargo.toml
View file @
6c32ab80
...
...
@@ -15,8 +15,10 @@ exclude = [
]
[features]
default
=[]
valgrind
=[]
default
=
[]
valgrind
=
[]
static-link
=
["librocksdb_sys/static-link"]
portable
=
["librocksdb_sys/portable"]
[[test]]
...
...
librocksdb_sys/Cargo.toml
View file @
6c32ab80
...
...
@@ -7,3 +7,10 @@ build = "build.rs"
[dependencies]
libc
=
"0.2.11"
tempdir
=
"0.3"
[features]
default
=
[]
static-link
=
[]
# portable doesn't require static link, though it's meaningless
# when not using with static-link right now in this crate.
portable
=
[]
librocksdb_sys/build.rs
View file @
6c32ab80
...
...
@@ -10,13 +10,10 @@ macro_rules! t {
}
fn
main
()
{
let
want_static
=
env
::
var
(
"ROCKSDB_SYS_STATIC"
)
.map
(|
s
|
s
==
"1"
)
.unwrap_or
(
false
);
if
!
want_static
{
if
!
cfg!
(
feature
=
"static-link"
)
{
return
;
}
let
target
=
env
::
var
(
"TARGET"
)
.unwrap
();
if
!
target
.contains
(
"linux"
)
&&
!
target
.contains
(
"darwin"
)
{
if
!
cfg!
(
target_os
=
"linux"
)
&&
!
cfg!
(
target_os
=
"macos"
)
{
// only linux and apple support static link right now
return
;
}
...
...
@@ -31,24 +28,31 @@ fn main() {
let
lib_name
=
format!
(
"lib{}.a"
,
lib
);
let
src
=
build
.join
(
&
lib_name
);
let
dst
=
dst
.join
(
&
lib_name
);
if
dst
.exists
()
{
if
dst
.exists
()
&&
*
lib
!=
"rocksdb"
{
continue
;
}
if
*
lib
==
"rocksdb"
&&
src
.exists
()
{
fs
::
remove_dir_all
(
&
src
)
.unwrap
();
}
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
);
if
cfg!
(
feature
=
"portable"
)
{
cmd
.env
(
"PORTABLE"
,
"1"
);
}
}
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
);
panic!
(
"failed to move {} to {}: {:?}"
,
src
.display
(),
dst
.display
(),
e
);
}
}
...
...
@@ -60,9 +64,15 @@ fn main() {
println!
(
"cargo:rustc-link-search=native={}"
,
dst
.display
());
let
mut
cpp_linked
=
false
;
let
std_lib_name
=
if
cfg!
(
target_os
=
"linux"
)
{
"libstdc++.a"
}
else
{
"libc++.a"
};
let
short_std_lib_name
=
&
std_lib_name
[
3
..
std_lib_name
.len
()
-
2
];
if
let
Ok
(
libs
)
=
env
::
var
(
"ROCKSDB_OTHER_STATIC"
)
{
for
lib
in
libs
.split
(
":"
)
{
if
lib
==
"stdc++"
{
if
lib
==
short_std_lib_name
{
cpp_linked
=
true
;
}
println!
(
"cargo:rustc-link-lib=static={}"
,
lib
);
...
...
@@ -74,19 +84,23 @@ fn main() {
}
}
if
!
cpp_linked
{
let
output
=
Command
::
new
(
p
.as_path
())
.arg
(
"find_stdcxx"
)
.output
()
.unwrap
();
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
());
println!
(
"cargo:rustc-link-search=native={}"
,
path
.parent
()
.unwrap
()
.display
());
return
;
}
}
}
println!
(
"failed to detect libstdc++.a: {:?}, fallback to dynamic"
,
output
);
println!
(
"cargo:rustc-link-lib=stdc++"
);
println!
(
"failed to detect {}: {:?}, fallback to dynamic"
,
std_lib_name
,
output
);
println!
(
"cargo:rustc-link-lib={}"
,
&
short_std_lib_name
);
}
}
...
...
librocksdb_sys/build.sh
View file @
6c32ab80
...
...
@@ -119,7 +119,7 @@ function compile_rocksdb() {
mv
librocksdb.a ../
}
function
find_
stdcxx
()
{
function
find_
library
()
{
if
[[
"
$CXX
"
=
""
]]
;
then
if
g++
--version
&>/dev/null
;
then
CXX
=
g++
...
...
@@ -130,11 +130,11 @@ function find_stdcxx() {
fi
fi
$CXX
--print-file-name
libstdc++.a
$CXX
--print-file-name
$1
}
if
[[
$#
-
ne
1
]]
;
then
error
$0
[
compile_bz2
\|
compile_z
\|
compile_lz4
\|
compile_rocksdb
\|
compile_snappy
\|
find_
stdcxx
]
if
[[
$#
-
eq
0
]]
;
then
error
$0
[
compile_bz2
\|
compile_z
\|
compile_lz4
\|
compile_rocksdb
\|
compile_snappy
\|
find_
library
]
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