Tools7 min read

CLI Reference

Complete reference for the bwslc command-line compiler.

Reading Time
7 min
Word Count
1,127
Sections
28
Try It Live

Turn the guide into code

Take the key idea from this page into the playground and validate it in a real shader instead of leaving it as theory.

Open Playground

The bwslc command compiles .bwsl shader files to SPIR-V internally and can emit SPIR-V, Metal, HLSL, GLSL, and GLSL ES artifacts.

Examples below use bwslc. In a source checkout, that binary is typically ./build/bwslc.

Basic Usage

bash
bwslc <input.bwsl | directory> [more inputs...] [options]

Passing more than one input, a directory, or -manifest activates batch mode. Batch mode compiles every discovered unit and reports all failures together instead of stopping at the first failed file.

Options

Core Options

OptionDescription
-o <dir>Output directory (default: current directory)
-manifest <file>Read input files or directories from a manifest file
-modules <dir>Add a module search path (repeatable)
-variant <k=v>Specialize one named shader variant (repeatable)
-dump-variant-spacePrint variant reflection JSON and exit
-checkRun diagnostics without writing output files
--stdinRead source from stdin instead of the input file
--source-file <path>Source path used for diagnostics/module resolution with --stdin
-pass <name>Compile a specific pass (default: all passes)
-stage <name>Compile a specific stage: vertex, fragment, or compute
-watchStay resident and recompile changed source or imported module files
-watch-interval <ms>File polling interval for -watch (default: 250, minimum: 20)

Output Format Flags

SPIR-V is generated internally for validation and cross-compilation. If no output format is requested, the CLI writes SPIR-V by default; when other formats are requested, use -spv to also write .spv sidecars.

FlagDescription
-spvWrite generated SPIR-V files alongside requested artifacts
-metalGenerate Metal Shading Language output
-hlslGenerate HLSL output
-glslGenerate GLSL 450 output
-glesGenerate GLSL ES 300 output
-gles-directGenerate GLSL ES directly from BWSL IR
-webglAlias for -gles
-bindingsEmit resolved resource binding JSON
-errors-jsonPrint machine-readable diagnostics JSON
-ast-jsonPrint parsed AST JSON and exit
-allGenerate all supported outputs

Debug Options

OptionDescription
-vVerbose output
-timingPrint timing information
-dump-irDump BWSL IR
-debug-namesEmit debug names in SPIR-V output
-validation <auto|strict|off>Choose SPIR-V validation behavior (default: auto)
-no-validateSkip SPIR-V validation
-internalsWrite SPIR-V disassembly and IR dump to JSON
-h, --helpShow help

Examples

SPIR-V Only

bash
bwslc shader.bwsl

Use -spv when requesting other artifacts but still wanting SPIR-V files written:

bash
bwslc shader.bwsl -spv -metal

SPIR-V + Metal

bash
bwslc shader.bwsl -metal -spv

Multiple Output Formats

bash
bwslc shader.bwsl -metal -hlsl -gles

All Outputs

bash
bwslc shader.bwsl -all

Source-Declared Resources

bash
bwslc shader.bwsl -all -bindings

Resources are declared in the shader with resources {} and selected per pass with use resources { ... }. The -bindings flag emits the resolved host binding metadata for those source-declared resources.

Specialize Shader Variants

bash
bwslc shader.bwsl -variant skinning=true -variant lighting=Clustered -metal

Boolean variants accept true, false, 1, or 0. Enum variants accept either a bare member name or a qualified name such as LightingMode::Clustered.

Dump Variant Reflection

bash
bwslc shader.bwsl -dump-variant-space

This prints JSON describing declared variants, implicit variants, legality rules, and the current selected values. See Shader Variants for the language-side model.

Custom Output Directory

bash
bwslc shader.bwsl -o dist/shaders -all

Batch Compile Files

bash
bwslc lighting.bwsl postfx.bwsl ui.bwsl -check

Every file is checked and the process exits nonzero if any file fails. Text output includes a batch summary; JSON mode emits one aggregate document with per-file diagnostics.

Batch Compile a Directory

bash
bwslc shaders/ -o dist/shaders -metal -hlsl

Directory inputs are scanned recursively for .bwsl files. Outputs mirror the source subdirectories under -o, so files with the same stem in different folders do not overwrite each other.

Use a Manifest

bash
bwslc -manifest shaders.txt -check -errors-json

Manifest files contain one file or directory per line:

text
# paths are relative to this manifest file
pipelines/
effects/bloom.bwsl
ui/hud.bwsl

Blank lines and # comments are ignored. Directory entries are scanned the same way as positional directory inputs, and overlapping entries are deduplicated.

Watch for Changes

bash
bwslc shaders/ -modules modules/ -o dist/shaders -gles -watch

Watch mode performs an initial build, then recompiles changed units when a source file or imported module file changes. Directory and manifest inputs are rescanned on each polling tick, so added and removed .bwsl files are picked up without restarting the compiler.

Use -errors-json when an editor or engine hot-reload process wants one parseable JSON build report per rebuild:

bash
bwslc shaders/ -modules modules/ -o dist/shaders -gles -watch -errors-json

Tune polling when needed:

bash
bwslc shaders/ -watch -watch-interval 100

Compile a Specific Pass

bash
bwslc shader.bwsl -pass MainPass

Compile a Specific Stage

bash
bwslc shader.bwsl -pass Simulate -stage compute

Add Module Search Paths

bash
bwslc shader.bwsl -modules ./modules -modules ./lib/shaders

Standard-library modules are embedded in the compiler, so imports such as import Math, import Debug, or import Sampling do not require a -modules path. Module search paths are still used for project modules. A disk module cannot override an embedded standard-library module name.

Emit JSON Diagnostics

bash
bwslc shader.bwsl -errors-json

This prints schema-versioned diagnostic JSON with severities, phases, stable BWSL... error codes, source locations, token details, and source context when available. Use it for editor integrations, CI annotations, and build tools that should not parse human-readable compiler output.

See Diagnostics for the JSON schema and complete error-code table.

For batch inputs, -errors-json emits a single aggregate document with batch: true, summary counts, and a files array of normal per-file diagnostic documents. For watch mode, each rebuild emits one aggregate JSON document with watch: true and event: "build".

Emit AST JSON

bash
bwslc shader.bwsl -ast-json

This parses the source and prints AST JSON for IDEs, code browsers, documentation tooling, and other structural integrations. The top-level object uses schema: "bwsl.ast.v2" and includes sourceFile, root, modules, pipelines, and nodeCounts.

AST nodes include id, type, index, line, column, and end positions when available. Variable declarations also expose typeLine, typeColumn, nameLine, and nameColumn. Declarations preceded by /// line comments or /** ... */ block comments can include a docs object with raw text, summary, @param entries, return text, and remaining tags.

Control SPIR-V Validation

bash
bwslc shader.bwsl -validation strict

Validation modes:

ModeBehavior
autoValidate when the SPIR-V validation tool is available; warn and continue if it is missing.
strictRequire validation and fail if the validation tool is missing or reports an error.
offSkip validation. -no-validate is an alias for this mode.

Emit Internal Debug Data

bash
bwslc shader.bwsl -internals -o build/shaders

Input Compatibility

Some modes intentionally stay single-input:

CombinationBehavior
--stdin with files, directories, or -manifestRejected
--stdin with -watchRejected
-ast-json with multiple inputsRejected
-dump-variant-space with multiple inputsRejected
-ast-json or -dump-variant-space with -watchRejected

Output Notes

Each compiled pass emits one output per selected stage and target format into the chosen output directory. Graphics passes produce vertex and fragment outputs; compute passes produce compute outputs.

For single-pass shaders, stage outputs use the input basename directly, such as shader.vert, shader.frag, and matching sidecars like shader.vert.json or shader.vert.spv. For multi-pass shaders, the pass name is appended to the stem, such as shader_MainPass.vert and shader_PostFX.frag.

In batch mode, multiple explicit files write into the selected output directory. Directory inputs preserve relative subdirectories under -o.

See Also