Zig Programming Language

241 readers
1 users here now

A lemm.ee community for Zig!

founded 2 years ago
MODERATORS
101
 
 

From the README:

A simple pretty printer for arbitrary data structures in Zig⚡️

Designed to inspect deeply-nested and recursive tree structures.

102
 
 

From the README:

zbind generates TypeScript bindings for calling Zig code compiled to native code or Wasm, in Node.js or Bun or browsers.

Example Zig code lib/main.zig:

const std = @import("std");
const zbind = @import("zbind");

pub fn hello(name: []const u8) void {
    std.debug.print("Hello, {s}!\n", .{ name });
}

pub fn main() void {}

comptime {
    zbind.init(@This());
}
103
 
 

FROM THE README:

zcached is a nimble and efficient in-memory caching system resembling databases like Redis. This README acts as a comprehensive guide, aiding in comprehension, setup, and optimal utilization.

zcached aims to offer rapid, in-memory caching akin to widely-used databases such as Redis. Its focus lies in user-friendliness, efficiency, and agility, making it suitable for various applications requiring swift data retrieval and storage.

Crafted using Zig, a versatile, modern, compiled programming language, zcached prides itself on a zero-dependency architecture. This unique feature enables seamless compilation and execution across systems equipped with a Zig compiler, ensuring exceptional portability and deployment ease.

104
 
 

Supports:

  • OpenGL 1.0 through 3.1
  • OpenGL 3.2 through 4.6 (Compatibility/Core profile)
  • OpenGL ES 1.1 (Common/Common-Lite profile)
  • OpenGL ES 2.0 through 3.2
  • OpenGL SC 2.0
105
 
 

Minimal Terraform HTTP backend in Zig

106
 
 

Server-side framework for Zig, relying heavily on dependency injection.

The code has been extracted from Ava PLS which has been using it for a few months already, and I'm using it in one other project which is going to production soon, so it's not just a toy, it actually works.

107
 
 

Zine is a static site generator written in Zig. Check out the linked Github page for examples and docs.

108
 
 

From the README:

bork

A TUI chat client tailored for livecoding on Twitch, currently in alpha stage.

Main features

  • Displays Twitch emotes in the terminal, including your own custom emotes!
  • Understands Twitch-specific concepts (subcriptions, gifted subs, ...).
  • Displays badges for your subs, mods, etc.
  • Supports clearing chat and deletes messages from banned users.
  • Click on a message to highlight it and let your viewers know who you're relpying to.
109
 
 

From the README:

jdz_allocator: A Zig General Purpose Memory Allocator

jdz_allocator is an original general purpose allocator inspired by Mattias Jansson's rpmalloc.

In its default configuration, it uses no global or threadlocal vars, making it compatible with Zig allocator design. This allows it to function without the need for any deinitThread calls while still achieving reasonable multi-threaded performance.

If multithreaded performance is essential, and cannot be handled appropriately through the use of multiple allocator instances, this allocator can be configured to use threadlocal arenas by setting global_allocator=true in the JdzAllocatorConfig. In this mode, make sure to call deinitThread before thread termination to free thread memory for re-use.

The global allocator is currently accessed through a JdzAllocator instance rather than the JdzAllocator type, which makes global global use inconvenient and error-prone - this will be addressed shortly.

Please note that this allocator is a work in progress, and has not yet been thoroughly tested. Usage and bug reports are appreciated and will help contribute to this allocator's completion.

Performance is also still being worked on, with a few obvious targets for improvement.

This allocator currently does not support page sizes larger than 64KiB.

110
 
 

Alpha-version of a new web framework and templating language.

Documentation here: https://www.jetzig.dev/documentation.html

111
 
 

From the video description:

When developing command line tools, handling user input via command line arguments is a crucial step. Zig offers a couple of args iterators in the standard library, depending on whether you're targeting Windows or not. In this episode we see how to use both, and as a bonus, we see a demonstration of using an ecosystem args parser called zig-clap.

112
5
submitted 2 years ago* (last edited 2 years ago) by cryptocode@lemm.ee to c/zig@lemm.ee
 
 

Accelerating the Zig Parser, streamed on Jan 12 2024

Presented by Niles Salter (@Validark)

113
 
 

Zig bindings for Godot 4

114
 
 

From the README:

Zig diffing from the ground up with Myers' algorithm for discovering shortest edit scripts.

Allows diffing of any set of values (even non-slice ones) as long as those values are eqlable by index.

115
 
 

A Nix Flake for packaging, building and running Zig projects.

116
 
 

From the announcement:

Today we’re announcing Mach nominated Zig versions, a sweet-spot between stable Zig and nightly Zig which offers a different balance of latest-and-greatest features and fixes, and less of a moving target.

117
 
 

From the README:

zimalloc

zimalloc is general purpose allocator for Zig, inspired by mimalloc.

Status

This project is under development and should currently be considered experimental/exploratory; there is no documentation and it has not been battle-tested. In particular there may be issues with multi-threaded workloads. Contributions of any kind (PRs, suggestions for improvements, resources or ideas related to benchmarking or testing) are welcome.

The allocator is significantly faster than std.heap.GeneralPurposeAllocator(.{}) but should not (yet) be expected to be competitive with other established general purpose allocators.

118
 
 

An XML parser loosely based on the std.json scanner API

119
 
 

From the README


A Nix Flake for developing Zig.

Features

  • A Nix dev shell for building Zig from src
    # Start dev shell
    nix develop .
    
  • An opinionated script (./run) that helps with building and testing Zig
    ./run buildBootstrap # Build stage3
    ./run usePrebuilt # Alternatively, use a signature-checked stage3 binary from ziglang.org
    ./run buildDebug # Use stage3 to create a Zig debug build
    ./run testBehavior # Run behavior tests for the debug build
    
    Getting from zero to a self-built Zig is really fast:
    ./run usePrebuilt && ./run buildDebug takes less than 3 minutes on an average desktop system.
  • Zig master pkgs
    nix build .#zig # Built from source
    nix build .#zigPrebuilt # Prebuilt static binary from ziglang.org
    

This repo is regularly updated to track Zig master.

Usage

See ./usage.sh on how to use this repo.

Dev

See ./dev/README.md on how to develop and contribute to this repo.

See also

zig-overlay, which packages the official prebuilt static Zig binaries with Nix.

120
 
 

MySQL driver written in pure zig

Features:

  • Native Zig code
  • TCP protocol
  • MySQL DateTime and Time support
  • comptime safety and type conversion as much as possible
121
 
 

zig-webui is a zig library of webui.

Github: https://github.com/webui-dev/zig-webui

WebUI is not a web-server solution or a framework, but it allows you to use any web browser as a GUI, with your preferred language in the backend and HTML5 in the frontend. All in a lightweight portable lib.

preview

We use zig to wrap the C library, which makes it easy for us to use it in zig.

Feature

  • Parent library written in pure C
  • Lightweight ~200 Kb & Small memory footprint
  • Fast binary communication protocol between WebUI and the browser (Instead of JSON)
  • Multi-platform & Multi-Browser
  • Using private profile for safety

Here is a text editor with zig-webui

text_editor

Examples

Here we make a minimal example with zig-webui:

First

We init a zig project with zig init-ext or zig init(zig nightly).

Then we add this to our build.zig.zon:

.@"zig-webui" = .{
        .url = "https://github.com/webui-dev/zig-webui/archive/main.tar.gz",
        .hash = <hash value>,
    },

Note that the hash is given by zig. Of course, zig nightly has provided a command to get package hash and write it to build.zig.zon:

zig fetch --save https://github.com/webui-dev/zig-webui/archive/main.tar.gz

Second

We need to config build.zig:

const zig_webui = b.dependency("zig-webui", .{
    .target = target,
    .optimize = optimize,
    .enable_tls = false, // whether enable tls support
    .is_static = true, // whether static link
});

// add module
exe.addModule("webui", zig_webui.module("webui"));

// link library
exe.linkLibrary(zig_webui.artifact("webui"));

OK, now we have configed this project!

Let us code!

Code

const webui = @import("webui");

pub fn main() !void {
    var nwin = webui.newWindow();
    _ = nwin.show("<html><head><script src=\"webui.js\"></script></head> Hello World ! </html>");
    webui.wait();
}

We import the package webui, and use its method newWindow to create a window, then show it(we ignored the returned value, it is bool to tell us whether the window showed correctly).

Finaly, we use webui.wait to block the main funcion, it will break when window is closed!

Currently zig-webui is still under development and more features will be added!

Github:https://github.com/webui-dev/zig-webui

122
 
 

Adds support for using the Zig programming language to Visual Studio 2022

Features:

  • Zig language syntax highlighting
  • Zig Language Server (ZLS) support (completions, tooltips, find references and more)
  • Tools path setup
  • Folder mode
    • Build and debug from VS 2022 using build.zig
  • Project mode
    • Build and debug from VS 2022 using project files
    • Application and library templates
    • Use project References node to link with other projects
  • Run code tests using Test Explorer
123
 
 

From the README:

A Proof of Concept (PoC) for a versatile standard for driving USB and Bluetooth peripherals via the HID protocol.

124
 
 

From the README:

This is a Zig implementation of a fast, discrete, bounded, Zipf-distributed random number generator. Our implementation offers a robust and efficient solution for generating Zipf-distributed numbers, ideal for various applications ranging from statistical modeling, natural language processing, database benchmarking and load testing.


Here's a great video about Zipf from Vsauce: https://www.youtube.com/watch?v=fCn8zs912OE

125
 
 

By Brook Jeynes

Length: 8:32

Description:

Inter-process communication is a way to share information between different processes. In this video, I'll dive into what IPC is and how to create shared memory with Zig.

Disclaimer: This code is not production safe and just for educational purposes.

You can find the code written in this video here: https://github.com/BrookJeynes/zig-shared-memory

view more: ‹ prev next ›