Zig Programming Language
last updated: 2024-04-04 03:52
Intro
- a general-purpose programming language and toolchain for maintaining robust, optimal and reusable software.
Install
- Debian/Ubuntu
$ sudo apt install zig
- Alpine Linux
$ doas apk add zig
- 최신 리눅스 버전 설치
- https://ziglang.org/download/
- os와 아키텍쳐에 맞는 파일을 다운로드한다.
- 압축을 푼 후
PATH
를 설정해주면 바로 사용 가능하다. - 현재 사용 버전: 0.12
$ tar xJf zig-linux-x86_64-0.12.0-dev.3212+40e64245f.tar.xz
$ ln -s zig-linux-x86_64-0.12.0-dev.3212+40e64245f/ zig
$ cd zig; ls
$ ./zig version
$ ./zig help
Hello World
hello-world.zig
const std = @import("std");
pub fn main() !void {
std.debug.print("Hello, World!\n", .{});
}
- run / test
$ zig run hello-world.zig
$ zig test hello-world.zig
- build (default=debug, small, fast, safe)
$ zig build-exe hello.zig
$ ./hello
$ zig build-exe --name hello-small -O ReleaseSmall hello.zig
$ zig build-exe --name hello-fast -O ReleaseFast hello.zig
$ zig build-exe --name hello-safe -O ReleaseSafe hello.zig
$ zig build-exe --name hello-debug -O Debug hello.zig
$ ls -l
$ ./hello-small
More Docs
Links
- home - https://ziglang.org/
- awesome zig - https://www.trackawesomelist.com/catdevnull/awesome-zig/readme/
Study and Docs
- zig-guide - https://zig.guide/
- reference - https://ziglang.org/documentation/0.11.0/
- zig-by-example - https://zig-by-example.com/
- zig std - https://ziglang.org/documentation/master/std/
- exercises - https://exercism.org/tracks/zig/exercises
- learn x in y minutes - https://learnxinyminutes.com/docs/zig/
Compile and Build
- zig-cc - https://andrewkelley.me/post/zig-cc-powerful-drop-in-replacement-gcc-clang.html
- Zig Build System Internals - https://mitchellh.com/zig/build-internals