diff --git a/.gitignore b/.gitignore
index 0135036b0..83d1031dc 100644
--- a/.gitignore
+++ b/.gitignore
@@ -2,6 +2,7 @@
zig-cache/
zig-out/
/result*
+example/*.wasm
test/ghostty
test/cases/**/*.actual.png
diff --git a/build.zig b/build.zig
index 9c6b4b9ce..8bd227b01 100644
--- a/build.zig
+++ b/build.zig
@@ -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" },
diff --git a/example/index.html b/example/index.html
new file mode 100644
index 000000000..f93da37d7
--- /dev/null
+++ b/example/index.html
@@ -0,0 +1,34 @@
+
+
+
+
+ WASM Example
+
+
+
+
+
diff --git a/nix/devshell.nix b/nix/devshell.nix
index ebc44c3d9..b587e1915 100644
--- a/nix/devshell.nix
+++ b/nix/devshell.nix
@@ -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
diff --git a/src/terminal/Terminal.zig b/src/terminal/Terminal.zig
index ac934263b..d86e5c2da 100644
--- a/src/terminal/Terminal.zig
+++ b/src/terminal/Terminal.zig
@@ -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");
diff --git a/src/terminal/c_api.zig b/src/terminal/c_api.zig
index fbebd0815..65bc54208 100644
--- a/src/terminal/c_api.zig
+++ b/src/terminal/c_api.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;
+ }
+}