zag

πŸš€ Getting Started with Zag

Welcome to Zag! This guide will walk you through setting up the Zag compiler and building your very first program.

πŸ“‹ Prerequisites

Before we begin, ensure you have the following installed on your system:

  1. Zig (0.15.0 or higher): Zag is written in Zig and uses its build system.
  2. C Compiler: Zag transpiles to C, so you need a C compiler like gcc, clang, or cc available in your $PATH.

πŸ› οΈ Step 1: Clone the Repository

First, download the Zag source code from GitHub:

git clone https://github.com/dtasada/zag.git
cd zag

πŸ—οΈ Step 2: Build the Compiler

Zag uses the standard Zig build system. You can build the compiler executable with a single command:

zig build install --prefix ~/.local

This will copy the zag compiler into ~/.local/bin/zag. If ~/.local/bin/ is in your $PATH, running zag will work. If not, add ~/.local/bin to your $PATH. You could also choose any other install prefix.

πŸ“ Step 3: Your First Zag Program

Create a new file at src/main.zag in the root directory:

// hello.zag
bind fn printf(fmt: &c_char, args...) c_int;

fn main() i32 {
    printf("Hello, Zag world!\n");
    return 0;
}

πŸš€ Step 4: Compile and Run

# Run the build command
zag build

What happened?

  1. Transpilation: The Zag compiler translates the Zag code into C code.
  2. Native Compilation: Zag invokes your system’s C compiler to produce a native binary.
  3. Binary: You can find your final executable in .zag-out/bin/main.

Try running it:

./.zag-out/bin/main

πŸ” Troubleshooting