Documentation
¶
Overview ¶
Package wesl embeds the official WESL JavaScript transpiler and runs it via the goja JavaScript runtime, letting Go code link WESL/WGSL sources into a single WGSL string without a Node.js dependency.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var Stdout atomic.Pointer[io.Writer]
Stdout, if set, receives console output (console.log/info/warn/error) from the embedded transpiler. When nil (the default) that output is discarded.
Functions ¶
This section is empty.
Types ¶
type Bundle ¶ added in v1.1.0
type Bundle struct {
// Name is the npm package name sanitized to be a valid WESL identifier
// (@ removed, / => __, - => _).
Name string
// Edition is the WESL edition of the code, e.g. "2026_pre".
Edition string
// Modules maps file paths (relative to the package root, e.g. "./lib.wgsl")
// to WESL/WGSL code strings.
Modules map[string]string
// Dependencies are the packages referenced by this package.
Dependencies []Bundle
}
Bundle is a bundle of WESL/WGSL modules that can be provided to the transpiler as a library.
type Files ¶
Files describe an in-memory file system that contains all files available to the transpiler.
type Options ¶
type Options struct {
// Files to present to the wesl transpiler
Files Files
// Constants to inject into the transpiler.
// Value must be either int, float32 or string
Constants map[string]any
// Conditions for @if etc
Conditions map[string]bool
// PackageName for the local sources (in addition to default "package::").
// Enables imports like `import mypkg::foo` alongside `import package::foo`.
// Should be a valid WGSL identifier (use underscores, not hyphens or slashes).
PackageName string
// Libs are library bundles available for the link.
Libs []Bundle
}
Options configures a single Transpile call.
type Transpiler ¶
type Transpiler struct {
// contains filtered or unexported fields
}
Transpiler links WESL/WGSL sources into WGSL. A Transpiler owns a JavaScript runtime and is not safe for concurrent use; create one per goroutine or guard it with a mutex. It can be reused across many Transpile calls.
func New ¶
func New() *Transpiler
New creates a Transpiler by spinning up a goja runtime and loading the embedded wesl JavaScript. It panics if the embedded source fails to load; since that only happens on a broken build, reuse a single Transpiler rather than creating one per call.
func (*Transpiler) Transpile ¶
func (t *Transpiler) Transpile(entrypoint string, opts Options) (string, error)
Transpile links the module graph rooted at entrypoint (a file name such as "main.wesl") into a single WGSL string, pulling in referenced local files and library bundles. Dead code outside the root is dropped. It returns an error if parsing or linking fails.