From ae6843d111e4d306eb05912de91a51da759af96c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Laurent=20St=C3=A9phenne?= Date: Wed, 20 Aug 2025 14:13:21 -0400 Subject: [PATCH] Fixed disabling feature http_client --- Cargo.lock | 1 + crates/gpui/Cargo.toml | 2 ++ crates/gpui/src/app.rs | 23 +++++++++---------- crates/gpui/src/app/test_context.rs | 2 +- crates/gpui/src/asset_cache.rs | 2 ++ crates/gpui/src/elements/img.rs | 22 +++++++++++++++++- crates/gpui/src/gpui.rs | 1 + .../gpui/src/platform/linux/wayland/client.rs | 2 +- 8 files changed, 40 insertions(+), 15 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 342bb1058f..439a9ef1ab 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -7497,6 +7497,7 @@ dependencies = [ "taffy", "thiserror 2.0.12", "unicode-segmentation", + "url", "usvg", "util", "uuid", diff --git a/crates/gpui/Cargo.toml b/crates/gpui/Cargo.toml index 9f5b66087d..0b9b84b848 100644 --- a/crates/gpui/Cargo.toml +++ b/crates/gpui/Cargo.toml @@ -50,6 +50,7 @@ wayland = [ "filedescriptor", "xkbcommon", "open", + "url", ] x11 = [ "blade-graphics", @@ -194,6 +195,7 @@ wayland-protocols = { version = "0.31.2", features = [ wayland-protocols-plasma = { version = "0.2.0", features = [ "client", ], optional = true } +url = { workspace = true, optional = true } # X11 as-raw-xcb-connection = { version = "1", optional = true } diff --git a/crates/gpui/src/app.rs b/crates/gpui/src/app.rs index bbd59fa7bc..ad4e8c3a4c 100644 --- a/crates/gpui/src/app.rs +++ b/crates/gpui/src/app.rs @@ -24,6 +24,7 @@ pub use async_context::*; use collections::{FxHashMap, FxHashSet, HashMap, VecDeque}; pub use context::*; pub use entity_map::*; +#[cfg(feature = "http_client")] use http_client::{HttpClient, Url}; use smallvec::SmallVec; #[cfg(any(test, feature = "test-support"))] @@ -132,22 +133,14 @@ impl Application { #[cfg(any(test, feature = "test-support"))] log::info!("GPUI was compiled in test mode"); - Self(App::new_app( - current_platform(false), - Arc::new(()), - Arc::new(NullHttpClient), - )) + Self(App::new_app(current_platform(false), Arc::new(()))) } /// Build an app in headless mode. This prevents opening windows, /// but makes it possible to run an application in an context like /// SSH, where GUI applications are not allowed. pub fn headless() -> Self { - Self(App::new_app( - current_platform(true), - Arc::new(()), - Arc::new(NullHttpClient), - )) + Self(App::new_app(current_platform(true), Arc::new(()))) } /// Assign @@ -161,6 +154,7 @@ impl Application { } /// Sets the HTTP client for the application. + #[cfg(feature = "http_client")] pub fn with_http_client(self, http_client: Arc) -> Self { let mut context_lock = self.0.borrow_mut(); context_lock.http_client = http_client; @@ -253,6 +247,7 @@ pub struct App { pub(crate) loading_assets: FxHashMap<(TypeId, u64), Box>, asset_source: Arc, pub(crate) svg_renderer: SvgRenderer, + #[cfg(feature = "http_client")] http_client: Arc, pub(crate) globals_by_type: FxHashMap>, pub(crate) entities: EntityMap, @@ -300,7 +295,6 @@ impl App { pub(crate) fn new_app( platform: Rc, asset_source: Arc, - http_client: Arc, ) -> Rc { let executor = platform.background_executor(); let foreground_executor = platform.foreground_executor(); @@ -327,7 +321,8 @@ impl App { svg_renderer: SvgRenderer::new(asset_source.clone()), loading_assets: Default::default(), asset_source, - http_client, + #[cfg(feature = "http_client")] + http_client: Arc::new(NullHttpClient), globals_by_type: FxHashMap::default(), entities, new_entity_observers: SubscriberSet::new(), @@ -850,11 +845,13 @@ impl App { } /// Returns the HTTP client for the application. + #[cfg(feature = "http_client")] pub fn http_client(&self) -> Arc { self.http_client.clone() } /// Sets the HTTP client for the application. + #[cfg(feature = "http_client")] pub fn set_http_client(&mut self, new_client: Arc) { self.http_client = new_client; } @@ -2033,8 +2030,10 @@ pub struct KeystrokeEvent { pub context_stack: Vec, } +#[cfg(feature = "http_client")] struct NullHttpClient; +#[cfg(feature = "http_client")] 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 c65c045f6b..7a35d49bc5 100644 --- a/crates/gpui/src/app/test_context.rs +++ b/crates/gpui/src/app/test_context.rs @@ -131,7 +131,7 @@ impl TestAppContext { let text_system = Arc::new(TextSystem::new(platform.text_system())); Self { - app: App::new_app(platform.clone(), asset_source, http_client), + app: App::new_app(platform.clone(), asset_source).with_http_client(http_client), background_executor, foreground_executor, dispatcher, diff --git a/crates/gpui/src/asset_cache.rs b/crates/gpui/src/asset_cache.rs index 9afbba8a0e..ef5013cace 100644 --- a/crates/gpui/src/asset_cache.rs +++ b/crates/gpui/src/asset_cache.rs @@ -11,6 +11,7 @@ use std::sync::Arc; #[derive(Debug, PartialEq, Eq, Hash, Clone)] pub enum Resource { /// This resource is at a given URI + #[cfg(feature = "http_client")] Uri(SharedUri), /// This resource is at a given path in the file system Path(Arc), @@ -18,6 +19,7 @@ pub enum Resource { Embedded(SharedString), } +#[cfg(feature = "http_client")] impl From for Resource { fn from(value: SharedUri) -> Self { Self::Uri(value) diff --git a/crates/gpui/src/elements/img.rs b/crates/gpui/src/elements/img.rs index 893860d7e1..b6c00d5c41 100644 --- a/crates/gpui/src/elements/img.rs +++ b/crates/gpui/src/elements/img.rs @@ -49,16 +49,19 @@ pub enum ImageSource { Custom(Arc Option, ImageCacheError>>>), } +#[cfg(feature = "http_client")] fn is_uri(uri: &str) -> bool { http_client::Uri::from_str(uri).is_ok() } +#[cfg(feature = "http_client")] impl From for ImageSource { fn from(value: SharedUri) -> Self { Self::Resource(Resource::Uri(value)) } } +#[cfg(feature = "http_client")] impl<'a> From<&'a str> for ImageSource { fn from(s: &'a str) -> Self { if is_uri(s) { @@ -69,6 +72,14 @@ impl<'a> From<&'a str> for ImageSource { } } +#[cfg(not(feature = "http_client"))] +impl<'a> From<&'a str> for ImageSource { + fn from(s: &'a str) -> Self { + Self::Resource(Resource::Embedded(s.to_string().into())) + } +} + +#[cfg(feature = "http_client")] impl From for ImageSource { fn from(s: String) -> Self { if is_uri(&s) { @@ -79,6 +90,13 @@ impl From for ImageSource { } } +#[cfg(not(feature = "http_client"))] +impl From for ImageSource { + fn from(s: String) -> Self { + Self::Resource(Resource::Embedded(s.into())) + } +} + impl From for ImageSource { fn from(s: SharedString) -> Self { s.as_ref().into() @@ -591,7 +609,6 @@ impl Asset for ImageAssetLoader { source: Self::Source, cx: &mut App, ) -> impl Future + Send + 'static { - let client = cx.http_client(); // TODO: Can we make SVGs always rescale? // let scale_factor = cx.scale_factor(); let svg_renderer = cx.svg_renderer(); @@ -599,7 +616,9 @@ impl Asset for ImageAssetLoader { async move { let bytes = match source.clone() { Resource::Path(uri) => fs::read(uri.as_ref())?, + #[cfg(feature = "http_client")] Resource::Uri(uri) => { + let client = cx.http_client(); let mut response = client .get(uri.as_ref(), ().into(), true) .await @@ -720,6 +739,7 @@ pub enum ImageCacheError { Io(Arc), /// An error that occurred while processing an image. #[error("unexpected http status for {uri}: {status}, body: {body}")] + #[cfg(feature = "http_client")] BadStatus { /// The URI of the image. uri: SharedUri, diff --git a/crates/gpui/src/gpui.rs b/crates/gpui/src/gpui.rs index 5e4b5fe6e9..83f1988f12 100644 --- a/crates/gpui/src/gpui.rs +++ b/crates/gpui/src/gpui.rs @@ -135,6 +135,7 @@ pub use executor::*; pub use geometry::*; pub use global::*; pub use gpui_macros::{AppContext, IntoElement, Render, VisualContext, register_action, test}; +#[cfg(feature = "http_client")] pub use http_client; pub use input::*; pub use inspector::*; diff --git a/crates/gpui/src/platform/linux/wayland/client.rs b/crates/gpui/src/platform/linux/wayland/client.rs index 189cfa1954..5e9a4ab76a 100644 --- a/crates/gpui/src/platform/linux/wayland/client.rs +++ b/crates/gpui/src/platform/linux/wayland/client.rs @@ -14,8 +14,8 @@ use calloop::{ use calloop_wayland_source::WaylandSource; use collections::HashMap; use filedescriptor::Pipe; -use http_client::Url; use smallvec::SmallVec; +use url::Url; use util::ResultExt; use wayland_backend::client::ObjectId; use wayland_backend::protocol::WEnum;