mirror of
https://github.com/ghostty-org/ghostty.git
synced 2025-08-02 14:57:31 +03:00
test wasm of the term package
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@ -2,6 +2,7 @@
|
||||
zig-cache/
|
||||
zig-out/
|
||||
/result*
|
||||
example/*.wasm
|
||||
test/ghostty
|
||||
test/cases/**/*.actual.png
|
||||
|
||||
|
@ -62,6 +62,7 @@ pub fn build(b: *std.build.Builder) !void {
|
||||
wasm.setTarget(.{ .cpu_arch = .wasm32, .os_tag = .freestanding });
|
||||
wasm.setBuildMode(mode);
|
||||
wasm.setOutputDir("zig-out");
|
||||
wasm.addPackage(pkg_tracy);
|
||||
|
||||
const step = b.step("term-wasm", "Build the terminal.wasm library");
|
||||
step.dependOn(&wasm.step);
|
||||
@ -158,6 +159,9 @@ fn addDeps(
|
||||
// Libuv
|
||||
step.addPackage(libuv.pkg);
|
||||
try libuv.link(b, step);
|
||||
|
||||
// Tracy
|
||||
step.addPackage(pkg_tracy);
|
||||
}
|
||||
|
||||
fn conformanceSteps(
|
||||
@ -203,6 +207,11 @@ fn root() []const u8 {
|
||||
return std.fs.path.dirname(@src().file) orelse unreachable;
|
||||
}
|
||||
|
||||
pub const pkg_tracy = std.build.Pkg{
|
||||
.name = "tracy",
|
||||
.source = .{ .path = root() ++ "/src/tracy/tracy.zig" },
|
||||
};
|
||||
|
||||
/// ANSI escape codes for colored log output
|
||||
const color_map = std.ComptimeStringMap([]const u8, .{
|
||||
&.{ "black", "30m" },
|
||||
|
34
example/index.html
Normal file
34
example/index.html
Normal file
@ -0,0 +1,34 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<title>WASM Example</title>
|
||||
</head>
|
||||
<body>
|
||||
<script>
|
||||
const importObject = {
|
||||
module: {},
|
||||
env: {
|
||||
// memory: new WebAssembly.Memory({ initial: 256 }),
|
||||
}
|
||||
};
|
||||
|
||||
fetch('ghostty-term.wasm').then(response =>
|
||||
response.arrayBuffer()
|
||||
).then(bytes =>
|
||||
WebAssembly.instantiate(bytes, importObject)
|
||||
).then(results => {
|
||||
const {
|
||||
terminal_new,
|
||||
terminal_free,
|
||||
terminal_print,
|
||||
} = results.instance.exports;
|
||||
|
||||
const term = terminal_new(80, 80);
|
||||
console.log(term);
|
||||
terminal_free(term);
|
||||
terminal_print('a');
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
@ -4,6 +4,7 @@
|
||||
, glxinfo
|
||||
, parallel
|
||||
, pkg-config
|
||||
, python
|
||||
, scdoc
|
||||
, tracy
|
||||
, vulkan-loader
|
||||
@ -47,6 +48,7 @@ in mkShell rec {
|
||||
# Testing
|
||||
gdb
|
||||
parallel
|
||||
python
|
||||
tracy
|
||||
vttest
|
||||
wraptest
|
||||
|
@ -14,7 +14,7 @@ const csi = @import("csi.zig");
|
||||
const sgr = @import("sgr.zig");
|
||||
const Selection = @import("Selection.zig");
|
||||
const Tabstops = @import("Tabstops.zig");
|
||||
const trace = @import("../tracy/tracy.zig").trace;
|
||||
const trace = @import("tracy").trace;
|
||||
const color = @import("color.zig");
|
||||
const Screen = @import("Screen.zig");
|
||||
|
||||
|
@ -1,5 +1,8 @@
|
||||
// This is the C-ABI API for the terminal package. This isn't used
|
||||
// by other Zig programs but by C or WASM interfacing.
|
||||
//
|
||||
// NOTE: This is far, far from complete. We did a very minimal amount to
|
||||
// prove that compilation works, but we haven't completed coverage yet.
|
||||
|
||||
const std = @import("std");
|
||||
const builtin = @import("builtin");
|
||||
@ -7,10 +10,10 @@ 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
|
||||
const alloc = if (builtin.link_libc)
|
||||
std.heap.c_allocator
|
||||
else
|
||||
std.heap.c_allocator;
|
||||
std.heap.page_allocator;
|
||||
|
||||
export fn terminal_new(cols: usize, rows: usize) ?*Terminal {
|
||||
const term = Terminal.init(alloc, cols, rows) catch return null;
|
||||
@ -25,3 +28,9 @@ export fn terminal_free(ptr: ?*Terminal) void {
|
||||
alloc.destroy(v);
|
||||
}
|
||||
}
|
||||
|
||||
export fn terminal_print(ptr: ?*Terminal, char: u32) void {
|
||||
if (ptr) |t| {
|
||||
t.print(@intCast(u21, char)) catch return null;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user