mirror of
https://github.com/ghostty-org/ghostty.git
synced 2025-08-02 14:57:31 +03:00
src/terminal can build into a minimal wasm library, I think
This commit is contained in:
15
build.zig
15
build.zig
@ -52,6 +52,21 @@ pub fn build(b: *std.build.Builder) !void {
|
|||||||
if (tracy) try tracylib.link(b, exe, target);
|
if (tracy) try tracylib.link(b, exe, target);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// term.wasm
|
||||||
|
{
|
||||||
|
const wasm = b.addSharedLibrary(
|
||||||
|
"ghostty-term",
|
||||||
|
"src/terminal/main_wasm.zig",
|
||||||
|
.{ .unversioned = {} },
|
||||||
|
);
|
||||||
|
wasm.setTarget(.{ .cpu_arch = .wasm32, .os_tag = .freestanding });
|
||||||
|
wasm.setBuildMode(mode);
|
||||||
|
wasm.setOutputDir("zig-out");
|
||||||
|
|
||||||
|
const step = b.step("term-wasm", "Build the terminal.wasm library");
|
||||||
|
step.dependOn(&wasm.step);
|
||||||
|
}
|
||||||
|
|
||||||
// Run
|
// Run
|
||||||
{
|
{
|
||||||
// Build our run step, which runs the main app by default, but will
|
// Build our run step, which runs the main app by default, but will
|
||||||
|
@ -8,6 +8,8 @@
|
|||||||
, tracy
|
, tracy
|
||||||
, vulkan-loader
|
, vulkan-loader
|
||||||
, vttest
|
, vttest
|
||||||
|
, wabt
|
||||||
|
, wasmtime
|
||||||
, wraptest
|
, wraptest
|
||||||
, zig
|
, zig
|
||||||
|
|
||||||
@ -48,6 +50,10 @@ in mkShell rec {
|
|||||||
tracy
|
tracy
|
||||||
vttest
|
vttest
|
||||||
wraptest
|
wraptest
|
||||||
|
|
||||||
|
# wasm
|
||||||
|
wabt
|
||||||
|
wasmtime
|
||||||
];
|
];
|
||||||
|
|
||||||
buildInputs = [
|
buildInputs = [
|
||||||
|
27
src/terminal/c_api.zig
Normal file
27
src/terminal/c_api.zig
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
// This is the C-ABI API for the terminal package. This isn't used
|
||||||
|
// by other Zig programs but by C or WASM interfacing.
|
||||||
|
|
||||||
|
const std = @import("std");
|
||||||
|
const builtin = @import("builtin");
|
||||||
|
const Allocator = std.mem.Allocator;
|
||||||
|
const Terminal = @import("main.zig").Terminal;
|
||||||
|
|
||||||
|
// The allocator that we want to use.
|
||||||
|
const alloc = if (builtin.target.isWasm())
|
||||||
|
std.heap.page_allocator
|
||||||
|
else
|
||||||
|
std.heap.c_allocator;
|
||||||
|
|
||||||
|
export fn terminal_new(cols: usize, rows: usize) ?*Terminal {
|
||||||
|
const term = Terminal.init(alloc, cols, rows) catch return null;
|
||||||
|
const result = alloc.create(Terminal) catch return null;
|
||||||
|
result.* = term;
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
export fn terminal_free(ptr: ?*Terminal) void {
|
||||||
|
if (ptr) |v| {
|
||||||
|
v.deinit(alloc);
|
||||||
|
alloc.destroy(v);
|
||||||
|
}
|
||||||
|
}
|
@ -1,3 +1,5 @@
|
|||||||
|
const builtin = @import("builtin");
|
||||||
|
|
||||||
const stream = @import("stream.zig");
|
const stream = @import("stream.zig");
|
||||||
const ansi = @import("ansi.zig");
|
const ansi = @import("ansi.zig");
|
||||||
const csi = @import("csi.zig");
|
const csi = @import("csi.zig");
|
||||||
@ -21,8 +23,6 @@ pub const EraseLine = csi.EraseLine;
|
|||||||
pub const TabClear = csi.TabClear;
|
pub const TabClear = csi.TabClear;
|
||||||
pub const Attribute = sgr.Attribute;
|
pub const Attribute = sgr.Attribute;
|
||||||
|
|
||||||
// Not exported because they're just used for tests.
|
|
||||||
|
|
||||||
test {
|
test {
|
||||||
_ = ansi;
|
_ = ansi;
|
||||||
_ = color;
|
_ = color;
|
||||||
|
4
src/terminal/main_wasm.zig
Normal file
4
src/terminal/main_wasm.zig
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
// This is the main file for the WASM module. The WASM module just
|
||||||
|
// imports the C API.
|
||||||
|
|
||||||
|
pub usingnamespace @import("c_api.zig");
|
Reference in New Issue
Block a user