mirror of
https://github.com/ghostty-org/ghostty.git
synced 2026-04-17 21:12:39 +00:00
This makes `libghostty-vt` build for freestanding wasm targets (aka a browser) and produce a `ghostty-vt.wasm` file. This exports the same C API that libghostty-vt does. This commit specifically makes the changes necessary for the build to build properly and for us to run the build in CI. We don't yet actually try using it...
26 lines
933 B
Zig
26 lines
933 B
Zig
//! This file contains helpers for wasm compilation.
|
|
const std = @import("std");
|
|
const builtin = @import("builtin");
|
|
const options = @import("build_options");
|
|
|
|
comptime {
|
|
if (!builtin.target.cpu.arch.isWasm()) {
|
|
@compileError("wasm.zig should only be analyzed for wasm32 builds");
|
|
}
|
|
}
|
|
|
|
/// True if we're in shared memory mode. If true, then the memory buffer
|
|
/// in JS will be backed by a SharedArrayBuffer and some behaviors change.
|
|
pub const shared_mem = options.wasm_shared;
|
|
|
|
/// The allocator to use in wasm environments.
|
|
///
|
|
/// The return values of this should NOT be sent to the host environment
|
|
/// unless toHostOwned is called on them. In this case, the caller is expected
|
|
/// to call free. If a pointer is NOT host-owned, then the wasm module is
|
|
/// expected to call the normal alloc.free/destroy functions.
|
|
pub const alloc = if (builtin.is_test)
|
|
std.testing.allocator
|
|
else
|
|
std.heap.wasm_allocator;
|