LinuxCommandLibrary

zig

Compile Zig code

TLDR

Compile the project in the current directory

$ zig build
copy

Compile and run the project in the current directory
$ zig build run
copy

Initialize a zig build project with library and executable
$ zig init
copy

Create and run a test build
$ zig test [path/to/file.zig]
copy

Cross compile, build and run a project for x86_64 architecture and windows operating system
$ zig build run -fwine -Dtarget=x86_64-windows
copy

Reformat Zig source into canonical form
$ zig fmt [path/to/file.zig]
copy

Translate a C file to zig
$ zig translate-c -lc [path/to/file.c]
copy

Use Zig as a drop-in C++ compiler
$ zig c++ [path/to/file.cpp]
copy

SYNOPSIS

zig subcommand [options]

PARAMETERS

build
    Build the project defined by the `build.zig` file.

run
    Build and run the project.

test
    Run the tests defined in the project.

init-exe
    Initialize a new executable project.

init-lib
    Initialize a new library project.

fmt
    Format Zig source code according to the official style.

translate-c
    Translates C code to Zig code.

-h or --help
    Show help message and exit.

-v or --version
    Display the Zig version.

DESCRIPTION

The `zig` command is the primary interface to the Zig programming language toolchain. It's a versatile command that encompasses compilation, linking, running, testing, and package management for Zig projects. It differentiates itself by prioritizing simplicity, transparency, and control over dependencies and build processes.

A key feature is its ability to cross-compile without external dependencies. This makes it ideal for building software for embedded systems or various target platforms. It supports various subcommands such as `build`, `run`, `test`, `init-exe`, `init-lib`, `fmt`, and more. The `build` subcommand serves as a build system that automatically manages dependencies specified in a `build.zig` file. It leverages a declarative build language, making build definitions more readable and maintainable. It also includes an integrated package manager that can fetch and link against external dependencies. Zig strives to provide a streamlined experience for software development and deployment by offering a comprehensive suite of tools within a single command.

BUILD SYSTEM

Zig includes a declarative build system driven by the `build.zig` file. This file defines build targets, dependencies, and other build-related settings in Zig code. This allows for build configurations to be written using the same language as the project. The build system is designed to be simple and extensible, allowing developers to define custom build steps and integrate with external tools. The build system supports incremental builds, caching, and other features to optimize build times.

PACKAGE MANAGER

Zig has a built-in package manager. Dependency management is done directly within the `build.zig` file. Zig offers reproducible builds and reliable dependency resolution.

Copied to clipboard