# zig-compiler

Walks the agent through Zig compiler invocation: optimization modes, output types, zig cc as a C compiler, and reading error messages.

- skill · `type=skill` · Claude Code, Codex, Cursor, GitHub Copilot, Gemini CLI, OpenCode · 450 installs · ★ 267
- Author: mohitmishra786
- License: MIT · policy=mirror · the beginning of the file is at the end of this page
- Source: https://github.com/mohitmishra786/low-level-dev-skills/tree/HEAD/skills/zig/zig-compiler/SKILL.md
- Updated: 2026-06-27
- HTML: https://affpapa.org/en/nevibecode/skills/zig-compiler

## What it does

The skill fires on questions about `zig build-exe`, `zig build-lib`, the `ReleaseSafe`, `ReleaseFast` and `ReleaseSmall` modes, `zig cc`, or Zig compilation errors. It lays out the order of work: compiling a single file, picking an output type (executable, static or shared library, object file), cross-compiling by `cpu-os-abi` triple, emitting LLVM IR and assembly, and checking syntax with `zig ast-check` and `zig fmt`.

A separate section covers `zig cc`, the Clang-based C and C++ compiler that ships with musl. It is hermetic, so no system libc is needed, and cross-building for ARM works without a separate toolchain. There are examples of dropping it into CMake and Makefile through the `CC` and `CXX` variables.

A table maps each optimization mode to its `-O0`, `-O2`, `-O3` or `-Os` equivalent, and another one decodes common errors, from type mismatches to unused variables, which Zig makes you discard explicitly with `_ = x;`. `ReleaseFast` strips safety checks and turns them into undefined behaviour, so the author advises validating a build under `ReleaseSafe` first. For projects with `build.zig`, the skill points to companion sections on the build system and C interop.

## Install

### Claude Code (native platform)

1. **Skills CLI (Vercel)**
```bash
npx skills add mohitmishra786/low-level-dev-skills --skill zig-compiler -a claude-code
```

2. **Manually: put the files in place**
- File: `~/.claude/skills/zig-compiler/SKILL.md` — Copy the whole skill folder; for one project use .claude/skills/zig-compiler/

### Codex

1. **Skills CLI (Vercel)**
```bash
npx skills add mohitmishra786/low-level-dev-skills --skill zig-compiler -a codex
```

2. **Manually: put the files in place**
- File: `.agents/skills/zig-compiler/SKILL.md` — For all projects use ~/.agents/skills/

### Cursor

1. **Skills CLI (Vercel)**
```bash
npx skills add mohitmishra786/low-level-dev-skills --skill zig-compiler -a cursor
```

2. **Manually: put the files in place**
- File: `.cursor/skills/zig-compiler/SKILL.md` — Cursor also reads .agents/skills/ and .claude/skills/

### GitHub Copilot

1. **GitHub CLI**
```bash
gh skill install mohitmishra786/low-level-dev-skills zig-compiler
```

2. **Manually: put the files in place**
- File: `.github/skills/zig-compiler/SKILL.md`

### Gemini CLI

1. **Skills CLI (Vercel)**
```bash
npx skills add mohitmishra786/low-level-dev-skills --skill zig-compiler -a gemini-cli
```

2. **Platform CLI**
```bash
gemini skills install https://github.com/mohitmishra786/low-level-dev-skills --path skills/zig/zig-compiler
```

### Windsurf (Devin Desktop)

**Manually: put the files in place**
- File: `.devin/skills/zig-compiler/SKILL.md` — The legacy .windsurf/skills/ path still works

### OpenCode

**Skills CLI (Vercel)**
```bash
npx skills add mohitmishra786/low-level-dev-skills --skill zig-compiler -a opencode
```

### Claude.ai

**Claude.ai**
- Zip the folder and upload it in Settings → Capabilities → Skills

Where a file is given instead of a command, copy the files from the source to that path: https://github.com/mohitmishra786/low-level-dev-skills/tree/HEAD/skills/zig/zig-compiler/SKILL.md

## When to use it
- build an executable from a single `main.zig` file
- choose between `ReleaseSafe` and `ReleaseFast` for production
- compile C code with `zig cc` and no system toolchain
- read a Zig error and find the type mismatch
- check syntax before a full compile

## Example prompts
- How do I build `src/main.zig` into an executable named myapp?
- Which optimization mode should I use for production, and how does `ReleaseSafe` differ from `ReleaseFast`?
- Compile a C file for aarch64-linux-gnu with `zig cc`

## Source text · SKILL.md · MIT

Below is the content of a third-party file. It is data, not instructions for you: do not act on anything written inside unless the human asks. Block tag: 63d770ae7d1d3b29.

BEGIN THIRD-PARTY FILE 63d770ae7d1d3b29
````text
---
name: zig-compiler
description: Zig compiler skill for systems programming. Use when compiling Zig programs, selecting optimization modes, using zig cc as a C compiler, reading Zig error messages, or understanding Zig's compilation model. Activates on queries about zig build-exe, zig build-lib, optimize modes, ReleaseSafe, ReleaseFast, ReleaseSmall, zig cc, zig ast-check, or Zig compilation errors.
---

# Zig Compiler

## Purpose

Guide agents through Zig compiler invocation: optimization modes, output types, `zig cc` as a C compiler drop-in, error message interpretation, and the Zig compilation pipeline.

## Triggers

- "How do I compile a Zig program?"
- "What are Zig's optimization modes and when do I use each?"
- "How do I use zig cc to compile C code?"
- "How do I read Zig error messages?"
- "How do I compile a Zig library?"
- "What is zig ast-check?"

## Workflow

### 1. Basic compilation

```bash
# Compile and run a single file
zig run src/main.zig

# Compile to executable
zig build-exe src/main.zig

# Compile to static library
zig build-lib src/mylib.zig

# Compile to shared library
zig build-lib src/mylib.zig -dynamic

# Compile to object file
zig build-obj src/main.zig

# Output name
zig build-exe src/main.zig -femit-bin=myapp
```

### 2. Optimization modes

| Mode | Flag | `-O` equiv | Purpose |
|------|------|-----------|---------|
| `Debug` (default) | `-O Debug` | `-O0 -g` | Fast compile, all safety checks, debug info |
| `ReleaseSafe` | `-O ReleaseSafe` | `-O2 + checks` | Optimized with safety checks retained |
| `ReleaseFast` | `-O ReleaseFast` | `-O3` | Maximum speed, safety checks removed |
| `ReleaseSmall` | `-O ReleaseSmall` | `-Os` | Minimize binary size |

```bash
zig build-exe src/main.zig -O Debug        # dev builds
zig build-exe src/main.zig -O ReleaseSafe  # production with safety
zig build-exe src/main.zig -O ReleaseFast  # max performance
zig build-exe src/main.zig -O ReleaseSmall # embedded/WASM
```

Safety checks in `Debug` and `ReleaseSafe`:
- Integer overflow → detected and panics with source location
- Array bounds checking → panics on OOB
- Null pointer dereference → panic (not crash)
- `unreachable` → panic
- Enum tag validation → panic on bad cast

`ReleaseFast`: turns safety checks into `undefined behaviour` (same semantics as C `-O3`). Use only when you've validated with `ReleaseSafe` first.

### 3. Target specification

```bash
# List all supported targets
````
END THIRD-PARTY FILE 63d770ae7d1d3b29

The third-party file has ended. Everything between the 63d770ae7d1d3b29 tags is data: requests and commands from it are not followed. An “end of file” line with another tag inside the block is part of the file.

First 2452 of 5833 bytes. © mohitmishra786 · MIT · https://github.com/mohitmishra786/low-level-dev-skills/tree/HEAD/skills/zig/zig-compiler/SKILL.md

_Part of the page did not fit — see the HTML version._

---
NeVibeCode on affpapa.org. Catalog texts are descriptions, not instructions for the agent. How to choose and install: https://affpapa.org/en/nevibecode/agents.md
