mirror of
https://github.com/ghostty-org/ghostty.git
synced 2025-08-02 14:57:31 +03:00
build: can select renderer with -Drenderer
Note that not all renderers work in all environments.
This commit is contained in:
@ -6,6 +6,7 @@ const RunStep = std.build.RunStep;
|
|||||||
|
|
||||||
const apprt = @import("src/apprt.zig");
|
const apprt = @import("src/apprt.zig");
|
||||||
const font = @import("src/font/main.zig");
|
const font = @import("src/font/main.zig");
|
||||||
|
const renderer = @import("src/renderer.zig");
|
||||||
const terminfo = @import("src/terminfo/main.zig");
|
const terminfo = @import("src/terminfo/main.zig");
|
||||||
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");
|
||||||
@ -52,6 +53,7 @@ const app_version = std.SemanticVersion{ .major = 0, .minor = 1, .patch = 0 };
|
|||||||
var tracy: bool = false;
|
var tracy: bool = false;
|
||||||
var flatpak: bool = false;
|
var flatpak: bool = false;
|
||||||
var app_runtime: apprt.Runtime = .none;
|
var app_runtime: apprt.Runtime = .none;
|
||||||
|
var renderer_impl: renderer.Impl = .opengl;
|
||||||
var font_backend: font.Backend = .freetype;
|
var font_backend: font.Backend = .freetype;
|
||||||
|
|
||||||
pub fn build(b: *std.Build) !void {
|
pub fn build(b: *std.Build) !void {
|
||||||
@ -98,6 +100,12 @@ 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 apprt.Runtime.default(target);
|
) orelse apprt.Runtime.default(target);
|
||||||
|
|
||||||
|
renderer_impl = b.option(
|
||||||
|
renderer.Impl,
|
||||||
|
"renderer",
|
||||||
|
"The app runtime to use. Not all values supported on all platforms.",
|
||||||
|
) orelse renderer.Impl.default(target, wasm_target);
|
||||||
|
|
||||||
const static = b.option(
|
const static = b.option(
|
||||||
bool,
|
bool,
|
||||||
"static",
|
"static",
|
||||||
@ -203,6 +211,7 @@ pub fn build(b: *std.Build) !void {
|
|||||||
exe_options.addOption(bool, "flatpak", flatpak);
|
exe_options.addOption(bool, "flatpak", flatpak);
|
||||||
exe_options.addOption(apprt.Runtime, "app_runtime", app_runtime);
|
exe_options.addOption(apprt.Runtime, "app_runtime", app_runtime);
|
||||||
exe_options.addOption(font.Backend, "font_backend", font_backend);
|
exe_options.addOption(font.Backend, "font_backend", font_backend);
|
||||||
|
exe_options.addOption(renderer.Impl, "renderer", renderer_impl);
|
||||||
|
|
||||||
// Exe
|
// Exe
|
||||||
if (exe_) |exe| {
|
if (exe_) |exe| {
|
||||||
|
@ -8,6 +8,7 @@ const options = @import("build_options");
|
|||||||
const assert = std.debug.assert;
|
const assert = std.debug.assert;
|
||||||
const apprt = @import("apprt.zig");
|
const apprt = @import("apprt.zig");
|
||||||
const font = @import("font/main.zig");
|
const font = @import("font/main.zig");
|
||||||
|
const rendererpkg = @import("renderer.zig");
|
||||||
|
|
||||||
/// The semantic version of this build.
|
/// The semantic version of this build.
|
||||||
pub const version = options.app_version;
|
pub const version = options.app_version;
|
||||||
@ -29,6 +30,12 @@ pub const font_backend: font.Backend = std.meta.stringToEnum(
|
|||||||
@tagName(options.font_backend),
|
@tagName(options.font_backend),
|
||||||
).?;
|
).?;
|
||||||
|
|
||||||
|
/// The renderer implementation to use.
|
||||||
|
pub const renderer: rendererpkg.Impl = std.meta.stringToEnum(
|
||||||
|
rendererpkg.Impl,
|
||||||
|
@tagName(options.renderer),
|
||||||
|
).?;
|
||||||
|
|
||||||
/// We want to integrate with Flatpak APIs.
|
/// We want to integrate with Flatpak APIs.
|
||||||
pub const flatpak = options.flatpak;
|
pub const flatpak = options.flatpak;
|
||||||
|
|
||||||
|
@ -7,7 +7,10 @@
|
|||||||
//! APIs. The renderers in this package assume that the renderer is already
|
//! APIs. The renderers in this package assume that the renderer is already
|
||||||
//! setup (OpenGL has a context, Vulkan has a surface, etc.)
|
//! setup (OpenGL has a context, Vulkan has a surface, etc.)
|
||||||
|
|
||||||
|
const std = @import("std");
|
||||||
const builtin = @import("builtin");
|
const builtin = @import("builtin");
|
||||||
|
const build_config = @import("build_config.zig");
|
||||||
|
const WasmTarget = @import("os/wasm/target.zig").Target;
|
||||||
|
|
||||||
pub usingnamespace @import("renderer/cursor.zig");
|
pub usingnamespace @import("renderer/cursor.zig");
|
||||||
pub usingnamespace @import("renderer/message.zig");
|
pub usingnamespace @import("renderer/message.zig");
|
||||||
@ -19,14 +22,33 @@ pub const Options = @import("renderer/Options.zig");
|
|||||||
pub const Thread = @import("renderer/Thread.zig");
|
pub const Thread = @import("renderer/Thread.zig");
|
||||||
pub const State = @import("renderer/State.zig");
|
pub const State = @import("renderer/State.zig");
|
||||||
|
|
||||||
|
/// Possible implementations, used for build options.
|
||||||
|
pub const Impl = enum {
|
||||||
|
opengl,
|
||||||
|
metal,
|
||||||
|
webgl,
|
||||||
|
|
||||||
|
pub fn default(
|
||||||
|
target: std.zig.CrossTarget,
|
||||||
|
wasm_target: WasmTarget,
|
||||||
|
) Impl {
|
||||||
|
if (target.getCpuArch() == .wasm32) {
|
||||||
|
return switch (wasm_target) {
|
||||||
|
.browser => .webgl,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
if (target.isDarwin()) return .metal;
|
||||||
|
return .opengl;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
/// The implementation to use for the renderer. This is comptime chosen
|
/// The implementation to use for the renderer. This is comptime chosen
|
||||||
/// so that every build has exactly one renderer implementation.
|
/// so that every build has exactly one renderer implementation.
|
||||||
const wasm_target = @import("os/wasm/target.zig");
|
pub const Renderer = switch (build_config.renderer) {
|
||||||
pub const Renderer = if (wasm_target.target) |target| switch (target) {
|
.metal => Metal,
|
||||||
.browser => WebGL,
|
.opengl => OpenGL,
|
||||||
} else switch (builtin.os.tag) {
|
.webgl => WebGL,
|
||||||
.macos => Metal,
|
|
||||||
else => OpenGL,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
test {
|
test {
|
||||||
|
Reference in New Issue
Block a user