mirror of
https://github.com/ghostty-org/ghostty.git
synced 2026-07-18 23:21:22 +00:00
vt: expose optimize mode in build info API
Add GHOSTTY_BUILD_INFO_OPTIMIZE to query the Zig optimization mode (debug, release safe/small/fast) the library was compiled with. This reads directly from builtin.mode at comptime so it requires no build system plumbing.
This commit is contained in:
@@ -31,6 +31,16 @@
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/**
|
||||
* Build optimization mode.
|
||||
*/
|
||||
typedef enum {
|
||||
GHOSTTY_OPTIMIZE_DEBUG = 0,
|
||||
GHOSTTY_OPTIMIZE_RELEASE_SAFE = 1,
|
||||
GHOSTTY_OPTIMIZE_RELEASE_SMALL = 2,
|
||||
GHOSTTY_OPTIMIZE_RELEASE_FAST = 3,
|
||||
} GhosttyOptimizeMode;
|
||||
|
||||
/**
|
||||
* Build info data types that can be queried.
|
||||
*
|
||||
@@ -60,6 +70,13 @@ typedef enum {
|
||||
* Output type: bool *
|
||||
*/
|
||||
GHOSTTY_BUILD_INFO_TMUX_CONTROL_MODE = 3,
|
||||
|
||||
/**
|
||||
* The optimization mode the library was built with.
|
||||
*
|
||||
* Output type: GhosttyOptimizeMode *
|
||||
*/
|
||||
GHOSTTY_BUILD_INFO_OPTIMIZE = 4,
|
||||
} GhosttyBuildInfo;
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,21 +1,32 @@
|
||||
const std = @import("std");
|
||||
const builtin = @import("builtin");
|
||||
const build_options = @import("terminal_options");
|
||||
const Result = @import("result.zig").Result;
|
||||
|
||||
const log = std.log.scoped(.build_info_c);
|
||||
|
||||
/// C: GhosttyOptimizeMode
|
||||
pub const OptimizeMode = enum(c_int) {
|
||||
debug = 0,
|
||||
release_safe = 1,
|
||||
release_small = 2,
|
||||
release_fast = 3,
|
||||
};
|
||||
|
||||
/// C: GhosttyBuildInfo
|
||||
pub const BuildInfo = enum(c_int) {
|
||||
invalid = 0,
|
||||
simd = 1,
|
||||
kitty_graphics = 2,
|
||||
tmux_control_mode = 3,
|
||||
optimize = 4,
|
||||
|
||||
/// Output type expected for querying the data of the given kind.
|
||||
pub fn OutType(comptime self: BuildInfo) type {
|
||||
return switch (self) {
|
||||
.invalid => void,
|
||||
.simd, .kitty_graphics, .tmux_control_mode => bool,
|
||||
.optimize => OptimizeMode,
|
||||
};
|
||||
}
|
||||
};
|
||||
@@ -48,6 +59,12 @@ fn getTyped(
|
||||
.simd => out.* = build_options.simd,
|
||||
.kitty_graphics => out.* = build_options.kitty_graphics,
|
||||
.tmux_control_mode => out.* = build_options.tmux_control_mode,
|
||||
.optimize => out.* = switch (builtin.mode) {
|
||||
.Debug => .debug,
|
||||
.ReleaseSafe => .release_safe,
|
||||
.ReleaseSmall => .release_small,
|
||||
.ReleaseFast => .release_fast,
|
||||
},
|
||||
}
|
||||
|
||||
return .success;
|
||||
@@ -74,6 +91,18 @@ test "get tmux_control_mode" {
|
||||
try testing.expectEqual(build_options.tmux_control_mode, value);
|
||||
}
|
||||
|
||||
test "get optimize" {
|
||||
const testing = std.testing;
|
||||
var value: OptimizeMode = undefined;
|
||||
try testing.expectEqual(Result.success, get(.optimize, @ptrCast(&value)));
|
||||
try testing.expectEqual(switch (builtin.mode) {
|
||||
.Debug => .debug,
|
||||
.ReleaseSafe => .release_safe,
|
||||
.ReleaseSmall => .release_small,
|
||||
.ReleaseFast => .release_fast,
|
||||
}, value);
|
||||
}
|
||||
|
||||
test "get invalid" {
|
||||
try std.testing.expectEqual(Result.invalid_value, get(.invalid, null));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user