Zig

Zig is Article description::a general-purpose programming language and toolchain for maintaining robust, optimal and reusable software. Zig aims to replace as the better language and can use or export C functions without FFI and compile code in C and C++, using libclang. Upstream also works on their own C compiler so that these functions will be available without libclang.

Prerequisites
Zig supports at least Linux kernel 3.16+. If building from source, it must be built with same compiler as LLVM/Clang, or the user will get in trouble (see relevant section in below).

Emerge
Packages are currently not stabilized on any arch and keyworded as testing on a small subset of arches, so the user need to testing keyword or latest git:

Then emerge the package:

ZIG_MCPU and ZIG_TARGET
To adjust for which target and CPU will be built for, there are variables ZIG_MCPU and ZIG_TARGET (that will be passed as   and   arguments to :

Setting a default slot
The command can be used to manipulate a /usr/bin/zig symlink.

Environment variables
Command args have higher precedence over the following environment variables:


 * ZIG_GLOBAL_CACHE_DIR - path to the directory where things that are shared between different compilations are cached
 * ZIG_LOCAL_CACHE_DIR - path to the directory where the current compilation is cached, by default next to build.zig
 * ZIG_LIB_DIR - path to Zig standard library

General usage
Most commands grouped together, like ast-check to translate-c, have the same command options.

In the second group, it is highly recommended to use -fstrip to reduce the executable size except for debugging purposes.

Build modes
Zig has 4 "build modes" (or "optimize modes" in recent versions):

LSP support
Unofficial language server is available as  in. For installing follow guide to enable GURU repository,  and run:

Text editors support
See this list of tools from upstream. Currently none of them are packaged.

Freestanding
User might want to take a look at posts Using Zig to build a bare metal RISCV32 binary and Build an IoT App with Zig and LoRaWAN.

"undefined reference to ..." during emerging
The most possible reason is that the LLVM and Clang packages were built with other C++ compiler than Zig. Ensure that the user set the same compiler and emerge again.

warning: Encountered error: UnexpectedEndOfFile, falling back to default ABI and dynamic linker.
Zig compiler relies on the presence of for choosing  when targeting host machine. It checks whether contains actual ELF file or is a symlink/shebang to another executable, and retries this operation recursively until found. Then, it tries to extract information about libc from this ELF file. If this message occurs, it means that Zig failed to detect it properly, and will choose default libc and ABI instead (e.g. musl on Linux). The workaround is by using the following args to the command:

Or:

Where  is the desired target, such as   or. For more information about target format see section.

External resources

 * Official list of the community spaces
 * Official list of community projects and awesome-zig list
 * Ziglings — learn Zig by fixing tiny broken programs, inspired by Rustlings
 * Differences between and