Docs · Toolchain
The vyi CLI
vyi is the compiler. This page lists every command, every flag, and every
exit status. Installing Vyi gets vyi onto your machine, and
guide 17, Tooling walks through the commands by
example.
vyi build [flags] [program] compile to a file
vyi run [flags] [program] [args...] compile and run
vyi check [flags] [program] report errors; write nothing
vyi test [flags] [dir] run every *.tests.vyi file under dir
vyi ast [flags] [program] print the syntax tree as JSON
vyi help print the usage textvyi help, vyi -h, and vyi --help print the usage text to stdout and exit
with status 0. vyi with no command, or with an unknown one, prints it to
stderr and exits with status 2.
Naming the program
build, run, check, and ast take one optional argument that says which
program to compile. An argument that ends in .vyi is a file; any other
argument is the name of an entry in a manifest.
| Argument | Compiles |
|---|---|
path/to/file.vyi | that file as the entry |
name | the entry called name in the entries of the nearest package.vyipac |
| none | every entry in the nearest package.vyipac, one after another, in order of name |
A .vyi file needs no manifest. When the file sits in a package whose
package.vyipac declares entries, it must be one of those entries, and any
other file is a usage error:
src/tool.vyi is not a declared entry in package.vyipac (have: shop, shop-admin).
An entry name, or no argument, needs a package.vyipac. vyi looks for it in
the current folder and then in each folder above it. These are usage errors,
with exit status 2:
| Situation | Message |
|---|---|
no package.vyipac found | no package.vyipac found (pass a .vyi path, or run inside a package) |
the manifest has no entries | package.vyipac declares no entries (pass a .vyi path, or add an entries block) |
| the name isn't an entry | no bin "nosuch" in package.vyipac entries (have: shop, shop-admin) |
The usage text says these commands require a package.vyipac. That holds
only for an entry name or no argument; a .vyi file works without one.
Before it compiles, vyi checks each entry the manifest declares. An entry
whose file doesn't exist, or whose file has no top-level main, is reported on
stderr as vyi: entryFileMissing: ... or vyi: entryFileNoMain: ... and left
out; the command goes on with the others (manifest).
When a command handles more than one entry, run, check, and ast print
=== name === on stderr before each one.
Flags go before the program
Flags go between the command and the program:
vyi run --target x86-64-linux hello.vyiFlag parsing stops at the first argument that isn't a flag. For vyi run,
everything after the program goes to your program as its arguments. The other
commands take nothing after the program, and anything there is a usage error
that says the flag goes first:
vyi build: unexpected arguments after the bin: [--target x86-64-linux] (flags go before the bin name)A flag's value can follow it (--target wasm) or be joined with =
(--target=wasm). One dash works as well as two (-target wasm). An unknown
flag prints flag provided but not defined and the command's usage line, and
exits with status 2.
Commands
vyi build
Compiles each program and writes it to a file. For each file it writes, it
prints wrote <path> on stderr; for a WebAssembly module the line ends with
the size, as in wrote out/wasm/hello (10850 bytes).
vyi build hello.vyi # out/wasm/hello
vyi build --target x86-64-linux hello.vyi # out/x86-64-linux/hello
vyi build -o hello.wasm hello.vyi # hello.wasm
vyi build # every entry
vyi build -o dist # every entry, under dist/Where the output goes:
| Building | Without -o | With -o <path> |
|---|---|---|
| one program | out/<target>/<name> | <path> |
| several entries | out/<target>/<name> for each | <path>/<target>/<name> for each |
<name> is the entry's name, or the file's name without .vyi. Folders that
don't exist are created.
--emit picks what to write:
--emit | Writes | Destination for one program |
|---|---|---|
wasm (default) | the program: a WebAssembly module on wasm, a linked executable on x86-64-linux and arm64-linux | the output path above |
wat | WebAssembly text. wasm target only | stdout; with -o <path>, that file (-o - is stdout) |
asm | the target's own listing: WebAssembly text on wasm, x86-64 assembly on x86-64-linux, AArch64 assembly on arm64-linux | as for wat |
These are usage errors, with exit status 2: any other --emit value; `--emit
wat with a native target (--emit wat is the wasm listing; target
x86-64-linux lists with --emit asm); and --emit wat or --emit asm` for
several entries without -o <dir>.
--asm-map <path> goes with --emit asm and one program. It writes a JSON
array to <path> that maps listing lines to source: each element has line
(the listing line), start and end (byte offsets in the source file), and
file. Only the arm64-linux listing records lines today; on the other
targets the array is empty. --asm-map without --emit asm, or with several
entries, is a usage error.
A native build links the program with a C compiler: the first of cc, gcc,
and clang on your PATH for x86-64-linux, and aarch64-linux-gnu-gcc for
arm64-linux (Targets). Without one, the build stops with
no C compiler found (need cc, gcc, or clang to link) or
no aarch64 C compiler found (need aarch64-linux-gnu-gcc) and exit status 1.
A program with an error writes nothing. When several entries are built, the others are still written, and the exit status is 1.
vyi run
Compiles each program in memory and runs it. Nothing is written to disk except a temporary executable for a native target, which is deleted afterwards.
vyi run hello.vyi
vyi run hello.vyi --verbose orders.txt
vyi run --target arm64-linux hello.vyiEverything after the program is passed to it as its arguments, read with
args() from @io. A -- right after the program is dropped, so
vyi run hello.vyi -- --verbose passes only --verbose. The program's name
is not among the arguments.
How each target runs:
| Target | How vyi run runs it |
|---|---|
wasm | in a runtime built into vyi. The program's standard input, output, and error are the terminal's, and it can open files by paths relative to the current folder |
x86-64-linux | links a temporary executable and runs it |
arm64-linux | links a temporary executable and runs it, through qemu-aarch64 when the machine isn't arm64 |
The exit status of vyi run is the program's (guide 07):
| The program | Prints on stderr | Exit status |
|---|---|---|
returns Ok(n) from main | nothing | n |
returns Err(e) from main | error: and the error's message | 1 |
| panics and nothing recovers | panic: , the reason, and the calls that led there | 101 |
runs out of stack on wasm | vyi run: stack overflow | 1 |
| is stopped by a signal on a native target | vyi run: program terminated by signal 11 (segmentation fault) | 128 plus the signal's number |
A native program that runs out of stack is stopped by signal 11 and exits with status 139 (guide 08).
When the program doesn't compile, vyi run prints the errors and exits with
status 1 without running anything. Given several entries, it runs each in turn
and exits with the last non-zero status, or 0.
--timings adds one line to stderr after the run,
VYI_TIMINGS compile_ns=<n> run_ns=<n>, the nanoseconds spent compiling and
running. The line starts with the ASCII record separator (byte 0x1E) so a
tool that wraps vyi run can find it and remove it.
vyi check
Compiles each program for the target (wasm unless --target says otherwise)
and writes nothing. It runs every check vyi build would, including the
target's own (see Errors from a target).
vyi check hello.vyi
vyi check --json hello.vyiA program without errors prints ok: <file> on stderr. A program with errors
prints them on stderr followed by error: aborting due to N previous errors.
The exit status is 0 when every program checked is clean and 1 otherwise.
--json prints the errors on stdout as JSON instead
(JSON output).
vyi test
Finds every file whose name ends in .tests.vyi in the folder, which is .
unless you name one, and in every folder below it. It compiles and runs each
file as its own program and prints a pass or fail line for each test, the
failed tests with their locations, and totals:
✓ math/add.tests.vyi (1 test)
✓ adds
❯ math/sub.tests.vyi (2 tests | 1 failed)
✓ subtracts
× fails
⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯ Failed Tests 1 ⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯
FAIL math/sub.tests.vyi > fails
❯ math/sub.tests.vyi:7:5
Test Files 1 failed | 1 passed (2)
Tests 1 failed | 2 passed (3)A test file has no main: vyi test runs its top-level calls in order.
Guide 16 shows how to write one.
The exit status is the number of test files that failed, and 0 when all pass.
A file fails when one of its tests fails, when it doesn't compile (shown as
× <file> (unable to compile) after its errors), or when it stops before it
finishes. With no test files, vyi test prints
no *.tests.vyi files under <dir> and exits with status 0. A folder that
doesn't exist is a usage error.
vyi test takes the same --target values as the other commands. Native tests
link and run the way vyi run does.
vyi ast
Prints a program's syntax tree as JSON on stdout. Each node is an object whose
$kind names the node ("File", "FnDecl", "ImportDecl") and whose other
keys are its fields.
vyi ast hello.vyi
vyi ast --pre-elaborate --spans hello.vyi
vyi ast --file src/lib.vyi| Flag | Effect |
|---|---|
| none | the tree after the compiler has resolved imports and rewritten shorthand forms such as ?T into what they stand for |
--pre-elaborate | the tree exactly as parsed, before any rewriting |
--spans | adds each node's Span: its Start and End byte offsets in the file |
--file <path> | the tree of one file, given relative to the package root (or the current folder without a manifest), whether or not it has a main |
A file with syntax errors still prints the tree the parser could build, and
vyi ast exits with status 0; vyi check reports the errors. vyi ast takes
--target, --os, and --packages, and none of the build flags.
vyi help
Prints the usage text to stdout and exits with status 0. -h and --help
are the same command.
Flags
| Flag | Commands | Meaning |
|---|---|---|
--target <name> | all | the target: wasm (default), x86-64-linux, or arm64-linux (Targets). Another name exits with status 2 |
--os <name> | all | the operating system to compile for, which targetOS in @target reports. The default comes from the target: wasm for wasm, linux for the Linux targets. Another value can give a program that doesn't run |
--packages <dir> | all | the folder that holds the standard packages (search order) |
--mode <mode> | build, run, check, test | the build mode: debug (default) or release (build modes). Another value exits with status 2 |
--passes <list> | build, run, check, test | turns x86-64-linux optimization passes on (+name) or off (-name), comma-separated. Release turns all of them on except lir-schedule; debug turns none on. The names: inline, lir-pattern, copy-elide, bce, unroll, lir-simplify, regplace, isa-rewrite, schedule, prefetch, simd, lir-schedule |
--extensions <list> | build, run, check, test | turns x86-64-linux CPU features on (+name) or off (-name), comma-separated: avx2, avx, popcnt, bmi1, bmi2, avx512f. avx2, avx, and popcnt are on by default. Turning on avx2 turns on avx, avx512f turns on avx2 and avx, and bmi2 turns on bmi1 |
--comptime-max-depth <n> | build, run, check, test | how many calls deep one compile-time evaluation may nest. Overrides comptime.maxDepth in the manifest; the default is 1024. A negative value exits with status 2 |
--comptime-max-steps <n> | build, run, check, test | how many steps (loop iterations and calls) one compile-time evaluation may take. Overrides comptime.maxSteps in the manifest; the default is 100000. A negative value exits with status 2 |
-o <path> | build | the output path, or the output folder for several entries |
--emit <kind> | build | wasm (default), wat, or asm |
--asm-map <path> | build | with --emit asm, write the listing's source map to <path> |
--timings | run | print the VYI_TIMINGS line after the run |
--json | check | print errors as JSON on stdout |
--pre-elaborate | ast | print the tree as parsed |
--spans | ast | add each node's byte offsets |
--file <path> | ast | print one file's tree |
A --passes or --extensions term that doesn't start with + or -, or
names nothing on the list, exits with status 2 and lists the names. A
--comptime-max-depth or --comptime-max-steps of 0 leaves the limit to
the manifest.
Environment
| Variable | Effect |
|---|---|
VYI_STDLIB_PATH | the folder that holds the standard packages, when --packages isn't given |
VYI_PACKAGES | the same, read after VYI_STDLIB_PATH |
XDG_DATA_HOME, XDG_DATA_DIRS | further places to look for the standard packages (search order) |
NO_COLOR | set to print errors without color |
VYI_FORCE_COLOR | set (to anything but 0) to print errors in color even when stderr isn't a terminal; CLICOLOR_FORCE=1 does the same |
NO_COLOR wins over the others. With none of them set, vyi uses color when
stderr is a terminal and TERM isn't dumb.
Exit status
| Status | When |
|---|---|
| 0 | the command succeeded: the files were written, check found no errors, the program returned Ok(0), every test file passed |
| 1 | a program has an error, so nothing was written or run; the entry file can't be read; linking or writing failed; the standard packages weren't found; or the program run by vyi run returned an error or ran out of stack on wasm |
| 2 | a usage error: no command or an unknown one, an unknown flag or flag value, an argument after the program, an unknown entry name, no manifest where one is needed, an --emit that doesn't fit, a test folder that doesn't exist |
other (run) | the program's own status: n from Ok(n), 101 after a panic, 128 plus the signal's number after a signal |
other (test) | the number of test files that failed |
Errors
The compiler reports every error it finds in one run. It goes on after the
first error, and after a syntax error, so one vyi check gives the whole list.
Errors from all the files of a program come out together, ordered by file and
position, and each is printed once:
error: this value has type [*con]u8, but the binding is declared i32
--> order.vyi:2:25
|
2 | con quantity: i32 = "three"
| ^^^^^^^
note: expected type declared here
--> order.vyi:2:19
|
2 | con quantity: i32 = "three"
| ^^^
error: aborting due to 1 previous errorA path in an error is relative to the folder that holds the program's
package.vyipac, or to the entry file's folder when there is no manifest.
Errors from a target
A construct the target can't compile yet is reported as an error like any
other. Its message starts with the target's name, and it fails check, build,
and run on that target:
error: x86-64-linux: top-level initializer of "w" cannot be encoded into its static global slot
--> main.vyi:6:9
|
6 | mut w = W{ t: &p }
| ^^^^^^^^^^Here W is a struct with an interface field, and w is a file-level variable
initialized with a pointer in that field. The language server doesn't compile
for a target, so the editor doesn't show these errors; vyi check does.
JSON output
vyi check --json prints the same errors, in the same order, as a JSON array
on stdout. A clean program prints []. The exit status is the same as without
--json.
[
{
"path": "order.vyi",
"op": "notAssignable",
"severity": "error",
"message": "this value has type [*con]u8, but the binding is declared i32",
"range": {
"start": { "line": 2, "col": 25 },
"end": { "line": 2, "col": 32 }
}
}
]| Field | Meaning |
|---|---|
path | the file, relative to the package root or the entry file's folder |
op | the kind of error, a name that stays the same from release to release, such as notAssignable or undefinedName |
severity | error, warning, info, or hint |
message | the text a person reads |
range | where the error is: line and col count from 1, and end is one past the last character |
vyi check --json prints the array on one line; it is spread over several
lines above for reading.