CLI Reference
The weir CLI is the main interface for compiling and running Weir programs. It supports both single-file mode (pass a .weir file) and package mode (discover weir.pkg in the current directory).
Commands
Section titled “Commands”weir run [file]
Section titled “weir run [file]”Compile and run a Weir program via Cranelift JIT.
weir run hello.weir # single fileweir run # package mode (reads weir.pkg)weir run --load libfoo.so # pre-load a shared library| Option | Description |
|---|---|
file | Path to .weir source file. Omit to use weir.pkg. |
--load <path> | Pre-load a shared library (makes symbols available via dlsym). Repeatable. |
weir build [file]
Section titled “weir build [file]”Compile a Weir program to a standalone native binary via AOT compilation.
weir build hello.weir # outputs ./helloweir build hello.weir -o bin/hello # custom output pathweir build -l glfw -l GL # link C librariesweir build --cc-arg helper.c # pass extra files to the C compilerweir build # package mode| Option | Description |
|---|---|
file | Path to .weir source file. Omit to use weir.pkg. |
-o, --output <path> | Output binary path. Defaults to source file stem or package name. |
-l, --link <lib> | Link against a C library (e.g. -l glfw). Repeatable. |
--cc-arg <arg> | Pass raw arguments to the C compiler. Repeatable. |
weir dev [file]
Section titled “weir dev [file]”Run a Weir program with live reloading. Watches for file changes and hot-swaps functions without restarting.
weir dev game.weir # watch single fileweir dev # package modeweir dev --load libfoo.so # pre-load libraries| Option | Description |
|---|---|
file | Path to .weir source file. Omit to use weir.pkg. |
--load <path> | Pre-load a shared library. Repeatable. |
When a file changes:
- The source is re-read, re-lexed, re-parsed, and re-typechecked
- Changed functions are recompiled via Cranelift
- Function pointers are swapped in the running program
- Execution continues with the new code
If the new code has errors, the old version keeps running and errors are reported.
weir check <file>
Section titled “weir check <file>”Type-check a Weir file without running it.
weir check hello.weirOutputs OK — no type errors on success, or type errors with locations on failure.
weir parse <file>
Section titled “weir parse <file>”Parse a Weir file and dump the AST. Useful for debugging the parser.
weir parse hello.weirweir interp <file>
Section titled “weir interp <file>”Run a Weir file via the tree-walking interpreter. Slower than JIT, but useful for debugging and testing.
weir interp hello.weirweir expand <file>
Section titled “weir expand <file>”Expand macros and print the resulting source. Like cargo expand for Rust.
weir expand hello.weirweir lsp
Section titled “weir lsp”Start the Weir Language Server Protocol server. Typically invoked by an editor, not directly.
weir lspPackage Mode
Section titled “Package Mode”When run, build, or dev are invoked without a file argument, the CLI looks for a weir.pkg manifest in the current directory:
cd demos/tetrisweir run # discovers weir.pkg, resolves deps, runs via JITweir build -o ../../tmp/tetris # AOT compile the packageweir dev # dev mode with live reloadThe package system:
- Parses
weir.pkgfor metadata, sources, and dependencies - Recursively resolves path-based dependencies
- Topologically sorts the dependency graph
- Validates import statements against actual module exports
- Compiles native C sources (if any) into a shared library
- Concatenates all sources and runs the standard pipeline
See Package System for details.