build: add Meson wrapper for libghostty-vt

Add Meson build system integration mirroring the existing CMake
wrapper. The top-level meson.build delegates to zig build lib-vt
using --prefix-lib-dir and --prefix-include-dir to place outputs
directly in the Meson build directory, avoiding stamp files and
source tree pollution. A sentinel .h output ensures Meson orders
the zig build before any downstream compiles.

Downstream projects can consume the library either as a Meson
subproject via a .wrap file or through pkg-config after install.
The dist/meson/README.md documents both approaches.

Includes a c-vt-meson example, CI job in test.yml for auto-discovered
Meson examples, meson and ninja in the nix devShell, and gitignore
updates for Meson build artifacts.
This commit is contained in:
Mitchell Hashimoto
2026-03-20 12:04:05 -07:00
parent 9ba2614ac1
commit 08bbc5b752
10 changed files with 379 additions and 0 deletions

4
example/.gitignore vendored
View File

@@ -2,4 +2,8 @@
dist/
node_modules/
example.wasm*
# CMake / Meson
build/
# Meson
subprojects/

View File

@@ -0,0 +1,42 @@
# c-vt-meson
Demonstrates consuming libghostty-vt from a Meson project using a
subproject. Creates a terminal, writes VT sequences into it, and
formats the screen contents as plain text.
## Building this example
Since this example lives inside the Ghostty repo, point the subproject
at the local checkout instead of fetching from GitHub:
```shell-session
cd example/c-vt-meson
mkdir -p subprojects
ln -s ../../.. subprojects/ghostty
meson setup build
meson compile -C build
./build/c_vt_meson
```
## Real World Usage
Create a `subprojects/ghostty.wrap` file in your project:
```ini
[wrap-git]
url = https://github.com/ghostty-org/ghostty.git
revision = main
depth = 1
```
Then in your `meson.build`:
```meson
ghostty_proj = subproject('ghostty')
ghostty_vt_dep = ghostty_proj.get_variable('ghostty_vt_dep')
executable('myapp', 'src/main.c', dependencies: ghostty_vt_dep)
```
Meson will clone the repository into `subprojects/ghostty/` on first
build and invoke `zig build lib-vt` automatically.

View File

@@ -0,0 +1,11 @@
project('c-vt-meson', 'c',
version: '0.1.0',
meson_version: '>= 1.1.0',
)
ghostty_proj = subproject('ghostty')
ghostty_vt_dep = ghostty_proj.get_variable('ghostty_vt_dep')
executable('c_vt_meson', 'src/main.c',
dependencies: ghostty_vt_dep,
)

View File

@@ -0,0 +1,52 @@
#include <assert.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ghostty/vt.h>
int main() {
// Create a terminal with a small grid
GhosttyTerminal terminal;
GhosttyTerminalOptions opts = {
.cols = 80,
.rows = 24,
.max_scrollback = 0,
};
GhosttyResult result = ghostty_terminal_new(NULL, &terminal, opts);
assert(result == GHOSTTY_SUCCESS);
// Write some VT-encoded content into the terminal
const char *commands[] = {
"Hello from a \033[1mMeson\033[0m-built program!\r\n",
"Line 2: \033[4munderlined\033[0m text\r\n",
"Line 3: \033[31mred\033[0m \033[32mgreen\033[0m \033[34mblue\033[0m\r\n",
};
for (size_t i = 0; i < sizeof(commands) / sizeof(commands[0]); i++) {
ghostty_terminal_vt_write(terminal, (const uint8_t *)commands[i],
strlen(commands[i]));
}
// Format the terminal contents as plain text
GhosttyFormatterTerminalOptions fmt_opts =
GHOSTTY_INIT_SIZED(GhosttyFormatterTerminalOptions);
fmt_opts.emit = GHOSTTY_FORMATTER_FORMAT_PLAIN;
fmt_opts.trim = true;
GhosttyFormatter formatter;
result = ghostty_formatter_terminal_new(NULL, &formatter, terminal, fmt_opts);
assert(result == GHOSTTY_SUCCESS);
uint8_t *buf = NULL;
size_t len = 0;
result = ghostty_formatter_format_alloc(formatter, NULL, &buf, &len);
assert(result == GHOSTTY_SUCCESS);
printf("Plain text (%zu bytes):\n", len);
fwrite(buf, 1, len, stdout);
printf("\n");
free(buf);
ghostty_formatter_free(formatter);
ghostty_terminal_free(terminal);
return 0;
}