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
2 changes: 1 addition & 1 deletion vortex-duckdb/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand Down
6 changes: 0 additions & 6 deletions vortex-duckdb/include/vortex.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
35 changes: 9 additions & 26 deletions vortex-duckdb/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -79,40 +79,23 @@ 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()
.vortex_expect("failed to register vortex scan replacement");
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()
}
Loading