Skip to content
Kavachकवच

The kavach Command: build

● Intermediate2 min

kavach build writes an executable: one file that runs your program at native speed.

terminal
kavach build
built .kavach/bin/my-app.exe

In a project, the executable goes to .kavach/bin/, named after the project. One file, kavach build hello.kav, becomes hello (hello.exe on Windows) in the current folder; -o names it. See Native Executables.

A smaller executable

terminal
kavach build --compress hello.kav -o hello
./hello

--compress packs the executable without losing anything: it unpacks itself when it starts, and the build prints what it saved, such as packed: 571 KB, 42% of 1346 KB. --compress=max packs harder. Some antivirus tools distrust programs that unpack themselves, which is why packing is asked for, not done by default.

A program's version

Every executable carries its package's name and version from kavach.toml, and the version and commit of the compiler that built it. kavach version prints them, so a program found on a server can be traced to its source:

terminal
kavach version .kavach/bin/my-app
my-app 0.1.0
built by kavach 0.1.0 (commit 8f8ae051)
  • A program built from one file has the file's name and no version.
  • With version_flag = true under [build] in kavach.toml, the program answers --version itself: given that one argument, it prints the same two lines and ends with exit code 0, before main runs. This holds however it runs: kavach run -- --version, run --native and the built executable.
  • Without the setting, --version is an argument like any other, for the program to read.
  • A program linked with the run-time library of another Kavach stops at its start with exit code 2 and a message saying so, instead of calling the wrong operations.