01 / Prepare

Build the tools

Clone Ziran and build the tools. You need a C compiler and make. Go is needed only to run generated Go output. build/bin/ziran version prints the version you built; the latest release is v0.3.1.

git clone https://github.com/ziranlang/ziran.git
cd ziran
make

make builds in parallel on half of your cores at low priority, so the rest of the machine stays responsive. make install-user puts ziran in ~/.local/bin; the commands below use build/bin/ziran so they work without installing. To run the project’s tests, use make check. Prebuilt downloads are not available yet.

02 / Source

Write a module

Save this as hello.zi. A source file is a module named after its filename.

main :: () {
    print("Hello, World!\n");
}

print substitutes each % in its format with the next argument, so print("Hello, %!\n", name) greets any name. Write %% for a percent sign.

Download hello.zi ↓

03 / Check and execute

Run the checked program

build/bin/ziran check --root . hello.zi
build/bin/ziran bundle --root . --entry hello:main -o hello.zx hello.zi
build/bin/ziran run hello.zx

The last command prints Hello, World!. To save checked IR, use build/bin/ziran ir --root . -o out hello.zi.

04 / Native output

Build a native program

The same checked source generates Go or C. For Go, --exe with an entry writes a runnable program:

build/bin/ziran build --target=go --pkg main --exe --entry hello:main --root . -o out/go hello.zi
(cd out/go && go run .)

C output is a module with a header that your program calls. Put #program_export on the line before main to make it a complete program:

build/bin/ziran build --target=c --root . -o out/c hello.zi
cc -std=c99 -Iout/c out/c/hello.c -o hello && ./hello

Every example on the examples page prints the same output on each of these targets.

Keep going

Follow the source contract