little added abstraction, c++ ffi shell#6
Closed
kishangoli wants to merge 2 commits into
Closed
Conversation
There was a problem hiding this comment.
Pull request overview
This PR introduces a small abstraction layer around the vector engine to allow swapping implementations later, and adds a minimal C++ FFI “shell” compiled via build.rs to support future Rust ↔ C++ communication.
Changes:
- Generalize the in-memory engine storage to a boxed
dyn VectorEnginein application state. - Move
dimension()onto theVectorEnginetrait so API handlers can validate vector sizes through the abstraction. - Add a C++ FFI stub (
native/...) and a Rust build script usingccto compile it.
Reviewed changes
Copilot reviewed 7 out of 8 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| src/state.rs | Store the engine behind Box<dyn VectorEngine> for implementation swapping. |
| src/engine.rs | Promote dimension() to the VectorEngine trait and implement it for FlatIndex. |
| src/api/handlers.rs | Remove now-unneeded VectorEngine import; handlers call dimension() through the state-held trait object. |
| native/src/vector_engine_ffi.cpp | Add initial C++ FFI allocation/free stubs. |
| native/include/vector_engine_ffi.h | Add FFI header declaring the C ABI surface. |
| Cargo.toml | Add cc as a build-dependency. |
| Cargo.lock | Lockfile updates for cc and transitive deps. |
| build.rs | Compile the C++ FFI stub during the Rust build. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
1
to
8
| use std::sync::{Arc, Mutex}; | ||
|
|
||
| use crate::engine::FlatIndex; | ||
| use crate::engine::{FlatIndex, VectorEngine}; | ||
|
|
||
| #[derive(Clone)] | ||
| pub struct AppState { | ||
| pub engine: Arc<Mutex<FlatIndex>>, | ||
| pub engine: Arc<Mutex<Box<dyn VectorEngine + Send>>>, | ||
| } |
Comment on lines
+5
to
+11
|
|
||
| extern "C" { | ||
|
|
||
| NativeVectorEngine* native_vector_engine_new(); | ||
| void native_vector_engine_free(NativeVectorEngine* engine); | ||
|
|
||
| } |
Comment on lines
+1
to
+7
| fn main() { | ||
| cc::Build::new() | ||
| .cpp(true) | ||
| .file("native/src/vector_engine_ffi.cpp") | ||
| .include("native/include") | ||
| .std("c++17") | ||
| .compile("vector_engine_ffi"); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
added some small api abstraction, dynamically allocating space for when we shift implementation. added ffi shell for rust -> c++ comms