On this page

0282. Single-file static app builds and manifest-driven asset embedding

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

  1. tenon build --static [--target T] -o app. Default dev builds stay dynamic with the host cc (fast, debuggable). Targets: x86_64-linux-musl, aarch64-linux-musl, x86_64-macos, aarch64-macos. Linux --static = fully static musl ELF (-static, no interpreter, no DT_NEEDED). macOS --static = one Mach-O whose only dynamic deps are libSystem (static libc is unsupported on macOS); ad-hoc signed for arm64.
  2. Toolchain resolution, in order: $CC if the user set it; musl-gcc for a native Linux target; zig cc -target T from $TENON_ZIG or 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.
  3. 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 --static in v1 (its TLS stack makes a static link fragile); the CurlProcess transport adapter (ADR-0247) still works where curl exists on the box. tenon build prints one summary line: static: yes · target · size · dynamic deps: none|libSystem.
  4. Embedding via the manifest, not grammar. A [embed.<module>] table in tenon.toml (dir, include globs) makes the driver generate an ordinary Tenon module, importable as import 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 become str literals using the existing escapes; other files become base64 str literals 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 to interp*. The module is regenerated automatically at check/build/run (keyed on file hashes in the build cache); tenon gen --embed <pkg> writes it out for review. Paths use the http.files.safe_path charset, 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.
  5. Windows is out of scope for M15.1; --target *-windows is E09xx "unsupported target".
  6. 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

Alternatives considered

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

  1. Target model + link plan as a pure function (link_plan(target, host, ffi) -> Result), toolchain resolution, E09xx codes, --static/--target flags. Files: crates/tenon/src/ driver.rs, main.rs, build_cache.rs, docs/spec/diagnostics.md. Frozen: no. Agent: Claude Sonnet.
  2. FFI static linking (pkg-config --static, .a lookup, 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).
  3. [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.
  4. Qualification scripts (Linux x86_64/aarch64 static check with readelf -d, macOS otool -L on 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).
  5. 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.

  1. Windows out of M15.1 scope? Default: yes; revisit after a user asks.
  2. Zig optional on PATH, or bundled in prebuilt releases? Default: optional now.
  3. Embedded module regenerated automatically, or committed like gen/? Default: automatic.
  4. Refuse libcurl under --static, or allow a dynamic libcurl exception? Default: refuse.
  5. 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.