Skip to content

Commit 131d89c

Browse files
committed
Split vortex-duckdb from the extension
Signed-off-by: Adam Gutglick <adam@spiraldb.com>
1 parent c2119d9 commit 131d89c

8 files changed

Lines changed: 86 additions & 35 deletions

File tree

Cargo.lock

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ members = [
2626
"vortex-bench",
2727
"vortex-datafusion",
2828
"vortex-duckdb",
29+
"vortex-duckdb-extension",
2930
"vortex-cuda",
3031
"vortex-cuda/cub",
3132
"vortex-cuda/ffi",

vortex-duckdb-extension/Cargo.toml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
[package]
2+
name = "vortex-duckdb-extension"
3+
version = { workspace = true }
4+
description = "C-compatible Vortex DuckDB extension artifacts"
5+
homepage = { workspace = true }
6+
repository = { workspace = true }
7+
authors = { workspace = true }
8+
license = { workspace = true }
9+
publish = false
10+
keywords = { workspace = true }
11+
include = { workspace = true }
12+
edition = { workspace = true }
13+
rust-version = { workspace = true }
14+
categories = { workspace = true }
15+
readme = { workspace = true }
16+
17+
[lib]
18+
name = "vortex_duckdb_extension"
19+
path = "src/lib.rs"
20+
crate-type = ["staticlib", "cdylib"]
21+
22+
[dependencies]
23+
vortex-duckdb = { workspace = true }
24+
25+
[lints]
26+
workspace = true

vortex-duckdb-extension/src/lib.rs

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
// SPDX-License-Identifier: Apache-2.0
2+
// SPDX-FileCopyrightText: Copyright the Vortex contributors
3+
4+
#![expect(clippy::missing_safety_doc)]
5+
6+
use std::ffi::c_char;
7+
use std::ffi::c_void;
8+
9+
/// Global symbol visibility in the Vortex extension:
10+
/// - Rust functions use C ABI with "_rust" suffix (e.g., vortex_init_rust)
11+
/// - C++ wrapper functions have the expected name without suffix (e.g., vortex_init)
12+
/// - C++ wrappers are annotated with DUCKDB_EXTENSION_API to ensure global visibility
13+
/// - C++ wrappers call the corresponding Rust functions
14+
///
15+
/// This ensures DuckDB can find the symbols when loading the extension.
16+
///
17+
/// The DuckDB extension ABI initialization function.
18+
#[unsafe(no_mangle)]
19+
pub unsafe extern "C" fn vortex_init_rust(db: *mut c_void) {
20+
unsafe { vortex_duckdb::initialize_extension_from_raw(db) };
21+
}
22+
23+
/// The DuckDB extension ABI version function.
24+
/// This function returns the version of the DuckDB library the extension is built against.
25+
#[unsafe(no_mangle)]
26+
pub extern "C" fn vortex_version_rust() -> *const c_char {
27+
vortex_duckdb::duckdb_library_version()
28+
}
29+
30+
/// An additional function we export to expose the version of the extension itself to C++ code.
31+
#[unsafe(no_mangle)]
32+
pub extern "C" fn vortex_extension_version_rust() -> *const c_char {
33+
vortex_duckdb::extension_version()
34+
}

vortex-duckdb/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ links = "duckdb"
2121
[lib]
2222
name = "vortex_duckdb"
2323
path = "src/lib.rs"
24-
crate-type = ["staticlib", "cdylib", "rlib"]
24+
crate-type = ["rlib"]
2525

2626
[dependencies]
2727
async-fs = { workspace = true }

vortex-duckdb/README.md

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,20 +18,26 @@ Link against the precompiled DuckDB release build.
1818
cargo build -p vortex-duckdb
1919
```
2020

21+
Build the C-compatible DuckDB extension artifacts with:
22+
23+
```bash
24+
cargo build -p vortex-duckdb-extension
25+
```
26+
2127
### Debug Build
2228

2329
Opt into DuckDB debug build: `VX_DUCKDB_DEBUG=1`.
2430

2531
```bash
26-
VX_DUCKDB_DEBUG=1 cargo build -p vortex-duckdb
32+
VX_DUCKDB_DEBUG=1 cargo build -p vortex-duckdb-extension
2733
```
2834

2935
### AddressSanitizer & ThreadSanitizer
3036

3137
Enable both ASAN & TSAN: `VX_DUCKDB_SAN=1`.
3238

3339
```bash
34-
VX_DUCKDB_DEBUG=1 VX_DUCKDB_SAN=1 cargo build -p vortex-duckdb
40+
VX_DUCKDB_DEBUG=1 VX_DUCKDB_SAN=1 cargo build -p vortex-duckdb-extension
3541
```
3642

3743
## Environment Variables

vortex-duckdb/include/vortex.h

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,6 @@
1515
extern "C" {
1616
#endif // __cplusplus
1717

18-
extern void vortex_init_rust(duckdb_database db);
19-
20-
extern const char *vortex_version_rust(void);
21-
22-
extern const char *vortex_extension_version_rust(void);
23-
2418
extern void duckdb_table_function_to_string(void *bind_data, duckdb_vx_string_map map);
2519

2620
extern

vortex-duckdb/src/lib.rs

Lines changed: 9 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33

44
#![expect(clippy::missing_safety_doc)]
55

6-
use std::ffi::CStr;
76
use std::ffi::c_char;
7+
use std::ffi::c_void;
88
use std::sync::LazyLock;
99
use std::sync::OnceLock;
1010

@@ -79,40 +79,23 @@ pub fn initialize(db: &DatabaseRef) -> VortexResult<()> {
7979
db.register_copy_function()
8080
}
8181

82-
/// Global symbol visibility in the Vortex extension:
83-
/// - Rust functions use C ABI with "_rust" suffix (e.g., vortex_init_rust)
84-
/// - C++ wrapper functions have the expected name without suffix (e.g., vortex_init)
85-
/// - C++ wrappers are annotated with DUCKDB_EXTENSION_API to ensure global visibility
86-
/// - C++ wrappers call the corresponding Rust functions
87-
///
88-
/// This ensures DuckDB can find the symbols when loading the extension.
89-
///
90-
/// The DuckDB extension ABI initialization function.
91-
#[unsafe(no_mangle)]
92-
pub unsafe extern "C" fn vortex_init_rust(db: cpp::duckdb_database) {
82+
/// Initialize the DuckDB extension from a raw DuckDB database pointer.
83+
pub unsafe fn initialize_extension_from_raw(db: *mut c_void) {
9384
init_tracing();
94-
let database = unsafe { Database::borrow(db) };
85+
let database = unsafe { Database::borrow(db.cast()) };
9586

9687
database
9788
.register_vortex_scan_replacement()
9889
.vortex_expect("failed to register vortex scan replacement");
9990
initialize(database).vortex_expect("Failed to initialize Vortex extension");
10091
}
10192

102-
/// The DuckDB extension ABI version function.
103-
/// This function returns the version of the DuckDB library the extension is built against.
104-
#[unsafe(no_mangle)]
105-
pub extern "C" fn vortex_version_rust() -> *const c_char {
93+
/// Returns the version of the DuckDB library the extension is built against.
94+
pub fn duckdb_library_version() -> *const c_char {
10695
unsafe { cpp::duckdb_library_version() }
10796
}
10897

109-
/// An additional function we export to expose the version of the extension itself to C++ code.
110-
#[unsafe(no_mangle)]
111-
pub extern "C" fn vortex_extension_version_rust() -> *const c_char {
112-
// We do some fiddly macros here to get ourselves a _static_ C-style string.
113-
// Otherwise, we'd be leaking memory.
114-
unsafe {
115-
CStr::from_bytes_with_nul_unchecked(concat!(env!("CARGO_PKG_VERSION"), "\0").as_bytes())
116-
}
117-
.as_ptr()
98+
/// Returns the version of the Vortex DuckDB extension.
99+
pub fn extension_version() -> *const c_char {
100+
concat!(env!("CARGO_PKG_VERSION"), "\0").as_ptr().cast()
118101
}

0 commit comments

Comments
 (0)