Skip to content

Commit 8981cc6

Browse files
authored
refactor: duckdb inclusion, again (#648)
1 parent e7bc2f1 commit 8981cc6

File tree

11 files changed

+97
-58
lines changed

11 files changed

+97
-58
lines changed

.github/workflows/ci.yml

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ concurrency:
1313
env:
1414
CARGO_TERM_COLOR: always
1515
CARGO_TERM_VERBOSE: true
16+
duckdb-version: "1.2.0"
1617

1718
jobs:
1819
test-core:
@@ -31,7 +32,7 @@ jobs:
3132
- name: Test
3233
run: cargo test -p stac --all-features
3334
check-features-core:
34-
name: Check stac features
35+
name: Check all features
3536
runs-on: ubuntu-latest
3637
defaults:
3738
run:
@@ -46,26 +47,33 @@ jobs:
4647
test:
4748
name: Test
4849
runs-on: ubuntu-latest
50+
steps:
51+
- uses: actions/checkout@v4
52+
- uses: Swatinem/rust-cache@v2
53+
- name: Format
54+
run: cargo fmt --check
55+
- name: Clippy
56+
run: cargo clippy --workspace -- -D warnings
57+
- name: Test
58+
run: cargo test --all-features
59+
test-with-duckdb:
60+
name: Test w/ DuckDB
61+
runs-on: ubuntu-latest
4962
env:
5063
DUCKDB_LIB_DIR: /opt/duckdb
51-
DUCKDB_INCLUDE_DIR: /opt/duckdb
5264
LD_LIBRARY_PATH: /opt/duckdb
5365
steps:
5466
- uses: actions/checkout@v4
5567
- uses: Swatinem/rust-cache@v2
5668
- uses: astral-sh/setup-uv@v5
5769
- name: Get DuckDB
5870
run: |
59-
wget https://github.com/duckdb/duckdb/releases/download/v1.2.0/libduckdb-linux-amd64.zip
71+
wget https://github.com/duckdb/duckdb/releases/download/v${{ env.duckdb-version }}/libduckdb-linux-amd64.zip
6072
unzip libduckdb-linux-amd64.zip -d /opt/duckdb
61-
- name: Format
62-
run: cargo fmt --check
63-
- name: Clippy
64-
run: cargo clippy --workspace --no-default-features -- -D warnings
6573
- name: Build # need to build first to get the executable for CLI tests
66-
run: cargo build --no-default-features
74+
run: cargo build -p stac-duckdb -p stac-cli -F duckdb
6775
- name: Test
68-
run: cargo test --no-default-features
76+
run: cargo test -p stac-duckdb -p stac-cli -F duckdb
6977
- name: Validate stac-server
7078
run: uv run --group stac-api-validator scripts/validate-stac-server
7179
- name: Validate stac-geoparquet
@@ -80,7 +88,6 @@ jobs:
8088
- v0.9.1
8189
env:
8290
DUCKDB_LIB_DIR: /opt/duckdb
83-
DUCKDB_INCLUDE_DIR: /opt/duckdb
8491
LD_LIBRARY_PATH: /opt/duckdb
8592
services:
8693
pgstac:
@@ -98,10 +105,6 @@ jobs:
98105
- uses: actions/checkout@v4
99106
- uses: Swatinem/rust-cache@v2
100107
- uses: astral-sh/setup-uv@v5
101-
- name: Get DuckDB
102-
run: |
103-
wget https://github.com/duckdb/duckdb/releases/download/v1.1.3/libduckdb-linux-amd64.zip
104-
unzip libduckdb-linux-amd64.zip -d /opt/duckdb
105108
- name: Test
106109
run: cargo test -p pgstac --all-features
107110
- name: Validate
@@ -114,7 +117,7 @@ jobs:
114117
- uses: dtolnay/rust-toolchain@nightly
115118
- uses: Swatinem/rust-cache@v2
116119
- name: Check
117-
run: cargo check --workspace --all-features
120+
run: cargo check --workspace
118121
msrv:
119122
runs-on: ubuntu-latest
120123
steps:

Cargo.toml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,8 @@ members = [
1212
]
1313
default-members = [
1414
"crates/api",
15-
"crates/cli",
1615
"crates/core",
1716
"crates/derive",
18-
"crates/duckdb",
1917
"crates/extensions",
2018
"crates/server",
2119
]

crates/cli/Cargo.toml

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,15 @@ categories.workspace = true
1212
rust-version.workspace = true
1313

1414
[features]
15-
default = ["duckdb-bundled", "pgstac"]
15+
default = []
1616
pgstac = ["stac-server/pgstac"]
17-
duckdb-bundled = ["duckdb/bundled"]
17+
duckdb = ["dep:stac-duckdb"]
18+
duckdb-bundled = ["duckdb", "stac-duckdb/bundled"]
1819

1920
[dependencies]
2021
anyhow.workspace = true
2122
axum.workspace = true
2223
clap = { workspace = true, features = ["derive"] }
23-
duckdb = { workspace = true }
24-
libduckdb-sys = { workspace = true }
2524
serde_json.workspace = true
2625
stac = { workspace = true, features = [
2726
"geoparquet-compression",
@@ -30,7 +29,7 @@ stac = { workspace = true, features = [
3029
"validate",
3130
] }
3231
stac-api = { workspace = true, features = ["client"] }
33-
stac-duckdb.workspace = true
32+
stac-duckdb = { workspace = true, optional = true }
3433
stac-server = { workspace = true, features = ["axum"] }
3534
tokio = { workspace = true, features = [
3635
"macros",

crates/cli/README.md

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@ Command Line Interface (CLI) for [STAC](https://stacspec.org/), named `stacrs`.
1111
## Installation
1212

1313
```sh
14-
cargo install stac-cli
14+
cargo install stac-cli -F duckdb # to use libduckdb on your system
15+
# or
16+
cargo install stac-cli -F duckdb-bundled # to build libduckdb on install (slow)
1517
```
1618

1719
Then:
@@ -46,7 +48,7 @@ $ stacrs validate item.json
4648

4749
**stacrs** provides the following subcommands:
4850

49-
- `stacrs search`: searches STAC APIs and geoparquet files
51+
- `stacrs search`: searches STAC APIs and, if the `duckdb` feature is enabled, geoparquet files
5052
- `stacrs serve`: serves a STAC API
5153
- `stacrs translate`: converts STAC from one format to another
5254
- `stacrs validate`: validates a STAC value
@@ -55,20 +57,14 @@ Use the `--help` flag to see all available options for the CLI and the subcomman
5557

5658
## Features
5759

58-
This crate has two features:
60+
This crate has three features:
5961

60-
- `pgstac`: enable a [pgstac](https://github.com/stac-utils/pgstac) backend for `stacrs serve` (enabled by default)
61-
- `duckdb-bundled`: bundle DuckDB by building it from source, instead of using a local installation (enabled by default)
62+
- `pgstac`: enable a [pgstac](https://github.com/stac-utils/pgstac) backend for `stacrs serve`
63+
- `duckdb`: build with DuckDB support, which enables searching [stac-geoparquet](https://github.com/stac-utils/stac-geoparquet) (requires DuckDB to be present on your system)
64+
- `duckdb-bundled`: bundle DuckDB by building it from source, instead of using a local installation (does _not_ require DuckDB to be present on your system)
6265

63-
### DuckDB
64-
65-
If you have DuckDB installed locally and want to use that shared library (instead of building it when you install), disable the `duckdb-bundled` feature:
66-
67-
```shell
68-
cargo install stac-cli --no-default-features -F pgstac
69-
```
70-
71-
This can dramatically speed up install time.
66+
> [!TIP]
67+
> If you're using the `duckdb` feature, set `DUCKDB_LIB_DIR` to the directory containing your **libduckdb**. If you're on macos and using [Homebrew](https://brew.sh/), this might be `export DUCKDB_LIB_DIR=/opt/homebrew/lib`
7268
7369
## Other info
7470

crates/cli/src/lib.rs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@
44

55
use anyhow::{anyhow, Error, Result};
66
use clap::{Parser, Subcommand};
7-
use duckdb as _;
8-
use libduckdb_sys as _;
97
use stac::{geoparquet::Compression, Collection, Format, Item, Links, Migrate, Validate};
108
use stac_api::{GetItems, GetSearch, Search};
119
use stac_server::Backend;
@@ -309,7 +307,14 @@ impl Stacrs {
309307
};
310308
let search: Search = get_search.try_into()?;
311309
let item_collection = if use_duckdb {
312-
stac_duckdb::search(href, search, *max_items)?
310+
#[cfg(feature = "duckdb")]
311+
{
312+
stac_duckdb::search(href, search, *max_items)?
313+
}
314+
#[cfg(not(feature = "duckdb"))]
315+
return Err(anyhow!(
316+
"the `duckdb` feature is not enabled, cannot search stac-geoparquet"
317+
));
313318
} else {
314319
stac_api::client::search(href, search, *max_items).await?
315320
};

crates/duckdb/Cargo.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@ license.workspace = true
1111
categories.workspace = true
1212
rust-version.workspace = true
1313

14+
[features]
15+
default = []
16+
bundled = ["duckdb/bundled"]
17+
1418
[dependencies]
1519
arrow.workspace = true
1620
chrono.workspace = true

crates/duckdb/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ If you want to build the DuckDB library as a part of this (or a downstream's) cr
2323
E.g. to test this crate if you don't have DuckDB locally:
2424

2525
```shell
26-
cargo test -p stac-duckdb -F duckdb/bundled
26+
cargo test -p stac-duckdb -F bundled
2727
```
2828

2929
See [the duckdb-rs docs](https://github.com/duckdb/duckdb-rs?tab=readme-ov-file#notes-on-building-duckdb-and-libduckdb-sys) for more.

docs/cli/index.md

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,20 +7,22 @@ description: The stac-rs command-line interface (CLI), stacrs
77
The **stac-rs** command-line interface can be installed two ways.
88
If you have Rust, use `cargo`:
99

10-
```shell
11-
cargo install stac-cli
10+
```sh
11+
cargo install stac-cli -F duckdb # to use libduckdb on your system
12+
# or
13+
cargo install stac-cli -F duckdb-bundled # to build libduckdb on install (slow)
1214
```
1315

14-
If you have Python, use `pip`:
16+
The CLI is called **stacrs**:
1517

1618
```shell
17-
python -m pip install stacrs
19+
stacrs --help
1820
```
1921

20-
The CLI is called **stacrs**:
22+
If you don't have DuckDB on your system, you can also use the Python wheel, which includes **libduckdb**:
2123

2224
```shell
23-
stacrs --help
25+
python -m pip install stacrs
2426
```
2527

2628
For examples of using the CLI, check out the slides from [@gadomski's](https://github.com/gadomski/) 2024 FOSS4G-NA presentation [here](https://www.gadom.ski/2024-09-FOSS4G-NA-stac-rs/).

scripts/format

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@
33
set -e
44

55
cargo fmt
6-
cargo clippy --workspace --all-features --fix
6+
cargo clippy --workspace --fix

scripts/lint

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@
33
set -e
44

55
cargo fmt --check
6-
cargo clippy --workspace --all-features -- -D warnings
6+
cargo clippy --workspace -- -D warnings

0 commit comments

Comments
 (0)