feat(wasm): port Ghostty's wasm32 build

Ports main_wasm.zig as crates/ghostty-wasm (cdylib exporting the Zig
names: atlas_*, face_*, deferred_face_*, shaper_*, config_*), the
web_canvas font face and shaper (backend selected on wasm32), os/wasm
(logging, target, JS interop) and config/Wasm.zig.

C-library dependencies (freetype, harfbuzz, fontconfig, onig, gettext,
D-Bus, rustix) are target-gated. Like Zig's wasm build, link regex
search (StringMap::search_iterator) is unavailable without Oniguruma;
Collection/SharedGrid/harfbuzz are compiled out on wasm32. ghostty-os
switches from forbid to deny unsafe_code for the JS import blocks.

The JS import ABI is currently a documented handle-based interface with
a reference host (js/ghostty_host.js); aligning it with zig-js's exact
import names follows separately.

Test Plan:
- cargo build --target wasm32-unknown-unknown -p ghostty-font \
  -p ghostty-config -p ghostty-terminal -p ghostty-vt -p ghostty-wasm
- cargo test -p ghostty-wasm (node runs the module against a fake canvas)
This commit is contained in:
ddidderr committed 2026-10-12 05:21:14 +02:00
1 parent 0915f7b935
commit d89691b0ce
33 files changed
+2866 -30

No files matched your search

+12 -10
View File
@@ -3976,7 +3976,18 @@ impl Config {
//
// See: https://github.com/Vladimir-csp/xdg-terminal-exec
{
#[cfg(unix)]
use std::os::unix::ffi::OsStrExt;
#[cfg(not(unix))]
trait OsStrExt {
fn as_bytes(&self) -> &[u8];
}
#[cfg(not(unix))]
impl OsStrExt for std::ffi::OsString {
fn as_bytes(&self) -> &[u8] {
self.as_encoded_bytes()
}
}
let cargs: Vec<std::ffi::CString> = argv
.iter()
.filter_map(|a| std::ffi::CString::new(a.as_bytes()).ok())
@@ -4619,22 +4630,13 @@ fn zig_io_error_name(err: &std::io::Error) -> String {
}
fn file_kind_name(meta: &std::fs::Metadata) -> &'static str {
use std::os::unix::fs::FileTypeExt;
let ft = meta.file_type();
if ft.is_dir() {
"directory"
} else if ft.is_symlink() {
"sym_link"
} else if ft.is_block_device() {
"block_device"
} else if ft.is_char_device() {
"character_device"
} else if ft.is_fifo() {
"named_pipe"
} else if ft.is_socket() {
"unix_domain_socket"
} else {
"unknown"
crate::theme::special_kind_name(ft)
}
}
+15 -2
View File
@@ -94,14 +94,21 @@ fn diag(diags: &mut DiagnosticList, message: String) {
}
fn kind_name(ft: std::fs::FileType) -> &'static str {
use std::os::unix::fs::FileTypeExt;
if ft.is_file() {
"file"
} else if ft.is_dir() {
"directory"
} else if ft.is_symlink() {
"sym_link"
} else if ft.is_block_device() {
} else {
special_kind_name(ft)
}
}
#[cfg(unix)]
pub(crate) fn special_kind_name(ft: std::fs::FileType) -> &'static str {
use std::os::unix::fs::FileTypeExt;
if ft.is_block_device() {
"block_device"
} else if ft.is_char_device() {
"character_device"
@@ -114,6 +121,12 @@ fn kind_name(ft: std::fs::FileType) -> &'static str {
}
}
/// wasm32 has no special file types (`std::os::unix` is unavailable).
#[cfg(not(unix))]
pub(crate) fn special_kind_name(_: std::fs::FileType) -> &'static str {
"unknown"
}
/// Verify that the file is a regular file, adding a diagnostic otherwise.
fn check_regular(file: &File, theme: &str, diags: &mut DiagnosticList) -> bool {
match file.metadata() {