Skip to content

Commit ed21356

Browse files
authored
Merge pull request #298 from mattsse/ef-remove-async-std
Remove async-std support
2 parents 9bf66fc + 3e1c11a commit ed21356

15 files changed

Lines changed: 56 additions & 339 deletions

File tree

.github/workflows/ci.yml

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -83,11 +83,5 @@ jobs:
8383
steps:
8484
- uses: actions/checkout@v6
8585
- uses: dtolnay/rust-toolchain@stable
86-
- name: Check examples with default features
87-
run: cargo check --examples --features tokio-runtime,bytes
88-
- name: Check async-std examples
89-
run: cargo check --examples --features async-std-runtime
90-
- name: Check fetcher examples
91-
run: |
92-
cargo check --example fetcher --features _fetcher-native-tokio
93-
cargo check --example fetcher-async-std --features async-std-runtime,_fetcher-native-async-std
86+
- name: Check examples
87+
run: cargo check --examples --features fetcher

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## [Unreleased]
99

10+
### Breaking Changes
11+
12+
- Removed async-std support
13+
1014
### Changed
1115

1216
- Updated edition to 2024

Cargo.toml

Lines changed: 7 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,8 @@ keywords = ["chrome", "chromedriver", "puppeteer", "automation"]
1414
categories = ["web-programming", "api-bindings", "development-tools::testing"]
1515

1616
[dependencies]
17-
async-tungstenite = "0.32.0"
17+
async-tungstenite = { version = "0.32.0", features = ["tokio-runtime"] }
1818
serde = { version = "1", features = ["derive"] }
19-
async-std = { version = "1", features = [
20-
"attributes",
21-
"unstable",
22-
], optional = true }
2319
futures = "0.3"
2420
chromiumoxide_types = { path = "chromiumoxide_types", version = "0.8" }
2521
chromiumoxide_cdp = { path = "chromiumoxide_cdp", version = "0.8" }
@@ -31,15 +27,14 @@ url = "2"
3127
base64 = "0.22"
3228
fnv = "1"
3329
futures-timer = "3"
34-
cfg-if = "1"
3530
tokio = { version = "1", features = [
3631
"rt",
3732
"rt-multi-thread",
3833
"time",
3934
"fs",
4035
"macros",
4136
"process",
42-
], optional = true }
37+
] }
4338
tracing = "0.1"
4439
pin-project-lite = "0.2"
4540
dunce = "1"
@@ -57,37 +52,17 @@ tracing-subscriber = "0.3"
5752
tokio = { version = "1", features = ["rt-multi-thread", "time", "macros"] }
5853

5954
[features]
60-
default = ["tokio-runtime", "bytes"]
61-
async-std-runtime = ["async-std", "async-tungstenite/async-std-runtime"]
62-
tokio-runtime = ["tokio", "async-tungstenite/tokio-runtime"]
63-
fetcher = []
55+
default = ["bytes"]
56+
fetcher = ["chromiumoxide_fetcher"]
6457
bytes = ["dep:bytes"]
6558
serde0 = []
6659

67-
# Temporary features until cargo weak dependencies bug is fixed
68-
# See https://github.com/rust-lang/cargo/issues/10801
69-
_fetcher-rustls-async-std = [
70-
"fetcher",
71-
"chromiumoxide_fetcher/_rustls-async-std",
72-
]
73-
_fetcher-rustls-tokio = ["fetcher", "chromiumoxide_fetcher/_rustls-tokio"]
74-
_fetcher-native-async-std = [
75-
"fetcher",
76-
"chromiumoxide_fetcher/_native-async-std",
77-
]
78-
_fetcher-native-tokio = ["fetcher", "chromiumoxide_fetcher/_native-tokio"]
79-
80-
[[example]]
81-
name = "wiki-async-std"
82-
required-features = ["async-std-runtime"]
83-
84-
[[example]]
85-
name = "fetcher-async-std"
86-
required-features = ["async-std-runtime", "_fetcher-native-async-std"]
60+
rustls = ["chromiumoxide_fetcher/rustls"]
61+
native-tls = ["chromiumoxide_fetcher/native-tls"]
8762

8863
[[example]]
8964
name = "fetcher"
90-
required-features = ["_fetcher-native-tokio"]
65+
required-features = ["fetcher"]
9166

9267
[[test]]
9368
name = "chromiumoxide_tests"

README.md

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -67,15 +67,7 @@ If you need something else, the `Page::execute` function allows for writing your
6767

6868
### Add chromiumoxide to your project
6969

70-
`chromiumoxide` comes with support for the [`tokio`](https://github.com/tokio-rs/tokio) and [`async-std`](https://github.com/async-rs/async-std) runtimes.
71-
72-
By default `chromiumoxide` is configured with `tokio`.
73-
74-
To use `chromiumoxide` with the `async-std` runtime:
75-
76-
```toml
77-
chromiumoxide = { version = "0.8.0", default-features = false, features = ["async-std-runtime"] }
78-
```
70+
`chromiumoxide` only supports the [`tokio`](https://github.com/tokio-rs/tokio) runtime.
7971

8072
## Generated Code
8173

@@ -90,15 +82,9 @@ All Events are bundled in single enum (`CdpEvent`)
9082
## Fetcher
9183

9284
By default `chromiumoxide` will try to find an installed version of chromium on the computer it runs on.
93-
It is possible to download and install one automatically for some platforms using the `fetcher`.
94-
95-
Ther features are currently a bit messy due to a Cargo bug and will be changed once it is resolved.
96-
Based on your runtime and TLS configuration you should enable one of the following:
85+
It is possible to download and install one automatically for some platforms using the `fetcher` feature.
9786

98-
- `_fetcher-rustls-async-std`
99-
- `_fetcher-rustls-tokio`
100-
- `_fetcher-native-async-std`
101-
- `_fetcher-native-tokio`
87+
You need to enable either the `rustls` or the `native-tls` feature to allow the fetcher to download binaries.
10288

10389
```rust
10490
use std::path::Path;

chromiumoxide_fetcher/Cargo.toml

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -34,22 +34,14 @@ directories = "6"
3434
serde = { version = "1", features = ["derive"] }
3535
tracing = "0.1"
3636
zip = { version = "0.6", default-features = false, features = ["deflate"] }
37-
async-std = { version = "1.5", features = ["unstable"], optional = true }
38-
tokio = { version = "1", features = ["fs"], optional = true }
39-
reqwest = { version = "0.12", default-features = false, features = [
40-
"json",
41-
], optional = true }
42-
surf = { version = "2.3", default-features = false, optional = true }
37+
tokio = { version = "1", features = ["fs", "io-util"] }
38+
reqwest = { version = "0.12", default-features = false, features = ["json"] }
4339

4440
[target.'cfg(target_os = "windows")'.dependencies]
4541
windows-version = "0.1"
4642

4743
[features]
48-
default = ["_native-tokio"]
49-
async-std-runtime = ["async-std", "surf"]
50-
tokio-runtime = ["tokio", "reqwest"]
44+
default = ["rustls"]
5145

52-
_rustls-async-std = ["surf/h1-client-rustls", "async-std-runtime"]
53-
_rustls-tokio = ["reqwest/rustls-tls", "tokio-runtime"]
54-
_native-async-std = ["surf/h1-client", "async-std-runtime"]
55-
_native-tokio = ["reqwest/native-tls", "tokio-runtime"]
46+
rustls = ["reqwest/rustls-tls"]
47+
native-tls = ["reqwest/native-tls"]

chromiumoxide_fetcher/src/runtime/mod.rs

Lines changed: 3 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1+
use std::path::{Path, PathBuf};
2+
13
use anyhow::Context;
24
use serde::Deserialize;
3-
use std::path::{Path, PathBuf};
5+
use tokio::io::AsyncWriteExt;
46

57
use self::zip::ZipArchive;
68

@@ -9,85 +11,6 @@ mod zip;
911
#[derive(Debug, Default)]
1012
pub struct Runtime;
1113

12-
#[cfg(feature = "async-std-runtime")]
13-
impl Runtime {
14-
pub async fn exists(folder_path: &Path) -> bool {
15-
async_std::fs::metadata(folder_path).await.is_ok()
16-
}
17-
18-
pub async fn download_json<T>(url: &str) -> anyhow::Result<T>
19-
where
20-
T: for<'de> Deserialize<'de>,
21-
{
22-
use surf::http;
23-
24-
let url = url.parse::<surf::Url>().context("Invalid metadata url")?;
25-
let mut res = surf::RequestBuilder::new(http::Method::Get, url)
26-
.await
27-
.map_err(|e| e.into_inner())
28-
.context("Failed to send request to host")?;
29-
if res.status() != surf::StatusCode::Ok {
30-
anyhow::bail!("Invalid metadata url");
31-
}
32-
let body = res
33-
.body_json::<T>()
34-
.await
35-
.map_err(|e| e.into_inner().context("Failed to read response body"))?;
36-
Ok(body)
37-
}
38-
39-
pub async fn download_text(url: &str) -> anyhow::Result<String> {
40-
use surf::http;
41-
let url = url.parse::<surf::Url>().context("Invalid metadata url")?;
42-
let mut res = surf::RequestBuilder::new(http::Method::Get, url)
43-
.await
44-
.map_err(|e| e.into_inner())
45-
.context("Failed to send request to host")?;
46-
if res.status() != surf::StatusCode::Ok {
47-
anyhow::bail!("Invalid metadata url");
48-
}
49-
let body = res
50-
.body_string()
51-
.await
52-
.map_err(|e| e.into_inner().context("Failed to read response body"))?;
53-
Ok(body)
54-
}
55-
56-
pub async fn download_file(url: &str, archive_path: &Path) -> anyhow::Result<()> {
57-
use async_std::io::WriteExt;
58-
use surf::http;
59-
60-
// Open file
61-
let file = async_std::fs::File::create(&archive_path)
62-
.await
63-
.context("Failed to create archive file")?;
64-
let mut file = async_std::io::BufWriter::new(file);
65-
66-
// Download
67-
let url = url.parse::<surf::Url>().context("Invalid archive url")?;
68-
let res = surf::RequestBuilder::new(http::Method::Get, url)
69-
.await
70-
.map_err(|e| e.into_inner())
71-
.context("Failed to send request to host")?;
72-
if res.status() != surf::StatusCode::Ok {
73-
anyhow::bail!("Invalid archive url");
74-
}
75-
async_std::io::copy(res, &mut file)
76-
.await
77-
.context("Failed to write to archive file")?;
78-
79-
// Flush to disk
80-
file.flush().await.context("Failed to flush to disk")?;
81-
Ok(())
82-
}
83-
84-
pub async fn unzip(archive_path: PathBuf, folder_path: PathBuf) -> anyhow::Result<()> {
85-
async_std::task::spawn_blocking(move || do_unzip(&archive_path, &folder_path)).await?;
86-
Ok(())
87-
}
88-
}
89-
90-
#[cfg(feature = "tokio-runtime")]
9114
impl Runtime {
9215
pub async fn exists(folder_path: &Path) -> bool {
9316
tokio::fs::metadata(folder_path).await.is_ok()
@@ -128,8 +51,6 @@ impl Runtime {
12851
}
12952

13053
pub async fn download_file(url: &str, archive_path: &Path) -> anyhow::Result<()> {
131-
use tokio::io::AsyncWriteExt;
132-
13354
// Open file
13455
let file = tokio::fs::File::create(&archive_path)
13556
.await

chromiumoxide_pdl/src/build/generator.rs

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use std::borrow::Cow;
22
use std::collections::{HashMap, HashSet, VecDeque};
33
use std::fs;
4-
use std::io::{self, Error, ErrorKind};
4+
use std::io::{self, Error};
55
use std::ops::Deref;
66
use std::path::{Path, PathBuf};
77

@@ -163,9 +163,7 @@ impl Generator {
163163
pub fn compile_pdls<P: AsRef<Path>>(&mut self, pdls: &[P]) -> io::Result<()> {
164164
let target: PathBuf = self.out_dir.clone().map(Ok).unwrap_or_else(|| {
165165
std::env::var_os("OUT_DIR")
166-
.ok_or_else(|| {
167-
Error::new(ErrorKind::Other, "OUT_DIR environment variable is not set")
168-
})
166+
.ok_or_else(|| Error::other("OUT_DIR environment variable is not set"))
169167
.map(Into::into)
170168
})?;
171169

@@ -174,24 +172,20 @@ impl Generator {
174172
for path in pdls {
175173
let path = path.as_ref();
176174
let file_name = path.file_stem().ok_or_else(|| {
177-
Error::new(
178-
ErrorKind::Other,
179-
format!("Failed to read file name for {}", path.display()),
180-
)
175+
Error::other(format!("Failed to read file name for {}", path.display()))
181176
})?;
182177
let mod_name = file_name.to_string_lossy().to_string();
183178
self.protocol_mods.push(mod_name);
184179

185180
let input = fs::read_to_string(path)?;
186-
let resolved =
187-
resolve_pdl(path, &input).map_err(|e| Error::new(ErrorKind::Other, e.message))?;
181+
let resolved = resolve_pdl(path, &input).map_err(|e| Error::other(e.message))?;
188182
inputs.push(resolved);
189183
}
190184

191185
let mut protocols = vec![];
192186

193187
for (idx, input) in inputs.iter().enumerate() {
194-
let pdl = parse_pdl(input).map_err(|e| Error::new(ErrorKind::Other, e.message))?;
188+
let pdl = parse_pdl(input).map_err(|e| Error::other(e.message))?;
195189

196190
self.domains
197191
.extend(pdl.domains.iter().map(|d| (d.name.to_string(), idx)));

examples/fetcher-async-std.rs

Lines changed: 0 additions & 56 deletions
This file was deleted.

0 commit comments

Comments
 (0)