Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use bindgen to auto generate ffi rust code #398

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions librocksdb_sys/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
12 changes: 12 additions & 0 deletions librocksdb_sys/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -134,6 +135,17 @@ fn build_rocksdb() -> Build {
build.define("OS_FREEBSD", None);
}

let bindings = bindgen::Builder::default()
.header("crocksdb/crocksdb/c.h")
.ctypes_prefix("libc")
.generate()
.expect("unable to generate rocksdb bindings");

let out_path = PathBuf::from(env::var("OUT_DIR").unwrap());
bindings
.write_to_file(out_path.join("bindings.rs"))
.expect("unable to write rocksdb bindings");

let cur_dir = env::current_dir().unwrap();
build.include(cur_dir.join("rocksdb").join("include"));
build.include(cur_dir.join("rocksdb"));
Expand Down
7 changes: 5 additions & 2 deletions librocksdb_sys/crocksdb/c.cc
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,9 @@ struct crocksdb_sst_file_meta_data_t {
struct crocksdb_compaction_options_t {
CompactionOptions rep;
};
struct crocksdb_compaction_reason_t {
CompactionReason rep;
};

struct crocksdb_map_property_t {
std::map<std::string, std::string> rep;
Expand Down Expand Up @@ -2003,9 +2006,9 @@ uint64_t crocksdb_compactionjobinfo_total_output_bytes(
return info->rep.stats.total_output_bytes;
}

CompactionReason crocksdb_compactionjobinfo_compaction_reason(
const crocksdb_compaction_reason_t* crocksdb_compactionjobinfo_compaction_reason(
const crocksdb_compactionjobinfo_t* info) {
return info->rep.compaction_reason;
return reinterpret_cast<const crocksdb_compaction_reason_t*>(&info->rep.compaction_reason);
}

/* ExternalFileIngestionInfo */
Expand Down
3 changes: 3 additions & 0 deletions librocksdb_sys/crocksdb/crocksdb/c.h
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ typedef struct crocksdb_iostats_context_t crocksdb_iostats_context_t;
typedef struct crocksdb_writestallinfo_t crocksdb_writestallinfo_t;
typedef struct crocksdb_writestallcondition_t crocksdb_writestallcondition_t;
typedef struct crocksdb_map_property_t crocksdb_map_property_t;
typedef struct crocksdb_compaction_reason_t crocksdb_compaction_reason_t;

typedef enum crocksdb_table_property_t {
kDataSize = 1,
Expand Down Expand Up @@ -756,6 +757,8 @@ crocksdb_compactionjobinfo_total_input_bytes(
extern C_ROCKSDB_LIBRARY_API uint64_t
crocksdb_compactionjobinfo_total_output_bytes(
const crocksdb_compactionjobinfo_t* info);
extern C_ROCKSDB_LIBRARY_API const crocksdb_compaction_reason_t*
crocksdb_compactionjobinfo_compaction_reason(const crocksdb_compactionjobinfo_t* info);

/* External file ingestion info */
extern C_ROCKSDB_LIBRARY_API const char*
Expand Down
Loading