0282. Single-file static app builds and manifest-driven asset embedding
- Status: Accepted (maintainer, 2026-11-22; recommended defaults for all open questions; frozen-file edits listed here approved)
- Date: 2026-11-22
- Plan: R7; M15.1 (narrows "macOS and Windows supported")
- Review: Planner #6; amends scope of 0245
Context
Decision boundary first. plans/prebuilt-release/
(T01–T07) ships the compiler as one executable
per target; ADR-0245 fixes which batteries ship
with it; scripts/dist/ linux-musl.sh already proves a
static musl tenon and a static generated program via
CC="zig cc -target $arch-linux-musl -static". None of
them lets an indie developer turn their CLI, TUI or web
server into one file to scp to a box. Today
tenon build uses the host cc
(driver::find_cc), links glibc dynamically, adds FFI
libs via pkg-config
(sqlite3, zlib, and libcurl for
Net.http), and reads HTML/CSS/JS/prompts from disk at
run time, so a deploy is a binary plus a directory plus matching
shared libraries. ADR-0006 forbids plugin grammar; string escapes
are only \n \t \r \\ \" \0, so arbitrary binary data
cannot be a plain str literal.
Decision
tenon build --static [--target T] -o app. Default dev builds stay dynamic with the hostcc(fast, debuggable). Targets:x86_64-linux-musl,aarch64-linux-musl,x86_64-macos,aarch64-macos. Linux--static= fully static musl ELF (-static, no interpreter, noDT_NEEDED). macOS--static= one Mach-O whose only dynamic deps arelibSystem(static libc is unsupported on macOS); ad-hoc signed for arm64.- Toolchain resolution, in order:
$CCif the user set it;musl-gccfor a native Linux target;zig cc -target Tfrom$TENON_ZIGor PATH (pinned minimum version) for anything else, including all cross builds. Zig is optional, not bundled; a missing toolchain is E09xx (allocate at implementation) naming the install command. Bundling Zig is a prebuilt-release decision, not this one. The target joins the build-cache key. - Native deps. Under
--static, an FFI plugin links its.a(pkg-config --static) or a vendored source build (R3 SQLite amalgamation per ADR-0273, zlib). A plugin with no static archive is E09xx listing the plugin and lib.Net.http/libcurl is refused under--staticin v1 (its TLS stack makes a static link fragile); theCurlProcesstransport adapter (ADR-0247) still works wherecurlexists on the box.tenon buildprints one summary line:static: yes · target · size · dynamic deps: none|libSystem. - Embedding via the manifest, not grammar. A
[embed.<module>]table intenon.toml(dir,includeglobs) makes the driver generate an ordinary Tenon module, importable asimport assets { get, text, paths, etag }:get(path: str) -> option<bytes>,text(path: str) -> option<str>,paths() -> vec<str>(sorted),etag(path: str) -> option<str>(SHA-256 hex prefix, computed at build). UTF-8 files becomestrliterals using the existing escapes; other files become base64strliterals decoded once by a private helper in the same generated module. No new IR constant, so the interpreter runs the same source and the backends agree with no change tointerp*. The module is regenerated automatically atcheck/build/run(keyed on file hashes in the build cache);tenon gen --embed <pkg>writes it out for review. Paths use thehttp.files.safe_pathcharset, must stay inside the package, follow no symlinks out, and are capped (8 MiB per file, E1156; the generated module must fit the 16 MiB compact source limit, so 16 MiB is the effective total, a little less for base64 binaries). Optimizing to raw C arrays waits for a bench. - Windows is out of scope for M15.1;
--target *-windowsis E09xx "unsupported target". - Deploy recipe, not a deploy tool. Docs show
tenon build --static --target x86_64-linux-musl -o app,scp, a systemd unit and Caddy in front (TLS, ADR-0281).
Prior art
- Go
//go:embedandCGO_ENABLED=0static binaries — https://pkg.go.dev/embed - Rust
include_bytes!/include_str!— https://doc.rust-lang.org/std/macro.include_bytes.html - Zig
@embedFileandzig cccross-compiling C — https://ziglang.org/documentation/master/#embedFile, https://andrewkelley.me/post/zig-cc-powerful-drop-in-replacement-gcc-clang.html - Deno
deno compile --include— https://docs.deno.com/runtime/reference/cli/compile/ - Apple QA1118, static linking of user binaries is unsupported — https://developer.apple.com/library/archive/qa/qa1118/_index.html
Alternatives considered
- An
embed("x")builtin or@embedattribute — kernel/grammar addition (ADR-0006), a new constant kind in both backends (frozen interpreter), and a form agents must learn. - Committed
gen/like derives — stale-asset bugs when an HTML edit forgetstenon gen, and binary churn in git. Auto-generation keeps one source of truth. - Bundle Zig in every toolchain — +40–50 MB download for a feature most dev builds skip.
- Static glibc — NSS/
dlopenwarnings and partial staticness; musl is the standard answer. - Append a zip to the binary (Bun/Deno style) — needs a runtime reader, breaks signing on macOS, and the interpreter path would differ.
Consequences
UX: one file, no runtime deps, starts instantly; assets cannot
drift from code. DX: one flag plus a short manifest table; same
code in dev and prod. AX: assets are ordinary imports with four
functions, checked at compile time (a missing path in
paths() is visible), and every failure is a coded
diagnostic. Harder: base64 adds 33% for binary assets; musl
malloc is slower (arenas absorb most of it); macOS
cross builds depend on Zig's SDK stubs and are best-effort until
qualified on a Mac runner. LANGUAGE.md: +1 sentence (~25 tokens)
linking diagnostics.md#packages-and-manifests, offset
by moving "Import-free files ignore visibility" there. Frozen
files: none. Backlog follow-ups: R3 must vendor SQLite for fully
static apps; PLAN.md M15.1 text needs a docs(plan)
edit dropping Windows.
Implementation slices
- Target model + link plan as a pure function
(
link_plan(target, host, ffi) -> Result), toolchain resolution, E09xx codes,--static/--targetflags. Files:crates/tenon/src/ driver.rs,main.rs,build_cache.rs,docs/spec/diagnostics.md. Frozen: no. Agent: Claude Sonnet. - FFI static linking
(
pkg-config --static,.alookup, vendored-source hook for R3), libcurl refusal, summary line. Files:driver.rs,cgen_ffi.rs,plugins/{sqlite,zlib}/ tenon.toml. Frozen: no. Agent: Claude Sonnet (after R3 decision). [embed]manifest + generated module (glob, caps, base64 helper, etag), unit tests on the generator text. Files:manifest.rs,gen.rs,modules.rs,docs/spec/ diagnostics.md, LANGUAGE.md (+1 sentence). Frozen: no. Agent: Claude Opus.- Qualification scripts (Linux x86_64/aarch64
static check with
readelf -d, macOSotool -Lon a Mac runner, http-demo with embedded assets) — on demand, not the gate. Files:scripts/dist/,bench/static-app/. Frozen: no. Agent: Gemini (agy Argon Low). - Docs: deploy recipe (systemd + Caddy) and
IDIOMS line. Files:
docs/,plans/. Frozen: no. Agent: Claude Sonnet.
Open questions (resolved)
Resolved by maintainer on 2026-11-22: every question takes its stated default.
- Windows out of M15.1 scope? Default: yes; revisit after a user asks.
- Zig optional on PATH, or bundled in prebuilt releases? Default: optional now.
- Embedded module regenerated automatically, or committed like
gen/? Default: automatic. - Refuse libcurl under
--static, or allow a dynamic libcurl exception? Default: refuse. - Embed caps 8 MiB/file, 32 MiB total? Default: yes. Amended at implementation (M23.17): the 16 MiB compact source limit makes 16 MiB of generated source the real total.