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
809c1dc9
Commit
809c1dc9
authored
Dec 18, 2019
by
Fu Chen
Committed by
pingcap-github-bot
Dec 18, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
bindgen: pre-generate bindings (#402)
parent
8d06b36b
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
66 additions
and
0 deletions
+66
-0
README.md
README.md
+8
-0
Cargo.toml
librocksdb_sys/Cargo.toml
+1
-0
x86_64-unknown-linux-gnu-bindings.rs
librocksdb_sys/bindings/x86_64-unknown-linux-gnu-bindings.rs
+0
-0
build.rs
librocksdb_sys/build.rs
+48
-0
generate-bindings.sh
scripts/generate-bindings.sh
+9
-0
No files found.
README.md
View file @
809c1dc9
...
...
@@ -34,6 +34,14 @@ $ git submodule update --init --recursive # if you just cloned the repository
$ cargo build
```
Bindings are pre-generated for x86_64 Linux. For other platforms, bindings are generated at compile time.
If the content in librocksdb_sys/crocksdb/crocksdb/c.h is updated, you may need to regenerate bindings:
```
$ ./scripts/generate-bindings.sh
```
## Running
###### Cargo.toml
...
...
librocksdb_sys/Cargo.toml
View file @
809c1dc9
...
...
@@ -23,6 +23,7 @@ sse = ["libtitan_sys/sse"]
[build-dependencies]
cc
=
"1.0.3"
cmake
=
"0.1"
bindgen
=
"0.52"
[dependencies.jemalloc-sys]
version
=
"0.1.8"
...
...
librocksdb_sys/bindings/x86_64-unknown-linux-gnu-bindings.rs
0 → 100644
View file @
809c1dc9
This source diff could not be displayed because it is too large. You can
view the blob
instead.
librocksdb_sys/build.rs
View file @
809c1dc9
...
...
@@ -11,6 +11,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.
extern
crate
bindgen
;
extern
crate
cc
;
extern
crate
cmake
;
...
...
@@ -24,7 +25,52 @@ use std::{env, str};
// See https://github.com/gnzlbg/jemallocator/blob/bfc89192971e026e6423d9ee5aaa02bc56585c58/jemalloc-sys/build.rs#L45
const
NO_JEMALLOC_TARGETS
:
&
[
&
str
]
=
&
[
"android"
,
"dragonfly"
,
"musl"
,
"darwin"
];
// Generate the bindings to rocksdb C-API.
// Try to disable the generation of platform-related bindings.
fn
bindgen_rocksdb
(
file_path
:
&
PathBuf
)
{
let
bindings
=
bindgen
::
Builder
::
default
()
.header
(
"crocksdb/crocksdb/c.h"
)
.ctypes_prefix
(
"libc"
)
.generate
()
.expect
(
"unable to generate rocksdb bindings"
);
bindings
.write_to_file
(
file_path
)
.expect
(
"unable to write rocksdb bindings"
);
}
// Determine if need to update bindings. Supported platforms do not
// need to be updated by default unless the UPDATE_BIND is specified.
// Other platforms use bindgen to generate the bindings every time.
fn
config_binding_path
()
{
let
file_path
:
PathBuf
;
match
env
::
var
(
"TARGET"
)
.unwrap_or
(
""
.to_owned
())
.as_str
()
{
"x86_64-unknown-linux-gnu"
=>
{
file_path
=
PathBuf
::
from
(
env
::
var
(
"CARGO_MANIFEST_DIR"
)
.unwrap
())
.join
(
"bindings"
)
.join
(
"x86_64-unknown-linux-gnu-bindings.rs"
);
if
env
::
var
(
"UPDATE_BIND"
)
.map
(|
s
|
s
==
"1"
.to_owned
())
.unwrap_or
(
false
)
{
bindgen_rocksdb
(
&
file_path
);
}
}
_
=>
{
file_path
=
PathBuf
::
from
(
env
::
var
(
"OUT_DIR"
)
.unwrap
())
.join
(
"rocksdb-bindings.rs"
);
bindgen_rocksdb
(
&
file_path
);
}
};
println!
(
"cargo:rustc-env=BINDING_PATH={}"
,
file_path
.to_str
()
.unwrap
()
);
}
fn
main
()
{
println!
(
"cargo:rerun-if-env-changed=UPDATE_BIND"
);
let
mut
build
=
build_rocksdb
();
build
.cpp
(
true
)
.file
(
"crocksdb/c.cc"
);
...
...
@@ -134,6 +180,8 @@ fn build_rocksdb() -> Build {
build
.define
(
"OS_FREEBSD"
,
None
);
}
config_binding_path
();
let
cur_dir
=
env
::
current_dir
()
.unwrap
();
build
.include
(
cur_dir
.join
(
"rocksdb"
)
.join
(
"include"
));
build
.include
(
cur_dir
.join
(
"rocksdb"
));
...
...
scripts/generate-bindings.sh
0 → 100755
View file @
809c1dc9
#!/bin/bash
# NOTE:
# This script is only used when you want to generate bindings yourself.
# The generated bindings will overwrite librocksdb_sys/bindings/*
export
UPDATE_BIND
=
1
cargo build
--target
x86_64-unknown-linux-gnu
rustfmt librocksdb_sys/bindings/
*
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