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
- func AssembleHTML(wasmExecJS, wasmGzB64 string, shell, externalWasm, hostEval bool) string
- func AssembleHTMLWithTemplate(template, wasmExecJS, wasmGzB64 string, externalWasm, hostEval bool) string
- func GoBuildArgs(wasmPath string, buildTags string) []string
- func HasBuildTag(rawTags, tag string) bool
- func ListGogenIRPackages(srcDir string) ([]string, error)
- func RenderMain(storeID string, hostEval bool) string
- func ResolveShell(wShell string) (customTemplate string, xtermShell bool, err error)
- func SplitProgramDebug(lgb []byte, outDir, override string) (stripped, companion []byte, path string, err error)
- func WriteGogenIRWireup(tmpDir, srcDir string) error
Constants ¶
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 ¶
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
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
HasBuildTag reports whether tag appears in rawTags (a `,`/space/tab/newline separated build-tag list).
func ListGogenIRPackages ¶ added in v1.12.0
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
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
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 SplitProgramDebug ¶ added in v1.13.0
func SplitProgramDebug(lgb []byte, outDir, override string) (stripped, companion []byte, path string, err error)
SplitProgramDebug strips a wasm bundle's program of its debug sections and returns the companion together with the path to write it to.
The path is derived from the bundle directory rather than a file inside it: every file in the output directory is served, and a debug sidecar is build output rather than something to hand to each visitor. outDir is canonicalized first, so `dist/`, `dist/.` and `.` all name the directory itself and never degrade the companion into a dotfile inside it.
override, when non-empty, selects the companion path explicitly. It is rejected when it names the bundle directory or anything under it: an override such as dist/index.html would pass a same-path check and then replace a generated asset with binary debug data.
func WriteGogenIRWireup ¶ added in v1.12.0
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.