Skip to content

Commit 3d54365

Browse files
authored
Download pre-built DuckDB libraries (#628)
How this works: When `DUCKDB_DOWNLOAD_LIB` is set, we map `CARGO_TARGET_DIR` to `target/duckdb-download/<target>/<version>`, download the matching DuckDB release archive, unzip it, and add the directory to the linker search path. We also copy the downloaded library into `target/<profile>/deps` so test binaries can load it without extra env vars, matching the `DUCKDB_LIB_DIR` flow. This will make building much easier - no toolchain to compile DuckDB, or manual downloads and fiddling with `DUCKDB_LIB_DIR`, etc. Inspired by - https://github.com/vortex-data/vortex/blob/develop/vortex-duckdb/build.rs - https://github.com/nbigaouette/onnxruntime-rs/blob/master/onnxruntime-sys/build.rs
2 parents 6cefb40 + 2d31488 commit 3d54365

File tree

5 files changed

+272
-20
lines changed

5 files changed

+272
-20
lines changed

.github/workflows/rust.yaml

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ concurrency:
1414

1515
jobs:
1616
test:
17+
# - Linux uses DUCKDB_DOWNLOAD_LIB (non-bundled)
18+
# - Windows uses pre-downloaded archives via DUCKDB_LIB_DIR
19+
# - bundled feature tested by --all-features
1720
name: Test ${{ matrix.target }}
1821
strategy:
1922
fail-fast: true
@@ -30,38 +33,28 @@ jobs:
3033
duckdb: libduckdb-linux-amd64.zip,
3134
}
3235
runs-on: ${{ matrix.os }}
36+
env:
37+
DUCKDB_DOWNLOAD_LIB: "1"
3338
steps:
3439
- uses: actions/checkout@v2
3540
- uses: actions-rust-lang/setup-rust-toolchain@v1
3641
with:
3742
target: ${{ matrix.target }}
3843

39-
# download libduckdb
4044
- uses: robinraju/[email protected]
4145
name: Download duckdb
46+
if: matrix.os == 'windows-latest'
4247
with:
4348
repository: "duckdb/duckdb"
4449
tag: "v1.4.2"
4550
fileName: ${{ matrix.duckdb }}
4651
out-file-path: .
4752

48-
# For Linux
49-
- name: Linux extract duckdb
50-
if: matrix.os == 'ubuntu-latest'
51-
uses: ihiroky/extract-action@v1
52-
with:
53-
file_path: ${{ github.workspace }}/${{ matrix.duckdb }}
54-
extract_dir: libduckdb
55-
5653
- run: cargo fmt --all -- --check
5754
if: matrix.os == 'ubuntu-latest'
5855

5956
- name: run cargo clippy
6057
if: matrix.os == 'ubuntu-latest'
61-
env:
62-
DUCKDB_LIB_DIR: ${{ github.workspace }}/libduckdb
63-
DUCKDB_INCLUDE_DIR: ${{ github.workspace }}/libduckdb
64-
LD_LIBRARY_PATH: ${{ github.workspace }}/libduckdb
6558
run: cargo clippy --all-targets --all-features --locked -- -D warnings
6659

6760
- name: Dry-run release of crates
@@ -91,13 +84,23 @@ jobs:
9184
DUCKDB_INCLUDE_DIR: ${{ github.workspace }}/libduckdb
9285

9386
- name: Build loadable extension
87+
if: matrix.os == 'ubuntu-latest'
88+
run: cargo build --example hello-ext --features="vtab-loadable"
89+
90+
- name: Build loadable extension (C API)
91+
if: matrix.os == 'ubuntu-latest'
92+
run: cargo build --example hello-ext-capi --features="vtab-loadable loadable-extension"
93+
94+
- name: Build loadable extension (windows)
95+
if: matrix.os == 'windows-latest'
9496
run: cargo build --example hello-ext --features="vtab-loadable"
9597
env:
9698
DUCKDB_LIB_DIR: ${{ github.workspace }}/libduckdb
9799
DUCKDB_INCLUDE_DIR: ${{ github.workspace }}/libduckdb
98100
LD_LIBRARY_PATH: ${{ github.workspace }}/libduckdb
99101

100-
- name: Build loadable extension
102+
- name: Build loadable extension C API (windows)
103+
if: matrix.os == 'windows-latest'
101104
run: cargo build --example hello-ext-capi --features="vtab-loadable loadable-extension"
102105
env:
103106
DUCKDB_LIB_DIR: ${{ github.workspace }}/libduckdb

Cargo.lock

Lines changed: 29 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

README.md

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,12 +204,20 @@ You can adjust this behavior in a number of ways:
204204
cargo build --examples
205205
```
206206

207-
3. Installing the duckdb development packages will usually be all that is required, but
207+
3. _Experimental:_ Setting `DUCKDB_DOWNLOAD_LIB=1` makes the build script download pre-built DuckDB binaries from GitHub Releases. This always links against the dynamic library in the archive (setting `DUCKDB_STATIC` has no effect), and it effectively automates the manual steps above. The archives are cached in `target/duckdb-download/<target>/<version>` and that directory is automatically added to the linker search path. The downloaded version always matches the `libduckdb-sys` crate version.
208+
209+
```shell
210+
DUCKDB_DOWNLOAD_LIB=1 cargo test
211+
```
212+
213+
4. Installing the duckdb development packages will usually be all that is required, but
208214
the build helpers for [pkg-config](https://github.com/alexcrichton/pkg-config-rs)
209215
and [vcpkg](https://github.com/mcgoo/vcpkg-rs) have some additional configuration
210216
options. The default when using vcpkg is to dynamically link,
211217
which must be enabled by setting `VCPKGRS_DYNAMIC=1` environment variable before build.
212218

219+
When none of the options above are used, the build script falls back to this discovery path and will emit the appropriate `cargo:rustc-link-lib` directives if DuckDB is found on your system.
220+
213221
### ICU extension and the bundled feature
214222

215223
When using the `bundled` feature, the ICU extension is not included due to crates.io's 10MB package size limit. This means some date/time operations (like `now() - interval '1 day'` or `ts::date` casts) will fail. You can load ICU at runtime:

crates/libduckdb-sys/Cargo.toml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,16 @@ flate2 = { workspace = true }
3232
pkg-config = { workspace = true, optional = true }
3333
prettyplease = { workspace = true, optional = true }
3434
quote = { workspace = true, optional = true }
35+
reqwest = { version = "0.12", default-features = false, features = [
36+
"blocking",
37+
"rustls-tls",
38+
] }
3539
serde = { workspace = true, features = ["derive"] }
3640
serde_json = { workspace = true }
3741
syn = { workspace = true, optional = true }
3842
tar = { workspace = true }
3943
vcpkg = { workspace = true, optional = true }
44+
zip = { version = "6", default-features = false, features = ["deflate"] }
4045

4146
[dev-dependencies]
4247
arrow = { workspace = true, features = ["ffi"] }

0 commit comments

Comments
 (0)