diff --git a/lib/oxigraph/Cargo.toml b/lib/oxigraph/Cargo.toml index d538ce89..995cf1c4 100644 --- a/lib/oxigraph/Cargo.toml +++ b/lib/oxigraph/Cargo.toml @@ -41,7 +41,7 @@ thiserror.workspace = true [target.'cfg(not(target_family = "wasm"))'.dependencies] libc = "0.2" -rocksdb = {git = "https://git.nextgraph.org/NextGraph/rust-rocksdb.git", branch = "master", features = [ ], optional = true } +rocksdb = {git = "https://git.nextgraph.org/NextGraph/rust-rocksdb.git", branch = "master", features = [ ] } [target.'cfg(all(target_family = "wasm", target_os = "unknown"))'.dependencies] getrandom.workspace = true diff --git a/lib/oxigraph/src/storage/backend/mod.rs b/lib/oxigraph/src/storage/backend/mod.rs index db2ebd5f..b94eb657 100644 --- a/lib/oxigraph/src/storage/backend/mod.rs +++ b/lib/oxigraph/src/storage/backend/mod.rs @@ -1,12 +1,12 @@ //! A storage backend //! RocksDB is available, if not in memory -#[cfg(any(target_family = "wasm", not(feature = "rocksdb")))] +#[cfg(any(target_family = "wasm"))] pub use fallback::{ColumnFamily, ColumnFamilyDefinition, Db, Iter, Reader, Transaction}; -#[cfg(all(not(target_family = "wasm"), feature = "rocksdb"))] +#[cfg(all(not(target_family = "wasm")))] pub use oxi_rocksdb::{ColumnFamily, ColumnFamilyDefinition, Db, Iter, Reader, Transaction}; -#[cfg(any(target_family = "wasm", not(feature = "rocksdb")))] +#[cfg(any(target_family = "wasm"))] mod fallback; -#[cfg(all(not(target_family = "wasm"), feature = "rocksdb"))] +#[cfg(all(not(target_family = "wasm")))] mod oxi_rocksdb; diff --git a/lib/oxigraph/src/storage/backend/oxi_rocksdb.rs b/lib/oxigraph/src/storage/backend/oxi_rocksdb.rs index 0f194a6e..5c5b96fd 100644 --- a/lib/oxigraph/src/storage/backend/oxi_rocksdb.rs +++ b/lib/oxigraph/src/storage/backend/oxi_rocksdb.rs @@ -28,6 +28,13 @@ use std::sync::{Arc, OnceLock}; use std::thread::{available_parallelism, yield_now}; use std::{fmt, io, ptr, slice}; +pub fn opt_bytes_to_ptr>(opt: Option) -> *const c_char { + match opt { + Some(v) => v.as_ref().as_ptr() as *const c_char, + None => ptr::null(), + } +} + macro_rules! ffi_result { ( $($function:ident)::*( $arg1:expr $(, $arg:expr)* $(,)? ) ) => {{ let mut status = rocksdb_status_t { @@ -440,6 +447,7 @@ impl Db { fn db_options( limit_max_open_files: bool, in_memory: bool, + key: Option<[u8; 32]>, ) -> Result<*mut rocksdb_options_t, StorageError> { static ROCKSDB_ENV: OnceLock = OnceLock::new(); static ROCKSDB_MEM_ENV: OnceLock = OnceLock::new(); @@ -487,8 +495,8 @@ impl Db { }) } else { ROCKSDB_ENV.get_or_init(|| { - let env = rocksdb_create_default_env(); - assert!(!env.is_null(), "rocksdb_create_default_env returned null"); + let env = rocksdb_create_encrypted_env(opt_bytes_to_ptr(key.as_ref())); + assert!(!env.is_null(), "rocksdb_create_encrypted_env returned null"); UnsafeEnv(env) }) }