v1.4.4UI FrameworkBSD-2-Clause

One renderer for native SSR and browser WASM. An isomorphic, zero-dependency C DOM scaffold and reactive state binder with JSX ergonomics. Canonical header is <bud/bud.h>.

GitHub
git clone https://github.com/tty-pt/libbud

bud logo

libbud

npm C99 BSD-2-Clause No dependencies Isomorphic SSR+WASM

One renderer for native SSR and browser WASM. An isomorphic, zero-dependency C DOM scaffold and reactive state binder with JSX ergonomics. Canonical header is <bud/bud.h>.

1. Quickstart: Declarative UI

Build and render a declarative HTML component in pure C99:

#include <stdio.h>
#include <bud/bud.h>
#include <bud/bud_jsx.h>

int main(void) {
    // Declarative JSX-style macro tree in pure C
    bud_node *doc = lx_frag_n(
        lx_el("h1", lx_text("Pure C UI")),
        lx_el("p", lx_attr("class", "lead"), lx_text("One renderer for SSR and browser WASM."))
    );

    // Serialize to clean, standards-compliant HTML string
    char *html = bud_render_html(doc);
    printf("%s\n", html);

    bud_free_string(html);
    bud_free(doc);
    return 0;
}

Compile and run:

cc ui_demo.c $(pkg-config --cflags --libs bud) -o ui_demo
./ui_demo

Dual-Target Compilation Pipeline

The exact same C file compiles to a native .so module for server SSR and a browser .wasm module for hydration:

# 1. Native compile for Server-Side Rendering (SSR):
cc -shared -fPIC -O2 -o mod.so mod.c $(pkg-config --cflags --libs bud)

# 2. WebAssembly compile for browser hydration (links installed libbud-wasm.a):
clang --target=wasm32 -O2 -nostdlib \
  -Wl,--no-entry -Wl,--export=bud_app_render \
  $(pkg-config --cflags bud) -o htdocs/mod.wasm mod.c \
  $(pkg-config --variable=wasm_lib bud)

2. The 5-Field State Binding Contract

libbud uses a declarative 5-field descriptor (bud_field_desc_t) to unpack JSON state into C memory without manual parsing (backed by libstele's zero-allocation <ttypt/iso_json.h> tokenizer):

static const bud_field_desc_t state_fields[] = {
    { "query",   BUD_TYPE_STR, offsetof(state_t, query),   sizeof(((state_t*)0)->query), "" },
    { "page",    BUD_TYPE_INT, offsetof(state_t, page),    sizeof(int), "1" },
    { "active",  BUD_TYPE_BOOL, offsetof(state_t, active), sizeof(int), "0" },
};
FieldTypeDescription
nameconst char *JSON key name
typebud_type_tType identifier (BUD_TYPE_STR, BUD_TYPE_INT, BUD_TYPE_BOOL)
offsetsize_tByte offset in C state struct (offsetof(state_t, member))
sizesize_tBuffer capacity (strings) or scalar byte size
def_valconst char *Fallback default value if absent from JSON

3. Core API & Subsystems

Header / ToolKey APIs / FeaturesDescription
<bud/bud.h>bud_element_lit, bud_text_lit, bud_render_html, bud_vdom_diff, bud_expand_tree, bud_arena_*Core VDOM tree, SSR HTML serializer, VDOM differ, chunked bump-allocator arenas, and zero-copy *_lit builders
<bud/bud_jsx.h>lx_el, lx_n, lx_frag, lx_text, lx_attr, lx_onDeclarative JSX-style C99 macro builders
<bud/bud_reconcile.h>bud_host_ops, bud_mount_new, bud_mount_update, bud_mount_flush, bud_use_state_raw, bud_use_ref_raw, bud_use_effectHost-agnostic reactive reconciler and hooks usable with browser DOM, liblamina, or custom hosts
<bud/bud_dom_host.h>bud_dom_host_ops, BUD_DOM_ROOT_HANDLE, bud_dom_dispatch, bud_dom_event_payloadBrowser DOM bud_host_ops adapter backed by htdocs/bud-cap.js
<bud/bud_state.h> / <bud/bud_app.h>bud_state_apply, bud_app_set_state5-field table-driven state binder and isomorphic app hooks
<bud/cx.h>, bin/cx, bin/cx-lspcx_transpile, cx_write_map_json, cx_write_header, on*Self, on:<literal>[:self].cx JSX-in-C transpiler, cx-lsp language server (flat metadata index, cross-file resolution, code actions), and tree-sitter-cx/ grammar

๐Ÿ‘‰ Source is organized into focused compilation units (src/libbud.c, src/bud_tpl.c, src/bud_render.c, src/bud_runtime.c, src/bud_json.c, src/bud_reconcile.c, src/bud_dom_host.c).


4. Isomorphic Architecture & Browser Capability Bridge

  1. Server-Side Render (SSR): The server executes bud_app_render(state), serializing the AST to plain HTML strings. State is injected into <script type="application/json" id="bud-state"> alongside #bud-root.
  2. Instant Paint: The browser renders clean HTML immediately with zero layout shiftโ€”even if JavaScript or WASM is disabled.
  3. WASM Capability Bridge (htdocs/bud-cap.js): Loads alongside @tty-pt/stele, exposing BudWasmBridge.dispatchExport and slotBridge metadata on stele capability registration, DOM host operations (bud_dom_host_ops), elToId reverse lookups, onAfterDispatch hooks, event payload propagation, { passive: false } wheel listeners, and unsynced/inactive <input>.value synchronization (with WASM exports audited against wasm-allowed-exports.lst). Downstream builds can locate libbud-wasm.a and bud-cap.js via pkg-config --variable=wasm_lib bud and pkg-config --variable=cap_js bud.

5. Installation & Build

Prebuilt Packages

Prebuilt packages for Linux (APT / Alpine / Arch / Fedora-RHEL), macOS (Homebrew), Windows (winget / MSYS2), OpenBSD, and mobile static sysroots for Android (https://tty.pt/android/ โ€” arm64-v8a, armeabi-v7a, x86_64) and iOS (https://tty.pt/ios/ โ€” libbud.xcframework) are distributed via tty.pt packages. Use libbud as the package name.

Build from Source

Building from source requires libstele (for <ttypt/iso_json.h> and the shared ttypt/include.mk build rules):

make                  # builds lib/libbud.so, bin/cx, bin/cx-lsp, and unit test binaries
make wasm-lib         # builds linkable lib/libbud-wasm.a for wasm32 consumers
make test             # runs bud_test, bud_reconcile_test, cx_test, and cx_lsp_test
make npm-test         # builds and runs @tty-pt/bud + JSX runtime tests
sudo make install     # installs headers, libbud, libbud-wasm.a, bud-cap.js, bin/cx, bin/cx-lsp, and bud.pc

6. JavaScript, TypeScript & JSX Bindings (@tty-pt/bud)

Official Node.js and Browser WebAssembly bindings are colocated in npm/:

npm config set @tty-pt:registry https://tty.pt/npm/
npm install @tty-pt/bud
  • Universal VDOM & Diffing (@tty-pt/bud): Virtual DOM builder (h), compiled C/WASM diffing (diffVdom), and npm/dist/bud-cap.js browser capability module (@tty-pt/bud/cap).
  • Automatic JSX Runtime (@tty-pt/bud/jsx-runtime): React-compatible jsx/jsxs/Fragment, hooks (useState, useReducer, useRef, useMemo, useCallback, useEffect, memo), and reconciler (render, flushSync), with a working TypeScript example in npm/examples/jsx-app/.
  • C Development Headers: Consume headers from node_modules/@tty-pt/bud/include.

๐Ÿ‘‰ For complete TypeScript usage, JSX runtime setup, and API reference, see npm/README.md.

License

BSD 2-Clause License. Copyright (c) 2026, tty-pt. See LICENSE.

Maintained by:tty-pt