-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Enabling loading of static compiled extensions #3147
Comments
I don't know if I like the If you don't care, there's nothing stopping you from adding However, according to the SQLite documentation, you can also simply call the extension's init function with your database after it's initialized: https://www.sqlite.org/loadext.html#statically_linking_a_run_time_loadable_extension You can get access to the raw Strangely, the functions exported from I would accept adding a method to pub type SqliteExtensionInit = extern "C" fn(*mut sqlite3, *mut *const c_char, *mut sqlite3_api_routines) -> c_int;
impl SqliteConnectOptions {
/// Add a statically linked extension to the database by directly calling its init function.
///
/// This is similar to [`sqlite3_auto_extension()`](https://www.sqlite.org/c3ref/auto_extension.html)
/// but is constrained just to databases created with this `SqliteConnectOptions`.
///
/// ### SAFETY
/// The function pointer must be safe to call from any thread for the lifetime of this `SqliteConnectOptions`.
///
/// If you wish to dynamically load an extension, consider [`Self::extension()`] or [`Self::extension_with_entrypoint()`] instead.
pub unsafe fn extension_with_init(
&mut self,
init: SqliteExtensionInit,
) -> &mut Self {
// ..
}
} |
Thank you both for the pointers and the comments! After some finagling I was able to load the extension by directly calling use sqlite_vss::{sqlite3_vector_init, sqlite3_vss_init};
unsafe {
let vss_vector_init = sqlite3_vector_init as *const ();
let vss_vector_init_correct: extern "C" fn(
db: *mut sqlite3,
pzErrMsg: *mut *const c_char,
pThunk: *const sqlite3_api_routines,
) -> i32 = std::mem::transmute(vss_vector_init);
libsqlite3_sys::sqlite3_auto_extension(Some(vss_vector_init_correct));
let vss_init = sqlite3_vss_init as *const ();
let vss_init_correct: extern "C" fn(
db: *mut sqlite3,
pzErrMsg: *mut *const c_char,
pThunk: *const sqlite3_api_routines,
) -> i32 = std::mem::transmute(vss_init);
libsqlite3_sys::sqlite3_auto_extension(Some(vss_init_correct));
} I also had to add the following to the fn main() {
if cfg!(target_os = "macos") {
println!("cargo:rustc-link-arg=-Wl,-undefined,dynamic_lookup,-lomp,-L/opt/homebrew/opt/libomp/lib");
} else if cfg!(target_os = "linux") {
println!("cargo:rustc-link-arg=-Wl,-undefined,dynamic_lookup,-lstdc++");
}
} This should also work with |
I would like to load sqlite-vss extension for vector search. But rather than loading via an external library I would like to statically compile it as part of the binary so it can be embedded in the same rust program.
Is there an equivalent of this in sql?
The text was updated successfully, but these errors were encountered: