From Gentoo Wiki
Jump to:navigation Jump to:search
Warning, this page is a work in progress by Gso321 (talk | contribs). Treat its contents with caution.

Zig is a general-purpose programming language and toolchain for maintaining robust, optimal and reusable software. Zig aims to replace C as the better language while being able to compile both C and C++.

dev-lang/zig and dev-lang/zig-bin are Zig's packages. dev-lang/zig is complied from source while dev-lang/zig-bin is a binary (no compiling). The rest of this article assumes the user is using dev-lang/zig (dev-lang/zig-bin may be replaced with dev-lang/zig-bin if the user uses it instead).



Zig supports at least Linux kernel 3.16+.[2]

USE flags

USE flags for dev-lang/zig A robust, optimal, and maintainable programming language

USE flags for dev-lang/zig-bin A robust, optimal, and maintainable programming language


Zig is currently unstable. To learn why unstable is bad experience, see this.
When compiling, Zig may use around 9.6 GiB RAM prior to 0.11.0.[3]

Change dev-lang/zig ACCEPT_KEYWORDS:

root #echo "dev-lang/zig ~amd64" >> /etc/portage/package.accept_keywords

Then compile the package:

root #emerge --ask -q dev-lang/zig


Compiling most packages with Zig results in build errors or runtime errors!!!

Setting custom-cflags useflag is NOT supported by upstream.

zig cc and zig c++ uses clang for now.

The system may be configured to compile selected packages other than gcc, clang, or other C/C++ compilers using zig. Some packages, like sys-devel/gcc requires setting custom-cflags:

FILE /etc/portage/profile/package.use.force
sys-devel/gcc custom-cflags

Basic example

FILE /etc/portage/env/complier-zig
CC="zig cc"
CXX="zig c++"
AR="zig ar"
# zig nm doesn't exist
RANLIB="zig ranlib"

COMMON_FLAGS="-O2 -march=native -pipe"

Then modify the file to the system's needs:

FILE /etc/portage/package.envUsing the Zig compiler for app-foo/bar and app-bar/baz
app-foo/bar compiler-zig
app-bar/baz compiler-zig


zig cc and zig c++ are Zig's C and C++ compiler respectively.


  1. Zig's license, retrieved on January 27, 2023
  2. Linux Kernel Version Support, retrieved on January 26, 2023.
  3. 0.10.0 Release Notes, retrieved on January 26, 2023.