Skip to content

Commit 4d7cc4a

Browse files
committed
herdr-core, herdr-desktop: support aarch64-darwin
Assisted-by: Claude Code (claude-opus-5-5)
1 parent 015761f commit 4d7cc4a

3 files changed

Lines changed: 268 additions & 25 deletions

File tree

‎pkgs/by-name/he/herdr-core/package.nix‎

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
{
22
lib,
3+
stdenv,
34
rustPlatform,
45
fetchFromGitHub,
56
zig_0_16,
7+
cctools,
68
installAgentSkills,
79
bash,
810
coreutils,
@@ -42,9 +44,23 @@ rustPlatform.buildRustPackage (finalAttrs: {
4244

4345
nativeBuildInputs = [
4446
installAgentSkills
45-
];
46-
47-
env.ZIG = lib.getExe zig_0_16;
47+
]
48+
# Ghostty combines its static archives with Apple's `libtool -static`.
49+
++ lib.optionals stdenv.hostPlatform.isDarwin [ cctools ];
50+
51+
env = {
52+
ZIG = lib.getExe zig_0_16;
53+
}
54+
// lib.optionalAttrs stdenv.hostPlatform.isLinux {
55+
# hc tells builds apart by their GNU build id, so a byte-identical copy of
56+
# the binary counts as the same build. Without one it falls back to the
57+
# file's identity.
58+
NIX_SET_BUILD_ID = "1";
59+
# The linker hashes the debug sections into the build id, and those hold
60+
# Zig cache paths that change from build to build. Dropping them at link
61+
# time keeps the build id reproducible; stdenv strips them anyway.
62+
NIX_LDFLAGS = "--strip-debug";
63+
};
4864

4965
postPatch =
5066
let
@@ -114,20 +130,14 @@ rustPlatform.buildRustPackage (finalAttrs: {
114130
chmod -R u+w "$ZIG_GLOBAL_CACHE_DIR/p"
115131
'';
116132

117-
# hc tells builds apart by their GNU build id, so a byte-identical copy of
118-
# the binary counts as the same build. Without one it falls back to the
119-
# file's identity.
120-
env.NIX_SET_BUILD_ID = "1";
121-
# The linker hashes the debug sections into the build id, and those hold
122-
# Zig cache paths that change from build to build. Dropping them at link
123-
# time keeps the build id reproducible; stdenv strips them anyway.
124-
env.NIX_LDFLAGS = "--strip-debug";
125-
126133
nativeCheckInputs = [
127134
git
128135
python3
129136
];
130137

138+
# Some tests check timings that Darwin builders miss.
139+
doCheck = !stdenv.hostPlatform.isDarwin;
140+
131141
# postPatch makes hc download a release build for every machine it sets up,
132142
# and these two tests try to set one up. The sandbox has no network.
133143
checkFlags = [
@@ -177,6 +187,7 @@ rustPlatform.buildRustPackage (finalAttrs: {
177187
platforms = [
178188
"x86_64-linux"
179189
"aarch64-linux"
190+
"aarch64-darwin"
180191
];
181192
};
182193
})
Lines changed: 205 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,205 @@
1+
diff --git a/vendor/gpui-pre-macos/src/window.rs b/vendor/gpui-pre-macos/src/window.rs
2+
index 1ba661c..4ddfce9 100644
3+
--- a/vendor/gpui-pre-macos/src/window.rs
4+
+++ b/vendor/gpui-pre-macos/src/window.rs
5+
@@ -65,7 +65,7 @@ use parking_lot::Mutex;
6+
use raw_window_handle as rwh;
7+
use smallvec::SmallVec;
8+
use std::{
9+
- cell::Cell,
10+
+ cell::{Cell, RefCell},
11+
ffi::{CStr, CString, c_void},
12+
mem,
13+
ops::Range,
14+
@@ -294,6 +294,19 @@ unsafe fn build_classes() {
15+
sel!(characterIndexForPoint:),
16+
character_index_for_point as extern "C" fn(&Object, Sel, NSPoint) -> u64,
17+
);
18+
+
19+
+ decl.add_method(
20+
+ sel!(accessibilityChildren),
21+
+ accessibility_children as extern "C" fn(&Object, Sel) -> id,
22+
+ );
23+
+ decl.add_method(
24+
+ sel!(accessibilityFocusedUIElement),
25+
+ accessibility_focused_ui_element as extern "C" fn(&Object, Sel) -> id,
26+
+ );
27+
+ decl.add_method(
28+
+ sel!(accessibilityHitTest:),
29+
+ accessibility_hit_test as extern "C" fn(&Object, Sel, NSPoint) -> id,
30+
+ );
31+
decl.register()
32+
};
33+
BLURRED_VIEW_CLASS = {
34+
@@ -713,7 +726,11 @@ struct MacWindowState {
35+
toggle_tab_bar_callback: Option<Box<dyn FnMut()>>,
36+
activated_least_once: bool,
37+
closed: Arc<AtomicBool>,
38+
- accesskit_adapter: Option<accesskit_macos::SubclassingAdapter>,
39+
+ // Kept behind an `Rc<RefCell<_>>` so the `GPUIView` accessibility methods can clone it
40+
+ // out and release the window state lock before calling into AccessKit. AppKit may
41+
+ // query accessibility while the lock is already held further up the stack, and
42+
+ // raising AccessKit events can synchronously trigger more queries.
43+
+ accesskit: Option<Rc<RefCell<AccessKitState>>>,
44+
// The parent window if this window is a sheet (Dialog kind)
45+
sheet_parent: Option<id>,
46+
}
47+
@@ -1153,7 +1170,7 @@ impl MacWindow {
48+
toggle_tab_bar_callback: None,
49+
activated_least_once: false,
50+
closed: Arc::new(AtomicBool::new(false)),
51+
- accesskit_adapter: None,
52+
+ accesskit: None,
53+
sheet_parent: None,
54+
}));
55+
let mut window = Self(state, marker);
56+
@@ -1385,15 +1402,10 @@ impl MacWindow {
57+
impl Drop for MacWindow {
58+
fn drop(&mut self) {
59+
let mut this = self.0.lock();
60+
- // `accesskit_macos::SubclassingAdapter::for_window` strong-retains the
61+
- // window's content view, and that content view keeps the `GPUIView` it
62+
- // hosts alive. Together with the `Arc<Mutex<MacWindowState>>` parked in
63+
- // both views' `windowState` ivar, that forms
64+
- // `MacWindowState -> adapter -> content view -> GPUIView -> MacWindowState`,
65+
- // a cycle the delegate/`frame_source` teardown below cannot break. Drop
66+
- // the adapter here so the native view, its `CAMetalLayer` and the
67+
- // renderer's command queue are actually released with the window.
68+
- drop(this.accesskit_adapter.take());
69+
+ // The `GPUIView` (and with it this state) can outlive the GPUI window until AppKit
70+
+ // finishes closing it. Accessibility queries arriving in the meantime fall back to
71+
+ // `NSView`'s defaults instead of serving a tree for a window GPUI no longer updates.
72+
+ this.accesskit.take();
73+
this.renderer.destroy();
74+
let window = this.native_window;
75+
let sheet_parent = this.sheet_parent.take();
76+
@@ -2385,23 +2397,30 @@ impl PlatformWindow for MacWindow {
77+
};
78+
let action_handler = A11yActionHandler(callbacks.action);
79+
80+
+ // `GPUIView` implements the `NSView` accessibility methods itself and forwards them to
81+
+ // this adapter. `accesskit_macos::SubclassingAdapter` is not used because restoring the
82+
+ // view's class when it is dropped corrupts the KVO isa-swizzling AppKit's Touch Bar
83+
+ // support has applied to the view, making AppKit throw while the window closes.
84+
let adapter = unsafe {
85+
- accesskit_macos::SubclassingAdapter::for_window(
86+
- lock.native_window as *mut c_void,
87+
- activation_handler,
88+
- action_handler,
89+
- )
90+
+ accesskit_macos::Adapter::new(lock.native_view.as_ptr().cast(), false, action_handler)
91+
};
92+
93+
- lock.accesskit_adapter = Some(adapter);
94+
+ lock.accesskit = Some(Rc::new(RefCell::new(AccessKitState {
95+
+ adapter,
96+
+ activation_handler,
97+
+ })));
98+
}
99+
100+
fn a11y_tree_update(&self, tree_update: accesskit::TreeUpdate) {
101+
- let events = {
102+
- let mut lock = self.0.lock();
103+
- lock.accesskit_adapter
104+
- .as_mut()
105+
- .and_then(|adapter| adapter.update_if_active(|| tree_update))
106+
+ let Some(accesskit) = self.0.lock().accesskit.clone() else {
107+
+ return;
108+
+ };
109+
+ let events = match accesskit.try_borrow_mut() {
110+
+ Ok(mut accesskit) => accesskit.adapter.update_if_active(|| tree_update),
111+
+ Err(_) => {
112+
+ log::error!("dropped accessibility tree update during an accessibility query");
113+
+ None
114+
+ }
115+
};
116+
if let Some(events) = events {
117+
events.raise();
118+
@@ -2413,6 +2432,11 @@ impl PlatformWindow for MacWindow {
119+
}
120+
}
121+
122+
+struct AccessKitState {
123+
+ adapter: accesskit_macos::Adapter,
124+
+ activation_handler: A11yActivationHandler,
125+
+}
126+
+
127+
struct A11yActivationHandler {
128+
callback: Box<dyn Fn() -> Option<accesskit::TreeUpdate> + Send + 'static>,
129+
}
130+
@@ -2509,6 +2533,54 @@ extern "C" fn dealloc_view(this: &Object, _: Sel) {
131+
}
132+
}
133+
134+
+/// Runs `f` with the view's AccessKit state, or returns `None` when accessibility is disabled,
135+
+/// not initialized yet, or already torn down. Also returns `None` instead of deadlocking or
136+
+/// panicking when the query arrives while GPUI holds the window state lock or from within
137+
+/// AccessKit itself.
138+
+fn with_accesskit_state<R>(view: &Object, f: impl FnOnce(&mut AccessKitState) -> R) -> Option<R> {
139+
+ let window_state = unsafe { get_window_state(view) };
140+
+ let accesskit = window_state.try_lock()?.accesskit.clone()?;
141+
+ let mut accesskit = accesskit.try_borrow_mut().ok()?;
142+
+ Some(f(&mut accesskit))
143+
+}
144+
+
145+
+extern "C" fn accessibility_children(this: &Object, _: Sel) -> id {
146+
+ with_accesskit_state(this, |state| {
147+
+ state
148+
+ .adapter
149+
+ .view_children(&mut state.activation_handler)
150+
+ .cast::<Object>()
151+
+ })
152+
+ .unwrap_or_else(|| unsafe { msg_send![super(this, class!(NSView)), accessibilityChildren] })
153+
+}
154+
+
155+
+extern "C" fn accessibility_focused_ui_element(this: &Object, _: Sel) -> id {
156+
+ with_accesskit_state(this, |state| {
157+
+ state
158+
+ .adapter
159+
+ .focus(&mut state.activation_handler)
160+
+ .cast::<Object>()
161+
+ })
162+
+ .unwrap_or_else(|| unsafe {
163+
+ msg_send![super(this, class!(NSView)), accessibilityFocusedUIElement]
164+
+ })
165+
+}
166+
+
167+
+extern "C" fn accessibility_hit_test(this: &Object, _: Sel, point: NSPoint) -> id {
168+
+ with_accesskit_state(this, |state| {
169+
+ state
170+
+ .adapter
171+
+ .hit_test(
172+
+ accesskit_macos::NSPoint::new(point.x, point.y),
173+
+ &mut state.activation_handler,
174+
+ )
175+
+ .cast::<Object>()
176+
+ })
177+
+ .unwrap_or_else(|| unsafe {
178+
+ msg_send![super(this, class!(NSView)), accessibilityHitTest: point]
179+
+ })
180+
+}
181+
+
182+
fn add_mouse_tracking_area(native_view: &Objc2NSView) {
183+
let options = NSTrackingAreaOptions::MouseEnteredAndExited
184+
| NSTrackingAreaOptions::MouseMoved
185+
@@ -3165,12 +3237,14 @@ extern "C" fn window_did_change_key_status(this: &Object, selector: Sel, _: id)
186+
let executor = lock.foreground_executor.clone();
187+
drop(lock);
188+
189+
- let a11y_events = {
190+
- let mut lock = window_state.lock();
191+
- lock.accesskit_adapter
192+
- .as_mut()
193+
- .and_then(|adapter| adapter.update_view_focus_state(is_active))
194+
- };
195+
+ let accesskit = window_state.lock().accesskit.clone();
196+
+ let a11y_events = accesskit.and_then(|accesskit| match accesskit.try_borrow_mut() {
197+
+ Ok(mut accesskit) => accesskit.adapter.update_view_focus_state(is_active),
198+
+ Err(_) => {
199+
+ log::error!("dropped accessibility focus change during an accessibility query");
200+
+ None
201+
+ }
202+
+ });
203+
if let Some(events) = a11y_events {
204+
events.raise();
205+
}

0 commit comments

Comments
 (0)