feat(lib): port libghostty, Ghostty's embedded C API
Ports apprt/embedded.zig, main_c.zig and config/CApi.zig + c_get.zig as crates/ghostty-lib (cdylib/staticlib/rlib `libghostty`), exporting every function of the unchanged include/ghostty.h - the ABI Ghostty's Swift macOS/iOS app links against. The embedded runtime implements the runtime traits over the host's C callbacks, so the real core drives it. - ghostty-core selects the renderer per target: Metal on Apple (surface NSView/UIView via RtSurface::platform_view), OpenGL elsewhere. - ghostty_config_get follows Zig's c_get rules via a CValue type (143 supported keys, checked against the Zig field types). - The inspector C API is complete; its Metal backend replaces ImGui's Metal renderer and has not run. Verification: generated C ABI probe (sizeof/alignof/offsetof of every struct/union, 755 enum values, every function linked, nm exports, headers byte-identical to upstream); a C host on Linux covering init, CLI actions, config, app, keys, focus and color scheme; an opt-in test-platform feature creating real surfaces on Linux with headless EGL and a pty (13 tests). Apple targets are clippy-clean but not run; the Swift app has not been built against it. Test Plan: - cargo test -p ghostty-lib (and --features test-platform) - cargo clippy --target aarch64-apple-darwin -p ghostty-lib (cross env in docs/rewrite/notes/macos-M1.md)
This commit is contained in:
1 parent
4787565397
commit
49d4ecefae
47 files changed
+10296
-34
No files matched your search
@@ -37,6 +37,8 @@ pub struct FieldInfo<T> {
|
||||
pub eq: fn(&T, &T) -> bool,
|
||||
/// Format this field as in `+show-config`.
|
||||
pub format: fn(&T, &str, &mut dyn fmt::Write) -> fmt::Result,
|
||||
/// The value in the form the C API exposes it.
|
||||
pub c_value: fn(&T) -> crate::c_value::CValue,
|
||||
}
|
||||
|
||||
impl<T> FieldInfo<T> {
|
||||
@@ -147,6 +149,7 @@ macro_rules! config_struct {
|
||||
let mut f = $crate::formatter::EntryFormatter::new(name, w);
|
||||
$crate::cli_args::ConfigField::format_entry(&a.$field, &mut f)
|
||||
},
|
||||
c_value: |a: &$name| $crate::cli_args::ConfigField::c_value(&a.$field),
|
||||
},
|
||||
)*
|
||||
];
|
||||
@@ -221,6 +224,10 @@ macro_rules! config_enum {
|
||||
::core::result::Result::Ok(())
|
||||
}
|
||||
|
||||
fn c_value(&self) -> $crate::c_value::CValue {
|
||||
$crate::c_value::CValue::EnumName(self.as_str())
|
||||
}
|
||||
|
||||
fn format_entry(
|
||||
&self,
|
||||
f: &mut $crate::formatter::EntryFormatter<'_>,
|
||||
@@ -274,6 +281,20 @@ macro_rules! config_packed {
|
||||
const KIND: $crate::cli_args::FieldKind =
|
||||
$crate::cli_args::FieldKind::Packed(Self::NAMES);
|
||||
|
||||
fn c_value(&self) -> $crate::c_value::CValue {
|
||||
// Packed bools: the first field is bit 0.
|
||||
let mut bits = 0u32;
|
||||
let mut _i = 0u32;
|
||||
$(
|
||||
if self.$field && _i < 32 { bits |= 1 << _i; }
|
||||
_i += 1;
|
||||
)*
|
||||
if _i > 32 {
|
||||
return $crate::c_value::CValue::Unsupported;
|
||||
}
|
||||
$crate::c_value::CValue::Packed(bits)
|
||||
}
|
||||
|
||||
fn parse_cli(
|
||||
&mut self,
|
||||
value: ::core::option::Option<&str>,
|
||||
|
||||
Reference in new issue
Block a user