Skip to content

Cargo features so builds can leave drivers out - #154

Merged
giswqs merged 3 commits into
mainfrom
feat/cargo-features
Oct 21, 2026
Merged

giswqs merged 3 commits into
mainfrom
feat/cargo-features

Conversation

@giswqs

@giswqs giswqs commented Oct 21, 2026

Copy link
Copy Markdown
Member

Closes #139.

Every driver is still on by default, so today's behaviour and the tests are unchanged, and the CLI, Python and JS crates keep depending on terrio with default features. A consumer can now use default-features = false and turn on only what it needs:

terrio = { version = "0.3", default-features = false, features = ["geotiff"] }

Features

Feature Adds
geotiff Empty: GeoTIFF/COG are the core and always built; the feature names what a build needs
parquet GeoParquet, the arrow module, Arrow streams (arrow, parquet, wbvector/geoparquet)
remote URLs, S3/GCS/Azure, range reads, STAC fetching, PROJ CDN grids (native only; cfg(remote) set by a build script)
netcdf-hdf5 NetCDF, HDF5, HDF-EOS
sqlite GeoPackage (vector and raster) and SQLite/SpatiaLite
tiles MBTiles, PMTiles, MVT (needs sqlite)
avif AVIF tiles (needs tiles)
zarr, jp2, flatgeobuf, osm, pointcloud, lerc, lzma Those drivers and codecs
gdal Unchanged, off by default

The core without features: GeoTIFF/COG (deflate, LZW, PackBits, ZSTD, WebP, JPEG, JPEG XL), the raw and ASCII rasters, PNG, JPEG, VRT, STAC, GeoJSON, TopoJSON, Shapefile, KML/KMZ, GML, GPX, CSV, MapInfo, the CRS engine, the operations and the streams.

Public API

  • Every RasterDriver/VectorDriver variant stays in every build. A driver a build leaves out has read/write false in its DriverInfo, and opening or writing its files returns Error::Unsupported("built without the zarr feature") (checked by extension and by signature, also for memory::open_bytes, GPKG:/NETCDF:/HDF5:/ZARR: names, URLs without remote, LERC/LZMA TIFFs).
  • Modules and types that belong to one feature exist only with it, marked with doc(cfg): arrow, pointcloud, http, s3, stream::ArrowStream, vector::{FlatGeobufInfo, RowGroupInfo} and the sparse readers, tiles::TileArchive and the archive functions, LazyRaster::from_tile_archive, info::Info::PointCloud, vfs::Location::remote.
  • tiles stays as a module in every build so that TileOpenOptions/TileWriteOptions (fields of VectorOpenOptions/VectorWriteOptions) keep existing; the archive code moved unchanged to tiles/archive.rs.

Untangling

  • cf_crs moved from drivers/netcdf.rs to drivers/cf.rs (shared by netCDF, HDF5 and Zarr).
  • The date helpers of geoparquet/arrow that profile.rs and geopackage.rs used moved to drivers/vector/datetime.rs; geometry_dims and FlatGeobuf's coord_count moved to crate::vector.
  • sparse.rs's parquet ChunkReader impl is behind parquet; is_avif moved next to TileFormat.
  • cog.rs, dataset.rs, info.rs, memory.rs, drivers/mod.rs, drivers/vector/mod.rs, stream/ and vfs.rs dispatch has a cfg per arm; HTTP sites that were not(wasm32) are now cfg(remote).
  • Builds without some features allow dead_code crate-wide (helpers only the left-out drivers use); the default build still denies it.
  • The NullSafeAllocator and --allow-undefined docs now say they are only for jp2.

Dependencies (unique crates in cargo tree -e normal, native)

Build Crates
default 208
--no-default-features --features geotiff 104
--no-default-features 104

The geotiff build has no arrow, parquet, hdf5, netcdf, openjp2, av1, lzma, lerc, laz, e57, flatgeobuf, osmpbfreader or ureq crates. It still has the jxl crates (jxl-oxide, zune-jpegxl): wbraster pulls them through wbgeotiff, which has no features to turn them off, so that part of the acceptance can't be met inside terrio.

CI

New Cargo features job: cargo hack check -p terrio --each-feature --no-dev-deps --exclude-features gdal with -D warnings, cargo build -p terrio --no-default-features --features geotiff --target wasm32-unknown-unknown, and a cargo tree check that the geotiff build pulls none of the optional codecs.

Docs

README and docs/rust.md (Features table, WebAssembly) describe the features; the crate docs list them too.

Follow-up

  • Upstream: make wbgeotiff's JPEG XL and WebP codecs optional and expose that through wbraster (not filed; needs a go-ahead since it is another project's repository).

Every driver stays on by default. With default-features = false, terrio
keeps GeoTIFF/COG, the plain raster and vector formats, the CRS engine
and the operations; parquet, remote, avif, netcdf-hdf5, osm, lzma,
flatgeobuf, jp2, lerc, pointcloud, tiles, zarr and sqlite add the rest.
geotiff is an empty feature naming the core.

Disabled drivers stay in RasterDriver and VectorDriver, listed as
neither read nor written, and fail with "built without the `...`
feature". Shared helpers move out of the gated drivers (CF grid
mappings, date conversions, coordinate counts, the AVIF signature), the
tile archives move to tiles/archive.rs so that the tile options stay,
and a build script sets cfg(remote) for the remote feature on native
targets.

A CI job checks each feature alone and none, the core for
wasm32-unknown-unknown, and that a geotiff build pulls none of the
optional codecs. Part of #139.
@coderabbitai

coderabbitai Bot commented Oct 21, 2026 •

Copy link
Copy Markdown

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 12 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

Learn how review limits work.

Review configuration:

⚙️ Run configuration
  • Configuration used: Organization UI
  • Review profile: ASSERTIVE
  • Plan: Advanced
  • Run ID: 1bf4fe18-68f2-490b-925b-b832408b9d51
📥 Commits

Reviewing files that changed from the base of the PR and between e8488f2 and 8929b9c.

📒 Files selected for processing: 43
  • .github/workflows/ci.yml
  • Cargo.toml
  • README.md
  • crates/terrio/Cargo.toml
  • crates/terrio/build.rs
  • crates/terrio/src/arrow.rs
  • crates/terrio/src/avif.rs
  • crates/terrio/src/cog.rs
  • crates/terrio/src/crs/grid.rs
  • crates/terrio/src/dataset.rs
  • crates/terrio/src/drivers/cf.rs
  • crates/terrio/src/drivers/gtiff_write.rs
  • crates/terrio/src/drivers/hdf5.rs
  • crates/terrio/src/drivers/jp2.rs
  • crates/terrio/src/drivers/mod.rs
  • crates/terrio/src/drivers/netcdf.rs
  • crates/terrio/src/drivers/vector/datetime.rs
  • crates/terrio/src/drivers/vector/flatgeobuf.rs
  • crates/terrio/src/drivers/vector/geopackage.rs
  • crates/terrio/src/drivers/vector/geoparquet.rs
  • crates/terrio/src/drivers/vector/mod.rs
  • crates/terrio/src/drivers/vector/profile.rs
  • crates/terrio/src/drivers/zarr.rs
  • crates/terrio/src/drivers/zarr_store.rs
  • crates/terrio/src/error.rs
  • crates/terrio/src/formats.rs
  • crates/terrio/src/info.rs
  • crates/terrio/src/lib.rs
  • crates/terrio/src/memory.rs
  • crates/terrio/src/ops/vector_filter.rs
  • crates/terrio/src/pointcloud/ept.rs
  • crates/terrio/src/pointcloud/read.rs
  • crates/terrio/src/sparse.rs
  • crates/terrio/src/stac.rs
  • crates/terrio/src/stream/mod.rs
  • crates/terrio/src/tiff_codecs.rs
  • crates/terrio/src/tiles/archive.rs
  • crates/terrio/src/tiles/mod.rs
  • crates/terrio/src/tiles/raster.rs
  • crates/terrio/src/tiles/source.rs
  • crates/terrio/src/vector.rs
  • crates/terrio/src/vfs.rs
  • docs/rust.md
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

Comment thread .github/workflows/ci.yml Resolved
Comment thread crates/terrio/src/stream/mod.rs Resolved
@github-actions

Copy link
Copy Markdown
Contributor

Code review

I read about 3,300 of the 4,256 diff lines. I did not read the rest of tiles/mod.rs or the tests. The PR makes the driver families optional cargo features, adds a cfg(remote) flag through build.rs, and moves shared helpers (cf_crs, the date/time code, coord_count) out of feature-gated modules. I did not build it or run the CI feature matrix.

Bugs

  • None found in the code I read. The #[cfg] gating, the ensure_built calls and the Error::disabled fallbacks looked consistent across dataset.rs, drivers/mod.rs, memory.rs, stream/mod.rs and info.rs.

Security

  • Nothing found.

Performance

  • Nothing found.

Quality

  • CI dependency check can false-positive (.github/workflows/ci.yml:154, medium confidence). The grep -E '^(arrow|…|laz|…)' pattern matches by prefix, so laz also matches lazy_static and lazycell. Anchor it to whole crate names (suggestion posted inline).
  • unreachable! in open_layers (crates/terrio/src/stream/mod.rs:242, low confidence). The old _ => arm meant GeoParquet. The new unreachable! panics if can_read_stream and the match arms drift apart. An Err(Error::Unsupported(..)) would be safer. The same pattern appears around line 801 for the writer side.
  • Blanket allow(dead_code) (lib.rs, low confidence). It applies whenever any feature is off, so it can hide genuinely dead code in partial builds. has_prefix and Error::disabled also carry their own #[allow(dead_code)], which makes the crate-level allow partly redundant.

CLAUDE.md

  • No CLAUDE.md guideline violations found in the changed files that I checked.

Comment thread .github/workflows/ci.yml Resolved
@github-actions

Copy link
Copy Markdown
Contributor

Code review

I read the first ~2,950 of the 4,256 diff lines. That covers the CI job, Cargo features, build.rs, the drivers/, stream/, memory.rs, dataset.rs, formats.rs, info.rs and tiff_codecs.rs changes, and the start of the new tiles/archive.rs. I did not review the rest of the tiles split, any tests or docs beyond what is in those lines, or the other crates' feature usage. I did not build or run anything.

Bugs

No correctness bugs found in the reviewed portion.

  • The feature gating looks consistent: each cfg(feature = ...) arm has a matching "built without the ... feature" fallback.
  • RasterDriver::info() and VectorDriver::info() now report disabled drivers as neither readable nor writable.
  • build.rs sets cfg(remote) only for the remote feature on non-wasm targets, so the old cfg(not(target_arch = "wasm32")) gates map across correctly.
  • Moving the date helpers into drivers/vector/datetime.rs and cf_crs into drivers/cf.rs changes no behavior.

Security

Nothing found. The changes only narrow what is compiled in, and the new CI step reads nothing outside the repository.

Performance

Nothing found. Optional dependencies are now actually optional, which is the point of the PR.

Quality

  • Low confidence, .github/workflows/ci.yml:154: the "pulls none of the optional codecs" regex omits flatbuffers, lz4_flex, delaunator, hmac and sha2. These are optional now too, so making one unconditional again would pass CI. I posted an inline suggestion.
  • Very low confidence: has_prefix in drivers/mod.rs is marked #[allow(dead_code)], and the crate-level cfg_attr(not(all(...)), allow(dead_code)) in lib.rs also hides unused code in reduced builds. The -D warnings job will therefore not catch helpers that go dead in a feature subset. That is a deliberate trade-off, but it weakens the CI check.

CLAUDE.md

I found no CLAUDE.md guideline violations in the files I reviewed.

Comment thread crates/terrio/src/lib.rs Resolved
Comment thread crates/terrio/src/memory.rs Resolved
@github-actions

Copy link
Copy Markdown
Contributor

Code review

I read the whole diff and the surrounding source, but I couldn't build or run anything here. The feature gating looks sound and I found no correctness bugs. That is from reading the code, so I can't rule out a combination that fails to compile. Two inline comments are posted.

Bugs

  • None found. Confidence: moderate, because it rests on reading the code. I checked the cfg gates in these places for missing or inconsistent arms:

    • drivers/mod.rs, dataset.rs, memory.rs, stream/mod.rs, info.rs and tiles/
    • the new cfg(remote) build script
    • the ensure_built checks added to the read and write paths
    • the read_vector_local early return for GeoPackage

    I found no missing arms.

  • memory.rs:276 (low-medium): without netcdf-hdf5, the byte sniff rejects any input that starts with CDF or the HDF5 signature, whatever its name. A text or CSV file beginning with "CDF" would get "built without the netcdf-hdf5 feature". Details are in the inline comment.

Security

  • None found. The new remote feature only gates the existing network code. Without it, URL and S3 locations fail with Error::disabled("remote") instead of reaching ureq, hmac or sha2.

Performance

  • None found. Everything is compile-time gating or code moved without change.

Quality

  • lib.rs:175 (medium): a crate-wide allow(dead_code) applies whenever any feature is off. That weakens the new cargo hack ... -D warnings CI job, because it can no longer report genuinely dead helpers in a feature subset. The extra #[allow(dead_code)] on has_prefix and Error::disabled is then redundant. Gating the specific items, as tiff_codecs.rs already does, would be tighter.
  • Nit (low): ops/vector_filter.rs links [crate::tiles::update_vector] in a doc comment. That link won't resolve without tiles, which can trip rustdoc link warnings in feature-subset doc builds.
  • Nit (low): parse_datetime and parse_date, moved into datetime.rs, slice by byte offset (&s[10..], s[8..10]). They can panic on non-ASCII input that puts a character boundary inside those ranges. This was already true before the move, so it's not part of this change, but it's worth a follow-up.

CLAUDE.md

  • No CLAUDE.md guidelines apply to the changed files that I could identify. The new code matches the surrounding style and comment density.

Checked and fine

  • Dependencies: the optional dep: mappings, avif -> tiles -> sqlite, and the wbvector feature split (geoparquet, osmpbf).
  • CI: the cargo tree crate check and the WebAssembly build step.
  • Docs: the README and docs/rust.md feature tables match Cargo.toml.

@giswqs
giswqs merged commit fa3cd52 into main Oct 21, 2026
16 checks passed
@giswqs
giswqs deleted the feat/cargo-features branch October 21, 2026 10:02
@giswqs giswqs mentioned this pull request Oct 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Cargo features so consumers can depend on only the drivers they use

1 participant