Zig Programming Language

Created: by Pradeep Gowda Updated: Apr 25, 2023 Tagged: programming-language · zig

[TOC]

The Zig Programming Language is an open-source programming language designed for robustness, optimality, and clarity.

Introduction

Code

Articles

Project Management

FFI

Twitter

Provide or link to a small (50-200 ish lines) idiomatic Go program demonstrating concurrency. (Elegant use of goroutines, channels, etc)

I’ll provide the equivalent Zig program using async/await and std.event.Loop for comparison.

My notes

Cross compiling zig

Code

# crosscompile.zig
const warn = @import("std").debug.warn;

pub fn main() void {
    warn("Hello, world!\n");
}

Compiling natively on Mac OSX

$ zig build-exe crosscompile.zig
$ file crosscompile
crosscompile: Mach-O 64-bit executable x86_64

Cross-compiling for Linux

The C ABI tuple of (operating system, architecture, C compiler environment) is defined by --target-os --target-arch --target-environ flags of zig. [ref]

zig build-exe crosscompile.zig --target-os linux --target-arch x86_64

Verify the executable file type created:

$ file crosscompile
crosscompile: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), statically linked, with debug_info, not stripped

Software written in Zig