Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.
chore: Make some of the deps of gpui optional (#16986)
Piotr Osiewicz4ec1f29df054
diff --git a/Cargo.lock b/Cargo.lockindex 963e50e7110..b1eea5f6f81 100644--- a/Cargo.lock+++ b/Cargo.lock@@ -4916,7 +4916,6 @@ dependencies = ["sum_tree","taffy","thiserror",- "time","unicode-segmentation","usvg","util",diff --git a/crates/gpui/Cargo.toml b/crates/gpui/Cargo.tomlindex 6d627dbed62..3d285ce59e3 100644--- a/crates/gpui/Cargo.toml+++ b/crates/gpui/Cargo.toml@@ -15,6 +15,7 @@ default = []test-support = ["backtrace","collections/test-support",+ "rand","util/test-support","http_client/test-support",]@@ -36,7 +37,6 @@ bytemuck = { version = "1", optional = true }collections.workspace = truector.workspace = truederive_more.workspace = true-env_logger.workspace = trueetagere = "0.2"futures.workspace = truegpui_macros.workspace = true@@ -50,7 +50,7 @@ parking = "2.0.0"parking_lot.workspace = truepostage.workspace = trueprofiling.workspace = true-rand.workspace = true+rand = { optional = true, workspace = true}raw-window-handle = "0.6"refineable.workspace = trueresvg = { version = "0.41.0", default-features = false }@@ -68,7 +68,6 @@ strum.workspace = truesum_tree.workspace = truetaffy = "0.4.3"thiserror.workspace = true-time.workspace = trueutil.workspace = trueuuid.workspace = truewaker-fn = "1.2.0"@@ -76,6 +75,8 @@ waker-fn = "1.2.0"[dev-dependencies]backtrace = "0.3"collections = { workspace = true, features = ["test-support"] }+env_logger.workspace = true+rand.workspace = trueutil = { workspace = true, features = ["test-support"] }http_client = { workspace = true, features = ["test-support"] }unicode-segmentation.workspace = true@@ -152,6 +153,7 @@ font-kit = { git = "https://github.com/zed-industries/font-kit", rev = "40391b7"x11-clipboard = "0.9.2"[target.'cfg(windows)'.dependencies]+rand.workspace = truewindows.workspace = truewindows-core = "0.58"diff --git a/crates/util/Cargo.toml b/crates/util/Cargo.tomlindex 3691af49f20..6257ffd6426 100644--- a/crates/util/Cargo.toml+++ b/crates/util/Cargo.toml@@ -13,7 +13,7 @@ path = "src/util.rs"doctest = true[features]-test-support = ["tempfile", "git2"]+test-support = ["tempfile", "git2", "rand"][dependencies]anyhow.workspace = true@@ -23,7 +23,7 @@ futures.workspace = truegit2 = { workspace = true, optional = true }globset.workspace = truelog.workspace = true-rand.workspace = true+rand = {workspace = true, optional = true}regex.workspace = truerust-embed.workspace = trueserde.workspace = true@@ -40,3 +40,4 @@ tendril = "0.4.3"[dev-dependencies]git2.workspace = truetempfile.workspace = true+rand.workspace = truediff --git a/crates/util/src/util.rs b/crates/util/src/util.rsindex 566ad336986..79880aa9ed5 100644--- a/crates/util/src/util.rs+++ b/crates/util/src/util.rs@@ -6,7 +6,7 @@ pub mod serde;pub mod test;use futures::Future;-use rand::{seq::SliceRandom, Rng};+use regex::Regex;use std::sync::OnceLock;use std::{@@ -517,54 +517,59 @@ pub fn defer<F: FnOnce()>(f: F) -> Deferred<F> {Deferred(Some(f))}-pub struct RandomCharIter<T: Rng> {- rng: T,- simple_text: bool,-}--impl<T: Rng> RandomCharIter<T> {- pub fn new(rng: T) -> Self {- Self {- rng,- simple_text: std::env::var("SIMPLE_TEXT").map_or(false, |v| !v.is_empty()),+#[cfg(any(test, feature = "test-support"))]+mod rng {+ use rand::{seq::SliceRandom, Rng};+ pub struct RandomCharIter<T: Rng> {+ rng: T,+ simple_text: bool,+ }++ impl<T: Rng> RandomCharIter<T> {+ pub fn new(rng: T) -> Self {+ Self {+ rng,+ simple_text: std::env::var("SIMPLE_TEXT").map_or(false, |v| !v.is_empty()),+ }}- }- pub fn with_simple_text(mut self) -> Self {- self.simple_text = true;- self+ pub fn with_simple_text(mut self) -> Self {+ self.simple_text = true;+ self+ }}-}-impl<T: Rng> Iterator for RandomCharIter<T> {- type Item = char;+ impl<T: Rng> Iterator for RandomCharIter<T> {+ type Item = char;- fn next(&mut self) -> Option<Self::Item> {- if self.simple_text {- return if self.rng.gen_range(0..100) < 5 {- Some('\n')- } else {- Some(self.rng.gen_range(b'a'..b'z' + 1).into())- };- }+ fn next(&mut self) -> Option<Self::Item> {+ if self.simple_text {+ return if self.rng.gen_range(0..100) < 5 {+ Some('\n')+ } else {+ Some(self.rng.gen_range(b'a'..b'z' + 1).into())+ };+ }- match self.rng.gen_range(0..100) {- // whitespace- 0..=19 => [' ', '\n', '\r', '\t'].choose(&mut self.rng).copied(),- // two-byte greek letters- 20..=32 => char::from_u32(self.rng.gen_range(('α' as u32)..('ω' as u32 + 1))),- // // three-byte characters- 33..=45 => ['✋', '✅', '❌', '❎', '⭐']- .choose(&mut self.rng)- .copied(),- // // four-byte characters- 46..=58 => ['🍐', '🏀', '🍗', '🎉'].choose(&mut self.rng).copied(),- // ascii letters- _ => Some(self.rng.gen_range(b'a'..b'z' + 1).into()),+ match self.rng.gen_range(0..100) {+ // whitespace+ 0..=19 => [' ', '\n', '\r', '\t'].choose(&mut self.rng).copied(),+ // two-byte greek letters+ 20..=32 => char::from_u32(self.rng.gen_range(('α' as u32)..('ω' as u32 + 1))),+ // // three-byte characters+ 33..=45 => ['✋', '✅', '❌', '❎', '⭐']+ .choose(&mut self.rng)+ .copied(),+ // // four-byte characters+ 46..=58 => ['🍐', '🏀', '🍗', '🎉'].choose(&mut self.rng).copied(),+ // ascii letters+ _ => Some(self.rng.gen_range(b'a'..b'z' + 1).into()),+ }}}}-+#[cfg(any(test, feature = "test-support"))]+pub use rng::RandomCharIter;/// Get an embedded file as a string.pub fn asset_str<A: rust_embed::RustEmbed>(path: &str) -> Cow<'static, str> {match A::get(path).unwrap().data {