mirror of
https://github.com/ghostty-org/ghostty.git
synced 2025-07-21 19:26:09 +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
|
/// Returns the default backend for a build environment. This is
|
||||||
/// meant to be called at comptime.
|
/// meant to be called at comptime.
|
||||||
pub fn default() Backend {
|
pub fn default() Backend {
|
||||||
const wasm = @import("../os/wasm.zig");
|
const wasm_target = @import("../os/wasm/target.zig");
|
||||||
if (wasm.target) |target| return switch (target) {
|
if (wasm_target.target) |target| return switch (target) {
|
||||||
.browser => .web_canvas,
|
.browser => .web_canvas,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -14,16 +14,6 @@ comptime {
|
|||||||
/// in JS will be backed by a SharedArrayBuffer and some behaviors change.
|
/// in JS will be backed by a SharedArrayBuffer and some behaviors change.
|
||||||
pub const shared_mem = options.wasm_shared;
|
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 allocator to use in wasm environments.
|
||||||
///
|
///
|
||||||
/// The return values of this should NOT be sent to the host environment
|
/// The return values of this should NOT be sent to the host environment
|
||||||
|
@ -1,9 +1,10 @@
|
|||||||
const std = @import("std");
|
const std = @import("std");
|
||||||
const builtin = @import("builtin");
|
const builtin = @import("builtin");
|
||||||
const wasm = @import("../wasm.zig");
|
const wasm = @import("../wasm.zig");
|
||||||
|
const wasm_target = @import("target.zig");
|
||||||
|
|
||||||
// Use the correct implementation
|
// Use the correct implementation
|
||||||
pub usingnamespace if (wasm.target) |target| switch (target) {
|
pub usingnamespace if (wasm_target.target) |target| switch (target) {
|
||||||
.browser => Browser,
|
.browser => Browser,
|
||||||
} else struct {};
|
} 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
|
/// The wasm target platform. This is used to toggle certain features
|
||||||
/// on and off since the standard triple target is often not specific
|
/// 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).
|
/// enough (i.e. we can't tell wasm32-freestanding is for browser or not).
|
||||||
pub const Target = enum {
|
pub const Target = enum {
|
||||||
browser,
|
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
|
/// 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 = @import("os/wasm.zig");
|
const wasm_target = @import("os/wasm/target.zig");
|
||||||
pub const Renderer = if (wasm.target) |target| switch (target) {
|
pub const Renderer = if (wasm_target.target) |target| switch (target) {
|
||||||
.browser => WebGL,
|
.browser => WebGL,
|
||||||
} else switch (builtin.os.tag) {
|
} else switch (builtin.os.tag) {
|
||||||
.macos => Metal,
|
.macos => Metal,
|
||||||
|
Reference in New Issue
Block a user