mirror of
https://github.com/ghostty-org/ghostty.git
synced 2025-08-02 14:57:31 +03:00
build: use BuildConfig struct
This commit is contained in:
39
build.zig
39
build.zig
@ -9,6 +9,7 @@ const font = @import("src/font/main.zig");
|
|||||||
const renderer = @import("src/renderer.zig");
|
const renderer = @import("src/renderer.zig");
|
||||||
const terminfo = @import("src/terminfo/main.zig");
|
const terminfo = @import("src/terminfo/main.zig");
|
||||||
const config_vim = @import("src/config/vim.zig");
|
const config_vim = @import("src/config/vim.zig");
|
||||||
|
const BuildConfig = @import("src/build_config.zig").BuildConfig;
|
||||||
const WasmTarget = @import("src/os/wasm/target.zig").Target;
|
const WasmTarget = @import("src/os/wasm/target.zig").Target;
|
||||||
const LibtoolStep = @import("src/build/LibtoolStep.zig");
|
const LibtoolStep = @import("src/build/LibtoolStep.zig");
|
||||||
const LipoStep = @import("src/build/LipoStep.zig");
|
const LipoStep = @import("src/build/LipoStep.zig");
|
||||||
@ -36,10 +37,8 @@ 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 flatpak: bool = false;
|
||||||
var app_runtime: apprt.Runtime = .none;
|
|
||||||
var renderer_impl: renderer.Impl = .opengl;
|
|
||||||
var font_backend: font.Backend = .freetype;
|
|
||||||
var libadwaita: bool = false;
|
var libadwaita: bool = false;
|
||||||
|
var config: BuildConfig = .{};
|
||||||
|
|
||||||
pub fn build(b: *std.Build) !void {
|
pub fn build(b: *std.Build) !void {
|
||||||
const optimize = b.standardOptimizeOption(.{});
|
const optimize = b.standardOptimizeOption(.{});
|
||||||
@ -67,30 +66,30 @@ pub fn build(b: *std.Build) !void {
|
|||||||
"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.",
|
||||||
) orelse false;
|
) orelse false;
|
||||||
|
|
||||||
font_backend = b.option(
|
config.font_backend = b.option(
|
||||||
font.Backend,
|
font.Backend,
|
||||||
"font-backend",
|
"font-backend",
|
||||||
"The font backend to use for discovery and rasterization.",
|
"The font backend to use for discovery and rasterization.",
|
||||||
) orelse font.Backend.default(target.result, wasm_target);
|
) orelse font.Backend.default(target.result, wasm_target);
|
||||||
|
|
||||||
app_runtime = b.option(
|
config.app_runtime = b.option(
|
||||||
apprt.Runtime,
|
apprt.Runtime,
|
||||||
"app-runtime",
|
"app-runtime",
|
||||||
"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 apprt.Runtime.default(target.result);
|
) orelse apprt.Runtime.default(target.result);
|
||||||
|
|
||||||
|
config.renderer = b.option(
|
||||||
|
renderer.Impl,
|
||||||
|
"renderer",
|
||||||
|
"The app runtime to use. Not all values supported on all platforms.",
|
||||||
|
) orelse renderer.Impl.default(target.result, wasm_target);
|
||||||
|
|
||||||
libadwaita = b.option(
|
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.",
|
||||||
) orelse true;
|
) orelse true;
|
||||||
|
|
||||||
renderer_impl = b.option(
|
|
||||||
renderer.Impl,
|
|
||||||
"renderer",
|
|
||||||
"The app runtime to use. Not all values supported on all platforms.",
|
|
||||||
) orelse renderer.Impl.default(target.result, wasm_target);
|
|
||||||
|
|
||||||
const static = b.option(
|
const static = b.option(
|
||||||
bool,
|
bool,
|
||||||
"static",
|
"static",
|
||||||
@ -182,7 +181,7 @@ pub fn build(b: *std.Build) !void {
|
|||||||
try benchSteps(b, target, optimize, emit_bench);
|
try benchSteps(b, target, optimize, emit_bench);
|
||||||
|
|
||||||
// We only build an exe if we have a runtime set.
|
// We only build an exe if we have a runtime set.
|
||||||
const exe_: ?*std.Build.Step.Compile = if (app_runtime != .none) b.addExecutable(.{
|
const exe_: ?*std.Build.Step.Compile = if (config.app_runtime != .none) b.addExecutable(.{
|
||||||
.name = "ghostty",
|
.name = "ghostty",
|
||||||
.root_source_file = .{ .path = "src/main.zig" },
|
.root_source_file = .{ .path = "src/main.zig" },
|
||||||
.target = target,
|
.target = target,
|
||||||
@ -190,6 +189,7 @@ pub fn build(b: *std.Build) !void {
|
|||||||
}) else null;
|
}) else null;
|
||||||
|
|
||||||
const exe_options = b.addOptions();
|
const exe_options = b.addOptions();
|
||||||
|
config.addOptions(exe_options);
|
||||||
exe_options.addOption(std.SemanticVersion, "app_version", version);
|
exe_options.addOption(std.SemanticVersion, "app_version", version);
|
||||||
exe_options.addOption([:0]const u8, "app_version_string", try std.fmt.allocPrintZ(
|
exe_options.addOption([:0]const u8, "app_version_string", try std.fmt.allocPrintZ(
|
||||||
b.allocator,
|
b.allocator,
|
||||||
@ -197,9 +197,6 @@ pub fn build(b: *std.Build) !void {
|
|||||||
.{version},
|
.{version},
|
||||||
));
|
));
|
||||||
exe_options.addOption(bool, "flatpak", flatpak);
|
exe_options.addOption(bool, "flatpak", flatpak);
|
||||||
exe_options.addOption(apprt.Runtime, "app_runtime", app_runtime);
|
|
||||||
exe_options.addOption(font.Backend, "font_backend", font_backend);
|
|
||||||
exe_options.addOption(renderer.Impl, "renderer", renderer_impl);
|
|
||||||
exe_options.addOption(bool, "libadwaita", libadwaita);
|
exe_options.addOption(bool, "libadwaita", libadwaita);
|
||||||
|
|
||||||
// Exe
|
// Exe
|
||||||
@ -246,7 +243,7 @@ pub fn build(b: *std.Build) !void {
|
|||||||
|
|
||||||
// If we're installing, we get the install step so we can add
|
// If we're installing, we get the install step so we can add
|
||||||
// additional dependencies to it.
|
// additional dependencies to it.
|
||||||
const install_step = if (app_runtime != .none) step: {
|
const install_step = if (config.app_runtime != .none) step: {
|
||||||
const step = b.addInstallArtifact(exe, .{});
|
const step = b.addInstallArtifact(exe, .{});
|
||||||
b.getInstallStep().dependOn(&step.step);
|
b.getInstallStep().dependOn(&step.step);
|
||||||
break :step step;
|
break :step step;
|
||||||
@ -742,7 +739,7 @@ fn addDeps(
|
|||||||
.cpu = cpu_opts,
|
.cpu = cpu_opts,
|
||||||
.optimize = step.root_module.optimize.?,
|
.optimize = step.root_module.optimize.?,
|
||||||
.@"enable-freetype" = true,
|
.@"enable-freetype" = true,
|
||||||
.@"enable-coretext" = font_backend.hasCoretext(),
|
.@"enable-coretext" = config.font_backend.hasCoretext(),
|
||||||
});
|
});
|
||||||
const ziglyph_dep = b.dependency("ziglyph", .{
|
const ziglyph_dep = b.dependency("ziglyph", .{
|
||||||
.target = target_triple,
|
.target = target_triple,
|
||||||
@ -782,7 +779,7 @@ fn addDeps(
|
|||||||
// We always need the Zig packages
|
// We always need the Zig packages
|
||||||
// TODO: This can't be the right way to use the new Zig modules system,
|
// TODO: This can't be the right way to use the new Zig modules system,
|
||||||
// so take a closer look at this again later.
|
// so take a closer look at this again later.
|
||||||
if (font_backend.hasFontconfig()) step.root_module.addImport(
|
if (config.font_backend.hasFontconfig()) step.root_module.addImport(
|
||||||
"fontconfig",
|
"fontconfig",
|
||||||
fontconfig_dep.module("fontconfig"),
|
fontconfig_dep.module("fontconfig"),
|
||||||
);
|
);
|
||||||
@ -828,7 +825,7 @@ fn addDeps(
|
|||||||
step.linkSystemLibrary2("pixman-1", dynamic_link_opts);
|
step.linkSystemLibrary2("pixman-1", dynamic_link_opts);
|
||||||
step.linkSystemLibrary2("zlib", dynamic_link_opts);
|
step.linkSystemLibrary2("zlib", dynamic_link_opts);
|
||||||
|
|
||||||
if (font_backend.hasFontconfig()) {
|
if (config.font_backend.hasFontconfig()) {
|
||||||
step.linkSystemLibrary2("fontconfig", dynamic_link_opts);
|
step.linkSystemLibrary2("fontconfig", dynamic_link_opts);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -857,7 +854,7 @@ fn addDeps(
|
|||||||
try static_libs.append(pixman_dep.artifact("pixman").getEmittedBin());
|
try static_libs.append(pixman_dep.artifact("pixman").getEmittedBin());
|
||||||
|
|
||||||
// Only Linux gets fontconfig
|
// Only Linux gets fontconfig
|
||||||
if (font_backend.hasFontconfig()) {
|
if (config.font_backend.hasFontconfig()) {
|
||||||
// Fontconfig
|
// Fontconfig
|
||||||
step.linkLibrary(fontconfig_dep.artifact("fontconfig"));
|
step.linkLibrary(fontconfig_dep.artifact("fontconfig"));
|
||||||
}
|
}
|
||||||
@ -875,7 +872,7 @@ fn addDeps(
|
|||||||
// get access to glib for dbus.
|
// get access to glib for dbus.
|
||||||
if (flatpak) step.linkSystemLibrary2("gtk4", dynamic_link_opts);
|
if (flatpak) step.linkSystemLibrary2("gtk4", dynamic_link_opts);
|
||||||
|
|
||||||
switch (app_runtime) {
|
switch (config.app_runtime) {
|
||||||
.none => {},
|
.none => {},
|
||||||
|
|
||||||
.glfw => {
|
.glfw => {
|
||||||
|
@ -28,7 +28,7 @@ pub const BuildConfig = struct {
|
|||||||
// support all types.
|
// support all types.
|
||||||
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_impl);
|
step.addOption(rendererpkg.Impl, "renderer", self.renderer);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Rehydrate our BuildConfig from the comptime options.
|
/// Rehydrate our BuildConfig from the comptime options.
|
||||||
|
Reference in New Issue
Block a user