diff --git a/Cargo.lock b/Cargo.lock index 5f5ee41625e..43e2b48b10b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -7575,7 +7575,7 @@ name = "gpui_apple" version = "0.1.0" dependencies = [ "anyhow", - "block", + "block2 0.6.2", "cbindgen", "cocoa 0.26.0", "core-foundation 0.10.0", diff --git a/Cargo.toml b/Cargo.toml index b1929a0a4d4..7735281bd54 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -566,7 +566,6 @@ backtrace = "0.3" base64 = "0.22" betlang = "0.1.1" bitflags = "2.6.0" -block = "0.1" block2 = "0.6" brush-parser = "0.3" bytes = "1.0" diff --git a/crates/gpui_apple/Cargo.toml b/crates/gpui_apple/Cargo.toml index ead06aa2c84..33ec05f7b4b 100644 --- a/crates/gpui_apple/Cargo.toml +++ b/crates/gpui_apple/Cargo.toml @@ -23,7 +23,7 @@ gpui.workspace = true [target.'cfg(target_os = "macos")'.dependencies] anyhow.workspace = true -block.workspace = true +block2.workspace = true cocoa.workspace = true core-foundation.workspace = true core-video.workspace = true diff --git a/crates/gpui_apple/src/metal_renderer.rs b/crates/gpui_apple/src/metal_renderer.rs index 93bac52377f..eddb3c1939f 100644 --- a/crates/gpui_apple/src/metal_renderer.rs +++ b/crates/gpui_apple/src/metal_renderer.rs @@ -1,6 +1,6 @@ use crate::metal_atlas::MetalAtlas; use anyhow::{Context as _, Result}; -use block::ConcreteBlock; +use block2::RcBlock; use cocoa::{ base::{NO, YES}, foundation::{NSSize, NSUInteger}, @@ -12,6 +12,7 @@ use gpui::{ }; #[cfg(any(test, feature = "bench-support", feature = "test-support"))] use image::RgbaImage; +use objc2::runtime::AnyObject; use core_foundation::base::TCFType; use core_video::{ @@ -520,13 +521,15 @@ impl MetalRenderer { let instance_buffer_pool = self.instance_buffer_pool.clone(); let instance_buffer = Cell::new(Some(writer.finish())); - let block = ConcreteBlock::new(move |_| { + let block = RcBlock::new(move |_: ptr::NonNull| { if let Some(instance_buffer) = instance_buffer.take() { instance_buffer_pool.lock().release(instance_buffer); } }); - let block = block.copy(); - command_buffer.add_completed_handler(&block); + // SAFETY: Both pointee types are opaque views of the same Objective-C block pointer ABI. + unsafe { + command_buffer.add_completed_handler(&*RcBlock::as_ptr(&block).cast()); + } Ok(command_buffer) } diff --git a/tooling/xtask/src/workspace.rs b/tooling/xtask/src/workspace.rs index 74d1fed2f47..e7a28c45a30 100644 --- a/tooling/xtask/src/workspace.rs +++ b/tooling/xtask/src/workspace.rs @@ -16,6 +16,9 @@ mod tests { use super::load_workspace; + /// Direct dependencies forbidden in workspace packages, paired with the reason shown on failure. + const FORBIDDEN_DIRECT_DEPENDENCIES: &[(&str, &str)] = &[("block", "use `block2` instead")]; + /// Crates that must not depend on each other, directly or transitively: /// such edges chain large UI crates one after another and serialize the /// build, badly hurting incremental compile times. Dev-dependencies are @@ -35,6 +38,34 @@ mod tests { ("title_bar", "git_ui"), ]; + #[test] + fn no_forbidden_direct_dependencies() { + let workspace = load_workspace().expect("failed to load cargo metadata"); + let mut violations = Vec::new(); + + for package in workspace.workspace_packages() { + for dependency in &package.dependencies { + let Some((_, reason)) = FORBIDDEN_DIRECT_DEPENDENCIES + .iter() + .find(|(name, _)| *name == dependency.name) + else { + continue; + }; + violations.push(format!( + "{} directly depends on `{}`; {reason}", + package.name, dependency.name + )); + } + } + + assert_eq!( + violations, + Vec::::new(), + "forbidden direct dependencies:\n{}", + violations.join("\n"), + ); + } + #[test] fn no_forbidden_dependencies_between_feature_crates() { let workspace = load_workspace().expect("failed to load cargo metadata");