A Go implementation of the WESL compiler — a superset of WGSL that adds a module system with cross-file imports and compile-time @if conditionals. It takes one or more WESL source files and produces a single, flat WGSL output suitable for use with the WebGPU API.
import "github.com/bluescreen10/wesl-go"
// Create a compiler instance.
c := wesl.New()
// Register source files. Paths are stored relative to the FS root so that
// package:: imports resolve correctly.
c.ParseFS(os.DirFS("./shaders"), "**/*.wesl")
// Compile an entry-point file, optionally passing compile-time feature flags.
wgsl, err := c.Compile("main.wesl", map[string]bool{"MY_FEATURE": true})
if err != nil {
log.Fatal(err)
}
fmt.Println(wgsl)Test cases are adapted from the WESL Test Suite maintained by the WebGPU Shading Language tooling working group.
