libghostty: -Dvt-features to compile out unused features

This introduces a `-Dvt-features` build option for libghostty-vt that
compiles out optional feature areas, primarily so size-conscious
embedders (e.g. wasm) can significantly trim the binary.

The flag is similar to `-Dcpu`, `+feature` or `feature` to enable it,
`-feature` to disable, magic word `all` to turn all features on or off.
Example: `-Dvt-features=-all,+render-state` builds only the render
state API.

### Sizes

| Build | Bytes | Brotli |
|---|---|---|
| default (all features) | 876,500 | 218,309 |
| web interactive (`-all,+render-state,+input-encode,+selection,+color,+grid-introspection`) | 661,119 | 168,994 |
| read-only viewer (`-all,+render-state`) | 537,441 | 132,858 |
| bare VT core (`-all`) | 515,422 | 125,756 |
| xterm.js browser bundle (incl. renderers) | 488,663 | 99,311 |
| @xterm/headless | 182,672 | 39,651 |

Note: xterm versions are stable as of this commit.
This commit is contained in:
Mitchell Hashimoto
2026-08-14 21:02:46 -07:00
parent 0e0893adff
commit 1fdbb8c912
11 changed files with 570 additions and 177 deletions

View File

@@ -95,6 +95,7 @@ jobs:
- build-flatpak
- build-libghostty-vt
- build-libghostty-vt-wasm
- build-libghostty-vt-features
- build-libghostty-vt-android
- build-libghostty-vt-macos
- build-libghostty-vt-windows
@@ -726,6 +727,52 @@ jobs:
echo "Verified ${artifact} requires simd128"
done
# Compile-only checks for the -Dvt-features flags so that future changes
# don't regress any feature combination.
build-libghostty-vt-features:
runs-on: namespace-profile-ghostty-sm
needs: test
env:
ZIG_LOCAL_CACHE_DIR: /zig/local-cache
ZIG_GLOBAL_CACHE_DIR: /zig/global-cache
steps:
- name: Checkout code
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
- name: Setup Cache
uses: namespacelabs/nscloud-cache-action@c5f8dab7560444c4bf8dbc64f1b203431873c547 # v1.6.1
with:
path: |
/nix
/zig
# Install Nix and use that to run our tests so our environment matches exactly.
- uses: cachix/install-nix-action@630ae543ea3a38a9a4166f03376c02c50f408342 # v31.11.0
with:
nix_path: nixpkgs=channel:nixos-unstable
- uses: cachix/cachix-action@5f2d7c5294214f71b873db4b969586b980625e71 # v17
with:
name: ghostty
authToken: "${{ secrets.CACHIX_AUTH_TOKEN }}"
- name: Compile feature flag matrix
run: |
features="snapshot formatter selection render_state input_encode color grid_introspection glyph_protocol kitty_graphics"
configs="-all"
for f in $features; do configs="$configs -all,+$f"; done
for cfg in $configs; do
echo "::group::-Dvt-features=$cfg"
# The wasm lib build compiles the C API export block; the
# test build compiles every module test without running any.
nix develop -c zig build -Demit-lib-vt \
"-Dvt-features=$cfg" \
-Dtarget=wasm32-freestanding
nix develop -c zig build test-lib-vt-build \
"-Dvt-features=$cfg"
echo "::endgroup::"
done
# lib-vt requires macOS runner for macOS/iOS builds because it requires the `apple_sdk` path
build-libghostty-vt-macos:
strategy: