Thor build tool
Thor is Zap’s project build tool. It keeps the compiler command, import maps,
native linker flags, and dependencies in one thor.toml file. Thor lives in
the tools/thor
submodule of the Zap repository, but it can also be installed as its own
project.
Create a project
Section titled “Create a project”Create a scaffold and enter it:
thor new hellocd hellothor runThe generated project has an entry file, a thor.toml, and a build/
directory for outputs. Thor uses the compiler’s normal prelude, so common
standard-library names such as List are available without a long
collection.List spelling.
Build and run
Section titled “Build and run”thor buildthor runUseful command-line overrides are:
thor build --compiler /path/to/zapcthor build -o build/custom-appthor build -O2thor build -- --emit-irThe -- marker passes the remaining flags directly to zapc. thor run
builds first and then executes the selected output.
Configure a project
Section titled “Configure a project”Here is a small configuration:
name = "hello"version = "0.1.0"out = "build/"entry = "src/main.zp"optimization = "O2"flags = "-Lnative -lm"
[imports]"@shared" = "../shared/src"
[dependencies]"zap-toml" = { url = "https://github.com/thezaplang/zap-toml", version = "0.1.0", commit = "..." }entry is the source file passed to the compiler. out selects the output
directory, flags adds compiler or linker flags, and optimization accepts
O0 through O3. Entries in [imports] become compiler import-map flags.
Dependencies are restored under vendor/<name> and their own build metadata
is used when present. Thor does not copy Zap’s standard library into each
project: it invokes the selected zapc, which resolves the standard library
from that compiler installation.
Add a dependency
Section titled “Add a dependency”thor add https://github.com/example/widgetthor buildthor add records the dependency in thor.toml. The next build restores and
builds it before compiling the project.
Build Thor from source
Section titled “Build Thor from source”The repository version is bootstrapped with the Zap compiler, then rebuilt by Thor:
git clone https://github.com/thezaplang/thorcd thor./build.sh./build/thor buildzapc must be available in PATH. The bootstrap build also restores Thor’s
pinned zap-toml dependency.