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:
1 parent
cd86fe92a8
commit
f2252bb165
51 files changed
+2426
-1621
No files matched your search
@@ -31,8 +31,22 @@ pub(crate) const fn parse_version(s: &str) -> (u32, u32, u32) {
|
||||
(parts[0], parts[1], parts[2])
|
||||
}
|
||||
|
||||
/// The GTK API level this build uses, i.e. the highest `gtk_4_*` cargo
|
||||
/// feature (the equivalent of the version macros in the C headers that Zig's
|
||||
/// `comptime_version` reads). Code calling newer symbols must be gated with
|
||||
/// the matching `cfg(feature = ...)` as well as [`at_least`].
|
||||
pub const BUILD_LEVEL: Version = if cfg!(feature = "gtk_4_16") {
|
||||
(4, 16, 0)
|
||||
} else {
|
||||
(4, 14, 0)
|
||||
};
|
||||
|
||||
/// Returns the runtime GTK version.
|
||||
pub fn get_runtime_version() -> Version {
|
||||
#[cfg(debug_assertions)]
|
||||
if let Some(v) = crate::fake_version::get("GHOSTTY_DEBUG_FAKE_GTK_VERSION") {
|
||||
return v;
|
||||
}
|
||||
(
|
||||
gtk::major_version(),
|
||||
gtk::minor_version(),
|
||||
@@ -47,12 +61,28 @@ pub fn log_version() {
|
||||
log::info!("GTK version build={a}.{b}.{c} runtime={x}.{y}.{z}");
|
||||
}
|
||||
|
||||
/// Verifies that the GTK version at runtime is at least the given version.
|
||||
/// Unlike Zig this can't compile out unknown symbols; callers needing newer
|
||||
/// API must gate it on a cargo feature too.
|
||||
/// Compile-time half of [`at_least`]: whether this build was compiled with
|
||||
/// at least the given GTK API level. `const` so that, like Zig's `comptime`
|
||||
/// check, it folds away the runtime check when it fails.
|
||||
#[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 GTK version is at least the given version.
|
||||
///
|
||||
/// Both the build level ([`comptime_at_least`]) and the library we are
|
||||
/// running against must satisfy it. Use this where the check affects which
|
||||
/// symbols are called; for checks that only depend on GTK's runtime behavior
|
||||
/// use [`runtime_at_least`].
|
||||
#[inline]
|
||||
pub fn at_least(major: u32, minor: u32, micro: u32) -> bool {
|
||||
// Anything below the build level is trivially satisfied by the runtime
|
||||
// requirement of the build level, but we still check the runtime.
|
||||
// If our build level is lower than the given version we return false
|
||||
// immediately; this prevents us from calling unknown symbols.
|
||||
if !comptime_at_least(major, minor, micro) {
|
||||
return false;
|
||||
}
|
||||
runtime_at_least(major, minor, micro)
|
||||
}
|
||||
|
||||
@@ -73,7 +103,8 @@ mod tests {
|
||||
#[test]
|
||||
fn at_least_test() {
|
||||
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));
|
||||
@@ -85,6 +116,22 @@ mod tests {
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn at_least_build_level_test() {
|
||||
// Zig's `atLeast` test, against the build level (our "headers").
|
||||
let (a, b, c) = BUILD_LEVEL;
|
||||
assert!(at_least(a, b, c));
|
||||
assert!(!at_least(a, b, c + 1));
|
||||
assert!(!at_least(a, b + 1, c));
|
||||
assert!(!at_least(a + 1, b, c));
|
||||
assert!(at_least(a - 1, b, c));
|
||||
assert!(at_least(a - 1, b + 1, c));
|
||||
assert!(at_least(a - 1, b, c + 1));
|
||||
assert!(at_least(a, b - 1, c + 1));
|
||||
assert!(comptime_at_least(a, b, c));
|
||||
assert!(!comptime_at_least(a, b, c + 1));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn runtime_until_test() {
|
||||
let (a, b, c) = get_runtime_version();
|
||||
|
||||
Reference in new issue
Block a user