gpui_apple: Remove block as a direct dependency (#64641)

# Objective

Get rid of instances of the `block` crate, as it will not compile in a
future version of Rust.

## Solution

Migrate an independent code block to the `objc2` crate family.

This is the last PR in this series, and we get to remove `block` as a
direct dependency!

## Testing

- Tested rendering on MacOS

Release Notes:

- N/A
- [GPUI] Removed `block` as a direct dependency
This commit is contained in:
tidely
2026-09-23 16:14:14 +00:00
committed by GitHub
parent eb2f43d982
commit b89471c52d
5 changed files with 40 additions and 7 deletions
Generated
+1 -1
View File
@@ -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",
-1
View File
@@ -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"
+1 -1
View File
@@ -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
+7 -4
View File
@@ -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<AnyObject>| {
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)
}
+31
View File
@@ -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::<String>::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");