Zig Programming Language

168 readers
3 users here now

A lemm.ee community for Zig!

founded 1 year ago
MODERATORS
76
 
 

Minimal Terraform HTTP backend in Zig

77
 
 

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.

78
 
 

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

79
 
 

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.
80
 
 

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.

81
 
 

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

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

82
 
 

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.

83
5
submitted 11 months ago* (last edited 11 months ago) by [email protected] to c/[email protected]
 
 

Accelerating the Zig Parser, streamed on Jan 12 2024

Presented by Niles Salter (@Validark)

84
 
 

Zig bindings for Godot 4

85
 
 

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.

86
 
 

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

87
 
 

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.

88
 
 

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.

89
 
 

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

90
 
 

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.

91
 
 

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
92
 
 

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

93
 
 

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
94
 
 

From the README:

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

95
 
 

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

96
 
 

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

97
 
 

From the README:

zig-gpio is a Zig library for controlling GPIO lines on Linux systems

This library can be used to access GPIO on devices such as Raspberry Pis or the Milk-V Duo

98
 
 

Cyber is a programming language for fast and concurrent scripting. Implemented mostly in Zig.

Release notes: https://cyberscript.dev/0.3/

Github: https://github.com/fubark/cyber

99
 
 

From the README:

A tiny library to allow writing to and reading from stream (a Reader and a Writer in Zig) in bits.

The original credits go to MichaelDipperstein for their implementation of bitfile.

100
 
 

From the README:

Libui-ng is a C library for creating cross-platform applications using the native widget toolkits for each platform. These bindings are a manual cleanup of the cimport of ui.h.

Each control type has been made an opaque with the extern functions embedded within in them. Additionally, functions using boolean values have been converted to use bool. Some helper functions have been made for writing event handlers.

view more: ‹ prev next ›