feat: port GTK version fallbacks, helpgen, bench modes, CLI leftovers

- apprt-gtk: Ghostty's runtime+build-time version gating (at_least)
  with cargo features adw_1_3/adw_1_4/adw_1_5/gtk_4_16 (default on) and
  the fallbacks for older libraries: MessageDialog (adw < 1.5),
  clipboard dialog without SwitchRow, pre-Banner debug warning and
  child-exited widgets, the old about dialog, GTK 4.16 CSS error source
  bytes. The minimum stays GTK 4.14 / libadwaita 1.5 (Ghostty's floor).
  The root build links with -z lazy so version-gated symbols don't keep
  older libraries from loading.
- ghostty-helpgen (port of helpgen.zig) generates CLI action help and
  keybinding action docs from doc comments at build time, replacing the
  checked-in help/*.txt; +help and +list-actions --docs stay
  byte-identical to Ghostty 1.3.1.
- ghostty-bench: libc wcwidth mode and separate simd/table and
  uucode/table code paths like Zig.
- ghostty-cli: Windows branches of edit-config, list-colors,
  list-keybinds and boo; ssh-cache DiskCache flock locking (no-op on
  Windows, as in Zig) with an exclusivity test.

Test Plan:
- cargo test --workspace
- diff <(cargo run -q -- +list-actions --docs) \
  <(ghostty +list-actions --docs)
This commit is contained in:
ddidderr committed 2026-10-12 06:38:33 +02:00
1 parent 020beb2d75
commit 4787565397
51 files changed
+2426 -1621

No files matched your search

+57 -3
View File
@@ -10,6 +10,10 @@ pub const COMPTIME_VERSION: Version =
/// Returns the runtime libadwaita version.
#[allow(unsafe_code)]
pub fn get_runtime_version() -> Version {
#[cfg(debug_assertions)]
if let Some(v) = crate::fake_version::get("GHOSTTY_DEBUG_FAKE_ADW_VERSION") {
return v;
}
// The safe `adw::major_version()` etc. assert that libadwaita was
// initialized, but the C functions don't need it (and `+version` has no
// display to initialize GTK with).
@@ -31,9 +35,36 @@ pub fn log_version() {
log::info!("libadwaita version build={a}.{b}.{c} runtime={x}.{y}.{z}");
}
/// Verifies that the libadwaita version at runtime is at least the given
/// version (callers needing newer API must also gate on a cargo feature).
/// The libadwaita API level this build uses, i.e. the highest `adw_1_*`
/// cargo feature (the equivalent of the version macros in `adwaita.h` that
/// Zig's `comptime_version` reads).
pub const BUILD_LEVEL: Version = if cfg!(feature = "adw_1_5") {
(1, 5, 0)
} else if cfg!(feature = "adw_1_4") {
(1, 4, 0)
} else if cfg!(feature = "adw_1_3") {
(1, 3, 0)
} else {
(1, 2, 0)
};
/// Compile-time half of [`at_least`]: whether this build was compiled with at
/// least the given libadwaita API level.
#[must_use]
pub const fn comptime_at_least(major: u32, minor: u32, micro: u32) -> bool {
let (a, b, c) = BUILD_LEVEL;
a > major || (a == major && (b > minor || (b == minor && c >= micro)))
}
/// Verifies that the running libadwaita version is at least the given
/// version, for both the build level and the library we are running against
/// (so generally you want both checks, like Zig's `atLeast`).
#[inline]
pub fn at_least(major: u32, minor: u32, micro: u32) -> bool {
// A lower build level means we must not call newer symbols at all.
if !comptime_at_least(major, minor, micro) {
return false;
}
runtime_at_least(major, minor, micro)
}
@@ -63,6 +94,14 @@ pub fn supports_banner() -> bool {
at_least(1, 3, 0)
}
/// Compile-time (build level only) variants of the `supports_*` checks. Zig
/// uses `supportsX()` at comptime to choose a class's parent type; Rust
/// picks types with the matching `cfg(feature = "adw_1_*")` and these const
/// functions document/assert the same decision.
pub const COMPTIME_SUPPORTS_DIALOGS: bool = comptime_at_least(1, 5, 0);
pub const COMPTIME_SUPPORTS_SWITCH_ROW: bool = comptime_at_least(1, 4, 0);
pub const COMPTIME_SUPPORTS_BANNER: bool = comptime_at_least(1, 3, 0);
#[cfg(test)]
mod tests {
use super::*;
@@ -75,7 +114,8 @@ mod tests {
return;
}
let (a, b, c) = get_runtime_version();
for f in [at_least, runtime_at_least] {
{
let f = runtime_at_least;
assert!(f(a, b, c));
assert!(!f(a, b, c + 1));
assert!(!f(a, b + 1, c));
@@ -86,4 +126,18 @@ mod tests {
assert!(f(a, b - 1, c + 1));
}
}
#[test]
fn version_at_least_build_level() {
let (a, b, c) = BUILD_LEVEL;
assert!(at_least(a, b, c) || get_runtime_version() < BUILD_LEVEL);
assert!(!at_least(a, b, c + 1));
assert!(!at_least(a, b + 1, c));
assert!(!at_least(a + 1, b, c));
assert!(comptime_at_least(a, b, c));
assert!(!comptime_at_least(a, b, c + 1));
assert_eq!(COMPTIME_SUPPORTS_DIALOGS, cfg!(feature = "adw_1_5"));
assert_eq!(COMPTIME_SUPPORTS_SWITCH_ROW, cfg!(feature = "adw_1_4"));
assert_eq!(COMPTIME_SUPPORTS_BANNER, cfg!(feature = "adw_1_3"));
}
}