Skip to content

Commit

Permalink
build loadable in test (#154)
Browse files Browse the repository at this point in the history
* build loadable in test

* test open_from_raw

* windows don't support bindgen as the generated code type is not easy

* remove bundled as required

* fix clippy
  • Loading branch information
wangfenjin authored Apr 26, 2023
1 parent 6b86026 commit 948b879
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 4 deletions.
10 changes: 7 additions & 3 deletions .github/workflows/rust.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ jobs:
with:
# Intentionally omit time feature until we're on time 0.3, at which
# point it should be added to `bundled-full`.
args: '--features "buildtime_bindgen modern-full vtab-full" --avoid-cfg-tarpaulin' # TODO restore to normal (https://github.com/xd009642/tarpaulin/issues/756#issuecomment-838769320)
args: '--features "buildtime_bindgen modern-full vtab-full vtab-loadable" --avoid-cfg-tarpaulin' # TODO restore to normal (https://github.com/xd009642/tarpaulin/issues/756#issuecomment-838769320)
version: 0.22.0
env:
DUCKDB_LIB_DIR: ${{ github.workspace }}/libduckdb
Expand All @@ -90,12 +90,16 @@ jobs:
value: $env:PATH;${{ github.workspace }}/libduckdb
- name: Run cargo-test
if: matrix.os == 'windows-latest'
run: cargo test --features "modern-full vtab-full"
run: cargo test --features "modern-full vtab-full vtab-loadable"
env:
DUCKDB_LIB_DIR: ${{ github.workspace }}/libduckdb
DUCKDB_INCLUDE_DIR: ${{ github.workspace }}/libduckdb
- name: Build loadable extension
run: cargo build --example hello-ext --features="vtab-loadable bundled"
run: cargo build --example hello-ext --features="vtab-loadable"
env:
DUCKDB_LIB_DIR: ${{ github.workspace }}/libduckdb
DUCKDB_INCLUDE_DIR: ${{ github.workspace }}/libduckdb
LD_LIBRARY_PATH: ${{ github.workspace }}/libduckdb

Windows:
name: Windows build from source
Expand Down
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -96,4 +96,4 @@ all-features = false
[[example]]
name = "hello-ext"
crate-type = ["cdylib"]
required-features = ["vtab-loadable", "bundled"]
required-features = ["vtab-loadable"]
10 changes: 10 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -668,6 +668,16 @@ mod test {
let _ = checked_memory_handle();
}

#[test]
fn test_open_from_raw() {
let con = Connection::open_in_memory();
assert!(con.is_ok());
let inner_con: InnerConnection = con.unwrap().db.into_inner();
unsafe {
assert!(Connection::open_from_raw(inner_con.db).is_ok());
}
}

#[test]
fn test_open_failure() -> Result<()> {
let filename = "no_such_file.db";
Expand Down
13 changes: 13 additions & 0 deletions src/vtab/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -250,4 +250,17 @@ mod test {
assert_eq!(val, ("Hello duckdb".to_string(),));
Ok(())
}

#[cfg(feature = "vtab-loadable")]
use duckdb_loadable_macros::duckdb_entrypoint;

// this function is never called, but is still type checked
// Exposes a extern C function named "libhello_ext_init" in the compiled dynamic library,
// the "entrypoint" that duckdb will use to load the extension.
#[cfg(feature = "vtab-loadable")]
#[duckdb_entrypoint]
fn libhello_ext_init(conn: Connection) -> Result<(), Box<dyn Error>> {
conn.register_table_function::<HelloVTab>("hello")?;
Ok(())
}
}

0 comments on commit 948b879

Please sign in to comment.