From 7f09bff76a51a337efe1bcac7a68ed517734f5f4 Mon Sep 17 00:00:00 2001 From: Lukas Wirth Date: Fri, 27 Feb 2026 10:18:03 +0100 Subject: [PATCH] gpui: Reduce amount of wasm cfgs in gpui (#50278) Release Notes: - N/A *or* Added/Fixed/Improved ... --- Cargo.lock | 2 +- crates/gpui/Cargo.toml | 3 +-- crates/gpui/src/app.rs | 11 +---------- crates/gpui/src/app/test_context.rs | 8 +------- crates/gpui/src/elements/img.rs | 9 --------- crates/gpui/src/executor.rs | 8 +------- crates/gpui/src/gpui.rs | 1 - crates/gpui/src/platform.rs | 2 +- crates/http_client/Cargo.toml | 10 ++++++---- crates/http_client/src/http_client.rs | 2 ++ crates/reqwest_client/Cargo.toml | 6 ++++-- crates/reqwest_client/src/reqwest_client.rs | 2 +- 12 files changed, 19 insertions(+), 45 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 85cf10d661d68a535cce85904d4ae9c3aedb651f..2d8b9858deb088f280e348f7f170fe720fd480b7 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -14242,13 +14242,13 @@ dependencies = [ "bytes 1.11.1", "futures 0.3.31", "gpui", + "gpui_util", "http_client", "http_client_tls", "log", "regex", "serde", "tokio", - "util", "zed-reqwest", ] diff --git a/crates/gpui/Cargo.toml b/crates/gpui/Cargo.toml index fbc8a10571d73ff34f8e37f4591b43c0fdaaab1f..4bd9510eac1710554f8eec52f22609db31c531ad 100644 --- a/crates/gpui/Cargo.toml +++ b/crates/gpui/Cargo.toml @@ -55,6 +55,7 @@ etagere = "0.2" futures.workspace = true futures-concurrency.workspace = true gpui_macros.workspace = true +http_client.workspace = true image.workspace = true inventory.workspace = true itertools.workspace = true @@ -103,8 +104,6 @@ web-time.workspace = true getrandom = { version = "0.3.4", features = ["wasm_js"] } uuid = { workspace = true, features = ["js"] } -[target.'cfg(not(target_family = "wasm"))'.dependencies] -http_client.workspace = true [target.'cfg(target_os = "macos")'.dependencies] block = "0.1" diff --git a/crates/gpui/src/app.rs b/crates/gpui/src/app.rs index dd81d9166d471632b62725f6ad1ce4faeca18c59..1bd5cd6b3c6a74ee840ac93b08554a82b1f050fa 100644 --- a/crates/gpui/src/app.rs +++ b/crates/gpui/src/app.rs @@ -27,7 +27,6 @@ use collections::{FxHashMap, FxHashSet, HashMap, VecDeque}; pub use context::*; pub use entity_map::*; use gpui_util::{ResultExt, debug_panic}; -#[cfg(not(target_family = "wasm"))] use http_client::{HttpClient, Url}; use smallvec::SmallVec; #[cfg(any(test, feature = "test-support"))] @@ -139,7 +138,6 @@ impl Application { Self(App::new_app( platform, Arc::new(()), - #[cfg(not(target_family = "wasm"))] Arc::new(NullHttpClient), )) } @@ -155,7 +153,6 @@ impl Application { } /// Sets the HTTP client for the application. - #[cfg(not(target_family = "wasm"))] pub fn with_http_client(self, http_client: Arc) -> Self { let mut context_lock = self.0.borrow_mut(); context_lock.http_client = http_client; @@ -585,7 +582,6 @@ pub struct App { pub(crate) loading_assets: FxHashMap<(TypeId, u64), Box>, asset_source: Arc, pub(crate) svg_renderer: SvgRenderer, - #[cfg(not(target_family = "wasm"))] http_client: Arc, pub(crate) globals_by_type: FxHashMap>, pub(crate) entities: EntityMap, @@ -642,7 +638,7 @@ impl App { pub(crate) fn new_app( platform: Rc, asset_source: Arc, - #[cfg(not(target_family = "wasm"))] http_client: Arc, + http_client: Arc, ) -> Rc { let background_executor = platform.background_executor(); let foreground_executor = platform.foreground_executor(); @@ -672,7 +668,6 @@ impl App { svg_renderer: SvgRenderer::new(asset_source.clone()), loading_assets: Default::default(), asset_source, - #[cfg(not(target_family = "wasm"))] http_client, globals_by_type: FxHashMap::default(), entities, @@ -1281,13 +1276,11 @@ impl App { } /// Returns the HTTP client for the application. - #[cfg(not(target_family = "wasm"))] pub fn http_client(&self) -> Arc { self.http_client.clone() } /// Sets the HTTP client for the application. - #[cfg(not(target_family = "wasm"))] pub fn set_http_client(&mut self, new_client: Arc) { self.http_client = new_client; } @@ -2512,10 +2505,8 @@ pub struct KeystrokeEvent { pub context_stack: Vec, } -#[cfg(not(target_family = "wasm"))] struct NullHttpClient; -#[cfg(not(target_family = "wasm"))] impl HttpClient for NullHttpClient { fn send( &self, diff --git a/crates/gpui/src/app/test_context.rs b/crates/gpui/src/app/test_context.rs index 7ce7f22e3c3cfef7beb531ce9443a172397e2e0f..dd4f37ed2a561f4259b41241c7cf4c83790a2b2f 100644 --- a/crates/gpui/src/app/test_context.rs +++ b/crates/gpui/src/app/test_context.rs @@ -120,16 +120,10 @@ impl TestAppContext { let foreground_executor = ForegroundExecutor::new(arc_dispatcher); let platform = TestPlatform::new(background_executor.clone(), foreground_executor.clone()); let asset_source = Arc::new(()); - #[cfg(not(target_family = "wasm"))] let http_client = http_client::FakeHttpClient::with_404_response(); let text_system = Arc::new(TextSystem::new(platform.text_system())); - let app = App::new_app( - platform.clone(), - asset_source, - #[cfg(not(target_family = "wasm"))] - http_client, - ); + let app = App::new_app(platform.clone(), asset_source, http_client); app.borrow_mut().mode = GpuiMode::test(); Self { diff --git a/crates/gpui/src/elements/img.rs b/crates/gpui/src/elements/img.rs index 59dd9de5fdfadf66fba622da6921b468726f439c..875f9e6dc1cc7d248f9e70488e52480dcca53fa3 100644 --- a/crates/gpui/src/elements/img.rs +++ b/crates/gpui/src/elements/img.rs @@ -594,7 +594,6 @@ impl Asset for ImageAssetLoader { source: Self::Source, cx: &mut App, ) -> impl Future + Send + 'static { - #[cfg(not(target_family = "wasm"))] let client = cx.http_client(); // TODO: Can we make SVGs always rescale? // let scale_factor = cx.scale_factor(); @@ -603,7 +602,6 @@ impl Asset for ImageAssetLoader { async move { let bytes = match source.clone() { Resource::Path(uri) => fs::read(uri.as_ref())?, - #[cfg(not(target_family = "wasm"))] Resource::Uri(uri) => { use anyhow::Context as _; use futures::AsyncReadExt as _; @@ -626,12 +624,6 @@ impl Asset for ImageAssetLoader { } body } - #[cfg(target_family = "wasm")] - Resource::Uri(_) => { - return Err(ImageCacheError::Other(Arc::new(anyhow::anyhow!( - "Uri resources are not supported on wasm" - )))); - } Resource::Embedded(path) => { let data = asset_source.load(&path).ok().flatten(); if let Some(data) = data { @@ -722,7 +714,6 @@ pub enum ImageCacheError { #[error("IO error: {0}")] Io(Arc), /// An error that occurred while processing an image. - #[cfg(not(target_family = "wasm"))] #[error("unexpected http status for {uri}: {status}, body: {body}")] BadStatus { /// The URI of the image. diff --git a/crates/gpui/src/executor.rs b/crates/gpui/src/executor.rs index d48be9dc30811cd5728fc07081c1d11d3405ec95..31c1ed80b92efb5dfa9ead6dcaf9050fe68ea399 100644 --- a/crates/gpui/src/executor.rs +++ b/crates/gpui/src/executor.rs @@ -564,15 +564,9 @@ mod test { let platform = TestPlatform::new(background_executor.clone(), foreground_executor); let asset_source = Arc::new(()); - #[cfg(not(target_family = "wasm"))] let http_client = http_client::FakeHttpClient::with_404_response(); - let app = App::new_app( - platform, - asset_source, - #[cfg(not(target_family = "wasm"))] - http_client, - ); + let app = App::new_app(platform, asset_source, http_client); (dispatcher, background_executor, app) } diff --git a/crates/gpui/src/gpui.rs b/crates/gpui/src/gpui.rs index 6e592655162471e5501030152a11bf67f3744578..af3fb51ce51f7df570a8e28faad23018ed7dc778 100644 --- a/crates/gpui/src/gpui.rs +++ b/crates/gpui/src/gpui.rs @@ -88,7 +88,6 @@ pub use geometry::*; pub use global::*; pub use gpui_macros::{AppContext, IntoElement, Render, VisualContext, register_action, test}; pub use gpui_util::arc_cow::ArcCow; -#[cfg(not(target_family = "wasm"))] pub use http_client; pub use input::*; pub use inspector::*; diff --git a/crates/gpui/src/platform.rs b/crates/gpui/src/platform.rs index 885e031cba3020b16fc6391a52bbcf49e9022707..a6714ff250f2f854c51d30bfea5e2e5911ce60ee 100644 --- a/crates/gpui/src/platform.rs +++ b/crates/gpui/src/platform.rs @@ -229,7 +229,7 @@ pub trait Platform: 'static { } /// A handle to a platform's display, e.g. a monitor or laptop screen. -pub trait PlatformDisplay: Send + Sync + Debug { +pub trait PlatformDisplay: Debug { /// Get the ID for this display fn id(&self) -> DisplayId; diff --git a/crates/http_client/Cargo.toml b/crates/http_client/Cargo.toml index 177f8639ca1a5d75bd0130979f4d550e3622a1b4..6273d773d8c4651fd292555e18d2a2462e6358df 100644 --- a/crates/http_client/Cargo.toml +++ b/crates/http_client/Cargo.toml @@ -19,8 +19,6 @@ doctest = true [dependencies] anyhow.workspace = true async-compression.workspace = true -async-fs.workspace = true -async-tar.workspace = true bytes.workspace = true derive_more.workspace = true futures.workspace = true @@ -31,7 +29,11 @@ parking_lot.workspace = true serde.workspace = true serde_json.workspace = true serde_urlencoded.workspace = true -sha2.workspace = true -tempfile.workspace = true url.workspace = true + +[target.'cfg(not(target_family = "wasm"))'.dependencies] util.workspace = true +async-fs.workspace = true +async-tar.workspace = true +sha2.workspace = true +tempfile.workspace = true diff --git a/crates/http_client/src/http_client.rs b/crates/http_client/src/http_client.rs index 1182ef74ca3d59a2d59419e185ff5bd673c5d505..5cf25a8277872ba3c6d502565e8057623b267d42 100644 --- a/crates/http_client/src/http_client.rs +++ b/crates/http_client/src/http_client.rs @@ -1,5 +1,7 @@ mod async_body; +#[cfg(not(target_family = "wasm"))] pub mod github; +#[cfg(not(target_family = "wasm"))] pub mod github_download; pub use anyhow::{Result, anyhow}; diff --git a/crates/reqwest_client/Cargo.toml b/crates/reqwest_client/Cargo.toml index 2f23ed3072f4d21d1ff053cb829931ae407f6d5b..41fcd1f5d2f8ca1c78b0a2261a7c48566999e0de 100644 --- a/crates/reqwest_client/Cargo.toml +++ b/crates/reqwest_client/Cargo.toml @@ -20,13 +20,15 @@ anyhow.workspace = true bytes.workspace = true futures.workspace = true http_client.workspace = true -http_client_tls.workspace = true serde.workspace = true log.workspace = true tokio = { workspace = true, features = ["rt", "rt-multi-thread"] } regex.workspace = true reqwest.workspace = true -util.workspace = true +gpui_util.workspace = true + +[target.'cfg(not(target_family = "wasm"))'.dependencies] +http_client_tls.workspace = true [dev-dependencies] gpui.workspace = true diff --git a/crates/reqwest_client/src/reqwest_client.rs b/crates/reqwest_client/src/reqwest_client.rs index 7c8ab84bd40fa76075a8cd377e942a5c73094b22..3239a48904a6c4e71c5b94a7de1b78426da7c51d 100644 --- a/crates/reqwest_client/src/reqwest_client.rs +++ b/crates/reqwest_client/src/reqwest_client.rs @@ -2,7 +2,7 @@ use std::error::Error; use std::sync::{LazyLock, OnceLock}; use std::{borrow::Cow, mem, pin::Pin, task::Poll, time::Duration}; -use util::defer; +use gpui_util::defer; use anyhow::anyhow; use bytes::{BufMut, Bytes, BytesMut};