Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make the mbtiles and pmtiles deps optional. #1124

Merged
merged 4 commits into from
Jan 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions martin/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ path = "src/bin/martin.rs"
[[bin]]
name = "martin-cp"
path = "src/bin/martin-cp.rs"
required-features = ["mbtiles"]

[[bench]]
name = "bench"
Expand All @@ -61,10 +62,10 @@ harness = false
[features]
default = ["fonts", "mbtiles", "pmtiles", "postgres", "sprites"]
fonts = ["dep:bit-set", "dep:pbf_font_tools"]
mbtiles = []
pmtiles = []
mbtiles = ["dep:mbtiles"]
pmtiles = ["dep:pmtiles", "dep:reqwest"]
postgres = ["dep:deadpool-postgres", "dep:json-patch", "dep:postgis", "dep:postgres", "dep:postgres-protocol", "dep:semver", "dep:tokio-postgres-rustls"]
sprites = ["dep:spreet"]
sprites = ["dep:spreet", "tokio/fs"]
bless-tests = []

[dependencies]
Expand All @@ -84,16 +85,16 @@ itertools.workspace = true
json-patch = { workspace = true, optional = true }
log.workspace = true
martin-tile-utils.workspace = true
mbtiles.workspace = true
mbtiles = { workspace = true, optional = true }
moka.workspace = true
num_cpus.workspace = true
pbf_font_tools = { workspace = true, optional = true }
pmtiles.workspace = true
pmtiles = { workspace = true, optional = true }
postgis = { workspace = true, optional = true }
postgres-protocol = { workspace = true, optional = true }
postgres = { workspace = true, optional = true }
regex.workspace = true
reqwest.workspace = true
reqwest = { workspace = true, optional = true }
rustls-native-certs.workspace = true
rustls-pemfile.workspace = true
rustls.workspace = true
Expand Down
1 change: 1 addition & 0 deletions martin/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ impl Config {
.weigher(|_key, value: &CacheValue| -> u32 {
match value {
CacheValue::Tile(v) => v.len().try_into().unwrap_or(u32::MAX),
#[cfg(feature = "pmtiles")]
CacheValue::PmtDirectory(v) => {
v.get_approx_byte_size().try_into().unwrap_or(u32::MAX)
}
Expand Down
1 change: 1 addition & 0 deletions martin/src/file_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ pub enum FileError {
#[error(r#"Unable to acquire connection to file: {0}"#)]
AcquireConnError(String),

#[cfg(feature = "pmtiles")]
#[error(r#"PMTiles error {0} processing {1}"#)]
PmtError(pmtiles::PmtError, String),
}
Expand Down
6 changes: 4 additions & 2 deletions martin/src/utils/cache.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use moka::future::Cache;
use pmtiles::Directory;

use crate::{TileCoord, TileData};

Expand All @@ -20,7 +19,8 @@ pub enum CacheKey {
#[derive(Debug, Clone)]
pub enum CacheValue {
Tile(TileData),
PmtDirectory(Directory),
#[cfg(feature = "pmtiles")]
PmtDirectory(pmtiles::Directory),
}

macro_rules! trace_cache {
Expand All @@ -38,13 +38,15 @@ macro_rules! trace_cache {

macro_rules! from_cache_value {
($value_type: path, $data: expr, $key: expr) => {
#[allow(irrefutable_let_patterns)]
if let $value_type(data) = $data {
data
} else {
panic!("Unexpected value type {:?} for key {:?} cache", $data, $key)
}
};
}

#[cfg(feature = "pmtiles")]
macro_rules! get_cached_value {
($cache: expr, $value_type: path, $make_key: expr) => {
Expand Down
2 changes: 2 additions & 0 deletions martin/src/utils/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use std::fmt::Write as _;
use std::io;
use std::path::PathBuf;

#[cfg(feature = "mbtiles")]
use mbtiles::MbtError;

use crate::file_config::FileError;
Expand Down Expand Up @@ -61,6 +62,7 @@ pub enum MartinError {
#[error(transparent)]
PostgresError(#[from] crate::pg::PgError),

#[cfg(feature = "mbtiles")]
#[error(transparent)]
MbtilesError(#[from] MbtError),

Expand Down
Loading