Skip to content
Merged
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
3 changes: 3 additions & 0 deletions crates/vdb-ffi/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,6 @@ edition = "2021"

[lib]
path = "src/lib.rs"

[build-dependencies]
bindgen = "0.72"
23 changes: 23 additions & 0 deletions crates/vdb-ffi/build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
use std::{env, path::PathBuf};

fn main() {
println!("cargo:rerun-if-changed=../../cpp/vector_engine_ffi.h");

let bindings = bindgen::Builder::default()
.header("../../cpp/vector_engine_ffi.h")
.clang_arg("-xc++")
.clang_arg("-std=c++17")
.clang_arg("-I../../cpp")
.allowlist_type("NativeVectorEngine")
.allowlist_type("NativeSearchResults")
.allowlist_function("native_.*")
.layout_tests(false)
.generate()
.expect("failed to generate FFI bindings with bindgen");

let out_dir = PathBuf::from(env::var("OUT_DIR").expect("OUT_DIR was not set"));

bindings
.write_to_file(out_dir.join("bindings.rs"))
.expect("failed to write generated bindings");
}
24 changes: 0 additions & 24 deletions crates/vdb-ffi/src/bindings.rs

This file was deleted.

6 changes: 2 additions & 4 deletions crates/vdb-ffi/src/engine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,8 @@ impl FfiSearchResults {
pub fn id_at(&self, index: usize) -> String {
let id_ptr = unsafe { native_search_results_id_at(self.handle, index) };

unsafe { CStr::from_ptr(id_ptr) }
.to_str()
.expect("native search result ID must be valid")
.to_string()
unsafe { CStr::from_ptr(id_ptr) }.to_str().expect("native search result ID must be valid").to_string()
// first converting pointer to rust CStr, then rust string
}

pub fn score_at(&self, index: usize) -> f32 {
Expand Down
6 changes: 5 additions & 1 deletion crates/vdb-ffi/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
mod bindings;
mod engine;

#[allow(non_camel_case_types, non_snake_case, non_upper_case_globals)]
mod bindings {
include!(concat!(env!("OUT_DIR"), "/bindings.rs"));
}

pub use engine::{FfiSearchResults, FfiVectorEngine};
Loading