diff --git a/Cargo.lock b/Cargo.lock index 587b99f..ec2668f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -238,15 +238,6 @@ dependencies = [ "serde", ] -[[package]] -name = "blake2" -version = "0.10.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "46502ad458c9a52b69d4d4d32775c788b7a1b85e8bc9d482d92250fc0e3f8efe" -dependencies = [ - "digest", -] - [[package]] name = "block-buffer" version = "0.10.4" @@ -1209,15 +1200,6 @@ dependencies = [ "wasm-bindgen", ] -[[package]] -name = "keccak" -version = "0.1.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ecc2af9a1119c51f12a14607e783cb977bde58bc069ff0c3da1095e635d70654" -dependencies = [ - "cpufeatures", -] - [[package]] name = "lazy_static" version = "1.5.0" @@ -1785,7 +1767,6 @@ version = "0.13.0" dependencies = [ "anyhow", "async-trait", - "blake2", "criterion", "flate2", "hex", @@ -1805,7 +1786,6 @@ dependencies = [ "serde_json", "sha1", "sha2", - "sha3", "tar", "target-triple", "tempfile", @@ -2444,16 +2424,6 @@ dependencies = [ "digest", ] -[[package]] -name = "sha3" -version = "0.10.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "75872d278a8f37ef87fa0ddbda7802605cb18344497949862c0d4dcb291eba60" -dependencies = [ - "digest", - "keccak", -] - [[package]] name = "sharded-slab" version = "0.1.7" diff --git a/examples/zonky/Cargo.toml b/examples/zonky/Cargo.toml index 469b823..997723c 100644 --- a/examples/zonky/Cargo.toml +++ b/examples/zonky/Cargo.toml @@ -7,5 +7,5 @@ version.workspace = true [dependencies] postgresql_archive = { path = "../../postgresql_archive" } -postgresql_embedded = { path = "../../postgresql_embedded" } +postgresql_embedded = { path = "../../postgresql_embedded", default-features = false, features = ["zonky"] } tokio = { workspace = true, features = ["full"] } diff --git a/postgresql_archive/Cargo.toml b/postgresql_archive/Cargo.toml index 96f7a1f..cee9435 100644 --- a/postgresql_archive/Cargo.toml +++ b/postgresql_archive/Cargo.toml @@ -12,15 +12,14 @@ version.workspace = true [dependencies] anyhow = { workspace = true } async-trait = { workspace = true } -blake2 = { workspace = true } -flate2 = { workspace = true } +flate2 = { workspace = true, optional = true } hex = { workspace = true } http = { workspace = true } human_bytes = { workspace = true, default-features = false } lazy_static = { workspace = true } -md-5 = { workspace = true } +md-5 = { workspace = true, optional = true } num-format = { workspace = true } -quick-xml = { workspace = true, features = ["serialize"] } +quick-xml = { workspace = true, features = ["serialize"], optional = true } regex = { workspace = true } reqwest = { workspace = true, default-features = false, features = ["json"] } reqwest-middleware = { workspace = true } @@ -28,19 +27,18 @@ reqwest-retry = { workspace = true } reqwest-tracing = { workspace = true } semver = { workspace = true } serde = { workspace = true, features = ["derive"] } -serde_json = { workspace = true } -sha1 = { workspace = true } -sha2 = { workspace = true } -sha3 = { workspace = true } -tar = { workspace = true } -target-triple = { workspace = true } +serde_json = { workspace = true, optional = true } +sha1 = { workspace = true, optional = true } +sha2 = { workspace = true, optional = true } +tar = { workspace = true, optional = true } +target-triple = { workspace = true, optional = true } tempfile = { workspace = true } thiserror = { workspace = true } tokio = { workspace = true, features = ["full"], optional = true } tracing = { workspace = true, features = ["log"] } url = { workspace = true } -xz2 = { workspace = true } -zip = { workspace = true } +xz2 = { workspace = true, optional = true } +zip = { workspace = true, optional = true } [dev-dependencies] criterion = { workspace = true } @@ -49,10 +47,39 @@ test-log = { workspace = true } tokio = { workspace = true } [features] -default = ["rustls-tls"] +default = [ + "rustls-tls", + "theseus", +] blocking = ["dep:tokio"] +github = [ + "dep:serde_json", +] +maven = [ + "dep:quick-xml", + "md5", + "sha1", + "sha2", +] +md5 = ["dep:md-5"] native-tls = ["reqwest/native-tls"] rustls-tls = ["reqwest/rustls-tls-native-roots"] +sha1 = ["dep:sha1"] +sha2 = ["dep:sha2"] +theseus = [ + "dep:flate2", + "dep:tar", + "dep:target-triple", + "github", + "sha2", +] +zonky = [ + "dep:flate2", + "dep:tar", + "dep:xz2", + "dep:zip", + "maven", +] [package.metadata.docs.rs] features = ["blocking"] diff --git a/postgresql_archive/README.md b/postgresql_archive/README.md index 69931cb..613a8f9 100644 --- a/postgresql_archive/README.md +++ b/postgresql_archive/README.md @@ -55,6 +55,32 @@ The following features are available: | `native-tls` | Enables native-tls support | No | | `rustls-tls` | Enables rustls-tls support | Yes | +### Configurations + +| Name | Description | Default? | +|-----------|-------------------------------------|----------| +| `theseus` | Enables theseus PostgreSQL binaries | Yes | +| `zonky` | Enables zonky PostgreSQL binaries | No | + +### Hashers + +| Name | Description | Default? | +|--------|----------------------|----------| +| `md5` | Enables md5 hashers | No | +| `sha1` | Enables sha1 hashers | No | +| `sha2` | Enables sha2 hashers | Yes¹ | + +¹ enabled by the `theseus` feature flag. + +### Repositories + +| Name | Description | Default? | +|----------|---------------------------|----------| +| `github` | Enables github repository | Yes¹ | +| `maven` | Enables maven repository | No | + +¹ enabled by the `theseus` feature flag. + ## Supported platforms `postgresql_archive` provides implementations for the following: diff --git a/postgresql_archive/src/configuration/mod.rs b/postgresql_archive/src/configuration/mod.rs index 3d88963..5ff0e25 100644 --- a/postgresql_archive/src/configuration/mod.rs +++ b/postgresql_archive/src/configuration/mod.rs @@ -1,2 +1,4 @@ +#[cfg(feature = "theseus")] pub mod theseus; +#[cfg(feature = "zonky")] pub mod zonky; diff --git a/postgresql_archive/src/extractor/registry.rs b/postgresql_archive/src/extractor/registry.rs index dbce144..0906c99 100644 --- a/postgresql_archive/src/extractor/registry.rs +++ b/postgresql_archive/src/extractor/registry.rs @@ -1,4 +1,7 @@ -use crate::configuration::{theseus, zonky}; +#[cfg(feature = "theseus")] +use crate::configuration::theseus; +#[cfg(feature = "zonky")] +use crate::configuration::zonky; use crate::Error::{PoisonedLock, UnsupportedExtractor}; use crate::Result; use lazy_static::lazy_static; @@ -63,7 +66,9 @@ impl Default for RepositoryRegistry { /// Creates a new repository registry with the default repositories registered. fn default() -> Self { let mut registry = Self::new(); + #[cfg(feature = "theseus")] registry.register(|url| Ok(url.starts_with(theseus::URL)), theseus::extract); + #[cfg(feature = "zonky")] registry.register(|url| Ok(url.starts_with(zonky::URL)), zonky::extract); registry } @@ -113,6 +118,7 @@ mod tests { } #[test] + #[cfg(feature = "theseus")] fn test_get_theseus_postgresql_binaries() { assert!(get(theseus::URL).is_ok()); } diff --git a/postgresql_archive/src/hasher/blake2b_512.rs b/postgresql_archive/src/hasher/blake2b_512.rs deleted file mode 100644 index 9281b39..0000000 --- a/postgresql_archive/src/hasher/blake2b_512.rs +++ /dev/null @@ -1,29 +0,0 @@ -use crate::Result; -use blake2::{Blake2b512, Digest}; - -/// Hashes the data using blake2b-512. -/// -/// # Errors -/// * If the data cannot be hashed. -pub fn hash(data: &Vec) -> Result { - let mut hasher = Blake2b512::new(); - hasher.update(data); - let hash = hex::encode(hasher.finalize()); - Ok(hash) -} - -#[cfg(test)] -mod tests { - use super::*; - - #[test] - fn test_hash() -> Result<()> { - let data = vec![4, 2]; - let hash = hash(&data)?; - assert_eq!( - "e487ff1a06742b6054c76387d7a0bf9e0f62964358b850d80d9f88071508ef855e745a8ba67617f850cf563b20f4ec0d5bd8233b2e85eb0ba4f31a14075fb3d9", - hash - ); - Ok(()) - } -} diff --git a/postgresql_archive/src/hasher/blake2s_256.rs b/postgresql_archive/src/hasher/blake2s_256.rs deleted file mode 100644 index 9546822..0000000 --- a/postgresql_archive/src/hasher/blake2s_256.rs +++ /dev/null @@ -1,29 +0,0 @@ -use crate::Result; -use blake2::{Blake2s256, Digest}; - -/// Hashes the data using blake2s-256. -/// -/// # Errors -/// * If the data cannot be hashed. -pub fn hash(data: &Vec) -> Result { - let mut hasher = Blake2s256::new(); - hasher.update(data); - let hash = hex::encode(hasher.finalize()); - Ok(hash) -} - -#[cfg(test)] -mod tests { - use super::*; - - #[test] - fn test_hash() -> Result<()> { - let data = vec![4, 2]; - let hash = hash(&data)?; - assert_eq!( - "d2e78507a899636d20314690e1683fd2116dd438b502645a8aa8f79fd579fb70", - hash - ); - Ok(()) - } -} diff --git a/postgresql_archive/src/hasher/mod.rs b/postgresql_archive/src/hasher/mod.rs index a214eaf..02b2bfc 100644 --- a/postgresql_archive/src/hasher/mod.rs +++ b/postgresql_archive/src/hasher/mod.rs @@ -1,9 +1,9 @@ -pub mod blake2b_512; -pub mod blake2s_256; +#[cfg(feature = "md5")] pub mod md5; pub mod registry; +#[cfg(feature = "sha1")] pub mod sha1; +#[cfg(feature = "sha2")] pub mod sha2_256; +#[cfg(feature = "sha2")] pub mod sha2_512; -pub mod sha3_256; -pub mod sha3_512; diff --git a/postgresql_archive/src/hasher/registry.rs b/postgresql_archive/src/hasher/registry.rs index 7ac9a59..b22b49b 100644 --- a/postgresql_archive/src/hasher/registry.rs +++ b/postgresql_archive/src/hasher/registry.rs @@ -1,5 +1,12 @@ +#[cfg(feature = "theseus")] use crate::configuration::theseus; -use crate::hasher::{md5, sha1, sha2_256, sha2_512}; +#[cfg(feature = "md5")] +use crate::hasher::md5; +#[cfg(feature = "sha1")] +use crate::hasher::sha1; +#[cfg(feature = "sha2")] +use crate::hasher::{sha2_256, sha2_512}; +#[cfg(feature = "maven")] use crate::repository::maven; use crate::Error::{PoisonedLock, UnsupportedHasher}; use crate::Result; @@ -67,23 +74,28 @@ impl Default for HasherRegistry { /// Creates a new hasher registry with the default hashers registered. fn default() -> Self { let mut registry = Self::new(); + #[cfg(feature = "theseus")] registry.register( |url, extension| Ok(url.starts_with(theseus::URL) && extension == "sha256"), sha2_256::hash, ); // Register the Maven hashers: https://maven.apache.org/resolver/about-checksums.html#implemented-checksum-algorithms + #[cfg(feature = "maven")] registry.register( |url, extension| Ok(url.starts_with(maven::URL) && extension == "md5"), md5::hash, ); + #[cfg(feature = "maven")] registry.register( |url, extension| Ok(url.starts_with(maven::URL) && extension == "sha1"), sha1::hash, ); + #[cfg(feature = "maven")] registry.register( |url, extension| Ok(url.starts_with(maven::URL) && extension == "sha256"), sha2_256::hash, ); + #[cfg(feature = "maven")] registry.register( |url, extension| Ok(url.starts_with(maven::URL) && extension == "sha512"), sha2_512::hash, @@ -148,6 +160,7 @@ mod tests { } #[test] + #[cfg(feature = "theseus")] fn test_get_invalid_extension_error() { let error = get(theseus::URL, "foo").unwrap_err(); assert_eq!( @@ -157,12 +170,14 @@ mod tests { } #[test] + #[cfg(feature = "theseus")] fn test_get_theseus_postgresql_binaries() { assert!(get(theseus::URL, "sha256").is_ok()); } #[test] - fn test_get_zonkyio_postgresql_binaries() { + #[cfg(feature = "maven")] + fn test_get_zonky_postgresql_binaries() { assert!(get(maven::URL, "sha512").is_ok()); } } diff --git a/postgresql_archive/src/hasher/sha3_256.rs b/postgresql_archive/src/hasher/sha3_256.rs deleted file mode 100644 index e575458..0000000 --- a/postgresql_archive/src/hasher/sha3_256.rs +++ /dev/null @@ -1,29 +0,0 @@ -use crate::Result; -use sha3::{Digest, Sha3_256}; - -/// Hashes the data using SHA3-256. -/// -/// # Errors -/// * If the data cannot be hashed. -pub fn hash(data: &Vec) -> Result { - let mut hasher = Sha3_256::new(); - hasher.update(data); - let hash = hex::encode(hasher.finalize()); - Ok(hash) -} - -#[cfg(test)] -mod tests { - use super::*; - - #[test] - fn test_hash() -> Result<()> { - let data = vec![4, 2]; - let hash = hash(&data)?; - assert_eq!( - "10a0812b3335c2f6de6dd195c77950e20dbd2e87ee95086db4e2fd42f1a78eed", - hash - ); - Ok(()) - } -} diff --git a/postgresql_archive/src/hasher/sha3_512.rs b/postgresql_archive/src/hasher/sha3_512.rs deleted file mode 100644 index 9c716f3..0000000 --- a/postgresql_archive/src/hasher/sha3_512.rs +++ /dev/null @@ -1,29 +0,0 @@ -use crate::Result; -use sha3::{Digest, Sha3_512}; - -/// Hashes the data using SHA3-512. -/// -/// # Errors -/// * If the data cannot be hashed. -pub fn hash(data: &Vec) -> Result { - let mut hasher = Sha3_512::new(); - hasher.update(data); - let hash = hex::encode(hasher.finalize()); - Ok(hash) -} - -#[cfg(test)] -mod tests { - use super::*; - - #[test] - fn test_hash() -> Result<()> { - let data = vec![4, 2]; - let hash = hash(&data)?; - assert_eq!( - "4bcb3a87557684ff56272f6bc7f542d728d1b953d8b0beb94ffdd97d9ba872550629c9eb98357060c7dce1786f91e6af948eb1ae21ec304f558a4651ff2b134f", - hash - ); - Ok(()) - } -} diff --git a/postgresql_archive/src/matcher/mod.rs b/postgresql_archive/src/matcher/mod.rs index 4ccde33..d108990 100644 --- a/postgresql_archive/src/matcher/mod.rs +++ b/postgresql_archive/src/matcher/mod.rs @@ -1,2 +1 @@ pub mod registry; -pub mod target_os_arch; diff --git a/postgresql_archive/src/matcher/registry.rs b/postgresql_archive/src/matcher/registry.rs index 6773738..4bd9e72 100644 --- a/postgresql_archive/src/matcher/registry.rs +++ b/postgresql_archive/src/matcher/registry.rs @@ -1,4 +1,7 @@ -use crate::configuration::{theseus, zonky}; +#[cfg(feature = "theseus")] +use crate::configuration::theseus; +#[cfg(feature = "zonky")] +use crate::configuration::zonky; use crate::Error::{PoisonedLock, UnsupportedMatcher}; use crate::Result; use lazy_static::lazy_static; @@ -65,7 +68,9 @@ impl Default for MatchersRegistry { /// Creates a new matcher registry with the default matchers registered. fn default() -> Self { let mut registry = Self::new(); + #[cfg(feature = "theseus")] registry.register(|url| Ok(url == theseus::URL), theseus::matcher); + #[cfg(feature = "zonky")] registry.register(|url| Ok(url == zonky::URL), zonky::matcher); registry } @@ -121,12 +126,14 @@ mod tests { } #[test] + #[cfg(feature = "theseus")] fn test_get_theseus_postgresql_binaries() { assert!(get(theseus::URL).is_ok()); } #[test] - fn test_get_zonykio_postgresql_binaries() { + #[cfg(feature = "zonky")] + fn test_get_zonyk_postgresql_binaries() { assert!(get(zonky::URL).is_ok()); } } diff --git a/postgresql_archive/src/matcher/target_os_arch.rs b/postgresql_archive/src/matcher/target_os_arch.rs deleted file mode 100644 index c7c535c..0000000 --- a/postgresql_archive/src/matcher/target_os_arch.rs +++ /dev/null @@ -1,105 +0,0 @@ -use regex::Regex; -use semver::Version; -use std::env; - -/// Default asset matcher that matches the asset name to the current target triple or OS/CPU -/// architecture. -/// -/// # Errors -/// * If the asset matcher fails. -pub fn matcher(name: &str, _version: &Version) -> crate::Result { - if !name.ends_with(".tar.gz") { - return Ok(false); - } - let target_re = regex(target_triple::TARGET)?; - if target_re.is_match(name) { - return Ok(true); - } - let os = env::consts::OS; - let os_re = regex(os)?; - let matches_os = match os { - "macos" => { - let darwin_re = regex("darwin")?; - os_re.is_match(name) || darwin_re.is_match(name) - } - _ => os_re.is_match(name), - }; - let arch = env::consts::ARCH; - let arch_re = regex(arch)?; - let matches_arch = match arch { - "x86_64" => { - let amd64_re = regex("amd64")?; - arch_re.is_match(name) || amd64_re.is_match(name) - } - "aarch64" => { - let arm64_re = regex("arm64")?; - arch_re.is_match(name) || arm64_re.is_match(name) - } - _ => arch_re.is_match(name), - }; - if matches_os && matches_arch { - return Ok(true); - } - Ok(false) -} - -/// Creates a new regex for the specified key. -/// -/// # Arguments -/// * `key` - The key to create the regex for. -/// -/// # Returns -/// * The regex. -/// -/// # Errors -/// * If the regex cannot be created. -fn regex(key: &str) -> crate::Result { - let regex = Regex::new(format!(r"[\W_]{key}[\W_]").as_str())?; - Ok(regex) -} - -#[cfg(test)] -mod tests { - use super::*; - use crate::Result; - - #[test] - fn test_asset_match_success() -> Result<()> { - let version = Version::parse("16.3.0")?; - let target = target_triple::TARGET; - let os = env::consts::OS; - let arch = env::consts::ARCH; - let names = vec![ - format!("postgresql-16.3.0-{target}.tar.gz"), - format!("postgresql-16.3.0-{os}-{arch}.tar.gz"), - format!("foo.{target}.tar.gz"), - format!("foo.{os}.{arch}.tar.gz"), - format!("foo-{arch}-{os}.tar.gz"), - ]; - - for name in names { - assert!(matcher(name.as_str(), &version)?, "{}", name); - } - Ok(()) - } - - #[test] - fn test_asset_match_errors() -> Result<()> { - let version = Version::parse("16.3.0")?; - let target = target_triple::TARGET; - let os = env::consts::OS; - let arch = env::consts::ARCH; - let names = vec![ - format!("foo{target}.tar.gz"), - format!("foo{os}-{arch}.tar.gz"), - format!("foo-{target}.tar"), - format!("foo-{os}-{arch}.tar"), - format!("foo-{os}{arch}.tar.gz"), - ]; - - for name in names { - assert!(!matcher(name.as_str(), &version)?, "{}", name); - } - Ok(()) - } -} diff --git a/postgresql_archive/src/repository/mod.rs b/postgresql_archive/src/repository/mod.rs index 1f6a587..5ff890e 100644 --- a/postgresql_archive/src/repository/mod.rs +++ b/postgresql_archive/src/repository/mod.rs @@ -1,4 +1,6 @@ +#[cfg(feature = "github")] pub mod github; +#[cfg(feature = "maven")] pub mod maven; pub mod model; pub mod registry; diff --git a/postgresql_archive/src/repository/registry.rs b/postgresql_archive/src/repository/registry.rs index 7f057dd..d6b19ef 100644 --- a/postgresql_archive/src/repository/registry.rs +++ b/postgresql_archive/src/repository/registry.rs @@ -1,5 +1,8 @@ -use crate::configuration::zonky::Zonky; -use crate::configuration::{theseus, zonky}; +#[cfg(feature = "theseus")] +use crate::configuration::theseus; +#[cfg(feature = "zonky")] +use crate::configuration::zonky; +#[cfg(feature = "github")] use crate::repository::github::repository::GitHub; use crate::repository::model::Repository; use crate::Error::{PoisonedLock, UnsupportedRepository}; @@ -65,11 +68,16 @@ impl Default for RepositoryRegistry { /// Creates a new repository registry with the default repositories registered. fn default() -> Self { let mut registry = Self::new(); + #[cfg(feature = "theseus")] registry.register( |url| Ok(url.starts_with(theseus::URL)), Box::new(GitHub::new), ); - registry.register(|url| Ok(url.starts_with(zonky::URL)), Box::new(Zonky::new)); + #[cfg(feature = "zonky")] + registry.register( + |url| Ok(url.starts_with(zonky::URL)), + Box::new(zonky::Zonky::new), + ); registry } } @@ -157,12 +165,14 @@ mod tests { } #[test] + #[cfg(feature = "theseus")] fn test_get_theseus_postgresql_binaries() { assert!(get(theseus::URL).is_ok()); } #[test] - fn test_get_zonkyio_postgresql_binaries() { + #[cfg(feature = "zonky")] + fn test_get_zonky_postgresql_binaries() { assert!(get(zonky::URL).is_ok()); } } diff --git a/postgresql_archive/tests/zonky.rs b/postgresql_archive/tests/zonky.rs index ace654e..55d0942 100644 --- a/postgresql_archive/tests/zonky.rs +++ b/postgresql_archive/tests/zonky.rs @@ -1,11 +1,18 @@ +#[cfg(feature = "zonky")] use postgresql_archive::configuration::zonky; +#[cfg(feature = "zonky")] use postgresql_archive::extract; +#[cfg(feature = "zonky")] use postgresql_archive::{get_archive, get_version}; +#[cfg(feature = "zonky")] use semver::VersionReq; +#[cfg(feature = "zonky")] use std::fs::remove_dir_all; +#[cfg(feature = "zonky")] use test_log::test; #[test(tokio::test)] +#[cfg(feature = "zonky")] async fn test_get_version_not_found() -> postgresql_archive::Result<()> { let invalid_version_req = VersionReq::parse("=1.0.0")?; let result = get_version(zonky::URL, &invalid_version_req).await; @@ -15,6 +22,7 @@ async fn test_get_version_not_found() -> postgresql_archive::Result<()> { } #[test(tokio::test)] +#[cfg(feature = "zonky")] async fn test_get_version() -> anyhow::Result<()> { let version_req = VersionReq::parse("=16.2.0")?; let latest_version = get_version(zonky::URL, &version_req).await?; @@ -24,6 +32,7 @@ async fn test_get_version() -> anyhow::Result<()> { } #[test(tokio::test)] +#[cfg(feature = "zonky")] async fn test_get_archive_and_extract() -> anyhow::Result<()> { let url = zonky::URL; let version_req = VersionReq::STAR; @@ -38,6 +47,7 @@ async fn test_get_archive_and_extract() -> anyhow::Result<()> { } #[test(tokio::test)] +#[cfg(feature = "zonky")] async fn test_get_archive_version_not_found() -> postgresql_archive::Result<()> { let invalid_version_req = VersionReq::parse("=1.0.0")?; let result = get_archive(zonky::URL, &invalid_version_req).await; diff --git a/postgresql_embedded/Cargo.toml b/postgresql_embedded/Cargo.toml index 2fef961..882dcfc 100644 --- a/postgresql_embedded/Cargo.toml +++ b/postgresql_embedded/Cargo.toml @@ -37,7 +37,7 @@ test-log = { workspace = true } tokio = { workspace = true, features = ["full"] } [features] -default = ["rustls-tls"] +default = ["rustls-tls", "theseus"] blocking = ["tokio"] bundled = [] native-tls = [ @@ -48,11 +48,17 @@ rustls-tls = [ "postgresql_archive/rustls-tls", "sqlx/tls-rustls", ] +theseus = [ + "postgresql_archive/theseus", +] tokio = [ "dep:tokio", "postgresql_commands/tokio", "sqlx/runtime-tokio", ] +zonky = [ + "postgresql_archive/zonky", +] [package.metadata.release] dependent-version = "upgrade" diff --git a/postgresql_embedded/README.md b/postgresql_embedded/README.md index a693043..98f8649 100644 --- a/postgresql_embedded/README.md +++ b/postgresql_embedded/README.md @@ -100,7 +100,9 @@ The following features are available: | `blocking` | Enables the blocking API; requires `tokio` | No | | `native-tls` | Enables native-tls support | No | | `rustls-tls` | Enables rustls-tls support | Yes | +| `theseus` | Enables theseus PostgreSQL binaries | Yes | | `tokio` | Enables using tokio for async | No | +| `zonky` | Enables zonky PostgreSQL binaries | No | ## Safety diff --git a/postgresql_embedded/build/bundle.rs b/postgresql_embedded/build/bundle.rs index fa3d4a8..b0f332f 100644 --- a/postgresql_embedded/build/bundle.rs +++ b/postgresql_embedded/build/bundle.rs @@ -1,7 +1,6 @@ #![allow(dead_code)] use anyhow::Result; -use postgresql_archive::configuration::theseus; use postgresql_archive::get_archive; use postgresql_archive::VersionReq; use std::fs::File; @@ -15,7 +14,11 @@ use std::{env, fs}; /// self-contained binary that does not require the PostgreSQL archive to be /// downloaded at runtime. pub(crate) async fn stage_postgresql_archive() -> Result<()> { - let releases_url = env::var("POSTGRESQL_RELEASES_URL").unwrap_or(theseus::URL.to_string()); + #[cfg(feature = "theseus")] + let default_releases_url = postgresql_archive::configuration::theseus::URL.to_string(); + #[cfg(not(feature = "theseus"))] + let default_releases_url = String::new(); + let releases_url = env::var("POSTGRESQL_RELEASES_URL").unwrap_or(default_releases_url); println!("PostgreSQL releases URL: {releases_url}"); let postgres_version_req = env::var("POSTGRESQL_VERSION").unwrap_or("*".to_string()); let version_req = VersionReq::from_str(postgres_version_req.as_str())?; diff --git a/postgresql_embedded/src/settings.rs b/postgresql_embedded/src/settings.rs index 5501044..d31c4d9 100644 --- a/postgresql_embedded/src/settings.rs +++ b/postgresql_embedded/src/settings.rs @@ -1,6 +1,5 @@ use crate::error::{Error, Result}; use home::home_dir; -use postgresql_archive::configuration::theseus; use postgresql_archive::VersionReq; use rand::distributions::Alphanumeric; use rand::Rng; @@ -94,8 +93,13 @@ impl Settings { .map(char::from) .collect(); + #[cfg(feature = "theseus")] + let releases_url = postgresql_archive::configuration::theseus::URL.to_string(); + #[cfg(not(feature = "theseus"))] + let releases_url = String::new(); + Self { - releases_url: theseus::URL.to_string(), + releases_url, version: default_version(), installation_dir: home_dir.join(".theseus").join("postgresql"), password_file, diff --git a/postgresql_embedded/tests/zonky.rs b/postgresql_embedded/tests/zonky.rs index 1206f4f..d98543a 100644 --- a/postgresql_embedded/tests/zonky.rs +++ b/postgresql_embedded/tests/zonky.rs @@ -1,7 +1,10 @@ +#[cfg(feature = "zonky")] use postgresql_archive::configuration::zonky; +#[cfg(feature = "zonky")] use postgresql_embedded::{PostgreSQL, Result, Settings, Status}; #[tokio::test] +#[cfg(feature = "zonky")] async fn test_zonky() -> Result<()> { let settings = Settings { releases_url: zonky::URL.to_string(),