skills/zig/zig-compiler/SKILL.md
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.
npx skillsauth add mohitmishra786/low-level-dev-skills zig-compilerInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
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.
# 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
| 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 |
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:
unreachable → panicReleaseFast: turns safety checks into undefined behaviour (same semantics as C -O3). Use only when you've validated with ReleaseSafe first.
# List all supported targets
zig targets
# Cross-compile for specific target
zig build-exe src/main.zig \
-target aarch64-linux-gnu \
-O ReleaseFast
# Embedded (no OS)
zig build-exe src/main.zig \
-target thumb-freestanding-eabi \
-O ReleaseSmall
# WebAssembly
zig build-exe src/main.zig \
-target wasm32-freestanding \
-O ReleaseSmall \
--export=main
# Common target triples: cpu-os-abi
# x86_64-linux-gnu, x86_64-windows-gnu, aarch64-macos-none
# thumbv7m-freestanding-eabi, wasm32-wasi, wasm32-freestanding
Zig ships a C/C++ compiler (zig cc / zig c++) backed by Clang and musl. It is hermetic — no system libc required.
# Compile C code
zig cc -O2 -Wall main.c -o myapp
# Compile C++ code
zig c++ -std=c++17 -O2 main.cpp -o myapp
# Cross-compile C for ARM (no cross toolchain needed!)
zig cc -target aarch64-linux-gnu -O2 main.c -o myapp-arm
# Statically link with musl
zig cc -target x86_64-linux-musl main.c -o myapp-static
# Use in CMake (override compiler)
CC="zig cc" CXX="zig c++" cmake -S . -B build
cmake --build build
# Use in Makefile
CC="zig cc" make
zig cc advantages over gcc/clang:
# Emit LLVM IR
zig build-exe src/main.zig --emit-llvm-ir
# Emit assembly
zig build-exe src/main.zig --emit-asm
cat main.s
# Emit binary and assembly
zig build-exe src/main.zig -femit-bin=myapp -femit-asm=myapp.s
# Check syntax without compiling
zig ast-check src/main.zig
# Format code
zig fmt src/main.zig
zig fmt src/ # format entire directory
# Check formatting without modifying
zig fmt --check src/
# Tokenize (debugging zig fmt)
zig tokenize src/main.zig
Zig error messages include:
src/main.zig:10:5: error: expected type 'u32', found 'i32'
x: i32 = 5,
^
src/main.zig:7:5: note: struct field 'x' declared here
x: u32,
^
Key error patterns:
| Error | Meaning |
|-------|---------|
| error: expected type 'X', found 'Y' | Type mismatch |
| error: use of undeclared identifier 'X' | Missing import or typo |
| error: integer overflow | Comptime overflow (caught at compile) |
| error: cannot assign to constant | Mutating a const variable |
| error: unused variable 'x' | All variables must be used |
| error: unused function parameter 'x' | Use _ = x; to suppress |
Suppress "unused" errors:
_ = unused_variable; // explicitly discard
# Check Zig version
zig version
# Show build configuration
zig env
# Show standard library location
zig env | grep lib_dir
For optimization mode details and target triple reference, see references/zig-optimize-modes.md.
skills/zig/zig-build-system for multi-file projects with build.zigskills/zig/zig-cinterop for calling C from Zig and vice versaskills/zig/zig-cross for cross-compilation targets and sysrootsskills/zig/zig-debugging for GDB/LLDB with Zig binariesdevelopment
QEMU/KVM skill for virtualization and kernel development. Use when running qemu-system-x86_64 with KVM, configuring virtio devices, VFIO passthrough, QMP monitor, libvirt, or booting custom kernels. Activates on queries about QEMU, KVM, virtio, VFIO, virsh, virt-install, or -kernel -append.
development
Hardware virtualization internals skill for Intel VT-x and AMD-V. Use when studying VMCS/VMCB, EPT/NPT page tables, VMEXIT handling, APIC virtualization, or building minimal hypervisors. Activates on queries about VMX, SVM, VMCS, EPT, NPT, VMEXIT, or type-1 hypervisor.
testing
Linux containers internals skill for namespaces, cgroups, and OCI. Use when understanding clone/unshare namespaces, cgroups v2 limits, overlayfs, runc, seccomp profiles, capabilities, or escape mitigations. Activates on queries about namespaces, cgroups, overlayfs, runc, seccomp-bpf, OCI spec, or container escape.
tools
Reverse engineering skill for binary analysis. Use when decompiling with Ghidra, analyzing with radare2, scripting RE tools, triaging with strings/file/xxd, or diffing binaries. Activates on queries about Ghidra, radare2, r2, decompiler, Binary Ninja, Diaphora, or stripped binary analysis.