General-purpose programming language and toolchain for maintaining robust, optimal, and reusable software.
Go to file
2019-02-25 13:34:25 -05:00
.builds ci: freebsd: remove '.git' from URL as per upstream suggestion 2019-02-14 09:46:08 -05:00
c_headers drop patches on top of clang's C headers 2018-09-10 15:55:39 -04:00
ci/azure ci: update msys packages before installing 2018-12-16 12:32:20 -05:00
cmake add zig cc command to act like a C compiler 2019-02-24 12:53:28 -05:00
deps LLD patch: allow non-allocated sections to go into allocated sections 2018-12-04 11:42:22 -05:00
doc docs for packed structs 2019-02-22 10:56:49 -05:00
example first class support for compiling C code 2019-02-25 11:45:00 -05:00
src building DLLs on Windows works better 2019-02-25 13:34:25 -05:00
src-self-hosted remove --no-rosegment workaround now that valgrind bug is fixed 2019-02-19 08:39:36 -05:00
std building DLLs on Windows works better 2019-02-25 13:34:25 -05:00
test building DLLs on Windows works better 2019-02-25 13:34:25 -05:00
.gitattributes Do not normalize langref.html.in line endings 2018-07-04 23:47:15 +12:00
.gitignore add a friendly note in .gitignore 2018-08-03 15:20:19 -04:00
build.zig remove --no-rosegment workaround now that valgrind bug is fixed 2019-02-19 08:39:36 -05:00
CMakeLists.txt add zig cc command to act like a C compiler 2019-02-24 12:53:28 -05:00
LICENSE add license 2015-08-05 16:22:18 -07:00
README.md README: add NetBSD to support table 2019-02-18 00:13:18 -05:00

ZIG

A programming language designed for robustness, optimality, and clarity.

Download & Documentation

Feature Highlights

  • Small, simple language. Focus on debugging your application rather than debugging knowledge of your programming language.
  • Ships with a build system that obviates the need for a configure script or a makefile. In fact, existing C and C++ projects may choose to depend on Zig instead of e.g. cmake.
  • A fresh take on error handling which makes writing correct code easier than writing buggy code.
  • Debug mode optimizes for fast compilation time and crashing with a stack trace when undefined behavior would happen.
  • ReleaseFast mode produces heavily optimized code. What other projects call "Link Time Optimization" Zig does automatically.
  • Compatible with C libraries with no wrapper necessary. Directly include C .h files and get access to the functions and symbols therein.
  • Provides standard library which competes with the C standard library and is always compiled against statically in source form. Zig binaries do not depend on libc unless explicitly linked.
  • Optional type instead of null pointers.
  • Safe unions, tagged unions, and C ABI compatible unions.
  • Generics so that one can write efficient data structures that work for any data type.
  • No header files required. Top level declarations are entirely order-independent.
  • Compile-time code execution. Compile-time reflection.
  • Partial compile-time function evaluation which eliminates the need for a preprocessor or macros.
  • The binaries produced by Zig have complete debugging information so you can, for example, use GDB, MSVC, or LLDB to debug your software.
  • Built-in unit tests with zig test.
  • Friendly toward package maintainers. Reproducible build, bootstrapping process carefully documented. Issues filed by package maintainers are considered especially important.
  • Cross-compiling is a primary use case.
  • In addition to creating executables, creating a C library is a primary use case. You can export an auto-generated .h file.

Supported Targets

Tier 1 Support

  • Not only can Zig generate machine code for these targets, but the standard library cross-platform abstractions have implementations for these targets. Thus it is practical to write a pure Zig application with no dependency on libc.
  • The CI server automatically tests these targets on every commit to master branch, and updates ziglang.org/download with links to pre-built binaries.
  • These targets have debug info capabilities and therefore produce stack traces on failed assertions.

Tier 2 Support

  • There may be some standard library implementations, but many abstractions will give an "Unsupported OS" compile error. One can link with libc or other libraries to fill in the gaps in the standard library.
  • These targets are known to work, but are not automatically tested, so there are occasional regressions.
  • Some tests may be disabled for these targets as we work toward Tier 1 support.

Tier 3 Support

  • The standard library has little to no knowledge of the existence of this target.
  • Because Zig is based on LLVM, it has the capability to build for these targets, and LLVM has the target enabled by default.
  • These targets are not frequently tested; one will likely need to contribute to Zig in order to build for these targets.
  • The Zig compiler might need to be updated with a few things such as
    • what sizes are the C integer types
    • C ABI calling convention for this target
    • bootstrap code and default panic handler

Tier 4 Support

  • Support for these targets is entirely experimental.
  • LLVM may have the target as an experimental target, which means that you need to use Zig-provided binaries for the target to be available, or build LLVM from source with special configure flags.
  • This target may be considered deprecated by an official party, such as macosx/i386 in which case this target will remain forever stuck in Tier 4.

Support Table

freestanding linux macosx windows freebsd netbsd UEFI other
x86_64 Tier 2 Tier 1 Tier 1 Tier 1 Tier 2 Tier 2 Tier 2 Tier 3
i386 Tier 2 Tier 2 Tier 4 Tier 2 Tier 3 Tier 3 Tier 3 Tier 3
arm Tier 2 Tier 3 Tier 3 Tier 3 Tier 3 Tier 3 Tier 3 Tier 3
arm64 Tier 2 Tier 2 Tier 3 Tier 3 Tier 3 Tier 3 Tier 3 Tier 3
bpf Tier 3 Tier 3 N/A N/A Tier 3 Tier 3 Tier 3 Tier 3
hexagon Tier 3 Tier 3 N/A N/A Tier 3 Tier 3 Tier 3 Tier 3
mips Tier 3 Tier 3 N/A N/A Tier 3 Tier 3 Tier 3 Tier 3
powerpc Tier 3 Tier 3 N/A N/A Tier 3 Tier 3 Tier 3 Tier 3
r600 Tier 3 Tier 3 N/A N/A Tier 3 Tier 3 Tier 3 Tier 3
amdgcn Tier 3 Tier 3 N/A N/A Tier 3 Tier 3 Tier 3 Tier 3
sparc Tier 3 Tier 3 N/A N/A Tier 3 Tier 3 Tier 3 Tier 3
s390x Tier 3 Tier 3 N/A N/A Tier 3 Tier 3 Tier 3 Tier 3
spir Tier 3 Tier 3 N/A N/A Tier 3 Tier 3 Tier 3 Tier 3
lanai Tier 3 Tier 3 N/A N/A Tier 3 Tier 3 Tier 3 Tier 3
wasm32 Tier 4 N/A N/A N/A N/A N/A N/A N/A
wasm64 Tier 4 N/A N/A N/A N/A N/A N/A N/A
riscv32 Tier 4 Tier 4 N/A N/A Tier 4 Tier 4 Tier 4 Tier 4
riscv64 Tier 4 Tier 4 N/A N/A Tier 4 Tier 4 Tier 4 Tier 4

Community

Building

Build Status

Note that you can download a binary of master branch.

Stage 1: Build Zig from C++ Source Code

Dependencies

POSIX
  • cmake >= 2.8.5
  • gcc >= 5.0.0 or clang >= 3.6.0
  • LLVM, Clang, LLD development libraries == 7.x, compiled with the same gcc or clang version above
Windows
  • cmake >= 2.8.5
  • Microsoft Visual Studio 2017
  • LLVM, Clang, LLD development libraries == 7.x, compiled with the same MSVC version above

Instructions

POSIX
mkdir build
cd build
cmake ..
make
make install
bin/zig build --build-file ../build.zig test
MacOS
brew install cmake llvm@7
brew outdated llvm@7 || brew upgrade llvm@7
mkdir build
cd build
cmake .. -DCMAKE_PREFIX_PATH=/usr/local/opt/llvm@7/
make install
bin/zig build --build-file ../build.zig test
Windows

See https://github.com/ziglang/zig/wiki/Building-Zig-on-Windows

Stage 2: Build Self-Hosted Zig from Zig Source Code

Note: Stage 2 compiler is not complete. Beta users of Zig should use the Stage 1 compiler for now.

Dependencies are the same as Stage 1, except now you can use stage 1 to compile Zig code.

bin/zig build --build-file ../build.zig --prefix $(pwd)/stage2 install

This produces ./stage2/bin/zig which can be used for testing and development. Once it is feature complete, it will be used to build stage 3 - the final compiler binary.

Stage 3: Rebuild Self-Hosted Zig Using the Self-Hosted Compiler

Note: Stage 2 compiler is not yet able to build Stage 3. Building Stage 3 is not yet supported.

Once the self-hosted compiler can build itself, this will be the actual compiler binary that we will install to the system. Until then, users should use stage 1.

Debug / Development Build

./stage2/bin/zig build --build-file ../build.zig --prefix $(pwd)/stage3 install

Release / Install Build

./stage2/bin/zig build --build-file ../build.zig install -Drelease-fast