mirror of
https://github.com/zed-industries/zed.git
synced 2026-11-19 06:59:22 +01:00
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:
Generated
+1
-1
@@ -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",
|
||||
|
||||
@@ -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"
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
|
||||
@@ -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");
|
||||
|
||||
Reference in New Issue
Block a user