libghostty_vt/build_info.rs
1//! Query compile-time build configuration of libghostty-vt.
2//!
3//! These values reflect the options the library was built with and are constant for the lifetime of the process.
4//!
5//! # Example
6//! ```rust
7//! use libghostty_vt::{Error, build_info::*};
8//!
9//! fn print_build_info() -> Result<(), Error> {
10//! println!(
11//! "SIMD: {}",
12//! if supports_simd().unwrap_or(false) { "enabled" } else { "disabled" }
13//! );
14//! println!(
15//! "Kitty graphics: {}",
16//! if supports_kitty_graphics().unwrap_or(false) { "enabled" } else { "disabled" }
17//! );
18//! println!(
19//! "Tmux control mode: {}",
20//! if supports_tmux_control_mode().unwrap_or(false) { "enabled" } else { "disabled" }
21//! );
22//! Ok(())
23//! }
24//! ```
25
26use std::mem::MaybeUninit;
27
28use crate::{
29 error::{Error, Result, from_result},
30 ffi,
31};
32
33/// Whether SIMD-accelerated code paths are enabled.
34pub fn supports_simd() -> Result<bool> {
35 build_info(ffi::GhosttyBuildInfo_GHOSTTY_BUILD_INFO_SIMD)
36}
37
38/// Whether Kitty graphics protocol support is available.
39pub fn supports_kitty_graphics() -> Result<bool> {
40 build_info(ffi::GhosttyBuildInfo_GHOSTTY_BUILD_INFO_KITTY_GRAPHICS)
41}
42
43/// Whether tmux control mode support is available.
44pub fn supports_tmux_control_mode() -> Result<bool> {
45 build_info(ffi::GhosttyBuildInfo_GHOSTTY_BUILD_INFO_TMUX_CONTROL_MODE)
46}
47
48/// The optimization mode the library was built with.
49pub fn optimize_mode() -> Result<OptimizeMode> {
50 build_info::<ffi::GhosttyOptimizeMode>(ffi::GhosttyBuildInfo_GHOSTTY_BUILD_INFO_OPTIMIZE)
51 .and_then(|v| v.try_into().map_err(|_| Error::InvalidValue))
52}
53
54fn build_info<T>(tag: ffi::GhosttyBuildInfo) -> Result<T> {
55 let mut value = MaybeUninit::zeroed();
56 let result = unsafe { ffi::ghostty_build_info(tag, std::ptr::from_mut(&mut value).cast()) };
57 from_result(result)?;
58 // SAFETY: Value should be initialized after successful call.
59 Ok(unsafe { value.assume_init() })
60}
61
62/// The optimization mode libghostty is compiled with.
63#[repr(u32)]
64#[derive(Copy, Clone, Debug, PartialEq, Eq, int_enum::IntEnum)]
65pub enum OptimizeMode {
66 /// Debug mode.
67 ///
68 /// Very slow with all safety checks enabled.
69 Debug = ffi::GhosttyOptimizeMode_GHOSTTY_OPTIMIZE_DEBUG,
70 /// Release mode optimized for safety.
71 ///
72 /// Faster than debug due to better code generation,
73 /// but still very slow due to active safety checks.
74 ReleaseSafe = ffi::GhosttyOptimizeMode_GHOSTTY_OPTIMIZE_RELEASE_SAFE,
75 /// Release mode optimized for size.
76 ReleaseSmall = ffi::GhosttyOptimizeMode_GHOSTTY_OPTIMIZE_RELEASE_SMALL,
77 /// Release mode optimized for speed.
78 ReleaseFast = ffi::GhosttyOptimizeMode_GHOSTTY_OPTIMIZE_RELEASE_FAST,
79}