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)
52 lines
1.4 KiB
Rust
52 lines
1.4 KiB
Rust
//! Compile-time platform predicates used by the input code
|
|
//! (`builtin.target.os.tag.isDarwin()` / `builtin.os.tag == .macos` in Zig).
|
|
//!
|
|
//! In test builds the predicates can be overridden per thread with
|
|
//! [`with_darwin`] so the macOS-only branches (option-as-alt, super-instead-
|
|
//! of-ctrl, keycode table column) are exercised on every host.
|
|
|
|
/// `isDarwin()`: macOS and iOS.
|
|
const DARWIN: bool = cfg!(target_vendor = "apple");
|
|
|
|
/// `os.tag == .macos`.
|
|
const MACOS: bool = cfg!(target_os = "macos");
|
|
|
|
#[cfg(test)]
|
|
thread_local! {
|
|
static OVERRIDE: std::cell::Cell<Option<(bool, bool)>> =
|
|
const { std::cell::Cell::new(None) };
|
|
}
|
|
|
|
/// True when targeting Darwin (macOS or iOS).
|
|
#[inline]
|
|
pub fn is_darwin() -> bool {
|
|
#[cfg(test)]
|
|
if let Some((darwin, _)) = OVERRIDE.with(std::cell::Cell::get) {
|
|
return darwin;
|
|
}
|
|
DARWIN
|
|
}
|
|
|
|
/// True when targeting macOS proper.
|
|
#[inline]
|
|
pub fn is_macos() -> bool {
|
|
#[cfg(test)]
|
|
if let Some((_, macos)) = OVERRIDE.with(std::cell::Cell::get) {
|
|
return macos;
|
|
}
|
|
MACOS
|
|
}
|
|
|
|
/// Run `f` pretending to be macOS (`darwin == macos == true`) or not.
|
|
#[cfg(test)]
|
|
pub fn with_darwin<R>(on: bool, f: impl FnOnce() -> R) -> R {
|
|
struct Reset(Option<(bool, bool)>);
|
|
impl Drop for Reset {
|
|
fn drop(&mut self) {
|
|
OVERRIDE.with(|o| o.set(self.0));
|
|
}
|
|
}
|
|
let _reset = Reset(OVERRIDE.with(|o| o.replace(Some((on, on)))));
|
|
f()
|
|
}
|