wasm

package
v1.12.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 20, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package wasm holds build-time JS and HTML assets for the `lg -w` WASM bundler. AssembleHTML returns a single self-contained HTML page given the Go runtime support source and the gzipped-base64 program WASM.

The host JS is split into two assets:

  • lg-host-core.js: the host-agnostic glue (COI, wasm decode, the window.LetGoHost surface, the worker/main-thread boot). Always emitted.
  • lg-shell-xterm.js: the default xterm.js shell, which binds to the runtime only through LetGoHost. Emitted unless shell == false, i.e. `lg -w -w-shell none`, where the client supplies its own shell.

lg-host-core.js carries two markers (__WASM_EXEC_JS__ and __WASM_GZ_B64__) the assembler substitutes with JSON-encoded JS strings. host.html carries __LG_XTERM_CSS__ / __LG_XTERM_JS__ (the xterm CDN tags, dropped in shell-less builds) and __LG_HOST_JS_BODY_PLACEHOLDER__ where the host JS is inlined.

Index

Constants

View Source
const HostBodyMarker = "__LG_HOST_JS_BODY_PLACEHOLDER__"

HostBodyMarker is where the assembled host JS is spliced into an HTML template (the embedded host.html, or a caller's custom -w-shell template).

Variables

This section is empty.

Functions

func AssembleHTML

func AssembleHTML(wasmExecJS, wasmGzB64 string, shell, externalWasm, hostEval bool) string

AssembleHTML returns the full self-contained HTML page produced by `lg -w`. With shell == true the default xterm shell and its CDN tags are included; with shell == false only the host-agnostic core ships and the client binds its own shell to window.LetGoHost. With externalWasm == true the payload is delivered as a separate main.wasm the loader fetches and streams (wasmGzB64 is ignored); otherwise it is gzip-base64 inlined into the page. With hostEval == true the page exposes LetGoHost.eval (the -w-host-eval bundle); when false it is omitted, so feature detection stays honest. Pure function: same inputs produce same output. Tested via golden files in testdata/.

func AssembleHTMLWithTemplate added in v1.12.0

func AssembleHTMLWithTemplate(template, wasmExecJS, wasmGzB64 string, externalWasm, hostEval bool) string

AssembleHTMLWithTemplate injects the assembled host JS into a caller-supplied HTML template at HostBodyMarker. The custom template owns its own shell/markup, so the built-in xterm assets are never added and no __LG_XTERM_* markers are touched. externalWasm/hostEval behave as in AssembleHTML.

func GoBuildArgs added in v1.12.0

func GoBuildArgs(wasmPath string, buildTags string) []string

GoBuildArgs builds the `go build` argument list for compiling the wasm binary at wasmPath, optionally with the given comma/space-separated build tags.

func HasBuildTag added in v1.12.0

func HasBuildTag(rawTags, tag string) bool

HasBuildTag reports whether tag appears in rawTags (a `,`/space/tab/newline separated build-tag list).

func ListGogenIRPackages added in v1.12.0

func ListGogenIRPackages(srcDir string) ([]string, error)

ListGogenIRPackages returns the slash-separated relative paths of every lowered-Go package (a directory containing at least one .go file) under srcDir/pkg/rt/core_go_lowered, sorted.

func RenderMain added in v1.11.0

func RenderMain(storeID string, hostEval bool) string

RenderMain fills wasmMainTmpl's placeholders: the storage-id, and the -w-host-eval splice (the window.Eval bridge + park, plus its syscall/js import). With hostEval false the marker lines are removed whole, so the default bundle's generated main is byte-identical to the pre-flag output.

func ResolveShell added in v1.12.0

func ResolveShell(wShell string) (customTemplate string, xtermShell bool, err error)

ResolveShell interprets the -w-shell flag: "xterm"/"none" pick the built-in shell; any other value is a custom HTML template path, which must exist and contain exactly one HostBodyMarker. Returns the custom template path ("" for built-in) and whether the built-in xterm shell is selected.

func WriteGogenIRWireup added in v1.12.0

func WriteGogenIRWireup(tmpDir, srcDir string) error

WriteGogenIRWireup writes tmpDir/main_gogen_ir.go — a gogen_ir-tagged file that blank-imports every lowered-Go package under srcDir/pkg/rt/core_go_lowered so the wasm build links the native lowerings.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL