Skip to content

feat: build WASM from ghostty-org/ghostty submodule with patches#23

Merged
sreya merged 8 commits into
mainfrom
patch
Nov 13, 2025
Merged

feat: build WASM from ghostty-org/ghostty submodule with patches#23
sreya merged 8 commits into
mainfrom
patch

Conversation

@sreya

@sreya sreya commented Nov 13, 2025

Copy link
Copy Markdown
Contributor

Major architectural change to build WASM from source instead of committing the binary to the repository.

Changes:

  • Add ghostty-org/ghostty as root-level submodule (pinned to 0f64b9a8e)
  • Add patches/ghostty-wasm-api.patch (33KB, 1006 lines)
    • Exposes 16 C API functions for terminal integration
    • Based on coder/ghostty fork commit bfd067d
  • Rewrite scripts/build-wasm.sh:
    • Initialize submodule if needed
    • Apply patch, build WASM with Zig, revert patch
    • Keeps submodule clean for easy updates
  • Update CI workflow:
    • Add Zig 0.15.2 installation to test and build jobs
    • Build WASM before running tests/build
    • Add WASM size check (512KB limit)
  • Update package.json:
    • Add build:wasm script
    • Integrate WASM build into main build process
  • Update .gitignore:
    • Ignore ghostty-vt.wasm (built locally and in CI)
    • Ignore ghostty/zig-out/ and ghostty/zig-cache/
  • Remove committed ghostty-vt.wasm binary (404KB)
  • Update README.md and INSTALL.md with new build instructions

Benefits:

  • Transparent build process (exact Ghostty version + patches visible)
  • Easier to update upstream Ghostty
  • Smaller git history (no binary commits)
  • WASM still included in npm package (built during prepublishOnly)

Build time: ~20 seconds for WASM, adds ~30 seconds to CI test/build jobs

Major architectural change to build WASM from source instead of committing
the binary to the repository.

Changes:
- Add ghostty-org/ghostty as root-level submodule (pinned to 0f64b9a8e)
- Add patches/ghostty-wasm-api.patch (33KB, 1006 lines)
  - Exposes 16 C API functions for terminal integration
  - Based on coder/ghostty fork commit bfd067d
- Rewrite scripts/build-wasm.sh:
  - Initialize submodule if needed
  - Apply patch, build WASM with Zig, revert patch
  - Keeps submodule clean for easy updates
- Update CI workflow:
  - Add Zig 0.15.2 installation to test and build jobs
  - Build WASM before running tests/build
  - Add WASM size check (512KB limit)
- Update package.json:
  - Add build:wasm script
  - Integrate WASM build into main build process
- Update .gitignore:
  - Ignore ghostty-vt.wasm (built locally and in CI)
  - Ignore ghostty/zig-out/ and ghostty/zig-cache/
- Remove committed ghostty-vt.wasm binary (404KB)
- Update README.md and INSTALL.md with new build instructions

Benefits:
- Transparent build process (exact Ghostty version + patches visible)
- Easier to update upstream Ghostty
- Smaller git history (no binary commits)
- WASM still included in npm package (built during prepublishOnly)

Build time: ~20 seconds for WASM, adds ~30 seconds to CI test/build jobs
- Remove ghostty/zig-out/ and ghostty/zig-cache/ from .gitignore
  (submodule contents are automatically ignored by git)
- Simplify INSTALL.md to just run build script
  (script handles submodule initialization automatically)
Replace manual Zig installation with mlugg/setup-zig@v1 action:
- Automatically caches Zig compiler between runs
- Caches global Zig cache directory for faster builds
- Verifies tarball signatures for security
- Cleaner, more maintainable CI code

Benefits:
- Faster CI (caching saves ~10 seconds per run)
- More reliable (uses community mirror list)
- Less boilerplate (3 lines vs 7 lines)
Building WASM should be an explicit step, not part of dependency installation.

Changes:
- Remove postinstall script from package.json
- Update README.md to remove postinstall mention
- Update INSTALL.md to clarify git installs need manual build

Benefits:
- fmt/lint/typecheck CI jobs no longer need Zig or submodules
- Cleaner separation: install = deps, build = artifacts
- Users have explicit control over when WASM is built
Create .github/actions/setup-zig to install Zig compiler:
- Supports Linux x86_64 and macOS (x86_64/aarch64)
- Downloads from ziglang.org/builds (more reliable than /download)
- Caches Zig installation between runs
- Adds retry logic for network resilience
- Verifies installation with zig version

Benefits over third-party actions:
- Full control over installation logic
- No external dependencies
- Can customize for our specific needs
- Better error messages and debugging

Fixes the curl error when downloading from /download endpoint.
Zig changed the download URL format starting with v0.14.1:
- Old format: zig-linux-x86_64-VERSION.tar.xz
- New format: zig-x86_64-linux-VERSION.tar.xz

Changes:
- Switch from /builds to /download endpoint
- Use correct ARCH-PLATFORM order (not PLATFORM-ARCH)
- Add comment documenting the format change

This fixes the 404 error when downloading Zig 0.15.2.
@sreya sreya merged commit 4143aeb into main Nov 13, 2025
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant