“Hello World” in Zig

  • Creating
➜  zig-playground git:(master) ✗ cat src/main.zig
const std = @import("std");

pub fn main() !void {
    var stdout_file = try std.io.getStdOut();
    try stdout_file.write("Hello from Zigland!\n");
}
  • Running
➜  zig-playground git:(master) ✗ zig build run
Hello from Zigland!
  • Looking at builds:
➜  zig-playground git:(master) ✗ l zig-cache/o
drwxr-xr-x - agam 20 May 18:34 1FaU34FwI7Ct04pmfOlMacuOykIOisQtTn1t1Q3lrQOZcsEF0qxJW3vLauzHjpwm
drwxr-xr-x - agam 20 May 18:36 fyjPplfax8VTFYlidzFwMj_gV5Dw_T9T4PVTNBaOPnxDE5dq2XRo28L0b-87xi0l
drwxr-xr-x - agam 20 May 18:36 r-sdQS7ThLQpXn2OhOye0gD2RSuygbP_R6dWnLJZKjgjdWqQxTSCKB3dHKbWucMG
drwxr-xr-x - agam 21 May 23:21 XxkweE8uWyMc9LocxqJMMKAwTGgBzcn4q3bEKH1tL8Kx-F5Gk3kopgQqLbVLXVbh
  • Debug build size:
➜  zig-playground git:(master) ✗ l zig-cache/o/r-sdQS7ThLQpXn2OhOye0gD2RSuygbP_R6dWnLJZKjgjdWqQxTSCKB3dHKbWucMG/zig-playground
.rwxr-xr-x 406k agam 20 May 18:36 zig-cache/o/r-sdQS7ThLQpXn2OhOye0gD2RSuygbP_R6dWnLJZKjgjdWqQxTSCKB3dHKbWucMG/zig-playground
  • “Release build” size:

zig build -Drelease-small=true

➜  zig-playground git:(master) ✗ l zig-cache/o/XxkweE8uWyMc9LocxqJMMKAwTGgBzcn4q3bEKH1tL8Kx-F5Gk3kopgQqLbVLXVbh/zig-playground
.rwxr-xr-x 53k agam 21 May 23:21 zig-cache/o/XxkweE8uWyMc9LocxqJMMKAwTGgBzcn4q3bEKH1tL8Kx-F5Gk3kopgQqLbVLXVbh/zig-playground

So, 406k for the debug build, 53k for the release build, very similar to Nim here, and comparing very favorably indeed to Rust or Go (!)