From 763dd18a0a8db63c4d2aebe32426084dfeff9559 Mon Sep 17 00:00:00 2001 From: wooden-worm Date: Thu, 29 Feb 2024 10:43:08 -0800 Subject: [PATCH 1/2] wasm build by adding `default-client` feature gate --- .github/workflows/rust.yml | 12 ++++++++++++ Cargo.toml | 6 ++++-- src/lib.rs | 9 ++++++--- 3 files changed, 22 insertions(+), 5 deletions(-) diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index 740d31a2..32bef814 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -17,6 +17,18 @@ jobs: - run: cargo build --verbose --all-targets - run: cargo test + wasm-build: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - name: Install latest nightly + uses: actions-rs/toolchain@v1 + with: + toolchain: stable + override: true + target: wasm32-unknown-unknown + - run: cargo build --verbose --target=wasm32-unknown-unknown --no-default-features + clippy: runs-on: ubuntu-latest steps: diff --git a/Cargo.toml b/Cargo.toml index b1fc4b8b..1b14870c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,7 @@ [package] name = "octocrab" version = "0.34.1" +resolver = "2" authors = ["XAMPPRocky "] edition = "2018" readme = "README.md" @@ -38,7 +39,7 @@ hyper = "1.1.0" hyper-rustls = { version = "0.26.0", optional = true } hyper-timeout = { version = "0.5.1", optional = true } hyper-tls = { version = "0.6.0", optional = true } -hyper-util = { version = "0.1.3", features = ["client-legacy", "http1"] } +hyper-util = { version = "0.1.3", features = ["http1"] } once_cell = "1.7.2" percent-encoding = "2.2.0" pin-project = "1.0.12" @@ -68,7 +69,7 @@ pretty_assertions = "1.4.0" graphql_client = "0.13.0" [features] -default = ["follow-redirect", "retry", "rustls", "timeout", "tracing"] +default = ["follow-redirect", "retry", "rustls", "timeout", "tracing", "default-client"] follow-redirect = ["tower-http/follow-redirect"] retry = ["tower/retry", "futures-util"] @@ -77,3 +78,4 @@ rustls-webpki-tokio = ["hyper-rustls/webpki-tokio"] opentls = ["hyper-tls"] stream = ["futures-core", "futures-util"] timeout = ["hyper-timeout", "tokio", "tower/timeout"] +default-client = ["hyper-util/client-legacy"] diff --git a/src/lib.rs b/src/lib.rs index 7b614d06..a51ccb90 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -205,8 +205,6 @@ use std::sync::{Arc, RwLock}; use std::time::Duration; use http::{header::HeaderName, StatusCode}; -#[cfg(all(not(feature = "opentls"), not(feature = "rustls")))] -use hyper::client::HttpConnector; use hyper::{Request, Response}; use once_cell::sync::Lazy; @@ -265,6 +263,7 @@ pub type Result = std::result::Result; const GITHUB_BASE_URI: &str = "https://api.github.com"; +#[cfg(feature = "default-client")] static STATIC_INSTANCE: Lazy> = Lazy::new(|| arc_swap::ArcSwap::from_pointee(Octocrab::default())); @@ -322,6 +321,7 @@ pub async fn map_github_error( /// # Ok(()) /// # } /// ``` +#[cfg(feature = "default-client")] pub fn initialise(crab: Octocrab) -> Arc { STATIC_INSTANCE.swap(Arc::from(crab)) } @@ -334,6 +334,7 @@ pub fn initialise(crab: Octocrab) -> Arc { /// let octocrab = octocrab::instance(); /// } /// ``` +#[cfg(feature = "default-client")] pub fn instance() -> Arc { STATIC_INSTANCE.load().clone() } @@ -590,10 +591,11 @@ impl OctocrabBuilder } /// Build a [`Client`] instance with the current [`Service`] stack. + #[cfg(feature = "default-client")] pub fn build(self) -> Result { let client: hyper_util::client::legacy::Client<_, String> = { #[cfg(all(not(feature = "opentls"), not(feature = "rustls")))] - let mut connector = HttpConnector::new(); + let mut connector = hyper::client::conn::http1::HttpConnector::new(); #[cfg(all(feature = "rustls", not(feature = "opentls")))] let connector = { @@ -918,6 +920,7 @@ impl fmt::Debug for Octocrab { /// - `base_uri`: `https://api.github.com` /// - `auth`: `None` /// - `client`: http client with the `octocrab` user agent. +#[cfg(feature = "default-client")] impl Default for Octocrab { fn default() -> Self { OctocrabBuilder::default().build().unwrap() From 18a999669e398c5b1586b2c62284a150ae490c26 Mon Sep 17 00:00:00 2001 From: wooden-worm Date: Thu, 29 Feb 2024 10:45:25 -0800 Subject: [PATCH 2/2] CI --- .github/workflows/rust.yml | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index 32bef814..7b5a9075 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -21,12 +21,8 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 - - name: Install latest nightly - uses: actions-rs/toolchain@v1 - with: - toolchain: stable - override: true - target: wasm32-unknown-unknown + - run: rustup default stable + - run: rustup target add wasm32-unknown-unknown - run: cargo build --verbose --target=wasm32-unknown-unknown --no-default-features clippy: