feat(macos): port Ghostty's macOS code paths (Metal, CoreText, Darwin)

Ports the macOS-specific Zig code behind cfg(target_os = "macos"):
- renderer: a GraphicsApi trait with generic::Renderer<G>; Metal backend
  (all renderer/metal/* files, shaders.metal verbatim, runtime library
  compile, IOSurface layer, CVDisplayLink), shadertoy -> MSL via naga;
  OpenGL remains the backend elsewhere.
- font: CoreText face, shaper and discovery with build.rs backend
  selection (coretext default; coretext-freetype / coretext-harfbuzz /
  coretext-noshape features), no fontconfig/freetype/harfbuzz on Apple.
- input: KeymapDarwin via UCKeyTranslate, option-as-alt, mac keycodes.
- os: macos, mach, cf_release_thread, NSProcessInfo args and macOS
  branches; config: macOS defaults, keybinds, Application Support paths.
- termio/core: login(1) wrapping, openpty/execvpe, Darwin child exit
  handling, os_log logging.

Compile-checked for aarch64/x86_64-apple-darwin (clippy -D warnings
clean) using the cross setup in docs/rewrite/notes/macos-M1.md; cannot
run here. The embedded runtime/C API (embedded.zig) is the next step.

Also includes the cross-platform integration edits shared by the crash,
verification, Windows and macOS work (Cargo target-gating, thread
crash-context hooks, apprt-gtk surface/IME refactor, termio/os cfg
gates), a cfg fix so ghostty-config builds on wasm32, and an allow for
the intentional recursion in the crash overflow test.

Test Plan:
- cargo test --workspace (3224 passed)
- cargo clippy --workspace --all-targets -- -D warnings
- cargo check --target aarch64-apple-darwin -p ghostty-renderer (with
  the documented cross env)
This commit is contained in:
ddidderr committed 2026-10-12 06:02:39 +02:00
1 parent 3c8fae1089
commit 452b782149
124 files changed
+14936 -1242

No files matched your search

+22
View File
@@ -1,12 +1,15 @@
#[cfg(any(target_os = "linux", target_os = "android"))]
use std::io::Read;
/// Kernel `TASK_COMM_LEN`.
#[cfg(any(target_os = "linux", target_os = "android"))]
const TASK_COMM_LEN: u64 = 16;
/// Returns true if the program was launched as a systemd service.
///
/// On Linux, this returns true if the program was launched as a systemd
/// service. It will return false if Ghostty was launched any other way.
#[cfg(any(target_os = "linux", target_os = "android"))]
pub fn launched_by_systemd() -> bool {
// On Linux, systemd sets the `INVOCATION_ID` (v232+) and the
// `JOURNAL_STREAM` (v231+) environment variables. If these
@@ -58,6 +61,12 @@ pub fn launched_by_systemd() -> bool {
&comm_data[..end] == b"systemd"
}
/// For other platforms (macOS, ...), this returns false.
#[cfg(not(any(target_os = "linux", target_os = "android")))]
pub fn launched_by_systemd() -> bool {
false
}
/// systemd notifications. Used by Ghostty to inform systemd of the state of the
/// process. Currently only used to notify systemd that we are ready and that
/// configuration reloading has started.
@@ -68,6 +77,7 @@ pub fn launched_by_systemd() -> bool {
/// avoid another external dependency. Linux systems that do not use
/// `systemd` should never start Ghostty with the `NOTIFY_SOCKET` environment
/// variable set and these functions essentially become a no-op.
#[cfg(any(target_os = "linux", target_os = "android"))]
pub mod notify {
use rustix::net::{
AddressFamily,
@@ -172,8 +182,17 @@ pub mod notify {
}
}
/// systemd notifications are a no-op on platforms without systemd.
#[cfg(not(any(target_os = "linux", target_os = "android")))]
pub mod notify {
pub fn ready() {}
pub fn reloading() {}
}
#[cfg(test)]
mod tests {
#[cfg(any(target_os = "linux", target_os = "android"))]
use std::os::unix::net::UnixDatagram;
use super::*;
@@ -190,6 +209,7 @@ mod tests {
);
}
#[cfg(any(target_os = "linux", target_os = "android"))]
fn recv_with_socket(f: impl FnOnce()) -> String {
let dir = crate::TempDir::init().unwrap();
let path = dir.path().join("notify.sock");
@@ -202,11 +222,13 @@ mod tests {
String::from_utf8(buf[..n].to_vec()).unwrap()
}
#[cfg(any(target_os = "linux", target_os = "android"))]
#[test]
fn notify_ready_sends_message() {
assert_eq!(recv_with_socket(notify::ready), "READY=1");
}
#[cfg(any(target_os = "linux", target_os = "android"))]
#[test]
fn notify_reloading_sends_message() {
let msg = recv_with_socket(notify::reloading);