c api: add ghostty_info to get metadata about the build

This commit is contained in:
Mitchell Hashimoto
2023-09-15 12:32:41 -07:00
parent 0ac1010d5a
commit de0f71c6a1
2 changed files with 42 additions and 0 deletions

View File

@@ -9,6 +9,7 @@
const std = @import("std");
const assert = std.debug.assert;
const builtin = @import("builtin");
const build_config = @import("build_config.zig");
const main = @import("main.zig");
const apprt = @import("apprt.zig");
@@ -23,6 +24,20 @@ pub const std_options = main.std_options;
pub usingnamespace @import("config.zig").CAPI;
pub usingnamespace apprt.runtime.CAPI;
/// ghostty_info_s
const Info = extern struct {
mode: BuildMode,
version: [*]const u8,
version_len: usize,
const BuildMode = enum(c_int) {
debug,
release_safe,
release_fast,
release_small,
};
};
/// Initialize ghostty global state. It is possible to have more than
/// one global state but it has zero practical benefit.
export fn ghostty_init() c_int {
@@ -30,3 +45,16 @@ export fn ghostty_init() c_int {
main.state.init();
return 0;
}
export fn ghostty_info() Info {
return .{
.mode = switch (builtin.mode) {
.Debug => .debug,
.ReleaseSafe => .release_safe,
.ReleaseFast => .release_fast,
.ReleaseSmall => .release_small,
},
.version = build_config.version_string.ptr,
.version_len = build_config.version_string.len,
};
}