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.

text
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 text

vyi 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.

ArgumentCompiles
path/to/file.vyithat file as the entry
namethe entry called name in the entries of the nearest package.vyipac
noneevery 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:

SituationMessage
no package.vyipac foundno package.vyipac found (pass a .vyi path, or run inside a package)
the manifest has no entriespackage.vyipac declares no entries (pass a .vyi path, or add an entries block)
the name isn't an entryno 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:

sh
vyi run --target x86-64-linux hello.vyi

Flag 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:

text
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).

sh
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:

BuildingWithout -oWith -o <path>
one programout/<target>/<name><path>
several entriesout/<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:

--emitWritesDestination for one program
wasm (default)the program: a WebAssembly module on wasm, a linked executable on x86-64-linux and arm64-linuxthe output path above
watWebAssembly text. wasm target onlystdout; with -o <path>, that file (-o - is stdout)
asmthe target's own listing: WebAssembly text on wasm, x86-64 assembly on x86-64-linux, AArch64 assembly on arm64-linuxas 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.

sh
vyi run hello.vyi
vyi run hello.vyi --verbose orders.txt
vyi run --target arm64-linux hello.vyi

Everything 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:

TargetHow vyi run runs it
wasmin 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-linuxlinks a temporary executable and runs it
arm64-linuxlinks 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 programPrints on stderrExit status
returns Ok(n) from mainnothingn
returns Err(e) from mainerror: and the error's message1
panics and nothing recoverspanic: , the reason, and the calls that led there101
runs out of stack on wasmvyi run: stack overflow1
is stopped by a signal on a native targetvyi 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).

sh
vyi check hello.vyi
vyi check --json hello.vyi

A 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:

text
 ✓ 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.

sh
vyi ast hello.vyi
vyi ast --pre-elaborate --spans hello.vyi
vyi ast --file src/lib.vyi
FlagEffect
nonethe tree after the compiler has resolved imports and rewritten shorthand forms such as ?T into what they stand for
--pre-elaboratethe tree exactly as parsed, before any rewriting
--spansadds 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

FlagCommandsMeaning
--target <name>allthe target: wasm (default), x86-64-linux, or arm64-linux (Targets). Another name exits with status 2
--os <name>allthe 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>allthe folder that holds the standard packages (search order)
--mode <mode>build, run, check, testthe build mode: debug (default) or release (build modes). Another value exits with status 2
--passes <list>build, run, check, testturns 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, testturns 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, testhow 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, testhow 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>buildthe output path, or the output folder for several entries
--emit <kind>buildwasm (default), wat, or asm
--asm-map <path>buildwith --emit asm, write the listing's source map to <path>
--timingsrunprint the VYI_TIMINGS line after the run
--jsoncheckprint errors as JSON on stdout
--pre-elaborateastprint the tree as parsed
--spansastadd each node's byte offsets
--file <path>astprint 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

VariableEffect
VYI_STDLIB_PATHthe folder that holds the standard packages, when --packages isn't given
VYI_PACKAGESthe same, read after VYI_STDLIB_PATH
XDG_DATA_HOME, XDG_DATA_DIRSfurther places to look for the standard packages (search order)
NO_COLORset to print errors without color
VYI_FORCE_COLORset (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

StatusWhen
0the command succeeded: the files were written, check found no errors, the program returned Ok(0), every test file passed
1a 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
2a 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:

text
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 error

A 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:

text
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.

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 }
    }
  }
]
FieldMeaning
paththe file, relative to the package root or the entry file's folder
opthe kind of error, a name that stays the same from release to release, such as notAssignable or undefinedName
severityerror, warning, info, or hint
messagethe text a person reads
rangewhere 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.