diff --git a/vortex-duckdb/Cargo.toml b/vortex-duckdb/Cargo.toml index 7dc239a4b1a..b6896910a89 100644 --- a/vortex-duckdb/Cargo.toml +++ b/vortex-duckdb/Cargo.toml @@ -21,7 +21,7 @@ links = "duckdb" [lib] name = "vortex_duckdb" path = "src/lib.rs" -crate-type = ["staticlib", "cdylib", "rlib"] +crate-type = ["rlib"] [dependencies] async-fs = { workspace = true } diff --git a/vortex-duckdb/include/vortex.h b/vortex-duckdb/include/vortex.h index 42edf13655c..57339009ba8 100644 --- a/vortex-duckdb/include/vortex.h +++ b/vortex-duckdb/include/vortex.h @@ -15,12 +15,6 @@ extern "C" { #endif // __cplusplus -extern void vortex_init_rust(duckdb_database db); - -extern const char *vortex_version_rust(void); - -extern const char *vortex_extension_version_rust(void); - extern void duckdb_table_function_to_string(void *bind_data, duckdb_vx_string_map map); extern diff --git a/vortex-duckdb/src/lib.rs b/vortex-duckdb/src/lib.rs index b21801b4564..4a4d563e55b 100644 --- a/vortex-duckdb/src/lib.rs +++ b/vortex-duckdb/src/lib.rs @@ -3,8 +3,8 @@ #![expect(clippy::missing_safety_doc)] -use std::ffi::CStr; use std::ffi::c_char; +use std::ffi::c_void; use std::sync::LazyLock; use std::sync::OnceLock; @@ -79,19 +79,10 @@ pub fn initialize(db: &DatabaseRef) -> VortexResult<()> { db.register_copy_function() } -/// Global symbol visibility in the Vortex extension: -/// - Rust functions use C ABI with "_rust" suffix (e.g., vortex_init_rust) -/// - C++ wrapper functions have the expected name without suffix (e.g., vortex_init) -/// - C++ wrappers are annotated with DUCKDB_EXTENSION_API to ensure global visibility -/// - C++ wrappers call the corresponding Rust functions -/// -/// This ensures DuckDB can find the symbols when loading the extension. -/// -/// The DuckDB extension ABI initialization function. -#[unsafe(no_mangle)] -pub unsafe extern "C" fn vortex_init_rust(db: cpp::duckdb_database) { +/// Initialize the DuckDB extension from a raw DuckDB database pointer. +pub unsafe fn initialize_extension_from_raw(db: *mut c_void) { init_tracing(); - let database = unsafe { Database::borrow(db) }; + let database = unsafe { Database::borrow(db.cast()) }; database .register_vortex_scan_replacement() @@ -99,20 +90,12 @@ pub unsafe extern "C" fn vortex_init_rust(db: cpp::duckdb_database) { initialize(database).vortex_expect("Failed to initialize Vortex extension"); } -/// The DuckDB extension ABI version function. -/// This function returns the version of the DuckDB library the extension is built against. -#[unsafe(no_mangle)] -pub extern "C" fn vortex_version_rust() -> *const c_char { +/// Returns the version of the DuckDB library the extension is built against. +pub fn duckdb_library_version() -> *const c_char { unsafe { cpp::duckdb_library_version() } } -/// An additional function we export to expose the version of the extension itself to C++ code. -#[unsafe(no_mangle)] -pub extern "C" fn vortex_extension_version_rust() -> *const c_char { - // We do some fiddly macros here to get ourselves a _static_ C-style string. - // Otherwise, we'd be leaking memory. - unsafe { - CStr::from_bytes_with_nul_unchecked(concat!(env!("CARGO_PKG_VERSION"), "\0").as_bytes()) - } - .as_ptr() +/// Returns the version of the Vortex DuckDB extension. +pub fn extension_version() -> *const c_char { + concat!(env!("CARGO_PKG_VERSION"), "\0").as_ptr().cast() }