build: move more options to BuildConfig

This commit is contained in:
Mitchell Hashimoto
2024-01-13 15:11:28 -08:00
parent dfa55988d6
commit d4b53cac06
2 changed files with 11 additions and 9 deletions

View File

@ -36,8 +36,6 @@ comptime {
const app_version = std.SemanticVersion{ .major = 0, .minor = 1, .patch = 0 }; const app_version = std.SemanticVersion{ .major = 0, .minor = 1, .patch = 0 };
/// Build options, see the build options help for more info. /// Build options, see the build options help for more info.
var flatpak: bool = false;
var libadwaita: bool = false;
var config: BuildConfig = .{}; var config: BuildConfig = .{};
pub fn build(b: *std.Build) !void { pub fn build(b: *std.Build) !void {
@ -60,7 +58,7 @@ pub fn build(b: *std.Build) !void {
var env = try std.process.getEnvMap(b.allocator); var env = try std.process.getEnvMap(b.allocator);
defer env.deinit(); defer env.deinit();
flatpak = b.option( config.flatpak = b.option(
bool, bool,
"flatpak", "flatpak",
"Build for Flatpak (integrates with Flatpak APIs). Only has an effect targeting Linux.", "Build for Flatpak (integrates with Flatpak APIs). Only has an effect targeting Linux.",
@ -84,7 +82,7 @@ pub fn build(b: *std.Build) !void {
"The app runtime to use. Not all values supported on all platforms.", "The app runtime to use. Not all values supported on all platforms.",
) orelse renderer.Impl.default(target.result, wasm_target); ) orelse renderer.Impl.default(target.result, wasm_target);
libadwaita = b.option( config.libadwaita = b.option(
bool, bool,
"gtk-libadwaita", "gtk-libadwaita",
"Enables the use of libadwaita when using the gtk rendering backend.", "Enables the use of libadwaita when using the gtk rendering backend.",
@ -196,8 +194,6 @@ pub fn build(b: *std.Build) !void {
"{}", "{}",
.{version}, .{version},
)); ));
exe_options.addOption(bool, "flatpak", flatpak);
exe_options.addOption(bool, "libadwaita", libadwaita);
// Exe // Exe
if (exe_) |exe| { if (exe_) |exe| {
@ -411,7 +407,7 @@ pub fn build(b: *std.Build) !void {
// https://developer.gnome.org/documentation/guidelines/maintainer/integrating.html // https://developer.gnome.org/documentation/guidelines/maintainer/integrating.html
// Desktop file so that we have an icon and other metadata // Desktop file so that we have an icon and other metadata
if (flatpak) { if (config.flatpak) {
b.installFile("dist/linux/app-flatpak.desktop", "share/applications/com.mitchellh.ghostty.desktop"); b.installFile("dist/linux/app-flatpak.desktop", "share/applications/com.mitchellh.ghostty.desktop");
} else { } else {
b.installFile("dist/linux/app.desktop", "share/applications/com.mitchellh.ghostty.desktop"); b.installFile("dist/linux/app.desktop", "share/applications/com.mitchellh.ghostty.desktop");
@ -870,7 +866,7 @@ fn addDeps(
// When we're targeting flatpak we ALWAYS link GTK so we // When we're targeting flatpak we ALWAYS link GTK so we
// get access to glib for dbus. // get access to glib for dbus.
if (flatpak) step.linkSystemLibrary2("gtk4", dynamic_link_opts); if (config.flatpak) step.linkSystemLibrary2("gtk4", dynamic_link_opts);
switch (config.app_runtime) { switch (config.app_runtime) {
.none => {}, .none => {},
@ -882,7 +878,7 @@ fn addDeps(
.gtk => { .gtk => {
step.linkSystemLibrary2("gtk4", dynamic_link_opts); step.linkSystemLibrary2("gtk4", dynamic_link_opts);
if (libadwaita) step.linkSystemLibrary2("adwaita-1", dynamic_link_opts); if (config.libadwaita) step.linkSystemLibrary2("adwaita-1", dynamic_link_opts);
}, },
} }
} }

View File

@ -18,6 +18,8 @@ const rendererpkg = @import("renderer.zig");
/// between options, make it easy to copy and mutate options for different /// between options, make it easy to copy and mutate options for different
/// build types, etc. /// build types, etc.
pub const BuildConfig = struct { pub const BuildConfig = struct {
flatpak: bool = false,
libadwaita: bool = false,
app_runtime: apprt.Runtime = .none, app_runtime: apprt.Runtime = .none,
renderer: rendererpkg.Impl = .opengl, renderer: rendererpkg.Impl = .opengl,
font_backend: font.Backend = .freetype, font_backend: font.Backend = .freetype,
@ -26,6 +28,8 @@ pub const BuildConfig = struct {
pub fn addOptions(self: BuildConfig, step: *std.Build.Step.Options) void { pub fn addOptions(self: BuildConfig, step: *std.Build.Step.Options) void {
// We need to break these down individual because addOption doesn't // We need to break these down individual because addOption doesn't
// support all types. // support all types.
step.addOption(bool, "flatpak", self.flatpak);
step.addOption(bool, "libadwaita", self.libadwaita);
step.addOption(apprt.Runtime, "app_runtime", self.app_runtime); step.addOption(apprt.Runtime, "app_runtime", self.app_runtime);
step.addOption(font.Backend, "font_backend", self.font_backend); step.addOption(font.Backend, "font_backend", self.font_backend);
step.addOption(rendererpkg.Impl, "renderer", self.renderer); step.addOption(rendererpkg.Impl, "renderer", self.renderer);
@ -34,6 +38,8 @@ pub const BuildConfig = struct {
/// Rehydrate our BuildConfig from the comptime options. /// Rehydrate our BuildConfig from the comptime options.
pub fn fromOptions() BuildConfig { pub fn fromOptions() BuildConfig {
return .{ return .{
.flatpak = options.flatpak,
.libadwaita = options.libadwaita,
.app_runtime = std.meta.stringToEnum(apprt.Runtime, @tagName(options.app_runtime)).?, .app_runtime = std.meta.stringToEnum(apprt.Runtime, @tagName(options.app_runtime)).?,
.font_backend = std.meta.stringToEnum(font.Backend, @tagName(options.font_backend)).?, .font_backend = std.meta.stringToEnum(font.Backend, @tagName(options.font_backend)).?,
.renderer = std.meta.stringToEnum(rendererpkg.Impl, @tagName(options.renderer)).?, .renderer = std.meta.stringToEnum(rendererpkg.Impl, @tagName(options.renderer)).?,