mirror of
https://github.com/ghostty-org/ghostty.git
synced 2025-07-21 11:16:08 +03:00
move wasm target struct around to avoid analyzing wasm file on non-wasm
This commit is contained in:
@ -56,8 +56,8 @@ pub const Backend = enum {
|
||||
/// Returns the default backend for a build environment. This is
|
||||
/// meant to be called at comptime.
|
||||
pub fn default() Backend {
|
||||
const wasm = @import("../os/wasm.zig");
|
||||
if (wasm.target) |target| return switch (target) {
|
||||
const wasm_target = @import("../os/wasm/target.zig");
|
||||
if (wasm_target.target) |target| return switch (target) {
|
||||
.browser => .web_canvas,
|
||||
};
|
||||
|
||||
|
@ -14,16 +14,6 @@ comptime {
|
||||
/// in JS will be backed by a SharedArrayBuffer and some behaviors change.
|
||||
pub const shared_mem = options.wasm_shared;
|
||||
|
||||
/// Our specific target platform.
|
||||
pub const target: ?Target = if (!builtin.target.isWasm()) null else target: {
|
||||
const result = @intToEnum(Target, @enumToInt(options.wasm_target));
|
||||
// This maybe isn't necessary but I don't know if enums without a specific
|
||||
// tag type and value are guaranteed to be the same between build.zig
|
||||
// compilation and our own source compilation so I have this just in case.
|
||||
std.debug.assert(std.mem.eql(u8, @tagName(result), @tagName(options.wasm_target)));
|
||||
break :target result;
|
||||
};
|
||||
|
||||
/// The allocator to use in wasm environments.
|
||||
///
|
||||
/// The return values of this should NOT be sent to the host environment
|
||||
|
@ -1,9 +1,10 @@
|
||||
const std = @import("std");
|
||||
const builtin = @import("builtin");
|
||||
const wasm = @import("../wasm.zig");
|
||||
const wasm_target = @import("target.zig");
|
||||
|
||||
// Use the correct implementation
|
||||
pub usingnamespace if (wasm.target) |target| switch (target) {
|
||||
pub usingnamespace if (wasm_target.target) |target| switch (target) {
|
||||
.browser => Browser,
|
||||
} else struct {};
|
||||
|
||||
|
@ -1,6 +1,20 @@
|
||||
const std = @import("std");
|
||||
const builtin = @import("builtin");
|
||||
const options = @import("build_options");
|
||||
|
||||
/// The wasm target platform. This is used to toggle certain features
|
||||
/// on and off since the standard triple target is often not specific
|
||||
/// enough (i.e. we can't tell wasm32-freestanding is for browser or not).
|
||||
pub const Target = enum {
|
||||
browser,
|
||||
};
|
||||
|
||||
/// Our specific target platform.
|
||||
pub const target: ?Target = if (!builtin.target.isWasm()) null else target: {
|
||||
const result = @intToEnum(Target, @enumToInt(options.wasm_target));
|
||||
// This maybe isn't necessary but I don't know if enums without a specific
|
||||
// tag type and value are guaranteed to be the same between build.zig
|
||||
// compilation and our own source compilation so I have this just in case.
|
||||
std.debug.assert(std.mem.eql(u8, @tagName(result), @tagName(options.wasm_target)));
|
||||
break :target result;
|
||||
};
|
||||
|
@ -21,8 +21,8 @@ pub const State = @import("renderer/State.zig");
|
||||
|
||||
/// The implementation to use for the renderer. This is comptime chosen
|
||||
/// so that every build has exactly one renderer implementation.
|
||||
const wasm = @import("os/wasm.zig");
|
||||
pub const Renderer = if (wasm.target) |target| switch (target) {
|
||||
const wasm_target = @import("os/wasm/target.zig");
|
||||
pub const Renderer = if (wasm_target.target) |target| switch (target) {
|
||||
.browser => WebGL,
|
||||
} else switch (builtin.os.tag) {
|
||||
.macos => Metal,
|
||||
|
Reference in New Issue
Block a user