2017-02-09 17:51:23 +00:00
|
|
|
![ZIG](http://ziglang.org/zig-logo.svg)
|
2015-08-06 01:44:05 +01:00
|
|
|
|
2017-08-09 22:52:02 +01:00
|
|
|
A programming language designed for robustness, optimality, and
|
2017-05-07 19:11:01 +01:00
|
|
|
clarity.
|
2015-08-06 01:44:05 +01:00
|
|
|
|
2016-05-13 19:38:14 +01:00
|
|
|
[ziglang.org](http://ziglang.org)
|
2016-02-10 05:31:49 +00:00
|
|
|
|
2017-10-17 21:05:46 +01:00
|
|
|
[Documentation](http://ziglang.org/documentation/master/)
|
2017-05-08 05:13:54 +01:00
|
|
|
|
2017-04-24 22:04:52 +01:00
|
|
|
## Feature Highlights
|
2016-01-26 08:39:45 +00:00
|
|
|
|
2017-05-07 19:11:01 +01:00
|
|
|
* Small, simple language. Focus on debugging your application rather than
|
2017-09-30 18:59:47 +01:00
|
|
|
debugging knowledge of your programming language.
|
2017-05-07 19:11:01 +01:00
|
|
|
* 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.
|
2017-10-13 14:31:03 +01:00
|
|
|
* ReleaseFast mode produces heavily optimized code. What other projects call
|
2017-05-07 19:11:01 +01:00
|
|
|
"Link Time Optimization" Zig does automatically.
|
2016-02-01 06:40:56 +00:00
|
|
|
* Compatible with C libraries with no wrapper necessary. Directly include
|
|
|
|
C .h files and get access to the functions and symbols therein.
|
2016-01-26 08:39:45 +00:00
|
|
|
* Provides standard library which competes with the C standard library and is
|
2017-04-25 06:26:37 +01:00
|
|
|
always compiled against statically in source form. Compile units do not
|
|
|
|
depend on libc unless explicitly linked.
|
2017-04-24 22:53:00 +01:00
|
|
|
* Nullable type instead of null pointers.
|
|
|
|
* Tagged union type instead of raw unions.
|
|
|
|
* Generics so that one can write efficient data structures that work for any
|
|
|
|
data type.
|
2016-01-26 08:39:45 +00:00
|
|
|
* No header files required. Top level declarations are entirely
|
|
|
|
order-independent.
|
2017-01-31 18:26:53 +00:00
|
|
|
* Compile-time code execution. Compile-time reflection.
|
|
|
|
* Partial compile-time function evaluation with eliminates the need for
|
|
|
|
a preprocessor or macros.
|
2016-01-26 08:39:45 +00:00
|
|
|
* The binaries produced by Zig have complete debugging information so you can,
|
|
|
|
for example, use GDB to debug your software.
|
2017-10-13 14:31:03 +01:00
|
|
|
* Built-in unit tests with `zig test`.
|
2016-02-15 22:51:10 +00:00
|
|
|
* Friendly toward package maintainers. Reproducible build, bootstrapping
|
|
|
|
process carefully documented. Issues filed by package maintainers are
|
|
|
|
considered especially important.
|
2017-04-24 22:04:52 +01:00
|
|
|
* Cross-compiling is a primary use case.
|
2015-12-07 04:55:28 +00:00
|
|
|
* In addition to creating executables, creating a C library is a primary use
|
|
|
|
case. You can export an auto-generated .h file.
|
2015-11-28 07:40:54 +00:00
|
|
|
|
2017-10-06 17:07:22 +01:00
|
|
|
### Support Table
|
2017-10-06 05:27:15 +01:00
|
|
|
|
2017-10-06 17:07:22 +01:00
|
|
|
Freestanding means that you do not directly interact with the OS
|
|
|
|
or you are writing your own OS.
|
|
|
|
|
|
|
|
Note that if you use libc or other libraries to interact with the OS,
|
|
|
|
that counts as "freestanding" for the purposes of this table.
|
|
|
|
|
|
|
|
| | freestanding | linux | macosx | windows | other |
|
|
|
|
|-------------|--------------|---------|---------|---------|---------|
|
|
|
|
|i386 | OK | planned | OK | OK | planned |
|
|
|
|
|x86_64 | OK | OK | OK | OK | planned |
|
|
|
|
|arm | OK | planned | planned | N/A | planned |
|
|
|
|
|aarch64 | OK | planned | planned | planned | planned |
|
|
|
|
|bpf | OK | planned | planned | N/A | planned |
|
|
|
|
|hexagon | OK | planned | planned | N/A | planned |
|
|
|
|
|mips | OK | planned | planned | N/A | planned |
|
|
|
|
|powerpc | OK | planned | planned | N/A | planned |
|
|
|
|
|r600 | OK | planned | planned | N/A | planned |
|
|
|
|
|amdgcn | OK | planned | planned | N/A | planned |
|
|
|
|
|sparc | OK | planned | planned | N/A | planned |
|
|
|
|
|s390x | OK | planned | planned | N/A | planned |
|
|
|
|
|thumb | OK | planned | planned | N/A | planned |
|
|
|
|
|spir | OK | planned | planned | N/A | planned |
|
|
|
|
|lanai | OK | planned | planned | N/A | planned |
|
|
|
|
|
2016-11-24 07:44:03 +00:00
|
|
|
## Community
|
|
|
|
|
|
|
|
* IRC: `#zig` on Freenode.
|
|
|
|
* Reddit: [/r/zig](https://www.reddit.com/r/zig)
|
|
|
|
* Email list: [ziglang@googlegroups.com](https://groups.google.com/forum/#!forum/ziglang)
|
|
|
|
|
2017-09-21 20:39:25 +01:00
|
|
|
### Wanted: Windows Developers
|
|
|
|
|
|
|
|
Help get the tests passing on Windows, flesh out the standard library for
|
|
|
|
Windows, streamline Zig installation and distribution for Windows. Work with
|
|
|
|
LLVM and LLD teams to improve PDB/CodeView/MSVC debugging. Implement stack traces
|
|
|
|
for Windows in the MinGW environment and the MSVC environment.
|
|
|
|
|
|
|
|
### Wanted: MacOS and iOS Developers
|
|
|
|
|
|
|
|
Flesh out the standard library for MacOS. Improve the MACH-O linker. Implement
|
|
|
|
stack traces for MacOS. Streamline the process of using Zig to build for
|
|
|
|
iOS.
|
|
|
|
|
|
|
|
### Wanted: Android Developers
|
|
|
|
|
|
|
|
Flesh out the standard library for Android. Streamline the process of using
|
|
|
|
Zig to build for Android and for depending on Zig code on Android.
|
|
|
|
|
|
|
|
### Wanted: Web Developers
|
|
|
|
|
|
|
|
Figure out what are the use cases for compiling Zig to WebAssembly. Create demo
|
|
|
|
projects with it and streamline experience for users trying to output
|
|
|
|
WebAssembly. Work on the documentation generator outputting useful searchable html
|
|
|
|
documentation. Create Zig modules for common web tasks such as WebSockets and gzip.
|
|
|
|
|
|
|
|
### Wanted: Embedded Developers
|
|
|
|
|
|
|
|
Flesh out the standard library for uncommon CPU architectures and OS targets.
|
|
|
|
Drive issue discussion for cross compiling and using Zig in constrained
|
|
|
|
or unusual environments.
|
|
|
|
|
|
|
|
### Wanted: Game Developers
|
|
|
|
|
|
|
|
Create cross platform Zig modules to compete with SDL and GLFW. Create an
|
|
|
|
OpenGL library that does not depend on libc. Drive the usability of Zig
|
|
|
|
for video games. Create a general purpose allocator that does not depend on
|
|
|
|
libc. Create demo games using Zig.
|
|
|
|
|
2015-12-07 04:55:28 +00:00
|
|
|
## Building
|
|
|
|
|
2017-04-25 06:26:37 +01:00
|
|
|
[![Build Status](https://travis-ci.org/zig-lang/zig.svg?branch=master)](https://travis-ci.org/zig-lang/zig)
|
2017-05-23 05:42:53 +01:00
|
|
|
[![Build status](https://ci.appveyor.com/api/projects/status/4t80mk2dmucrc38i/branch/master?svg=true)](https://ci.appveyor.com/project/andrewrk/zig-d3l86/branch/master)
|
2017-04-21 16:06:15 +01:00
|
|
|
|
2017-12-23 05:29:39 +00:00
|
|
|
### Stage 1: Build Zig from C++ Source Code
|
2016-01-26 04:56:29 +00:00
|
|
|
|
2017-12-23 05:29:39 +00:00
|
|
|
#### Dependencies
|
2016-09-05 21:36:21 +01:00
|
|
|
|
2017-09-25 17:51:26 +01:00
|
|
|
##### POSIX
|
|
|
|
|
2016-09-05 21:36:21 +01:00
|
|
|
* gcc >= 5.0.0 or clang >= 3.6.0
|
2016-02-12 21:07:12 +00:00
|
|
|
* cmake >= 2.8.5
|
2017-12-23 05:29:39 +00:00
|
|
|
* LLVM, Clang, LLD libraries == 5.x, compiled with the same gcc or clang version above
|
2016-09-05 21:36:21 +01:00
|
|
|
|
2017-09-25 17:51:26 +01:00
|
|
|
##### Windows
|
|
|
|
|
|
|
|
* Microsoft Visual Studio 2015
|
2017-12-23 05:29:39 +00:00
|
|
|
* LLVM, Clang, LLD libraries == 5.x, compiled with the same MSVC version above
|
2017-09-25 17:51:26 +01:00
|
|
|
|
2017-12-23 05:29:39 +00:00
|
|
|
#### Instructions
|
2015-12-10 22:34:38 +00:00
|
|
|
|
2016-05-01 01:17:59 +01:00
|
|
|
If you have gcc or clang installed, you can find out what `ZIG_LIBC_LIB_DIR`,
|
|
|
|
`ZIG_LIBC_STATIC_LIB_DIR`, and `ZIG_LIBC_INCLUDE_DIR` should be set to
|
|
|
|
(example below).
|
2015-12-15 20:02:02 +00:00
|
|
|
|
2015-12-07 04:55:28 +00:00
|
|
|
```
|
|
|
|
mkdir build
|
|
|
|
cd build
|
2017-02-24 21:10:11 +00:00
|
|
|
cmake .. -DCMAKE_INSTALL_PREFIX=$(pwd) -DZIG_LIBC_LIB_DIR=$(dirname $(cc -print-file-name=crt1.o)) -DZIG_LIBC_INCLUDE_DIR=$(echo -n | cc -E -x c - -v 2>&1 | grep -B1 "End of search list." | head -n1 | cut -c 2- | sed "s/ .*//") -DZIG_LIBC_STATIC_LIB_DIR=$(dirname $(cc -print-file-name=crtbegin.o))
|
2015-12-07 04:55:28 +00:00
|
|
|
make
|
2015-12-10 22:34:38 +00:00
|
|
|
make install
|
2017-04-20 07:26:36 +01:00
|
|
|
./zig build --build-file ../build.zig test
|
2015-12-07 04:55:28 +00:00
|
|
|
```
|
2015-12-10 22:34:38 +00:00
|
|
|
|
2017-12-23 05:29:39 +00:00
|
|
|
##### MacOS
|
2017-09-18 15:47:37 +01:00
|
|
|
|
2017-09-18 15:50:27 +01:00
|
|
|
`ZIG_LIBC_LIB_DIR` and `ZIG_LIBC_STATIC_LIB_DIR` are unused.
|
|
|
|
|
2017-09-18 15:47:37 +01:00
|
|
|
```
|
|
|
|
brew install llvm@5
|
|
|
|
brew outdated llvm@5 || brew upgrade llvm@5
|
|
|
|
mkdir build
|
|
|
|
cd build
|
2017-09-18 15:50:27 +01:00
|
|
|
cmake .. -DCMAKE_PREFIX_PATH=/usr/local/opt/llvm@5/ -DCMAKE_INSTALL_PREFIX=$(pwd)
|
2017-09-18 15:47:37 +01:00
|
|
|
make install
|
2017-09-18 15:51:12 +01:00
|
|
|
./zig build --build-file ../build.zig test
|
2017-09-18 15:47:37 +01:00
|
|
|
```
|
|
|
|
|
2017-12-23 05:29:39 +00:00
|
|
|
##### Windows
|
2017-10-10 23:04:02 +01:00
|
|
|
|
|
|
|
See https://github.com/zig-lang/zig/wiki/Building-Zig-on-Windows
|
|
|
|
|
2017-12-23 05:29:39 +00:00
|
|
|
### Stage 2: Build Self-Hosted Zig from Zig Source Code
|
2015-12-10 22:34:38 +00:00
|
|
|
|
2017-12-23 05:29:39 +00:00
|
|
|
*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 have a working zig compiler.
|
2015-12-15 20:06:42 +00:00
|
|
|
|
2015-12-10 22:34:38 +00:00
|
|
|
```
|
2017-12-23 05:29:39 +00:00
|
|
|
bin/zig build --build-file ../build.zig --prefix $(pwd)/stage2 install
|
|
|
|
```
|
|
|
|
|
|
|
|
### Stage 3: Rebuild Self-Hosted Zig Using the Self-Hosted Compiler
|
|
|
|
|
|
|
|
This is the actual compiler binary that we will install to the system.
|
|
|
|
|
|
|
|
#### 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
|
2015-12-10 22:34:38 +00:00
|
|
|
```
|
2016-01-16 00:12:26 +00:00
|
|
|
|
2016-04-23 17:57:38 +01:00
|
|
|
### Test Coverage
|
|
|
|
|
|
|
|
To see test coverage in Zig, configure with `-DZIG_TEST_COVERAGE=ON` as an
|
|
|
|
additional parameter to the Debug build.
|
|
|
|
|
|
|
|
You must have `lcov` installed and available.
|
|
|
|
|
|
|
|
Then `make coverage`.
|
|
|
|
|
|
|
|
With GCC you will get a nice HTML view of the coverage data. With clang,
|
|
|
|
the last step will fail, but you can execute
|
|
|
|
`llvm-cov gcov $(find CMakeFiles/ -name "*.gcda")` and then inspect the
|
|
|
|
produced .gcov files.
|
|
|
|
|
2017-04-13 10:27:39 +01:00
|
|
|
### Related Projects
|
|
|
|
|
|
|
|
* [zig-mode](https://github.com/AndreaOrru/zig-mode) - Emacs integration
|
2017-04-24 21:17:28 +01:00
|
|
|
* [zig.vim](https://github.com/zig-lang/zig.vim) - Vim configuration files
|
2017-07-15 00:30:13 +01:00
|
|
|
* [vscode-zig](https://github.com/zig-lang/vscode-zig) - Visual Studio Code extension
|
2017-08-26 01:14:33 +01:00
|
|
|
* [zig-compiler-completions](https://github.com/tiehuis/zig-compiler-completions) - bash and zsh completions for the zig compiler
|
2017-09-07 22:31:26 +01:00
|
|
|
* [NppExtension](https://github.com/ice1000/NppExtension) - Notepad++ syntax highlighting
|