Skip to content

Commit

Permalink
make rattler-package-streaming compile with wasm
Browse files Browse the repository at this point in the history
  • Loading branch information
wolfv committed Aug 23, 2023
1 parent c462253 commit e286552
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 5 deletions.
6 changes: 5 additions & 1 deletion crates/rattler_networking/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,24 @@ readme.workspace = true
[features]
native-tls = ['reqwest/native-tls']
rustls-tls = ['reqwest/rustls-tls']
blocking = ['reqwest/blocking']

[dependencies]
anyhow = "1.0.71"
dirs = "5.0.1"
keyring = "2.0.4"
lazy_static = "1.4.0"
libc = "0.2.147"
reqwest = { version = "0.11.18", features = ["blocking"], default-features = false}
reqwest = { version = "0.11.18", default-features = false}
retry-policies = { version = "0.2.0", default-features = false }
serde = "1.0.171"
serde_json = "1.0.102"
thiserror = "1.0.43"
tracing = "0.1.37"

[target.'cfg( target_arch = "wasm32" )'.dependencies]
getrandom = { version = "0.2.10", features = ["js"] }

[dev-dependencies]
anyhow = "1.0.71"
insta = { version = "1.30.0", features = ["json"] }
Expand Down
4 changes: 4 additions & 0 deletions crates/rattler_networking/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ impl AuthenticatedClient {
}
}

#[cfg(feature = "blocking")]
/// A blocking client that can be used to make authenticated requests, based on the [`reqwest::blocking::Client`]
pub struct AuthenticatedClientBlocking {
/// The underlying client
Expand All @@ -120,6 +121,7 @@ pub struct AuthenticatedClientBlocking {
auth_storage: AuthenticationStorage,
}

#[cfg(feature = "blocking")]
impl AuthenticatedClientBlocking {
/// Create a new authenticated client from the given client and authentication storage
pub fn from_client(
Expand All @@ -133,6 +135,7 @@ impl AuthenticatedClientBlocking {
}
}

#[cfg(feature = "blocking")]
impl Default for AuthenticatedClientBlocking {
fn default() -> Self {
AuthenticatedClientBlocking {
Expand All @@ -142,6 +145,7 @@ impl Default for AuthenticatedClientBlocking {
}
}

#[cfg(feature = "blocking")]
impl AuthenticatedClientBlocking {
/// Create a GET request builder for the given URL (see also [`reqwest::blocking::Client::get`])
pub fn get<U: IntoUrl>(&self, url: U) -> reqwest::blocking::RequestBuilder {
Expand Down
6 changes: 3 additions & 3 deletions crates/rattler_package_streaming/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ rattler_networking = { version = "0.7.0", path = "../rattler_networking", defaul
[features]
default = ['native-tls']
tokio = ["dep:tokio", "bzip2/tokio", "tokio/fs", "tokio-util/io", "tokio-util/io-util", "reqwest?/stream", "futures-util"]
native-tls = ['reqwest?/native-tls']
rustls-tls = ['reqwest?/rustls-tls']
reqwest = ["reqwest/blocking"]
native-tls = ['rattler_networking/native-tls']
rustls-tls = ['rattler_networking/rustls-tls']
blocking = ["rattler_networking/blocking"]

[dev-dependencies]
tempfile = "3.6.0"
Expand Down
9 changes: 9 additions & 0 deletions crates/rattler_package_streaming/src/reqwest/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,17 @@
#[cfg(feature = "tokio")]
pub mod tokio;

#[cfg(feature = "blocking")]
use crate::{ExtractError, ExtractResult};
#[cfg(feature = "blocking")]
use rattler_conda_types::package::ArchiveType;
#[cfg(feature = "blocking")]
use rattler_networking::AuthenticatedClientBlocking;
#[cfg(feature = "blocking")]
use reqwest::blocking::Response;
#[cfg(feature = "blocking")]
use reqwest::IntoUrl;
#[cfg(feature = "blocking")]
use std::path::Path;

/// Extracts the contents a `.tar.bz2` package archive from the specified remote location.
Expand All @@ -23,6 +29,7 @@ use std::path::Path;
/// Path::new("/tmp"))
/// .unwrap();
/// ```
#[cfg(feature = "blocking")]
pub fn extract_tar_bz2(
client: AuthenticatedClientBlocking,
url: impl IntoUrl,
Expand Down Expand Up @@ -52,6 +59,7 @@ pub fn extract_tar_bz2(
/// Path::new("/tmp"))
/// .unwrap();
/// ```
#[cfg(feature = "blocking")]
pub fn extract_conda(
client: AuthenticatedClientBlocking,
url: impl IntoUrl,
Expand Down Expand Up @@ -82,6 +90,7 @@ pub fn extract_conda(
/// Path::new("/tmp"))
/// .unwrap();
/// ```
#[cfg(feature = "blocking")]
pub fn extract(
client: AuthenticatedClientBlocking,
url: impl IntoUrl,
Expand Down
2 changes: 1 addition & 1 deletion crates/rattler_package_streaming/tests/extract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ async fn test_extract_conda_async(#[case] input: &str, #[case] sha256: &str, #[c
assert_eq!(&format!("{:x}", result.md5), md5);
}

#[cfg(feature = "reqwest")]
#[cfg(all(feature = "reqwest", feature = "blocking"))]
#[apply(url_archives)]
fn test_extract_url(#[case] url: &str, #[case] sha256: &str, #[case] md5: &str) {
use rattler_networking::AuthenticatedClientBlocking;
Expand Down

0 comments on commit e286552

Please sign in to comment.