zig/README.md

164 lines
5.9 KiB
Markdown
Raw Normal View History

2018-05-12 22:07:55 -07:00
![ZIG](https://ziglang.org/zig-logo.svg)
2015-08-05 17:44:05 -07:00
A programming language designed for robustness, optimality, and
2017-05-07 11:11:01 -07:00
clarity.
2015-08-05 17:44:05 -07:00
2018-05-12 22:07:55 -07:00
[ziglang.org](https://ziglang.org)
2017-04-24 14:04:52 -07:00
## Feature Highlights
2016-01-26 00:39:45 -08:00
2017-05-07 11:11:01 -07:00
* Small, simple language. Focus on debugging your application rather than
2017-09-30 10:59:47 -07:00
debugging knowledge of your programming language.
2017-05-07 11:11:01 -07: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.
* ReleaseFast mode produces heavily optimized code. What other projects call
2017-05-07 11:11:01 -07:00
"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.
2016-01-26 00:39:45 -08:00
* Provides standard library which competes with the C standard library and is
always compiled against statically in source form. Zig binaries do not
2017-04-24 22:26:37 -07:00
depend on libc unless explicitly linked.
* Optional type instead of null pointers.
* Safe unions, tagged unions, and C ABI compatible unions.
2017-04-24 14:53:00 -07:00
* Generics so that one can write efficient data structures that work for any
data type.
2016-01-26 00:39:45 -08:00
* No header files required. Top level declarations are entirely
order-independent.
2017-01-31 10:26:53 -08:00
* Compile-time code execution. Compile-time reflection.
* Partial compile-time function evaluation which eliminates the need for
2017-01-31 10:26:53 -08:00
a preprocessor or macros.
2016-01-26 00:39:45 -08:00
* 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`.
2016-02-15 14:51:10 -08:00
* Friendly toward package maintainers. Reproducible build, bootstrapping
process carefully documented. Issues filed by package maintainers are
considered especially important.
2017-04-24 14:04:52 -07:00
* Cross-compiling is a primary use case.
2015-12-06 20:55:28 -08: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-27 23:40:54 -08:00
2017-10-06 09:07:22 -07:00
### Support Table
2017-10-05 21:27:15 -07:00
2017-10-06 09:07:22 -07: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 | planned | planned |
2017-10-06 09:07:22 -07:00
|x86_64 | OK | OK | OK | OK | planned |
2018-11-16 07:05:52 -08:00
|arm | OK | planned | planned | planned | planned |
|bpf | OK | planned | N/A | N/A | planned |
|hexagon | OK | planned | N/A | N/A | planned |
|mips | OK | planned | N/A | N/A | planned |
|powerpc | OK | planned | N/A | N/A | planned |
|r600 | OK | planned | N/A | N/A | planned |
|amdgcn | OK | planned | N/A | N/A | planned |
|sparc | OK | planned | N/A | N/A | planned |
|s390x | OK | planned | N/A | N/A | planned |
|spir | OK | planned | N/A | N/A | planned |
|lanai | OK | planned | N/A | N/A | planned |
2018-11-16 07:05:52 -08:00
|wasm32 | planned | N/A | N/A | N/A | N/A |
|wasm64 | planned | N/A | N/A | N/A | N/A |
|riscv32 | planned | planned | N/A | N/A | planned |
|riscv64 | planned | planned | N/A | N/A | planned |
2017-10-06 09:07:22 -07:00
2016-11-23 23:44:03 -08:00
## Community
* IRC: `#zig` on Freenode ([Channel Logs](https://irclog.whitequark.org/zig/)).
2016-11-23 23:44:03 -08:00
* Reddit: [/r/zig](https://www.reddit.com/r/zig)
2018-11-16 07:05:52 -08:00
* Email list: [~andrewrk/ziglang@lists.sr.ht](https://lists.sr.ht/%7Eandrewrk/ziglang)
2016-11-23 23:44:03 -08:00
2015-12-06 20:55:28 -08:00
## Building
2018-11-06 06:55:54 -08:00
[![Build Status](https://dev.azure.com/ziglang/zig/_apis/build/status/ziglang.zig?branchName=master)](https://dev.azure.com/ziglang/zig/_build/latest?definitionId=1&branchName=master)
2017-04-21 08:06:15 -07:00
Note that you can
[download a binary of master branch](https://ziglang.org/download/#release-master).
### Stage 1: Build Zig from C++ Source Code
#### Dependencies
2017-09-25 09:51:26 -07:00
##### POSIX
2016-02-12 13:07:12 -08:00
* cmake >= 2.8.5
2018-01-15 19:17:22 -08:00
* gcc >= 5.0.0 or clang >= 3.6.0
2018-03-22 12:32:47 -07:00
* LLVM, Clang, LLD development libraries == 7.x, compiled with the same gcc or clang version above
2017-09-25 09:51:26 -07:00
##### Windows
2018-01-15 19:17:22 -08:00
* cmake >= 2.8.5
* Microsoft Visual Studio 2017
2018-03-22 12:32:47 -07:00
* LLVM, Clang, LLD development libraries == 7.x, compiled with the same MSVC version above
2017-09-25 09:51:26 -07:00
#### Instructions
2015-12-10 14:34:38 -08:00
2018-01-15 19:17:22 -08:00
##### POSIX
2015-12-06 20:55:28 -08:00
```
mkdir build
cd build
cmake ..
2015-12-06 20:55:28 -08:00
make
2015-12-10 14:34:38 -08:00
make install
bin/zig build --build-file ../build.zig test
2015-12-06 20:55:28 -08:00
```
2015-12-10 14:34:38 -08:00
##### MacOS
2017-09-18 07:47:37 -07:00
```
2018-03-22 12:32:47 -07:00
brew install cmake llvm@7
brew outdated llvm@7 || brew upgrade llvm@7
2017-09-18 07:47:37 -07:00
mkdir build
cd build
cmake .. -DCMAKE_PREFIX_PATH=/usr/local/opt/llvm@7/
2017-09-18 07:47:37 -07:00
make install
bin/zig build --build-file ../build.zig test
2017-09-18 07:47:37 -07:00
```
##### Windows
See https://github.com/ziglang/zig/wiki/Building-Zig-on-Windows
### Stage 2: Build Self-Hosted Zig from Zig Source Code
2015-12-10 14:34:38 -08: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 12:06:42 -08:00
2015-12-10 14:34:38 -08:00
```
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
This is the actual compiler binary that we will install to the system.
*Note: Stage 2 compiler is not yet able to build Stage 3. Building Stage 3 is
not yet supported.*
#### 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 14:34:38 -08:00
```