Env::version()

master
Niko PLP 1 year ago
parent 963faad14f
commit 813d75890f
  1. 4
      Cargo.toml
  2. 3
      librocksdb-sys/api/.clang-format
  3. 18
      librocksdb-sys/api/c.cc
  4. 11
      librocksdb-sys/api/c.h
  5. 2
      librocksdb-sys/build.rs
  6. 11
      src/env.rs

@ -5,11 +5,11 @@ version = "0.21.0"
edition = "2018"
rust-version = "1.60"
authors = ["Tyler Neely <t@jujit.su>", "David Greenberg <dsg123456789@gmail.com>"]
repository = "https://github.com/rust-rocksdb/rust-rocksdb"
repository = "https://git.nextgraph.org/NextGraph/rust-rocksdb"
license = "Apache-2.0"
categories = [ "database" ]
keywords = ["database", "embedded", "LSM-tree", "persistence"]
homepage = "https://github.com/rust-rocksdb/rust-rocksdb"
homepage = "https://git.nextgraph.org/NextGraph/rust-rocksdb"
exclude = [
".gitignore",
".travis.yml",

@ -0,0 +1,3 @@
---
BasedOnStyle: Google
...

@ -0,0 +1,18 @@
#include "../rocksdb/include/rocksdb/version.h"
#include "c.h"
static char* CopyString(const std::string& str) {
char* result = reinterpret_cast<char*>(malloc(sizeof(char) * str.size()));
memcpy(result, str.data(), sizeof(char) * str.size());
return result;
}
extern "C" {
char* rocksdb_version() {
auto name = ROCKSDB_NAMESPACE::GetRocksVersionAsString(true);
return CopyString(name);
}
}

@ -0,0 +1,11 @@
#pragma once
#ifdef __cplusplus
extern "C" {
#endif
char* rocksdb_version();
#ifdef __cplusplus
}
#endif

@ -32,6 +32,7 @@ fn rocksdb_include_dir() -> String {
fn bindgen_rocksdb() {
let bindings = bindgen::Builder::default()
.header(rocksdb_include_dir() + "/rocksdb/c.h")
.header("api/c.h")
.derive_debug(false)
.blocklist_type("max_align_t") // https://github.com/rust-lang-nursery/rust-bindgen/issues/550
.ctypes_prefix("libc")
@ -255,6 +256,7 @@ fn build_rocksdb() {
}
config.file("build_version.cc");
config.file("api/c.cc");
config.cpp(true);
config.flag_if_supported("-std=c++17");

@ -1,6 +1,7 @@
use std::sync::Arc;
use libc::{self, c_int};
use crate::ffi_util::from_cstr;
use libc::{self, c_char, c_int};
use crate::{ffi, Error};
@ -30,6 +31,14 @@ impl Drop for EnvWrapper {
}
impl Env {
pub fn version() -> String {
unsafe {
let ptr: *const c_char = ffi::rocksdb_version();
let s = from_cstr(ptr);
s
}
}
/// Returns default env
pub fn new() -> Result<Self, Error> {
let env = unsafe { ffi::rocksdb_create_default_env() };

Loading…
Cancel
Save