Docs/Getting started

Command line

Build, run, check and format code with the valk command.

On this page

The valk command compiles, runs, checks and formats code. Every command takes a directory, such as src, or one or more .valk files.

Build an executable#

Terminal
valk build src -o app              # write ./app (app.exe on Windows)
valk build src -o app --release    # optimized
valk build hello.valk -o hello     # a single file works too

Unchanged files are not compiled again on the next build. --clean ignores that cache.

Build and run#

Terminal
valk build src -o app --run         # build, then start it
valk run src -- alice bob           # build and run; program arguments go after --
valk build src -o app --run --watch # rebuild and restart when a file changes

The program reads its arguments in main, see Functions.

Run tests#

Terminal
valk build src --test --run
valk build src tests --test --run                  # tests kept in their own directory
valk build src tests --test --filter "login" --run # only tests whose name contains "login"
valk build src tests --test --coverage --run       # print line and function coverage

Pass -- --coverage-uncovered to list missed lines or -- --coverage-out coverage.lcov to write an LCOV report. See Testing for writing tests and coverage.

Run benchmarks#

Terminal
valk bench src                            # build with --bench --opt and run
valk bench src --filter "hash"            # only benchmarks whose name contains "hash"
valk bench src -- --bench-time 1000       # target duration in ms (default 250)
valk build src --bench --release -o bench # build once, run later

valk bench enables --bench, --opt (unless --opt or --release is already passed), and --run. See Benchmarks.

Check without building#

Terminal
valk build src --lint
valk build src --lint --deny-warnings # fail if any warning is emitted (-Werror)

--lint reports errors and warnings for every source file of the package, without needing a main and without writing an executable. Add --all-errors to list every error instead of only the first, or --deny-warnings (-Werror) to fail the build on any warning.

Format code#

Terminal
valk fmt src           # format in place, list the files that changed
valk fmt src --check   # list unformatted files and exit 1, write nothing (for CI)

Look up documentation#

Terminal
valk doc Array.sort             # one declaration of the standard library
valk doc http.Server            # a type and its members
valk doc . Client.request       # a declaration of the package in this directory
valk doc . --markdown -o api.md # docs for a whole project

The text comes from the /// comments above declarations, see Documentation comments.

Common build options#

Option Effect
-o path Output path
--run, -r Run after building
--watch, -w Rebuild when a file changes
--test, -t Build the tests instead of main
--bench Build the benchmarks instead of main (Testing)
--coverage Track which lines and functions run and print a coverage report on exit (Testing)
--filter name Only build tests or benchmarks whose name contains name
--opt Build with optimizations
--release All optimizations, no symbol table
--debug, -d Debug info, stack trace on panic (Debugging)
--stack-traces Line tables and panic stack traces without disabling optimizations (Debugging)
--target name Build for another platform: linux-x64, linux-arm64, macos-x64, macos-arm64, win-x64 (Cross compiling)
--cpu name Use the CPU features of native or a named CPU such as x86-64-v3
--def A=1,B=2 Set compile-time definitions
--no-warn, -nw Hide warnings
--deny-warnings, -Werror Fail the build when any warning is emitted
--clean, -c Ignore the build cache
-v, -vv, -vvv Show compile details

valk build -h lists every option.

Project commands#

A project can name its own build and run steps under make in valk.json:

JSON
{
    "make": {
        "app": { "dir": "src", "args": "-o ./app" },
        "test": ["valk build src tests --test -o ./test-bin", "./test-bin"]
    }
}
Terminal
valk ls          # list the project's commands
valk make app    # run one
valk make        # run the first one

An entry with dir is compiled with args; a line or a list of lines is run as shell commands.

Editor and shell support#

  • valk lsp run starts the language server; the VS Code extension runs it for you.
  • valk completion bash prints tab completion for bash; zsh and fish also work.
  • valk version prints the compiler version. Use vman to install or switch versions, see Projects & packages.