avatar_url
stringlengths 46
116
⌀ | name
stringlengths 1
46
| full_name
stringlengths 7
60
| created_at
stringdate 2016-04-01 08:17:56
2025-05-20 11:38:17
| description
stringlengths 0
387
⌀ | default_branch
stringclasses 45
values | open_issues
int64 0
4.93k
| stargazers_count
int64 0
78.2k
| forks_count
int64 0
3.09k
| watchers_count
int64 0
78.2k
| tags_url
stringlengths 0
94
| license
stringclasses 27
values | topics
listlengths 0
20
| size
int64 0
4.82M
| fork
bool 2
classes | updated_at
stringdate 2018-11-13 14:41:18
2025-05-22 08:23:54
| has_build_zig
bool 2
classes | has_build_zig_zon
bool 2
classes | zig_minimum_version
stringclasses 60
values | repo_from
stringclasses 3
values | dependencies
listlengths 0
121
| readme_content
stringlengths 0
437k
| dependents
listlengths 0
21
|
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
https://avatars.githubusercontent.com/u/7270159?v=4 | gyro | mattnite/gyro | 2020-06-12T20:12:12Z | A Zig package manager with an index, build runner, and build dependencies. | master | 11 | 573 | 23 | 573 | https://api.github.com/repos/mattnite/gyro/tags | MIT | [
"package-manager",
"zig"
]
| 21,465 | false | 2025-03-20T06:39:18Z | true | false | unknown | github | []
|
gyro: a zig package manager
<blockquote>
A gyroscope is a device used for measuring or maintaining orientation
</blockquote>
<a></a> <a></a> <a></a>
GYRO IS NOW ARCHIVED, THANK YOU EVERYONE FOR YOUR FEEDBACK AND TIME. ZIG NOW HAS AN OFFICIAL PACKAGE MANAGER AND DAMN IT'S GOOD.
Table of contents
<ul>
<li><a>Introduction</a></li>
<li><a>Installation</a></li>
<li><a>Building</a></li>
<li><a>How tos</a></li>
<li><a>Initialize project</a><ul>
<li><a>Setting up build.zig</a></li>
<li><a>Ignoring gyro.lock</a></li>
</ul>
</li>
<li><a>Export a package</a></li>
<li><a>Publishing a package to astrolabe.pm</a></li>
<li><a>Adding dependencies</a><ul>
<li><a>From package index</a></li>
<li><a>From a git repo</a></li>
<li><a>From Github</a></li>
<li><a>From url</a></li>
<li><a>Build dependencies</a></li>
</ul>
</li>
<li><a>Removing dependencies</a></li>
<li><a>Local development</a></li>
<li><a>Update dependencies -- for package consumers</a></li>
<li><a>Use gyro in Github Actions</a><ul>
<li><a>Publishing from an action</a></li>
</ul>
</li>
<li><a>Completion Scripts</a></li>
<li><a>Design philosophy</a></li>
<li><a>Generated files</a></li>
<li><a>gyro.zzz</a></li>
<li><a>gyro.lock</a></li>
<li><a>deps.zig</a></li>
<li><a>./gyro/</a></li>
</ul>
Introduction
Gyro is an unofficial package manager for the Zig programming language. It
improves a developer's life by giving them a package experience similar to
cargo. Dependencies are declared in a <a>gyro.zzz</a> file in the root of your
project, and are exposed to you programmatically in the <code>build.zig</code> file by
importing <code>@import("deps.zig").pkgs</code>. In short, all that's needed on your part
is how you want to add packages to different objects you're building:
```zig
const Builder = @import("std").build.Builder;
const pkgs = @import("deps.zig").pkgs;
pub fn build(b: *Builder) void {
const exe = b.addExecutable("main", "src/main.zig");
pkgs.addAllTo(exe);
exe.install();
}
```
To make the job of finding suitable packages to use in your project easier,
gyro is paired with a package index located at
<a>astrolabe.pm</a>. A simple <code>gyro add alexnask/iguanaTLS</code>
will add the latest version of <code>iguanaTLS</code> (pure Zig TLS library) as a
dependency. To build your project all that's needed is <code>gyro build</code> which
works exactly like <code>zig build</code>, you can append the same arguments, except it
automatically downloads any missing dependencies. To learn about other If you
want to use a dependency from github, you can add it by explicitly with <code>github
add -s github <user>/<repo> [<ref>]</code>. <code><ref></code> is an optional arg which can be
a branch, tag, or commit hash, if not specified, gyro uses the default branch.
Installation
In order to install gyro, all you need to do is extract one of the <a>release
tarballs</a> for your system and add the
single static binary to your PATH. Gyro requires the latest stable version of
the Zig compiler (0.10.1 at time of writing)
Building
If you'd like to build from source, the only thing you need is the Zig compiler:
<code>git clone https://github.com/mattnite/gyro.git
cd gyro
zig build -Drelease-safe</code>
How tos
Instead of just documenting all the different subcommands, this documentation
just lists out all the different scenarios that Gyro was built for. And if you
wanted to learn more about the cli you can simply <code>gyro <subcommand> --help</code>.
Initialize project
If you have an existing project on Github that's a library then you can populate
<a>gyro.zzz</a> file with metadata:
<code>gyro init <user>/<repo></code>
For both new and existing libraries you'd want to check out <a>export a
package</a>, if you don't plan on <a>publishing to
astrolabe</a> then ensuring the root file is
declared is all that's needed. For projects that are an executable or considered
the 'root' of the dependency tree, all you need to do is <a>add
dependencies</a>.
Setting up build.zig
In build.zig, the dependency tree can be imported with
<code>zig
const pkgs = @import("deps.zig").pkgs;</code>
then in the build function all the packages can be added to an artifact with:
<code>zig
pkgs.addAllTo(lib);</code>
individual packages exist in the pkgs namespace, so a package named <code>mecha</code> can
be individually added:
<code>zig
lib.addPackage(pkgs.mecha)</code>
Ignoring gyro.lock
<a>gyro.lock</a> is intended for reproducible builds. It is advised to add it to
<code>.gitignore</code> if your project is a library.
Export a package
This operation doesn't have a cli equivalent so editing of <a>gyro.zzz</a>
is required, if you followed <a>initializing a project</a> and
grabbed metadata from Github, then a lot of this work is done for you -- but
still probably needs some attention:
<ul>
<li>the root file, it is <code>src/main.zig</code> by default</li>
<li>the version</li>
<li>file globs describing which files are actually part of the package. It is
encouraged to include the license and readme.</li>
<li>metadata: description, tags, source_url, etc.</li>
<li><a>dependencies</a></li>
</ul>
Publishing a package to astrolabe.pm
In order to publish to astrolabe you need a Github account and a browser. If
your project exports multiple packages you'll need to append the name, otherwise
you can simply:
<code>gyro publish</code>
This should open your browser to a page asking for a alphanumeric code which you
can find printed on the command line. Enter this code, this will open another
page to confirm read access to your user and your email from your Github
account. Once that is complete, Gyro will publish your package and if successful
a link to it will be printed to stdout.
An access token is cached so that this browser sign-on process only needs to be
done once for a given dev machine.
If you'd like to add publishing from a CI system see <a>Publishing from an
action</a>.
Adding dependencies
From package index
<code>gyro add <user>/<pkg></code>
From a git repo
Right now if the repo isn't from Github then you can add an entry to your <code>deps</code>
like so:
<code>deps:
pkgname:
git:
url: "https://some.repo/user/repo.git"
ref: main
root: my/root.zig</code>
From Github
If you add a package from Github, gyro will get the default branch, and try to
figure out the root path for you:
<code>gyro add --src github <user>/<repo></code>
From url
Note that at this time it is not possible to add a dependency from a url using
the command line. However, it is possible to give a url to a .tar.gz file by
adding it to your <code>gyro.zzz</code> file.
<code>yaml
deps:
pkgname:
url: "https://path/to/my/library.tar.gz"
root: libname/rootfile.zig</code>
In this example, when <code>library.tar.gz</code> is extracted the top level directory is
<code>libname</code>.
Build dependencies
It's also possible to use packaged code in your <code>build.zig</code>, since this would
only run at build time and not required in your application or library these are
kept separate from your regular dependencies in your project file.
When you want to add a dependency as a build dep, all you need to do is add
<code>--build-dep</code> to the gyro invocation. For example, let's assume I need to do
some parsing with a package called <code>mecha</code>:
<code>gyro add --build-dep mattnite/zzz</code>
and in my <code>build.zig</code>:
```zig
const Builder = @import("std").build.Builder;
const pkgs = @import("gyro").pkgs;
const zzz = @import("zzz");
pub fn build(b: *Builder) void {
const exe = b.addExecutable("main", "src/main.zig");
pkgs.addAllTo(exe);
exe.install();
<code>// maybe do some workflow based on gyro.zzz
var tree = zzz.ZTree(1, 100){};
...
</code>
}
```
Removing dependencies
Removing a dependency only requires the alias (string used to import):
<code>gyro rm iguanaTLS</code>
Local development
One can switch out a dependency for a local copy using the <code>redirect</code>
subcommand. Let's say we're using <code>mattnite/tar</code> from astrolabe and we come
across a bug, we can debug with a local version of the package by running:
<code>gyro redirect -a tar -p ../tar</code>
This will point gyro at your local copy, and when you're done you can revert the
redirect(s) with:
<code>gyro redirect --clean</code>
Multiple dependencies can be redirected. Build dependencies are redirected by
passing <code>-b</code>. You can even redirect the dependencies of a local package.
HOT tip: add this to your git <code>pre-commit</code> hook to catch you before accidentally
commiting redirects:
<code>gyro redirect --check</code>
Update dependencies -- for package consumers
Updating dependencies only works for package consumers as it modifies
<a>gyro.lock</a>. It does not change dependency requirements, merely resolves the
dependencies to their latest versions. Simply:
<code>gyro update</code>
Updating single dependencies will come soon, right now everything is updated.
Use gyro in Github Actions
You can get your hands on Gyro for github actions
<a>here</a>, it does not install
the zig compiler so remember to include that as well!
Publishing from an action
It's possible to publish your package in an action or other CI system. If the
environment variable <code>GYRO_ACCESS_TOKEN</code> exists, Gyro will use that for the
authenticated publish request instead of using Github's device flow. For Github
actions this requires <a>creating a personal access
token</a>
with scope <code>read:user</code> and <code>user:email</code> and <a>adding it to an
Environment</a>,
and adding that Environment to your job. This allows you to access your token in
the <code>secrets</code> namespace. Here's an example publish job:
```yaml
name: Publish
on: workflow_dispatch
jobs:
publish:
runs-on: ubuntu-latest
environment: publish
steps:
- uses: mattnite/setup-gyro@v1
- uses: actions/checkout@v2
- run: gyro publish
env:
GYRO_ACCESS_TOKEN: ${{ secrets.GYRO_ACCESS_TOKEN }}
```
Completion Scripts
Completion scripts can be generated by the <code>completion</code> subcommand, it is run
like so:
<code>gyro completion -s <shell> <install path></code>
Right now only <code>zsh</code> is the only supported shell, and this will create a <code>_gyro</code>
file in the install path. If you are using <code>oh-my-zsh</code> then this path should be
<code>$HOME/.oh-my-zsh/completions</code>.
Design philosophy
The two main obectives for gyro are providing a great user experience and
creating a platform for members of the community to get their hands dirty with
Zig package management. The hope here is that this experience will better
inform the development of the official package manager.
To create a great user experience, gyro is inspired by Rust's package manager,
Cargo. It does this by taking over the build runner so that <code>zig build</code> is
effectively replaced with <code>gyro build</code>, and this automatically downloads missing
dependencies and allows for <a>build dependencies</a>. Other
features include easy <a>addition of dependencies</a> through
the cli, <a>publishing packages on
astrolabe.pm</a>, as well as local
development.
The official Zig package manager is going to be decentralized, meaning that
there will be no official package index. Gyro has a centralized feel in that the
best UX is to use Astrolabe, but you can use it without interacting with the
package index. It again comes down to not spending effort on supporting
everything imaginable, and instead focus on experimenting with big design
decisions around package management.
Generated files
gyro.zzz
This is your project file, it contains the packages you export (if any),
dependencies, and build dependencies. <code>zzz</code> is a file format similar to yaml but
has a stricter spec and is implemented in zig.
A map of a gyro.zzz file looks something like this:
```yaml
pkgs:
pkg_a:
version: 0.0.0
root: path/to/root.zig
description: the description field
license: spdix-id
homepage_url: https://straight.forward
source_url: https://straight.forward
<code># these are shown on astrolabe
tags:
http
cli
# allows for globbing, doesn't do recursive globbing yet
files:
LICENSE
README.md # this is displayed on the astrolabe
build.zig
src/*.zig
</code>
# exporting a second package
pkg_b:
version: 0.0.0
...
like 'deps' but these can be directly imported in build.zig
build_deps:
...
most 'keys' are the string used to import in zig code, the exception being
packages from the default package index which have a shortend version
deps:
# a package from the default package index, user is 'bruh', its name is 'blarg'
# and is imported with the same string
bruh/blarg: ^0.1.0
# importing blarg from a different package index, have to use a different
# import string, I'll use 'flarp'
flarp:
pkg:
name: blarg
user: arst
version: ^0.3.0
repository: something.gg
# a git package, imported with string 'mecha'
mecha:
git:
url: "https://github.com/Hejsil/mecha.git"
ref: zig-master
root: mecha.zig
# a raw url, imported with string 'raw' (remember its gotta be a tar.gz)
raw:
url: "https://example.com/foo.tar.gz"
root: bar.zig
# a local path, usually used for local development using the redirect
# subcommand, but could be used for vendoring or monorepos
blarg:
local: deps/blarg
root: src/main.zig
```
gyro.lock
This contains a lockfile for reproducible builds, it is only useful in compiled
projects, not libraries. Adding gyro.lock to your package will not affect
resolved versions of dependencies for your users -- it is suggested to add this
file to your <code>.gitignore</code> for libraries.
deps.zig
This is the generated file that's imported by <code>build.zig</code>, it can be imported
with <code>@import("deps.zig")</code> or <code>@import("gyro")</code>. Unless you are vendoring your
dependencies, this should be added to <code>.gitignore</code>.
.gyro/
This directory holds the source code of all your dependencies. Path names are
human readable and look something like <code><package>-<user>-<version></code> so in many
cases it is possible to navigate to dependencies and make small edits if you run
into bugs. For a more robust way to edit dependencies see <a>local
development</a>
It is suggested to add this to <code>.gitignore</code> as well. | []
|
https://avatars.githubusercontent.com/u/3932972?v=4 | zig-network | ikskuh/zig-network | 2020-04-28T11:39:38Z | A smallest-common-subset of socket functions for crossplatform networking, TCP & UDP | master | 12 | 553 | 67 | 553 | https://api.github.com/repos/ikskuh/zig-network/tags | MIT | [
"networking",
"tcp",
"tcp-client",
"tcp-server",
"udp",
"zig",
"zig-package"
]
| 287 | false | 2025-05-11T19:27:47Z | true | true | unknown | github | []
| Zig Network Abstraction
Small network abstraction layer around TCP & UDP.
Features
<ul>
<li>Implements the minimal API surface for basic networking</li>
<li>Makes cross-platform abstractions</li>
<li>Supports blocking and non-blocking I/O via <code>select</code>/<code>poll</code></li>
<li>UDP multicast support</li>
</ul>
Usage
Use with the package manager
<code>build.zig.zon</code>:
<code>zig
.{
.name = "appname",
.version = "0.0.0",
.dependencies = .{
.network = .{
.url = "https://github.com/MasterQ32/zig-network/archive/<COMMIT_HASH_HERE>.tar.gz",
.hash = "HASH_GOES_HERE",
},
},
}</code>
(To aquire the hash, please remove the line containing <code>.hash</code>, the compiler will then tell you which line to put back)
<code>build.zig</code>:
<code>zig
exe.addModule("network", b.dependency("network", .{}).module("network"));</code>
Usage example
```zig
const network = @import("network");
test "Connect to an echo server" {
try network.init();
defer network.deinit();
<code>const sock = try network.connectToHost(std.heap.page_allocator, "tcpbin.com", 4242, .tcp);
defer sock.close();
const msg = "Hi from socket!\n";
try sock.writer().writeAll(msg);
var buf: [128]u8 = undefined;
std.debug.print("Echo: {}", .{buf[0..try sock.reader().readAll(buf[0..msg.len])]});
</code>
}
```
See <a>async.zig</a> for a more complete example on how to use asynchronous I/O to make a small TCP server.
Run examples
Build all examples:
<code>bash
$ zig build examples</code>
Build a specific example:
<code>bash
$ zig build sync-examples</code>
To test an example, eg. <code>echo</code>:
<code>bash
$ ./zig-out/bin/echo 3000</code>
in another terminal
<code>bash
$ nc localhost 3000
hello
hello
how are you
how are you</code>
Notes
On Windows receive and send function calls are asynchronous and cooperate with the standard library event loop
when <code>io_mode = .evented</code> is set in the root file of your program.
Other calls (connect, listen, accept etc) are blocking. | [
"https://github.com/ikskuh/gurl"
]
|
https://avatars.githubusercontent.com/u/3759175?v=4 | mecha | Hejsil/mecha | 2020-06-10T11:02:59Z | A parser combinator library for Zig | master | 6 | 523 | 24 | 523 | https://api.github.com/repos/Hejsil/mecha/tags | MIT | [
"functional",
"parser",
"parser-combinators",
"parser-library",
"parsers",
"zig",
"zig-library",
"zig-package"
]
| 154 | false | 2025-05-09T20:28:43Z | true | true | 0.14.0 | github | []
| Mecha
A parser combinator library for the <a><code>Zig</code></a>
programming language. Time to make your own parser mech!
```zig
const mecha = @import("mecha");
const std = @import("std");
const Rgb = struct {
r: u8,
g: u8,
b: u8,
};
fn toByte(v: u4) u8 {
return @as(u8, v) * 0x10 + v;
}
const hex1 = mecha.int(u4, .{
.parse_sign = false,
.base = 16,
.max_digits = 1,
}).map(toByte);
const hex2 = mecha.int(u8, .{
.parse_sign = false,
.base = 16,
.max_digits = 2,
});
const rgb1 = mecha.manyN(hex1, 3, .{}).map(mecha.toStruct(Rgb));
const rgb2 = mecha.manyN(hex2, 3, .{}).map(mecha.toStruct(Rgb));
const rgb = mecha.combine(.{
mecha.ascii.char('#').discard(),
mecha.oneOf(.{ rgb2, rgb1 }),
});
test "rgb" {
const testing = std.testing;
const allocator = testing.allocator;
const a = (try rgb.parse(allocator, "#aabbcc")).value.ok;
try testing.expectEqual(@as(u8, 0xaa), a.r);
try testing.expectEqual(@as(u8, 0xbb), a.g);
try testing.expectEqual(@as(u8, 0xcc), a.b);
<code>const b = (try rgb.parse(allocator, "#abc")).value.ok;
try testing.expectEqual(@as(u8, 0xaa), b.r);
try testing.expectEqual(@as(u8, 0xbb), b.g);
try testing.expectEqual(@as(u8, 0xcc), b.b);
const c = (try rgb.parse(allocator, "#000000")).value.ok;
try testing.expectEqual(@as(u8, 0), c.r);
try testing.expectEqual(@as(u8, 0), c.g);
try testing.expectEqual(@as(u8, 0), c.b);
const d = (try rgb.parse(allocator, "#000")).value.ok;
try testing.expectEqual(@as(u8, 0), d.r);
try testing.expectEqual(@as(u8, 0), d.g);
try testing.expectEqual(@as(u8, 0), d.b);
</code>
}
```
Installation
Developers tend to either use
* The latest tagged release of Zig
* The latest build of Zigs master branch
Depending on which developer you are, you need to run different <code>zig fetch</code> commands:
```sh
Version of mecha that works with a tagged release of Zig
Replace <code><REPLACE ME></code> with the version of mecha that you want to use
See: https://github.com/Hejsil/mecha/releases
zig fetch --save https://github.com/Hejsil/mecha/archive/refs/tags/.tar.gz
Version of mecha that works with latest build of Zigs master branch
zig fetch --save git+https://github.com/Hejsil/mecha
```
Then add the following to <code>build.zig</code>:
<code>zig
const mecha = b.dependency("mecha", .{});
exe.root_module.addImport("mecha", clap.module("mecha"));</code> | [
"https://github.com/FOLLGAD/zig-wasm-parser",
"https://github.com/Hejsil/lemonbar-maker",
"https://github.com/vezel-dev/graf"
]
|
https://avatars.githubusercontent.com/u/65570835?v=4 | zgl | ziglibs/zgl | 2020-07-03T13:19:40Z | Zig OpenGL Wrapper | master | 4 | 500 | 68 | 500 | https://api.github.com/repos/ziglibs/zgl/tags | MIT | [
"bindings",
"zig",
"zig-package",
"ziglang"
]
| 277 | false | 2025-05-19T11:48:34Z | true | true | unknown | github | []
| ZGL – Zig OpenGL Bindings
This library provides a thin, type-safe binding for OpenGL.
Example
```zig
// Use classic OpenGL flavour
var vao = gl.createVertexArray();
defer gl.deleteVertexArray(vao);
// Use object oriented flavour
var vertex_buffer = gl.Buffer.create();
defer vertex_buffer.delete();
```
Installation
Add zgl to your <code>build.zig.zon</code> with the following command:
<code>zig fetch --save https://github.com/ziglibs/zgl/archive/[commit_hash].tar.gz</code>
Replace [commit_hash] with the latest commit or tagged release.
Then add the following to your <code>build.zig</code>:
<code>zig
const zgl = b.dependency("zgl", .{
.target = target,
.optimize = optimize,
});
exe.root_module.addImport("zgl", zgl.module("zgl"));</code>
Then import it with <code>const gl = @import("zgl");</code>, and build as normal with <code>zig build</code>.
Development Philosophy
This library is developed incrementally. That means that functions and other things will be included on-demand and not just for the sake of completeness.
If you think a function is missing, fork the library, implement the missing function similar to the other functions and make a pull request. Issues that request implementation of missing functions will be closed immediatly.
Generated Bindings
This library includes OpenGL 4.5 bindings, generated by <a>zig-opengl</a>. Bindings for a different version may be substituted by replacing <a>binding.zig</a>. | [
"https://github.com/chadwain/zss"
]
|
https://avatars.githubusercontent.com/u/1916079?v=4 | zig-sqlite | vrischmann/zig-sqlite | 2020-12-12T01:45:21Z | zig-sqlite is a small wrapper around sqlite's C API, making it easier to use with Zig. | master | 0 | 473 | 63 | 473 | https://api.github.com/repos/vrischmann/zig-sqlite/tags | MIT | [
"sqlite",
"zig",
"zig-package"
]
| 10,562 | false | 2025-05-21T21:11:30Z | true | true | 0.14.0 | github | [
{
"commit": null,
"name": "sqlite",
"tar_url": null,
"type": "remote",
"url": "https://sqlite.org/2025/sqlite-amalgamation-3480000.zip"
}
]
| zig-sqlite
This package is a thin wrapper around <a>sqlite</a>'s C API.
<em>Maintainer note</em>: I'm currently on a break working with Zig and don't intend to work on new features for zig-sqlite.
I will keep it updated for the latest Zig versions because that doesn't take too much of my time.
Status
While the core functionality works right now, the API is still subject to changes.
If you use this library, expect to have to make changes when you update the code.
Zig release support
<code>zig-sqlite</code> only tracks Zig master (as can be found <a>here</a>). The plan is to support releases once Zig 1.0 is released but this can still change.
So your mileage may vary if you try to use <code>zig-sqlite</code>.
Table of contents
<ul>
<li><a>zig-sqlite</a></li>
<li><a>Status</a></li>
<li><a>Zig release support</a></li>
<li><a>Table of contents</a></li>
<li><a>Requirements</a></li>
<li><a>Features</a></li>
<li><a>Installation</a></li>
<li><a>Usage</a></li>
<li><a>Demo</a></li>
<li><a>Initialization</a></li>
<li><a>Preparing a statement</a><ul>
<li><a>Common use</a></li>
<li><a>Diagnostics</a></li>
</ul>
</li>
<li><a>Executing a statement</a></li>
<li><a>Reuse a statement</a></li>
<li><a>Reading data in one go</a><ul>
<li><a>Type parameter</a></li>
<li><a><code>Statement.one</code></a></li>
<li><a><code>Statement.all</code> and <code>Statement.oneAlloc</code></a></li>
</ul>
</li>
<li><a>Iterating</a><ul>
<li><a><code>Iterator.next</code></a></li>
<li><a><code>Iterator.nextAlloc</code></a></li>
</ul>
</li>
<li><a>Bind parameters and resultset rows</a></li>
<li><a>Custom type binding and reading</a></li>
<li><a>Note about complex allocations</a></li>
<li><a>Comptime checks</a></li>
<li><a>Check the number of bind parameters.</a></li>
<li><a>Assign types to bind markers and check them.</a></li>
<li><a>User defined SQL functions</a></li>
<li><a>Scalar functions</a></li>
<li><a>Aggregate functions</a></li>
</ul>
Requirements
<a>Zig master</a> is the only required dependency.
For sqlite, you have options depending on your target:
* On Windows the only supported way at the moment to build <code>zig-sqlite</code> is with the bundled sqlite source code file.
* On Linux we have two options:
* use the system and development package for sqlite (<code>libsqlite3-dev</code> for Debian and derivatives, <code>sqlite3-devel</code> for Fedora)
* use the bundled sqlite source code file.
Features
<ul>
<li>Preparing, executing statements</li>
<li>comptime checked bind parameters</li>
<li>user defined SQL functions</li>
</ul>
Installation
Use the following <code>zig fetch</code> command:
<code>zig fetch --save git+https://github.com/vrischmann/zig-sqlite</code>
Now in your <code>build.zig</code> you can access the module like this:
<code>zig
const sqlite = b.dependency("sqlite", .{
.target = target,
.optimize = optimize,
});
exe.root_module.addImport("sqlite", sqlite.module("sqlite"));</code>
Usage
Demo
See https://github.com/vrischmann/zig-sqlite-demo for a quick demo.
Initialization
Import <code>zig-sqlite</code> like this:
<code>zig
const sqlite = @import("sqlite");</code>
You must create and initialize an instance of <code>sqlite.Db</code>:
<code>zig
var db = try sqlite.Db.init(.{
.mode = sqlite.Db.Mode{ .File = "/home/vincent/mydata.db" },
.open_flags = .{
.write = true,
.create = true,
},
.threading_mode = .MultiThread,
});</code>
The <code>init</code> method takes a <code>InitOptions</code> struct which will be used to configure sqlite.
Only the <code>mode</code> field is mandatory, the other fields have sane default values.
Preparing a statement
Common use
sqlite works exclusively by using prepared statements. The wrapper type is <code>sqlite.Statement</code>. Here is how you get one:
```zig
try db.exec("CREATE TABLE IF NOT EXISTS employees(id integer primary key, name text, age integer, salary integer)", .{}, .{});
const query =
\SELECT id, name, age, salary FROM employees WHERE age > ? AND age < ?
;
var stmt = try db.prepare(query);
defer stmt.deinit();
```
The <code>Db.prepare</code> method takes a <code>comptime</code> query string.
Diagnostics
If you want failure diagnostics you can use <code>prepareWithDiags</code> like this:
<code>zig
var diags = sqlite.Diagnostics{};
var stmt = db.prepareWithDiags(query, .{ .diags = &diags }) catch |err| {
std.log.err("unable to prepare statement, got error {}. diagnostics: {s}", .{ err, diags });
return err;
};
defer stmt.deinit();</code>
Executing a statement
For queries which do not return data (<code>INSERT</code>, <code>UPDATE</code>) you can use the <code>exec</code> method:
```zig
const query =
\INSERT INTO employees(name, age, salary) VALUES(?, ?, ?)
;
var stmt = try db.prepare(query);
defer stmt.deinit();
try stmt.exec(.{}, .{
.name = "José",
.age = 40,
.salary = 20000,
});
```
See the section "Bind parameters and resultset rows" for more information on the types mapping rules.
Reuse a statement
You can reuse a statement by resetting it like this:
```zig
const query =
\UPDATE employees SET salary = ? WHERE id = ?
;
var stmt = try db.prepare(query);
defer stmt.deinit();
var id: usize = 0;
while (id < 20) : (id += 1) {
stmt.reset();
try stmt.exec(.{}, .{
.salary = 2000,
.id = id,
});
}
```
Reading data in one go
For queries which return data you have multiple options:
* <code>Statement.all</code> which takes an allocator and can allocate memory.
* <code>Statement.one</code> which does not take an allocator and cannot allocate memory (aside from what sqlite allocates itself).
* <code>Statement.oneAlloc</code> which takes an allocator and can allocate memory.
Type parameter
All these methods take a type as first parameter.
The type represents a "row", it can be:
* a struct where each field maps to the corresponding column in the resultset (so field 0 must map to column 1 and so on).
* a single type, in that case the resultset must only return one column.
The type can be a pointer but only when using the methods taking an allocator.
Not all types are allowed, see the section "Bind parameters and resultset rows" for more information on the types mapping rules.
<code>Statement.one</code>
Using <code>one</code>:
```zig
const query =
\SELECT name, age FROM employees WHERE id = ?
;
var stmt = try db.prepare(query);
defer stmt.deinit();
const row = try stmt.one(
struct {
name: [128:0]u8,
age: usize,
},
.{},
.{ .id = 20 },
);
if (row) |r| {
const name_ptr: [*:0]const u8 = &r.name;
std.log.debug("name: {s}, age: {}", .{ std.mem.span(name_ptr), r.age });
}
}
<code>``
Notice that to read text we need to use a 0-terminated array; if the</code>name<code>column is bigger than 127 bytes the call to</code>one` will fail.
If the length of the data is variable then the sentinel is mandatory: without one there would be no way to know where the data ends in the array.
However if the length is fixed, you can read into a non 0-terminated array, for example:
```zig
const query =
\SELECT id FROM employees WHERE name = ?
;
var stmt = try db.prepare(query);
defer stmt.deinit();
const row = try stmt.one(
[16]u8,
.{},
.{ .name = "Vincent" },
);
if (row) |id| {
std.log.debug("id: {s}", .{std.fmt.fmtSliceHexLower(&id)});
}
```
If the column data doesn't have the correct length a <code>error.ArraySizeMismatch</code> will be returned.
The convenience function <code>sqlite.Db.one</code> works exactly the same way:
```zig
const query =
\SELECT age FROM employees WHERE id = ?
;
const row = try db.one(usize, query, .{}, .{ .id = 20 });
if (row) |age| {
std.log.debug("age: {}", .{age});
}
```
<code>Statement.all</code> and <code>Statement.oneAlloc</code>
Using <code>all</code>:
```zig
const query =
\SELECT name FROM employees WHERE age > ? AND age < ?
;
var stmt = try db.prepare(query);
defer stmt.deinit();
const allocator = std.heap.page_allocator; // Use a suitable allocator
const names = try stmt.all([]const u8, allocator, .{}, .{
.age1 = 20,
.age2 = 40,
});
for (names) |name| {
std.log.debug("name: {s}", .{ name });
}
```
Using <code>oneAlloc</code>:
```zig
const query =
\SELECT name FROM employees WHERE id = ?
;
var stmt = try db.prepare(query);
defer stmt.deinit();
const allocator = std.heap.page_allocator; // Use a suitable allocator
const row = try stmt.oneAlloc([]const u8, allocator, .{}, .{
.id = 200,
});
if (row) |name| {
std.log.debug("name: {s}", .{name});
}
```
Iterating
Another way to get the data returned by a query is to use the <code>sqlite.Iterator</code> type.
You can only get one by calling the <code>iterator</code> method on a statement.
The <code>iterator</code> method takes a type which is the same as with <code>all</code>, <code>one</code> or <code>oneAlloc</code>: every row retrieved by calling <code>next</code> or <code>nextAlloc</code> will have this type.
Iterating is done by calling the <code>next</code> or <code>nextAlloc</code> method on an iterator. Just like before, <code>next</code> cannot allocate memory while <code>nextAlloc</code> can allocate memory.
<code>next</code> or <code>nextAlloc</code> will either return an optional value or an error; you should keep iterating until <code>null</code> is returned.
<code>Iterator.next</code>
```zig
var stmt = try db.prepare("SELECT age FROM employees WHERE age < ?");
defer stmt.deinit();
var iter = try stmt.iterator(usize, .{
.age = 20,
});
while (try iter.next(.{})) |age| {
std.debug.print("age: {}\n", .{age});
}
```
<code>Iterator.nextAlloc</code>
```zig
var stmt = try db.prepare("SELECT name FROM employees WHERE age < ?");
defer stmt.deinit();
var iter = try stmt.iterator([]const u8, .{
.age = 20,
});
const allocator = std.heap.page_allocator; // Use a suitable allocator
while (true) {
var arena = std.heap.ArenaAllocator.init(allocator);
defer arena.deinit();
<code>const name = (try iter.nextAlloc(arena.allocator(), .{})) orelse break;
std.debug.print("name: {s}\n", .{name});
</code>
}
```
Bind parameters and resultset rows
Since sqlite doesn't have many <a>types</a> only a small number of Zig types are allowed in binding parameters and in resultset mapping types.
Here are the rules for bind parameters:
* any Zig <code>Int</code> or <code>ComptimeInt</code> is treated as a <code>INTEGER</code>.
* any Zig <code>Float</code> or <code>ComptimeFloat</code> is treated as a <code>REAL</code>.
* <code>[]const u8</code>, <code>[]u8</code> is treated as a <code>TEXT</code>.
* the custom <code>sqlite.Blob</code> type is treated as a <code>BLOB</code>.
* the custom <code>sqlite.Text</code> type is treated as a <code>TEXT</code>.
* the <code>null</code> value is treated as a <code>NULL</code>.
* non-null optionals are treated like a regular value, null optionals are treated as a <code>NULL</code>.
Here are the rules for resultset rows:
* <code>INTEGER</code> can be read into any Zig <code>Int</code> provided the data fits.
* <code>REAL</code> can be read into any Zig <code>Float</code> provided the data fits.
* <code>TEXT</code> can be read into a <code>[]const u8</code> or <code>[]u8</code>.
* <code>TEXT</code> can be read into any array of <code>u8</code> with a sentinel provided the data fits.
* <code>BLOB</code> follows the same rules as <code>TEXT</code>.
* <code>NULL</code> can be read into any optional.
Note that arrays must have a sentinel because we need a way to communicate where the data actually stops in the array, so for example use <code>[200:0]u8</code> for a <code>TEXT</code> field.
Custom type binding and reading
Sometimes the default field binding or reading logic is not what you want, for example if you want to store an enum using its tag name instead of its integer value or
if you want to store a byte slice as an hex string.
To accomplish this you must first define a wrapper struct for your type. For example if your type is a <code>[4]u8</code> and you want to treat it as an integer:
```zig
pub const MyArray = struct {
data: [4]u8,
<code>pub const BaseType = u32;
pub fn bindField(self: MyArray, _: std.mem.Allocator) !BaseType {
return std.mem.readIntNative(BaseType, &self.data);
}
pub fn readField(_: std.mem.Allocator, value: BaseType) !MyArray {
var arr: MyArray = undefined;
std.mem.writeIntNative(BaseType, &arr.data, value);
return arr;
}
</code>
};
```
Now when you bind a value of type <code>MyArray</code> the value returned by <code>bindField</code> will be used for binding instead.
Same for reading, when you select <em>into</em> a <code>MyArray</code> row or field the value returned by <code>readField</code> will be used instead.
<em>NOTE</em>: when you <em>do</em> allocate in <code>bindField</code> or <code>readField</code> make sure to pass a <code>std.heap.ArenaAllocator</code>-based allocator.
The binding or reading code does not keep tracking of allocations made in custom types so it can't free the allocated data itself; it's therefore required
to use an arena to prevent memory leaks.
Note about complex allocations
Depending on your queries and types there can be a lot of allocations required. Take the following example:
```zig
const User = struct {
id: usize,
first_name: []const u8,
last_name: []const u8,
data: []const u8,
};
fn fetchUsers(allocator: std.mem.Allocator, db: *sqlite.Db) ![]User {
var stmt = try db.prepare("SELECT id FROM user WHERE id > $id");
defer stmt.deinit();
<code>return stmt.all(User, allocator, .{}, .{ .id = 20 });
</code>
}
```
This will do multiple allocations:
* one for each id field in the <code>User</code> type
* one for the resulting slice
To facilitate memory handling, consider using an arena allocator like this:
```zig
const allocator = std.heap.page_allocator; // Use a suitable allocator
var arena = std.heap.ArenaAllocator.init(allocator);
defer arena.deinit();
const users = try fetchUsers(arena.allocator(), db);
_ = users;
```
This is especially recommended if you use custom types that allocate memory since, as noted above, it's necessary to prevent memory leaks.
Comptime checks
Prepared statements contain <em>comptime</em> metadata which is used to validate every call to <code>exec</code>, <code>one</code> and <code>all</code> <em>at compile time</em>.
Check the number of bind parameters.
The first check makes sure you provide the same number of bind parameters as there are bind markers in the query string.
Take the following code:
```zig
var stmt = try db.prepare("SELECT id FROM user WHERE age > ? AND age < ? AND weight > ?");
defer stmt.deinit();
const allocator = std.heap.page_allocator; // Use a suitable allocator
const rows = try stmt.all(usize, allocator, .{}, .{
.age_1 = 10,
.age_2 = 20,
});
_ = rows;
<code>It fails with this compilation error:</code>
/home/vincent/dev/perso/libs/zig-sqlite/sqlite.zig:738:17: error: number of bind markers not equal to number of fields
@compileError("number of bind markers not equal to number of fields");
^
/home/vincent/dev/perso/libs/zig-sqlite/sqlite.zig:817:22: note: called from here
self.bind(values);
^
/home/vincent/dev/perso/libs/zig-sqlite/sqlite.zig:905:41: note: called from here
var iter = try self.iterator(Type, values);
^
./src/main.zig:19:30: note: called from here
const rows = try stmt.all(usize, allocator, .{}, .{
^
./src/main.zig:5:29: note: called from here
pub fn main() anyerror!void {
```
Assign types to bind markers and check them.
The second (and more interesting) check makes sure you provide appropriately typed values as bind parameters.
This check is not automatic since with a standard SQL query we have no way to know the types of the bind parameters, to use it you must provide theses types in the SQL query with a custom syntax.
For example, take the same code as above but now we also bind the last parameter:
```zig
var stmt = try db.prepare("SELECT id FROM user WHERE age > ? AND age < ? AND weight > ?");
defer stmt.deinit();
const allocator = std.heap.page_allocator; // Use a suitable allocator
const rows = try stmt.all(usize, allocator, .{}, .{
.age_1 = 10,
.age_2 = 20,
.weight = false,
});
_ = rows;
```
This compiles correctly even if the <code>weight</code> field in our <code>user</code> table is of the type <code>INTEGER</code>.
We can make sure the bind parameters have the right type if we rewrite the query like this:
```zig
var stmt = try db.prepare("SELECT id FROM user WHERE age > ? AND age < ? AND weight > ?{usize}");
defer stmt.deinit();
const allocator = std.heap.page_allocator; // Use a suitable allocator
const rows = try stmt.all(usize, allocator, .{}, .{
.age_1 = 10,
.age_2 = 20,
.weight = false,
});
_ = rows;
<code>Now this fails to compile:</code>
/home/vincent/dev/perso/libs/zig-sqlite/sqlite.zig:745:25: error: value type bool is not the bind marker type usize
@compileError("value type " ++ @typeName(struct_field.field_type) ++ " is not the bind marker type " ++ @typeName(typ));
^
/home/vincent/dev/perso/libs/zig-sqlite/sqlite.zig:817:22: note: called from here
self.bind(values);
^
/home/vincent/dev/perso/libs/zig-sqlite/sqlite.zig:905:41: note: called from here
var iter = try self.iterator(Type, values);
^
./src/main.zig:19:30: note: called from here
const rows = try stmt.all(usize, allocator, .{}, .{
^
./src/main.zig:5:29: note: called from here
pub fn main() anyerror!void {
<code>``
The syntax is straightforward: a bind marker</code>?<code>followed by</code>{<code>, a Zig type name and finally</code>}`.
There are a limited number of types allowed currently:
* all <a>integer</a> types.
* all <a>arbitrary bit-width integer</a> types.
* all <a>float</a> types.
* bool.
* strings with <code>[]const u8</code> or <code>[]u8</code>.
* strings with <code>sqlite.Text</code>.
* blobs with <code>sqlite.Blob</code>.
It is probably possible to support arbitrary types if they can be marshaled to an SQLite type. This is something to investigate.
<strong>NOTE</strong>: this is done at compile time and is quite CPU intensive, therefore it's possible you'll have to play with <a>@setEvalBranchQuota</a> to make it compile.
To finish our example, passing the proper type allows it compile:
```zig
var stmt = try db.prepare("SELECT id FROM user WHERE age > ? AND age < ? AND weight > ?{usize}");
defer stmt.deinit();
const allocator = std.heap.page_allocator; // Use a suitable allocator
const rows = try stmt.all(usize, allocator, .{}, .{
.age_1 = 10,
.age_2 = 20,
.weight = @as(usize, 200),
});
_ = rows;
```
User defined SQL functions
sqlite supports <a>user-defined SQL functions</a> which come in two types:
* scalar functions
* aggregate functions
In both cases the arguments are <a>sqlite3_values</a> and are converted to Zig values using the following rules:
* <code>TEXT</code> values can be either <code>sqlite.Text</code> or <code>[]const u8</code>
* <code>BLOB</code> values can be either <code>sqlite.Blob</code> or <code>[]const u8</code>
* <code>INTEGER</code> values can be any Zig integer
* <code>REAL</code> values can be any Zig float
Scalar functions
You can define a scalar function using <code>db.createScalarFunction</code>:
```zig
try db.createScalarFunction(
"blake3",
struct {
fn run(input: []const u8) [std.crypto.hash.Blake3.digest_length]u8 {
var hash: [std.crypto.hash.Blake3.digest_length]u8 = undefined;
std.crypto.hash.Blake3.hash(input, &hash, .{});
return hash;
}
}.run,
.{},
);
const hash = try db.one([std.crypto.hash.Blake3.digest_length]u8, "SELECT blake3('hello')", .{}, .{});
```
Each input arguments in the function call in the statement is passed on to the registered <code>run</code> function.
Aggregate functions
You can define an aggregate function using <code>db.createAggregateFunction</code>:
```zig
const MyContext = struct {
sum: u32,
};
var my_ctx = MyContext{ .sum = 0 };
try db.createAggregateFunction(
"mySum",
&my_ctx,
struct {
fn step(fctx: sqlite.FunctionContext, input: u32) void {
var ctx = fctx.userContext(<em>MyContext) orelse return;
ctx.sum += input;
}
}.step,
struct {
fn finalize(fctx: sqlite.FunctionContext) u32 {
const ctx = fctx.userContext(</em>MyContext) orelse return 0;
return ctx.sum;
}
}.finalize,
.{},
);
const result = try db.one(usize, "SELECT mySum(nb) FROM foobar", .{}, .{});
```
Each input arguments in the function call in the statement is passed on to the registered <code>step</code> function.
The <code>finalize</code> function is called once at the end.
The context (2nd argument of <code>createAggregateFunction</code>) can be whatever you want; both the <code>step</code> and <code>finalize</code> functions must
have their first argument of the same type as the context. | []
|
https://avatars.githubusercontent.com/u/4969905?v=4 | zig-string | JakubSzark/zig-string | 2020-09-01T17:06:14Z | A String Library made for Zig | master | 5 | 468 | 34 | 468 | https://api.github.com/repos/JakubSzark/zig-string/tags | MIT | [
"library",
"simple",
"string",
"utf-8",
"zig",
"zig-string"
]
| 110 | false | 2025-05-20T11:35:27Z | true | true | 0.14.0 | github | []
| Zig String (A UTF-8 String Library)
<a></a>
This library is a UTF-8 compatible <strong>string</strong> library for the <strong>Zig</strong> programming language.
I made this for the sole purpose to further my experience and understanding of zig.
Also it may be useful for some people who need it (including myself), with future projects. Project is also open for people to add to and improve. Please check the <strong>issues</strong> to view requested features.
Basic Usage
```zig
const std = @import("std");
const String = @import("./zig-string.zig").String;
// ...
// Use your favorite allocator
var arena = std.heap.ArenaAllocator.init(std.heap.page_allocator);
defer arena.deinit();
// Create your String
var myString = String.init(arena.allocator());
defer myString.deinit();
// Use functions provided
try myString.concat("🔥 Hello!");
_ = myString.pop();
try myString.concat(", World 🔥");
// Success!
std.debug.assert(myString.cmp("🔥 Hello, World 🔥"));
```
Installation
Add this to your build.zig.zon
```zig
.dependencies = .{
.string = .{
.url = "https://github.com/JakubSzark/zig-string/archive/refs/heads/master.tar.gz",
//the correct hash will be suggested by zig
}
}
```
And add this to you build.zig
```zig
const string = b.dependency("string", .{
.target = target,
.optimize = optimize,
});
exe.root_module.addImport("string", string.module("string"));
```
You can then import the library into your code like this
<code>zig
const String = @import("string").String;</code>
How to Contribute
<ol>
<li>Fork</li>
<li>Clone</li>
<li>Add Features (Use Zig FMT)</li>
<li>Make a Test</li>
<li>Pull Request</li>
<li>Success!</li>
</ol>
Working Features
If there are any issues with <b>complexity</b> please <b>open an issue</b>
(I'm no expert when it comes to complexity)
| Function | Description |
| ------------------ | ------------------------------------------------------------------------ |
| allocate | Sets the internal buffer size |
| capacity | Returns the capacity of the String |
| charAt | Returns character at index |
| clear | Clears the contents of the String |
| clone | Copies this string to a new one |
| cmp | Compares to string literal |
| concat | Appends a string literal to the end |
| deinit | De-allocates the String |
| find | Finds first string literal appearance |
| rfind | Finds last string literal appearance |
| includesLiteral | Whether or not the provided literal is in the String |
| includesString | Whether or not the provided String is within the String |
| init | Creates a String with an Allocator |
| init_with_contents | Creates a String with specified contents |
| insert | Inserts a character at an index |
| isEmpty | Checks if length is zero |
| iterator | Returns a StringIterator over the String |
| len | Returns count of characters stored |
| pop | Removes the last character |
| remove | Removes a character at an index |
| removeRange | Removes a range of characters |
| repeat | Repeats string n times |
| reverse | Reverses all the characters |
| split | Returns a slice based on delimiters and index |
| splitAll | Returns a slice of slices based on delimiters |
| splitToString | Returns a String based on delimiters and index |
| splitAllToStrings | Returns a slice of Strings based on delimiters |
| lines | Returns a slice of Strings split by newlines |
| str | Returns the String as a slice |
| substr | Creates a string from a range |
| toLowercase | Converts (ASCII) characters to lowercase |
| toOwned | Creates an owned slice of the String |
| toUppercase | Converts (ASCII) characters to uppercase |
| toCapitalized | Converts the first (ASCII) character of each word to uppercase |
| trim | Removes whitelist from both ends |
| trimEnd | Remove whitelist from the end |
| trimStart | Remove whitelist from the start |
| truncate | Realloc to the length |
| setStr | Set's buffer value from string literal |
| writer | Returns a std.io.Writer for the String |
| startsWith | Determines if the given string begins with the given value |
| endsWith | Determines if the given string ends with the given value |
| replace | Replace all occurrences of the search string with the replacement string | | [
"https://github.com/jnordwick/znh"
]
|
https://avatars.githubusercontent.com/u/3932972?v=4 | ZigAndroidTemplate | ikskuh/ZigAndroidTemplate | 2020-07-25T15:59:33Z | This repository contains a example on how to create a minimal Android app in Zig. | master | 16 | 386 | 36 | 386 | https://api.github.com/repos/ikskuh/ZigAndroidTemplate/tags | MIT | [
"android",
"android-support",
"app-framework",
"zig",
"zig-package",
"ziglang"
]
| 1,265 | false | 2025-05-19T11:00:52Z | true | false | unknown | github | []
| Android Apps in Zig
This repository contains multiple examples of creating a minimal Android app in Zig.
Examples
There are 4 different examples. The examples have no dependencies on C code except for the android libraries, so they can be considered pure Zig apps.
To select which example to build and run, pass the example flag (e.g. <code>-Dexample=egl</code>). Valid values for the example flag are <code>egl</code>, <code>minimal</code>, <code>textview</code>, and <code>invocationhandler</code>.
We're running a CI that will verify the build for Windows, macOS and Linux:
<a></a>
Minimal
<code>examples/minimal</code> includes just enough code to get the app running.
EGL
<code>examples/egl/</code> initializes OpenGL and renders a color cycle. Touchscreen events will activate a sine wave synth and be displayed as small circles beneath the fingers that will fade as soon as no event for the same finger will happen again.
The code contains some commented examples on how to interface with the JNI to use advanced features of the <code>ANativeActivity</code>.
Textview
<code>examples/textview/</code> creates a Textview component with Android's built-in UI to display "Hello, World!".
InvocationHandler
<code>examples/invocationhandler</code> builds on the textview example. It shows how to pass a callback to the JNI by creating a button component that reacts to being pressed.
Presentation
There is a <a>FOSDEM Talk</a> you can watch here:
<ul>
<li><a>MP4 Video</a></li>
<li><a>WebM Video</a></li>
</ul>
Since the time of recording ZigAndroidTemplate has changed in some major ways.
What's missing
<ul>
<li>Configuration management example</li>
<li>Save/load app state example</li>
</ul>
Requirements & Build
You need the <a>Android SDK</a> installed together with the <a>Android NDK</a>.
You also need <a>adb</a> and a Java SDK installed (required for <code>jarsigner</code>).
Now you need to generate yourself a keystore to sign your apps. For debugging purposes, the build script contains a helper. Just invoke <code>zig build keystore</code> to generate yourself a debug keystore that can be used with later build invocations.
<strong>Note</strong> that the build file might ask you to configure some paths. Do as requested and just run the build again, it should work then.
If all of the above is done, you should be able to build the app by running <code>zig build</code>.
There are convenience options with <code>zig build push</code> (installs the app on a connected phone) and <code>zig build run</code> (which installs, then runs the app).
Quick Start
Install the <a><code>sdkmanager</code></a> and invoke the following command line:
```
Android Platforms for your target Android version
Min version: Android 5
sdkmanager --install "platforms;android-21"
you can install other versions as well
remember to set it like <code>zig build -Dandroid=android99</code>
sdkmanager --install "build-tools;33.0.1"
sdkmanager --install "ndk;25.1.8937393"
zig build keystore install run
```
This should build an APK and install it on your connected phone if possible.
Getting started
Check out the <a><code>build.zig</code></a> to see how to build a new android app. The <a><code>examples</code></a> folder has multiple examples for making minimal android apps.
Credits
Huge thanks to <a>@cnlohr</a> to create <a>rawdrawandroid</a> and making this project possible! | []
|
https://avatars.githubusercontent.com/u/60377?v=4 | zig-ecs | prime31/zig-ecs | 2020-06-01T04:23:04Z | null | master | 4 | 339 | 46 | 339 | https://api.github.com/repos/prime31/zig-ecs/tags | MIT | [
"zig"
]
| 304 | false | 2025-05-21T18:36:58Z | true | true | 0.14.0 | github | []
| Zig ECS
Zig ECS is a zig port of the fantasic <a>Entt</a>. Entt is <em>highly</em> templated C++ code which depending on your opinion is either a good thing or satan itself in code form. Zig doesn't have the same concept as C++ templates so the templated code was changed over to use Zig's generics and compile time metaprogramming.
What does a zigified Entt look like?
Below are examples of a View and a Group, the two main ways to work with entities in the ecs along with the scaffolding code.
Declare some structs to work with:
<code>zig
pub const Velocity = struct { x: f32, y: f32 };
pub const Position = struct { x: f32, y: f32 };</code>
Setup the Registry, which holds the entity data and is where we run our queries:
<code>zig
var reg = ecs.Registry.init(std.testing.allocator);</code>
Create a couple entities and add some components to them
<code>zig
const entity = reg.create();
reg.add(entity, Position{ .x = 0, .y = 0 });
reg.add(entity, Velocity{ .x = 5, .y = 7 });
...</code>
Create and iterate a View that matches all entities with a <code>Velocity</code> and <code>Position</code> component:
```zig
var view = reg.view(.{ Velocity, Position }, .{});
var iter = view.entityIterator();
while (iter.next()) |entity| {
const pos = view.getConst(Position, entity); // readonly copy
var vel = view.get(Velocity, entity); // mutable
}
```
The same example using an owning Group and iterating with <code>each</code>:
```zig
var group = reg.group(.{ Velocity, Position }, .{}, .{});
group.each(each);
fn each(e: struct { vel: <em>Velocity, pos: </em>Position }) void {
e.pos.<em>.x += e.vel.x;
e.pos.</em>.y += e.vel.y;
}
```
Component Storage Overview
<ul>
<li><strong>View</strong>: stores no data in the ECS. Iterates on the fly with no cache to speed up iteration. Start with a <code>View</code> for most things and you can always upgrade to a <code>Group</code>/<code>OwningGroup</code> if you need more speed.</li>
<li><strong>Group</strong>: stores and maintains an accurate list of all the entities matching the query. This query cache speeds up iteration since it already knows exactly which entities match the query. The downside is that it requires memory and cpu cycles to keep the cache up-to-date.</li>
<li><strong>OwningGroup</strong>: for any components in an <code>OwningGroup</code> the actual component storage containers are constantly reordered as entities are added/removed from the <code>Registry</code>. This allows direct iteration with no gaps of the component data. An <code>OwningGroup</code> does not require much extra memory but it is more cpu intensive if there is a lot of component churn (adding/removing of the owned components).</li>
</ul> | [
"https://github.com/JamzOJamz/terraria-classic"
]
|
https://avatars.githubusercontent.com/u/2567177?v=4 | zware | malcolmstill/zware | 2021-02-01T04:27:54Z | Zig WebAssembly Runtime Engine | master | 15 | 328 | 14 | 328 | https://api.github.com/repos/malcolmstill/zware/tags | MIT | [
"wasm",
"webassembly",
"zig",
"zig-package",
"ziglang"
]
| 3,281 | false | 2025-05-18T10:26:15Z | true | true | 0.14.0 | github | [
{
"commit": "39f85a791cbbad91a253a851841a29777efdc2cd.tar.gz",
"name": "wabt",
"tar_url": "https://github.com/WebAssembly/wabt/archive/39f85a791cbbad91a253a851841a29777efdc2cd.tar.gz.tar.gz",
"type": "remote",
"url": "https://github.com/WebAssembly/wabt"
},
{
"commit": "e25ae159357c055b3a6fac99043644e208d26d2a.tar.gz",
"name": "testsuite",
"tar_url": "https://github.com/WebAssembly/testsuite/archive/e25ae159357c055b3a6fac99043644e208d26d2a.tar.gz.tar.gz",
"type": "remote",
"url": "https://github.com/WebAssembly/testsuite"
}
]
| zware
<strong>Zig WebAssembly Runtime Engine</strong>
About
<code>zware</code> is a library for executing WebAssembly embedded in <a>Zig</a> programs.
Example
From <code>examples/fib</code>:
```zig
const std = @import("std");
const zware = @import("zware");
const Store = zware.Store;
const Module = zware.Module;
const Instance = zware.Instance;
const GeneralPurposeAllocator = std.heap.GeneralPurposeAllocator;
var gpa = GeneralPurposeAllocator(.{}){};
pub fn main() !void {
defer _ = gpa.deinit();
const alloc = gpa.allocator();
<code>const bytes = @embedFile("fib.wasm");
var store = Store.init(alloc);
defer store.deinit();
var module = Module.init(alloc, bytes);
defer module.deinit();
try module.decode();
var instance = Instance.init(alloc, &store, module);
try instance.instantiate();
defer instance.deinit();
const n = 39;
var in = [1]u64{n};
var out = [1]u64{0};
try instance.invoke("fib", in[0..], out[0..], .{});
const result: i32 = @bitCast(@as(u32, @truncate(out[0])));
std.debug.print("fib({}) = {}\n", .{ n, result });
</code>
}
```
Requirements
Compile-time
<ul>
<li>Zig 0.12 (master)</li>
</ul>
Run-time
<ul>
<li>None, zig generates static binaries:</li>
</ul>
<code>bash
➜ zware git:(master) ✗ ldd fib
not a dynamic executable</code>
Goals
<ul>
<li>Embed WebAssembly programs in other zig programs</li>
<li>Be fast enough to be useful</li>
</ul>
Status
<ul>
<li>The project is very much alpha quality</li>
<li>WebAssembly 2.0 supported (apart from the vector / SIMD support which is WIP)</li>
<li>The WebAssembly official testsuite passes (not including SIMD tests)</li>
<li>Partial WASI support</li>
</ul>
Running tests
Use <code>zig build --help</code> to see all the test targets, here's a summary of the important ones:
<code>sh
zig build test # Run all the tests (includes unittest and testsuite)
zig build unittest # Run the library unittests
zig build testsuite # Run all the testsuite tests
zig build test-NAME # Run the NAME testsuite test, i.e. test-type</code>
Does it run doom?
Yes, <a>yes it does</a>
https://github.com/malcolmstill/zware/assets/2567177/c9acdcb2-69e7-495f-b3f1-89cf6b807a43 | []
|
https://avatars.githubusercontent.com/u/1519747?v=4 | bold | kubkon/bold | 2021-01-23T06:25:16Z | bold: the bold linker | main | 3 | 318 | 25 | 318 | https://api.github.com/repos/kubkon/bold/tags | MIT | [
"linker",
"zig",
"zig-package"
]
| 4,575 | false | 2025-05-20T02:44:02Z | true | true | unknown | github | []
| bold - the <em>bold</em> linker
<blockquote>
Bold used to be emerald, but due to time constraints and other commitments I am unable to develop and maintain the other drivers.
Emerald now lives in another repo -> <a>kubkon/emerald-old</a>.
</blockquote>
<code>bold</code> is a drop-in replacement for Apple system linker <code>ld</code>, written fully in Zig. It is on par with the LLVM lld linker,
faster than the legacy Apple ld linker, but slower than the rewritten Apple ld linker. Some benchmark results between the linkers
when linking stage3-zig compiler which includes linking LLVM statically:
```sh
$ hyperfine ./bold.sh ./ld.sh ./ld_legacy.sh ./lld.sh
Benchmark 1: ./bold.sh
Time (mean ± σ): 978.5 ms ± 9.9 ms [User: 3083.2 ms, System: 949.2 ms]
Range (min … max): 967.6 ms … 998.7 ms 10 runs
Benchmark 2: ./ld.sh
Time (mean ± σ): 439.0 ms ± 5.4 ms [User: 1769.9 ms, System: 273.1 ms]
Range (min … max): 432.2 ms … 447.9 ms 10 runs
Benchmark 3: ./ld_legacy.sh
Time (mean ± σ): 1.986 s ± 0.021 s [User: 3.100 s, System: 0.221 s]
Range (min … max): 1.968 s … 2.030 s 10 runs
Benchmark 4: ./lld.sh
Time (mean ± σ): 1.043 s ± 0.009 s [User: 1.206 s, System: 0.210 s]
Range (min … max): 1.031 s … 1.060 s 10 runs
Summary
./ld.sh ran
2.23 ± 0.04 times faster than ./bold.sh
2.38 ± 0.04 times faster than ./lld.sh
4.52 ± 0.07 times faster than ./ld_legacy.sh
```
In the results
* <code>bold.sh</code> calls <code>bold</code> with all the required inputs and flags
* <code>ld.sh</code> calls the rewritten Apple linker
* <code>ld_legacy.sh</code> calls <code>ld -ld_classic</code> the legacy Apple linker
* <code>lld.sh</code> calls LLVM lld linker
tl;dr <code>bold</code> is currently directly competing with LLVM lld but behind the Apple ld linker.
Quick start guide
Building
You will need Zig 0.14.0 in your path. You can download it from <a>here</a>.
<code>$ zig build -Doptimize=ReleaseFast</code>
You can then pass it to your system C/C++ compiler with <code>-B</code> or <code>-fuse-ld</code> flag (note that the latter is supported mainly/only by clang):
```
$ cat < hello.c
include
int main() {
fprintf(stderr, "Hello, World!\n");
return 0;
}
EOF
Using clang
$ clang hello.c -fuse-ld=bold
Using gcc
$ gcc hello.c -B/path/to/bold
```
Testing
If you'd like to run unit and end-to-end tests, run the tests like you'd normally do for any other Zig project.
<code>$ zig build test</code>
Contributing
You are welcome to contribute to this repo. | []
|
https://avatars.githubusercontent.com/u/755611?v=4 | liz | dundalek/liz | 2020-11-28T11:30:32Z | Lisp-flavored general-purpose programming language (based on Zig) | master | 0 | 277 | 2 | 277 | https://api.github.com/repos/dundalek/liz/tags | MIT | [
"clojure",
"compiler",
"language",
"lisp",
"liz",
"zig"
]
| 397 | false | 2025-04-25T19:07:13Z | false | false | unknown | github | []
| Liz: Lisp-flavored general-purpose programming language (based on Zig)
Borrowing <a>Zig</a>'s tagline:
<blockquote>
General-purpose programming language and toolchain for maintaining robust, optimal, and reusable software.
</blockquote>
<ul>
<li>Written as Clojure-looking S-expressions (<a>EDN</a>) and translated to Zig code.</li>
<li><a>Type-A</a> Lisp-flavored language. I call it "Lisp-flavored" because Liz is missing many fundamental features to be called a Lisp or even a Clojure dialect (no closures, no persistent data structures).</li>
<li>When you need a language closer to the metal and Clojure with GraalVM's native image is too much overhead.</li>
<li>Supports many targets including x86, ARM, RISC-V, WASM and <a>more</a></li>
</ul>
Why is Zig an interesting choice as a lower-level language for Clojure programmers? (compared to Rust, Go or other languages):
<ul>
<li>Focus on simplicity</li>
<li>Seamless interop with C without the need to write bindings.
Similar quality like Clojure seamlessly interoperating with Java.</li>
<li>Incremental compilation with the Zig self-hosted compiler.
To accomplish this Zig uses a Global Offset Table for all function calls which is similar to Clojure Vars. Therefore it will be likely possible to implement a true REPL.</li>
<li>Decomplecting principles
Most higher-level languages have bundled memory management, which disqualifies them from certain use cases. Zig decomplects memory management by introducing explicit Allocator interface, programmer can choose fitting memory management mechanism with regard to performance/convenience trade-offs.</li>
</ul>
<strong>Status:</strong> <em>Experimental, but proving itself on a few projects.</em>
Examples
Hello World:
```clojure
;; hello.liz
(const print (.. (@import "std") -debug -print))
(defn ^void main []
(print "Hello, world!\n" []))
```
It will get translated into:
<code>zig
const print = @import("std").debug.print;
pub fn main() void {
print("Hello, world!\n", .{});
}</code>
Run with:
<code>$ liz hello.liz && zig run hello.zig
Hello, world!</code>
FizzBuzz example:
```clojure
(const print (.. (@import "std") -debug -print))
(defn ^void main []
(var ^usize i 1)
(while-step (<= i 100) (inc! i)
(cond
(zero? (mod i 15)) (print "FizzBuzz\n" [])
(zero? (mod i 3)) (print "Fizz\n" [])
(zero? (mod i 5)) (print "Buzz\n" [])
:else (print "{}\n" [i]))))
```
See also:
- more <a>examples</a>
- Advent of Code <a>solutions</a>
- Rendering <a>TUI with Notcurses</a>
Documentation
Read the work in progress <a>language guide</a>.
To see how a form is used you can also take a look at <a>samples</a> adapted from Zig docs.
Usage
Download <a>Liz</a> and <a>Zig</a>. To compile files from Liz to Zig pass them as parameters:
```sh
liz file1.liz file2.liz
file1.zig and file2.zig will be created
```
Then use <code>zig run</code> or <code>zig build-exe</code> on the generated <code>.zig</code> files.
Alternatively you can use the JAR:
<code>java -jar liz.jar file1.liz file2.liz</code>
Extension and Syntax highlighting
Use <code>.liz</code> file extension. It works pretty well to use Clojure syntax highlighting, add <code>-*- clojure -*-</code> metadata to the source file for Github and text editors to apply highlighting.
<code>;; -*- clojure -*-</code>
Design principles
<ul>
<li>Create 1:1 mapping, everything expressible in Zig should be expressible in Liz, or can be considered a bug.</li>
<li>If a Zig feature maps cleanly to Clojure then use the Clojure variant and name.</li>
<li>If the mapping conflicts then use the Zig vocabulary.</li>
</ul>
License
MIT
Development
Get the source:
<code>sh
git clone https://github.com/dundalek/liz.git
cd liz</code>
Build platform independent uberjar:
<code>sh
scripts/build-jar</code>
Build the native binary (requires <a>GraalVM</a>):
```sh
If you don't have native-image on PATH then you need to specify GRAALVM_HOME
export GRAALVM_HOME=/your/path/to/graal
scripts/build-native
```
Use Clojure CLI:
<code>sh
clj -M -m liz.main file1.liz file2.liz</code>
Run tests:
<code>sh
clj -Mtest</code> | []
|
https://avatars.githubusercontent.com/u/3932972?v=4 | zig-args | ikskuh/zig-args | 2020-03-04T21:34:00Z | Simple-to-use argument parser with struct-based config | master | 8 | 275 | 28 | 275 | https://api.github.com/repos/ikskuh/zig-args/tags | MIT | [
"option-parser",
"option-parsing",
"zig",
"zig-package",
"ziglang"
]
| 78 | false | 2025-05-12T10:06:42Z | true | true | 0.14.0-dev.2801+4d8c24c6c | github | []
| Zig Argument Parser
Simple-to-use argument parser with struct-based config
Features
<ul>
<li>Automatic option generation from a config struct</li>
<li>Familiar <em>look & feel</em>:<ul>
<li>Everything after the first <code>--</code> is assumed to be a positional argument</li>
<li>A single <code>-</code> is interpreted as a positional argument which can be used as the stdin/stdout file placeholder</li>
<li>Short options with no argument can be combined into a single argument: <code>-dfe</code></li>
<li>Long options can use either <code>--option=value</code> or <code>--option value</code> syntax (use <code>--option=--</code> if you need <code>--</code> as a long option argument)</li>
<li>verbs (sub-commands), with verb specific options. Non-verb specific (global) options can come before or after the
verb on the command line. Non-verb option arguments are processed <em>before</em> determining verb. (see <code>demo_verb.zig</code>)</li>
</ul>
</li>
<li>Integrated support for primitive types:<ul>
<li>All integer types (signed & unsigned)</li>
<li>Floating point types</li>
<li>Booleans (takes optional argument. If no argument given, the bool is set, otherwise, one of <code>yes</code>, <code>true</code>, <code>y</code>, <code>no</code>, <code>false</code>, <code>n</code> is interpreted)</li>
<li>Strings</li>
<li>Enumerations</li>
</ul>
</li>
</ul>
Use in your project
Add the dependency in your <code>build.zig.zon</code> by running the following command:
<code>bash
zig fetch --save=args git+https://github.com/ikskuh/zig-args#master</code>
Add it to your exe in <code>build.zig</code>:
<code>zig
exe.root_module.addImport("args", b.dependency("args", .{ .target = target, .optimize = optimize }).module("args"));</code>
Then you can import it from your code:
<code>zig
const argsParser = @import("args");</code>
Example
```zig
const options = argsParser.parseForCurrentProcess(struct {
// This declares long options for double hyphen
output: ?[]const u8 = null,
@"with-offset": bool = false,
@"with-hexdump": bool = false,
@"intermix-source": bool = false,
numberOfBytes: ?i32 = null,
signed_number: ?i64 = null,
unsigned_number: ?u64 = null,
mode: enum { default, special, slow, fast } = .default,
<code>// This declares short-hand options for single hyphen
pub const shorthands = .{
.S = "intermix-source",
.b = "with-hexdump",
.O = "with-offset",
.o = "output",
};
</code>
}, argsAllocator, .print) catch return 1;
defer options.deinit();
std.debug.print("executable name: {?s}\n", .{options.executable_name});
std.debug.print("parsed options:\n", .{});
inline for (std.meta.fields(@TypeOf(options.options))) |fld| {
std.debug.print("\t{s} = {any}\n", .{
fld.name,
@field(options.options, fld.name),
});
}
std.debug.print("parsed positionals:\n", .{});
for (options.positionals) |arg| {
std.debug.print("\t'{s}'\n", .{arg});
}
```
Versions
<ul>
<li>Branch <a>master</a> tracks Zig master</li>
<li>Branch <a>0.13.x</a> tracks Zig 0.13.0</li>
<li>Tag <a>0.9.0</a> tracks Zig 0.9.0</li>
</ul> | [
"https://github.com/ikskuh/gurl",
"https://github.com/jerome-trc/viletech-2022"
]
|
https://avatars.githubusercontent.com/u/19482899?v=4 | fastfilter | hexops/fastfilter | 2021-01-31T02:30:50Z | fastfilter: Binary fuse & xor filters for Zig (faster and smaller than bloom filters) | main | 0 | 271 | 15 | 271 | https://api.github.com/repos/hexops/fastfilter/tags | NOASSERTION | [
"bloom-filter",
"probabilistic-programming",
"xor-filter",
"zig",
"ziglang"
]
| 173 | false | 2025-05-16T00:24:27Z | true | false | unknown | github | []
| fastfilter: Binary fuse & xor filters for Zig <a></a>
<a></a>
<a></a>
Binary fuse filters & xor filters are probabilistic data structures which allow for quickly checking whether an element is part of a set.
Both are faster and more concise than Bloom filters, and smaller than Cuckoo filters. Binary fuse filters are a bleeding-edge development and are competitive with Facebook's ribbon filters:
<ul>
<li>Thomas Mueller Graf, Daniel Lemire, Binary Fuse Filters: Fast and Smaller Than Xor Filters (<em>not yet published</em>)</li>
<li>Thomas Mueller Graf, Daniel Lemire, <a>Xor Filters: Faster and Smaller Than Bloom and Cuckoo Filters</a>, Journal of Experimental Algorithmics 25 (1), 2020. DOI: 10.1145/3376122</li>
</ul>
Benefits of Zig implementation
This is a <a>Zig</a> implementation, which provides many practical benefits:
<ol>
<li><strong>Iterator-based:</strong> you can populate xor or binary fuse filters using an iterator, without keeping your entire key set in-memory and without it being a contiguous array of keys. This can reduce memory usage when populating filters substantially.</li>
<li><strong>Distinct allocators:</strong> you can provide separate Zig <code>std.mem.Allocator</code> implementations for the filter itself and population, enabling interesting opportunities like mmap-backed population of filters with low physical memory usage.</li>
<li><strong>Generic implementation:</strong> use <code>Xor(u8)</code>, <code>Xor(u16)</code>, <code>BinaryFuse(u8)</code>, <code>BinaryFuse(u16)</code>, or experiment with more exotic variants like <code>Xor(u4)</code> thanks to Zig's <a>bit-width integers</a> and generic type system.</li>
</ol>
Zig's safety-checking and checked overflows has also enabled us to improve the upstream C/Go implementations where overflow and undefined behavior went unnoticed.<a>[1]</a>
Usage
Decide if xor or binary fuse filters fit your use case better: <a>should I use binary fuse filters or xor filters?</a>
Get your keys into <code>u64</code> values. If you have strings, structs, etc. then use something like Zig's <a><code>std.hash_map.getAutoHashFn</code></a> to convert your keys to <code>u64</code> first. ("It is not important to have a good hash function, but collisions should be unlikely (~1/2^64).")
Create a <code>build.zig.zon</code> file in your project (replace <code>$LATEST_COMMIT</code> with the latest commit hash):
<code>.{
.name = "mypkg",
.version = "0.1.0",
.dependencies = .{
.fastfilter = .{
.url = "https://github.com/hexops/fastfilter/archive/$LATEST_COMMIT.tar.gz",
},
},
}</code>
Run <code>zig build</code> in your project, and the compiler instruct you to add a <code>.hash = "..."</code> field next to <code>.url</code>.
Then use the dependency in your <code>build.zig</code>:
<code>zig
pub fn build(b: *std.Build) void {
...
exe.addModule("fastfilter", b.dependency("fastfilter", .{
.target = target,
.optimize = optimize,
}).module("fastfilter"));
}</code>
In your <code>main.zig</code>, make use of the library:
```zig
const std = @import("std");
const testing = std.testing;
const fastfilter = @import("fastfilter");
test "mytest" {
const allocator = std.heap.page_allocator;
<code>// Initialize the binary fuse filter with room for 1 million keys.
const size = 1_000_000;
var filter = try fastfilter.BinaryFuse8.init(allocator, size);
defer filter.deinit(allocator);
// Generate some consecutive keys.
var keys = try allocator.alloc(u64, size);
defer allocator.free(keys);
for (keys, 0..) |key, i| {
_ = key;
keys[i] = i;
}
// Populate the filter with our keys. You can't update a xor / binary fuse filter after the
// fact, instead you should build a new one.
try filter.populate(allocator, keys[0..]);
// Now we can quickly test for containment. So fast!
try testing.expect(filter.contain(1) == true);
</code>
}
```
(you can just add this project as a Git submodule in yours for now, as <a>Zig's official package manager is still under way</a>.)
Binary fuse filters automatically deduplicate any keys during population. If you are using a different filter type (you probably shouldn't be!) then keys must be unique or else filter population will fail. You can use the <code>fastfilter.AutoUnique(u64)(keys)</code> helper to deduplicate (in typically O(N) time complexity), see the tests in <code>src/unique.zig</code> for usage examples.
Serialization
To serialize the filters, you only need to encode these struct fields:
<code>zig
pub fn BinaryFuse(comptime T: type) type {
return struct {
...
seed: u64,
segment_length: u32,
segment_length_mask: u32,
segment_count: u32,
segment_count_length: u32,
fingerprints: []T,
...</code>
<code>T</code> will be the chosen fingerprint size, e.g. <code>u8</code> for <code>BinaryFuse8</code> or <code>Xor8</code>.
Look at <a><code>std.io.Writer</code></a> and <a><code>std.io.BitWriter</code></a> for ideas on actual serialization.
Similarly, for xor filters you only need these struct fields:
<code>zig
pub fn Xor(comptime T: type) type {
return struct {
seed: u64,
blockLength: u64,
fingerprints: []T,
...</code>
Should I use binary fuse filters or xor filters?
If you're not sure, start with <code>BinaryFuse8</code> filters. They're fast, and have a false-positive probability rate of 1/256 (or 0.4%).
There are many tradeoffs, primarily between:
<ul>
<li>Memory usage</li>
<li>Containment check time</li>
<li>Population / creation time & memory usage</li>
</ul>
See the <a>benchmarks</a> section for a comparison of the tradeoffs between binary fuse filters and xor filters, as well as how larger bit sizes (e.g. <code>BinaryFuse(u16)</code>) consume more memory in exchange for a lower false-positive probability rate.
Note that <em>fuse filters</em> are not to be confused with <em>binary fuse filters</em>, the former have issues with construction, often failing unless you have a large number of unique keys. Binary fuse filters do not suffer from this and are generally better than traditional ones in several ways. For this reason, we consider traditional fuse filters deprecated.
Note about extremely large datasets
This implementation supports key iterators, so you do not need to have all of your keys in-memory, see <code>BinaryFuse8.populateIter</code> and <code>Xor8.populateIter</code>.
If you intend to use a xor filter with datasets of 100m+ keys, there is a possible faster implementation <em>for construction</em> found in the C implementation <a><code>xor8_buffered_populate</code></a> which is not implemented here.
Changelog
The API is generally finalized, but we may make some adjustments as Zig changes or we learn of more idiomatic ways to express things. We will release v1.0 once Zig v1.0 is released.
<strong>v0.11.0</strong>
<ul>
<li>fastfilter is now available via the Zig package manager.</li>
<li>Updated to the latest version of Zig nightly <code>0.12.0-dev.706+62a0fbdae</code></li>
</ul>
<strong>v0.10.3</strong>
<ul>
<li>Updated to the latest version of Zig <code>0.12.0-dev.706+62a0fbdae</code> (<code>build.zig</code> <code>.path</code> -> <code>.source</code> change.)</li>
</ul>
<strong>v0.10.2</strong>
<ul>
<li>Fixed a few correctness / integer overflow/underflow possibilities where we were inconsistent with the Go/C implementations of binary fuse filters.</li>
<li>Added debug-mode checks for iterator correctness (wraparound behavior.)</li>
</ul>
<strong>v0.10.1</strong>
<ul>
<li>Updated to the latest version of Zig <code>0.12.0-dev.706+62a0fbdae</code></li>
</ul>
<strong>v0.10.0</strong>
<ul>
<li>All types are now unmanaged (allocator must be passed via parameters)</li>
<li>Renamed <code>util.sliceIterator</code> to <code>fastfilter.SliceIterator</code></li>
<li><code>SliceIterator</code> is now unmanaged / does not store an allocator.</li>
<li><code>SliceIterator</code> now stores <code>[]const T</code> instead of <code>[]T</code> internally.</li>
<li><code>BinaryFuseFilter.max_iterations</code> is now a constant.</li>
<li>Added <code>fastfilter.MeasuredAllocator</code> for measuring allocations.</li>
<li>Improved usage example.</li>
<li>Properly free xorfilter/fusefilter fingerprints.</li>
<li>Updated benchmark to latest Zig version.</li>
</ul>
<strong>v0.9.3</strong>
<ul>
<li>Fixed potential integer overflow.</li>
</ul>
<strong>v0.9.2</strong>
<ul>
<li>Handle duplicated keys automatically</li>
<li>Added a <code>std.build.Pkg</code> definition</li>
<li>Fixed an unlikely bug</li>
<li>Updated usage instructions</li>
<li>Updated to Zig v0.10.0-dev.1736</li>
</ul>
<strong>v0.9.1</strong>
<ul>
<li>Updated to Zig v0.10.0-dev.36</li>
</ul>
<strong>v0.9.0</strong>
<ul>
<li>Renamed repository github.com/hexops/xorfilter -> github.com/hexops/fastfilter to account for binary fuse filters.</li>
<li>Implemented bleeding-edge (paper not yet published) "Binary Fuse Filters: Fast and Smaller Than Xor Filters" algorithm by Thomas Mueller Graf, Daniel Lemire</li>
<li><code>BinaryFuse</code> filters are now recommended by default, are generally better than Xor and Fuse filters.</li>
<li>Deprecated traditional <code>Fuse</code> filters (<code>BinaryFuse</code> are much better.)</li>
<li>Added much improved benchmarking suite with more details on memory consumption during filter population, etc.</li>
</ul>
<strong>v0.8.0</strong>
initial release with support for Xor and traditional Fuse filters of varying bit sizes, key iterators, serialization, and a slice de-duplication helper.
Benchmarks
Benchmarks were ran on both a 2019 Macbook Pro and Windows 10 desktop machine using e.g.:
<code>zig run -O ReleaseFast src/benchmark.zig -- --xor 8 --num-keys 1000000</code>
<strong>Benchmarks:</strong> 2019 Macbook Pro, Intel i9 (1M - 100M keys)
* CPU: 2.3 GHz 8-Core Intel Core i9
* Memory: 16 GB 2667 MHz DDR4
* Zig version: `0.12.0-dev.706+62a0fbdae`
| Algorithm | # of keys | populate | contains(k) | false+ prob. | bits per entry | peak populate | filter total |
|--------------|------------|------------|-------------|--------------|----------------|---------------|--------------|
| binaryfuse8 | 1000000 | 37.5ms | 24.0ns | 0.00391115 | 9.04 | 22 MiB | 1 MiB |
| binaryfuse16 | 1000000 | 45.5ms | 24.0ns | 0.00001524 | 18.09 | 24 MiB | 2 MiB |
| binaryfuse32 | 1000000 | 56.0ms | 24.0ns | 0 | 36.18 | 28 MiB | 4 MiB |
| xor2 | 1000000 | 108.0ms | 25.0ns | 0.2500479 | 9.84 | 52 MiB | 1 MiB |
| xor4 | 1000000 | 99.0ms | 25.0ns | 0.06253865 | 9.84 | 52 MiB | 1 MiB |
| xor8 | 1000000 | 103.4ms | 25.0ns | 0.0039055 | 9.84 | 52 MiB | 1 MiB |
| xor16 | 1000000 | 104.7ms | 26.0ns | 0.00001509 | 19.68 | 52 MiB | 2 MiB |
| xor32 | 1000000 | 102.2ms | 25.0ns | 0 | 39.36 | 52 MiB | 4 MiB |
| | | | | | | | |
| binaryfuse8 | 10000000 | 621.2ms | 36.0ns | 0.0039169 | 9.02 | 225 MiB | 10 MiB |
| binaryfuse16 | 10000000 | 666.6ms | 102.0ns | 0.0000147 | 18.04 | 245 MiB | 21 MiB |
| binaryfuse32 | 10000000 | 769.0ms | 135.0ns | 0 | 36.07 | 286 MiB | 43 MiB |
| xor2 | 10000000 | 1.9s | 43.0ns | 0.2500703 | 9.84 | 527 MiB | 11 MiB |
| xor4 | 10000000 | 2.0s | 41.0ns | 0.0626137 | 9.84 | 527 MiB | 11 MiB |
| xor8 | 10000000 | 1.9s | 42.0ns | 0.0039369 | 9.84 | 527 MiB | 11 MiB |
| xor16 | 10000000 | 2.2s | 106.0ns | 0.0000173 | 19.68 | 527 MiB | 23 MiB |
| xor32 | 10000000 | 2.2s | 140.0ns | 0 | 39.36 | 527 MiB | 46 MiB |
| | | | | | | | |
| binaryfuse8 | 100000000 | 7.4s | 145.0ns | 0.003989 | 9.01 | 2 GiB | 107 MiB |
| binaryfuse16 | 100000000 | 8.4s | 169.0ns | 0.000016 | 18.01 | 2 GiB | 214 MiB |
| binaryfuse32 | 100000000 | 10.2s | 173.0ns | 0 | 36.03 | 2 GiB | 429 MiB |
| xor2 | 100000000 | 28.5s | 144.0ns | 0.249843 | 9.84 | 5 GiB | 117 MiB |
| xor4 | 100000000 | 27.4s | 154.0ns | 0.062338 | 9.84 | 5 GiB | 117 MiB |
| xor8 | 100000000 | 28.0s | 153.0ns | 0.004016 | 9.84 | 5 GiB | 117 MiB |
| xor16 | 100000000 | 29.5s | 161.0ns | 0.000012 | 19.68 | 5 GiB | 234 MiB |
| xor32 | 100000000 | 29.4s | 157.0ns | 0 | 39.36 | 5 GiB | 469 MiB |
| | | | | | | | |
Legend:
* **contains(k)**: The time taken to check if a key is in the filter
* **false+ prob.**: False positive probability, the probability that a containment check will erroneously return true for a key that has not actually been added to the filter.
* **bits per entry**: The amount of memory in bits the filter uses to store a single entry.
* **peak populate**: Amount of memory consumed during filter population, excluding keys themselves (8 bytes * num_keys.)
* **filter total**: Amount of memory consumed for filter itself in total (bits per entry * entries.)
<strong>Benchmarks:</strong> Windows 10, AMD Ryzen 9 3900X (1M - 100M keys)
* CPU: 3.79Ghz AMD Ryzen 9 3900X
* Memory: 32 GB 2133 MHz DDR4
* Zig version: `0.12.0-dev.706+62a0fbdae`
| Algorithm | # of keys | populate | contains(k) | false+ prob. | bits per entry | peak populate | filter total |
|--------------|------------|------------|-------------|--------------|----------------|---------------|--------------|
| binaryfuse8 | 1000000 | 44.6ms | 24.0ns | 0.00390796 | 9.04 | 22 MiB | 1 MiB |
| binaryfuse16 | 1000000 | 48.9ms | 25.0ns | 0.00001553 | 18.09 | 24 MiB | 2 MiB |
| binaryfuse32 | 1000000 | 49.9ms | 25.0ns | 0.00000001 | 36.18 | 28 MiB | 4 MiB |
| xor2 | 1000000 | 77.3ms | 25.0ns | 0.25000163 | 9.84 | 52 MiB | 1 MiB |
| xor4 | 1000000 | 80.0ms | 25.0ns | 0.06250427 | 9.84 | 52 MiB | 1 MiB |
| xor8 | 1000000 | 76.0ms | 25.0ns | 0.00391662 | 9.84 | 52 MiB | 1 MiB |
| xor16 | 1000000 | 83.7ms | 26.0ns | 0.00001536 | 19.68 | 52 MiB | 2 MiB |
| xor32 | 1000000 | 79.1ms | 27.0ns | 0 | 39.36 | 52 MiB | 4 MiB |
| fuse8 | 1000000 | 69.4ms | 25.0ns | 0.00390663 | 9.10 | 49 MiB | 1 MiB |
| fuse16 | 1000000 | 71.5ms | 27.0ns | 0.00001516 | 18.20 | 49 MiB | 2 MiB |
| fuse32 | 1000000 | 71.1ms | 27.0ns | 0 | 36.40 | 49 MiB | 4 MiB |
| | | | | | | | |
| binaryfuse8 | 10000000 | 572.3ms | 33.0ns | 0.0038867 | 9.02 | 225 MiB | 10 MiB |
| binaryfuse16 | 10000000 | 610.6ms | 108.0ns | 0.0000127 | 18.04 | 245 MiB | 21 MiB |
| binaryfuse32 | 10000000 | 658.2ms | 144.0ns | 0 | 36.07 | 286 MiB | 43 MiB |
| xor2 | 10000000 | 1.2s | 39.0ns | 0.249876 | 9.84 | 527 MiB | 11 MiB |
| xor4 | 10000000 | 1.2s | 39.0ns | 0.0625026 | 9.84 | 527 MiB | 11 MiB |
| xor8 | 10000000 | 1.2s | 41.0ns | 0.0038881 | 9.84 | 527 MiB | 11 MiB |
| xor16 | 10000000 | 1.3s | 117.0ns | 0.0000134 | 19.68 | 527 MiB | 23 MiB |
| xor32 | 10000000 | 1.3s | 147.0ns | 0 | 39.36 | 527 MiB | 46 MiB |
| fuse8 | 10000000 | 1.1s | 36.0ns | 0.0039089 | 9.10 | 499 MiB | 10 MiB |
| fuse16 | 10000000 | 1.1s | 112.0ns | 0.0000172 | 18.20 | 499 MiB | 21 MiB |
| fuse32 | 10000000 | 1.1s | 145.0ns | 0 | 36.40 | 499 MiB | 43 MiB |
| | | | | | | | |
| binaryfuse8 | 100000000 | 6.9s | 167.0ns | 0.00381 | 9.01 | 2 GiB | 107 MiB |
| binaryfuse16 | 100000000 | 7.2s | 171.0ns | 0.000009 | 18.01 | 2 GiB | 214 MiB |
| binaryfuse32 | 100000000 | 8.5s | 174.0ns | 0 | 36.03 | 2 GiB | 429 MiB |
| xor2 | 100000000 | 16.8s | 166.0ns | 0.249868 | 9.84 | 5 GiB | 117 MiB |
| xor4 | 100000000 | 18.9s | 183.0ns | 0.062417 | 9.84 | 5 GiB | 117 MiB |
| xor8 | 100000000 | 19.1s | 168.0ns | 0.003873 | 9.84 | 5 GiB | 117 MiB |
| xor16 | 100000000 | 16.9s | 171.0ns | 0.000021 | 19.68 | 5 GiB | 234 MiB |
| xor32 | 100000000 | 19.4s | 189.0ns | 0 | 39.36 | 5 GiB | 469 MiB |
| fuse8 | 100000000 | 19.6s | 167.0ns | 0.003797 | 9.10 | 4 GiB | 108 MiB |
| fuse16 | 100000000 | 20.8s | 171.0ns | 0.000015 | 18.20 | 4 GiB | 216 MiB |
| fuse32 | 100000000 | 21.5s | 176.0ns | 0 | 36.40 | 4 GiB | 433 MiB |
| | | | | | | | |
Legend:
* **contains(k)**: The time taken to check if a key is in the filter
* **false+ prob.**: False positive probability, the probability that a containment check will erroneously return true for a key that has not actually been added to the filter.
* **bits per entry**: The amount of memory in bits the filter uses to store a single entry.
* **peak populate**: Amount of memory consumed during filter population, excluding keys themselves (8 bytes * num_keys.)
* **filter total**: Amount of memory consumed for filter itself in total (bits per entry * entries.)
Related readings
<ul>
<li>Blog post by Daniel Lemire: <a>Xor Filters: Faster and Smaller Than Bloom Filters</a></li>
<li>Fuse Filters (<a>arxiv paper</a>), as described <a>by @jbapple</a> (note these are not to be confused with <em>binary fuse filters</em>.)</li>
</ul>
Special thanks
<ul>
<li><a><strong>Thomas Mueller Graf</strong></a> and <a><strong>Daniel Lemire</strong></a> - <em>for their excellent research into xor filters, xor+ filters, their C implementation, and more.</em></li>
<li><a><strong>Martin Dietzfelbinger</strong></a> and <a><strong>Stefan Walzer</strong></a> - <em>for their excellent research into fuse filters.</em></li>
<li><a><strong>Jim Apple</strong></a> - <em>for their C implementation<a>[1]</a> of fuse filters</em></li>
<li><a><strong>@Andoryuuta</strong></a> - <em>for providing substantial help in debugging several issues in the Zig implementation.</em></li>
</ul>
If it was not for the above people, I (<a>@emidoots</a>) would not have been able to write this implementation and learn from the excellent <a>C implementation</a>. Please credit the above people if you use this library. | []
|
https://avatars.githubusercontent.com/u/65570835?v=4 | known-folders | ziglibs/known-folders | 2020-05-18T21:48:43Z | Provides access to well-known folders across several operating systems | master | 3 | 262 | 23 | 262 | https://api.github.com/repos/ziglibs/known-folders/tags | MIT | [
"zig",
"zig-library",
"zig-package"
]
| 99 | false | 2025-04-27T02:49:16Z | true | true | 0.14.0-dev.3445+6c3cbb0c8 | github | []
| Zig Known Folders Project
Design Goals
<ul>
<li>Minimal API surface</li>
<li>Provide the user with an option to either obtain a directory handle or a path name</li>
<li>Keep to folders that are available on all operating systems</li>
</ul>
API
```zig
pub const KnownFolder = enum {
home,
documents,
pictures,
music,
videos,
desktop,
downloads,
public,
fonts,
app_menu,
cache,
roaming_configuration,
local_configuration,
global_configuration,
data,
runtime,
executable_dir,
};
pub const Error = error{ ParseError, OutOfMemory };
pub const KnownFolderConfig = struct {
xdg_force_default: bool = false,
xdg_on_mac: bool = false,
};
/// Returns a directory handle, or, if the folder does not exist, <code>null</code>.
pub fn open(allocator: std.mem.Allocator, folder: KnownFolder, args: std.fs.Dir.OpenOptions) (std.fs.Dir.OpenError || Error)!?std.fs.Dir;
/// Returns the path to the folder or, if the folder does not exist, <code>null</code>.
pub fn getPath(allocator: std.mem.Allocator, folder: KnownFolder) Error!?[]const u8;
```
Installation
<blockquote>
<span class="bg-blue-100 text-blue-800 text-xs font-medium me-2 px-2.5 py-0.5 rounded dark:bg-blue-900 dark:text-blue-300">NOTE</span>
The minimum supported Zig version is <code>0.14.0-dev.3445+6c3cbb0c8</code>.
</blockquote>
Initialize a <code>zig build</code> project if you haven't already.
<code>bash
zig init</code>
Add the <code>known_folders</code> package to your <code>build.zig.zon</code>.
<code>bash
zig fetch --save git+https://github.com/ziglibs/known-folders.git</code>
You can then import <code>known-folders</code> in your <code>build.zig</code> with:
<code>zig
const known_folders = b.dependency("known_folders", .{}).module("known-folders");
const exe = b.addExecutable(...);
// This adds the known-folders module to the executable which can then be imported with `@import("known-folders")`
exe.root_module.addImport("known-folders", known_folders);</code>
Configuration
In your root file, add something like this to configure known-folders:
<code>zig
pub const known_folders_config = .{
.xdg_on_mac = true,
}</code> | [
"https://github.com/EngineersBox/Flow",
"https://github.com/getchoo/ziggy-with-it",
"https://github.com/ikskuh/gurl",
"https://github.com/jrachele/zig-sync",
"https://github.com/kothavade/zldr",
"https://github.com/paoda/zba",
"https://github.com/reykjalin/todui"
]
|
https://avatars.githubusercontent.com/u/2859122?v=4 | zalgebra | kooparse/zalgebra | 2020-10-07T17:15:35Z | Linear algebra library for games and real-time graphics. | main | 0 | 254 | 34 | 254 | https://api.github.com/repos/kooparse/zalgebra/tags | MIT | [
"gamedev",
"graphics",
"linear-algebra",
"mat4",
"math",
"matrix",
"quaternion",
"vec3",
"vectors",
"zig",
"ziglang"
]
| 240 | false | 2025-05-13T16:46:11Z | true | true | 0.11.0 | github | []
| zalgebra
Linear algebra library for games and computer graphics.
The goal is to become as complete and useful as the Unity one. I'm currently using it for my projects and will continue to update it as new needs are coming.
If you would like to contribute, don't hesitate! :)
Note: <strong>The main branch is for the latest Zig release (0.14.x), use <a>latest</a> for latest master changements</strong>
Examples
Example of usage is located at <a>example/</a>.
```zig
const za = @import("zalgebra");
const Vec3 = za.Vec3;
const Mat4 = za.Mat4;
pub fn main () void {
const projection = za.perspective(45.0, 800.0 / 600.0, 0.1, 100.0);
const view = za.lookAt(Vec3.new(0.0, 0.0, -3.), Vec3.zero(), Vec3.up());
const model = Mat4.fromTranslate(Vec3.new(0.2, 0.5, 0.0));
const mvp = Mat4.mul(projection, view.mul(model));
std.debug.format("{}", .{mvp});
}
```
Quick reference
Aliases
| Type | Description |
| ------------ | ---------------------------------------- |
| Vec2 | Two dimensional vector for <code>f32</code> |
| Vec2_f64 | Two dimensional vector for <code>f64</code> |
| Vec2_i32 | Two dimensional vector for <code>i32</code> |
| Vec2_usize | Two dimensional vector for <code>usize</code> |
| Vec3 | Three dimensional vector for <code>f32</code> |
| Vec3_f64 | Three dimensional vector for <code>f64</code> |
| Vec3_i32 | Three dimensional vector for <code>i32</code> |
| Vec3_usize | Three dimensional vector for <code>usize</code> |
| Vec4 | Four dimensional vector for <code>f32</code> |
| Vec4_f64 | Four dimensional vector for <code>f64</code> |
| Vec4_i32 | Four dimensional vector for <code>i32</code> |
| Vec4_usize | Four dimensional vector for <code>usize</code> |
| Mat3 | 3x3 matrix for <code>f32</code> |
| Mat3_f64 | 3x3 matrix for <code>f64</code> |
| Mat4 | 4x4 matrix for <code>f32</code> |
| Mat4_f64 | 4x4 matrix for <code>f64</code> |
| Quat | Quaternion for <code>f32</code> |
| Quat_f64 | Quaternion for <code>f64</code> |
| perspective | Perspective function for <code>f32</code> 4x4 mat4 |
| orthographic | Orthographic function for <code>f32</code> 4x4 mat4 |
| lookAt | LookAt function for <code>f32</code> 4x4 mat4 |
Vectors
| Methods | Description |
| --------- | -------------------------------------------------------------------------- |
| new | Construct a vector from 2 to 4 components |
| x | Return first component |
| y | Return second component |
| z | Return third component (only for vec3, vec4) |
| w | Return fourth component (only for vec4) |
| at | Return component from given index |
| set | Set all components to the same given value |
| negate | Scale all components by -1 |
| cast | Cast a type to another type |
| fromSlice | Construct new vectors from slice |
| zero | Shorthand for <code>(0, 0, 0)</code> |
| one | Shorthand for <code>(1, 1, 1)</code> |
| up | Shorthand for <code>(0, 1, 0)</code> |
| down | Shorthand for <code>(0, -1, 0)</code> |
| right | Shorthand for <code>(1, 0, 0)</code> |
| left | Shorthand for <code>(-1, 0, 0)</code> |
| forward | Shorthand for <code>(0, 0, 1)</code> (only for vec3 and vec4) |
| back | Shorthand for <code>(0, 0, -1)</code> (only for vec3 and vec4) |
| toArray | Return an array of same size. |
| getAngle | Return angle in degrees between two vectors (only for vec2 and vec3) |
| rotate | Rotate vector by angle (in degrees) |
| length | Return the magnitude of the current vector |
| lengthSq | Return the magnitude squared of the current vector |
| distance | Return the distance between two points |
| norm | Construct a new normalized vector based on the given one |
| eql | Return <code>true</code> if two vectors are equals |
| sub | Construct new vector resulting from the substraction between two vectors |
| add | Construct new vector resulting from the addition between two vectors |
| div | Construct new vector resulting from the division between two vectors |
| mul | Construct new vector resulting from the multiplication between two vectors |
| scale | Construct new vector after multiplying each components by a given scalar |
| cross | Construct the cross product (as vector) from two vectors (only for vec3) |
| dot | Return the dot product between two vectors |
| lerp | Linear interpolation between two vectors |
| min | Construct vector from the min components between two vectors |
| max | Construct vector from the max components between two vectors |
Matrices
Note: All matrices are column-major.
| Methods | Description |
| -------------------- | ------------------------------------------------------------------------------------- |
| identity | Construct an identity matrix |
| set | Set all matrix values to given value |
| fromSlice | Construct new matrix from given slice of data |
| getSlice | Return the inner data as a slice |
| transpose | Return the transpose matrix |
| negate | Scale all components by -1 |
| cast | Cast a type to another type |
| eql | Return <code>true</code> if two matrices are equals |
| mulByVec4 | Multiply a given vec4 by matrix (only for mat4) |
| fromTranslate | Construct a translation matrix |
| translate | Construct a translation from the given matrix according to given axis (vec3) |
| fromRotation | Construct a rotation matrix |
| fromEulerAngles | Construct a rotation matrix from pitch/yaw/roll in degrees (X _ Y _ Z) |
| rotate | Construct a rotation from the given matrix according to given axis (vec3) |
| fromScale | Construct a scale matrix |
| scale | Construct a scale from the given matrix according to given axis (vec3) |
| extractTranslation | Return a vector with proper translation |
| orthoNormalize | Ortho normalize the given matrix. |
| extractEulerAngles | Return a vector with Euler angles in degrees (pitch/yaw/roll) |
| extractScale | Return a vector with proper scale |
| perspective | Construct a perspective matrix from given fovy, aspect ratio, near/far inputs |
| perspectiveReversedZ | Construct a perspective matrix with reverse Z and infinite far plane. |
| orthographic | Construct an orthographic matrix from given left, right, bottom, top, near/far inputs |
| lookAt | Construct a right-handed lookAt matrix from given position (eye) and target |
| mul | Multiply two matrices |
| inv | Inverse the given matrix |
| recompose | Return mat4 matrix from given <code>translation</code>, <code>rotation</code> and <code>scale</code> components |
| decompose | Return components <code>translation</code>, <code>rotation</code> and <code>scale</code> from given 4x4 matrix. |
Quaternions
| Methods | Description |
| ----------------- | ---------------------------------------------------------------------------------------------- |
| new | Construct new quat from given floats |
| identity | Construct quat as <code>(1, 0, 0, 0)</code> |
| set | Set all components to the same given value |
| cast | Cast a type to another type |
| fromSlice | Construct new quaternion from slice |
| fromVec3 | Construct quaternion from vec3 |
| eql | Return <code>true</code> if two quaternions are equal |
| norm | Normalize given quaternion |
| length | Return the magniture of the given quaternion |
| inv | Construct inverse quaternion |
| sub | Construct quaternion resulting from the subtraction of two given ones |
| add | Construct quaternion resulting from the addition of two given ones |
| mul | Construct quaternion resulting from the multiplication of two given ones |
| scale | Construct new quaternion resulting from the multiplication of all components by a given scalar |
| dot | Return the dot product between two quaternions |
| toMat3 | Convert given quat to rotation 3x3 matrix |
| toMat4 | Convert given quat to rotation 4x4 matrix |
| fromEulerAngles | Construct quaternion from Euler angles |
| fromAxis | Construct quat from angle around specified axis |
| extractAxisAngles | Get the rotation angle and axis for a given quaternion |
| extractRotation | Get euler angles from given quaternion |
| rotateVec | Rotate given vector |
Utilities
| Methods | Description |
| --------- | --------------------------------------- |
| toRadians | Convert degrees to radians |
| toDegrees | Convert radians to degrees |
| lerp | Linear interpolation between two floats |
Contributing to the project
Don’t be shy about shooting any questions you may have. If you are a beginner/junior, don’t hesitate, I will always encourage you. It’s a safe place here. Also, I would be very happy to receive any kind of pull requests, you will have (at least) some feedback/guidance rapidly.
Behind screens, there are human beings, living any sort of story. So be always kind and respectful, because we all sheer to learn new things.
Thanks
This project is inspired by <a>Handmade Math</a>, <a>nalgebra</a> and <a>Unity</a>. | [
"https://github.com/Avokadoen/zig_vulkan",
"https://github.com/fabioarnold/hello-webgl",
"https://github.com/zenith391/Stella-Dei"
]
|
https://avatars.githubusercontent.com/u/4407382?v=4 | OffensiveZig | darkr4y/OffensiveZig | 2020-11-23T08:09:06Z | Some attempts at using Zig(https://ziglang.org/) in penetration testing. | main | 1 | 239 | 16 | 239 | https://api.github.com/repos/darkr4y/OffensiveZig/tags | BSD-2-Clause | [
"nim",
"zig"
]
| 40 | false | 2025-05-19T13:07:31Z | false | false | unknown | github | []
|
OffensiveZig
The purpose of this project is to do some experiments with <a>Zig</a>, and to explore the possibility of using it for implant development and general offensive operations. it is inspired by <a>@byt3bl33d3r</a>'s project "<a>OffensiveNim</a>".
Table of Contents
<ul>
<li><a>OffensiveZig</a></li>
<li><a>Table of Contents</a></li>
<li><a>Why Zig?</a></li>
<li><a>Try to Learn Zig in Y minutes</a></li>
<li><a>How to play</a></li>
<li><a>Cross Compiling</a></li>
<li><a>Interfacing with C/C++</a></li>
<li><a>Creating Windows DLLs with an exported <code>DllMain</code></a></li>
<li><a>Optimizing executables for size</a></li>
<li><a>Opsec Considerations</a></li>
<li><a>Converting C code to Zig</a></li>
<li><a>Language Bridges</a></li>
<li><a>Debugging</a></li>
<li><a>Setting up a dev environment</a></li>
<li><a>Interesting Zig libraries</a></li>
<li><a>Zig for implant dev links</a></li>
<li><a>Comparison of Zig and Nim</a></li>
<li><a>Summary</a></li>
<li><a>Contributors</a></li>
</ul>
Why Zig?
<ul>
<li>The Zig toolchain offers the capability to cross-compile C/C++ projects using commands like <em>zig cc</em> or <em>zig c++</em>. This functionality allows you to efficiently utilize the Zig toolchain for building your pre-existing C/C++ projects.</li>
<li>Zig operates without relying on a VM/runtime, the static executable is super small.</li>
<li>Zig boasts a minimal Rust-like syntax while retaining the simplicity of C, enabling swift development of native payloads and prototypes.</li>
<li>Zig offers seamless integration with C libraries without the need for Foreign Function Interface (FFI) bindings.</li>
<li>Zig emphasizes manual memory management and transparent control flow, avoiding hidden complexities.</li>
<li>Zig excels in facilitating cross-compilation without the need for a separate "cross toolchain," and can build for various targets listed <a>here</a>.</li>
<li>Compiling to WebAssembly and interacting with JavaScript code within a browser is relatively straightforward in Zig <a>here</a>.</li>
<li>The <a>community</a> is known for its approachability, friendliness, and high level of activity. The Zig <a>Discord</a> server serves as a valuable platform for asking questions and staying informed about the latest developments within the language.</li>
</ul>
Try to Learn Zig in Y minutes
If you're eager to learn Zig quickly and effectively, there's a wealth of resources to aid your journey. For a rapid grasp of Zig's syntax and concepts, you can dive into the <a>Learn Zig in Y Minutes guide</a>. To delve deeper into Zig's intricacies, explore the official documentation for various Zig versions <a>here</a>. Engage with the vibrant Zig community through <a>Ziggit</a>.
How to play
<strong>Examples in this project</strong>
| File | Description |
| --- | --- |
| <code>keylogger_bin.zig</code> | Keylogger using <code>SetWindowsHookEx</code> |
| <code>pop_bin.zig</code> | Call <code>MessageBox</code> WinApi <em>without</em> using a 3rd-party library |
| <code>pop_lib.zig</code> | Example of creating a Windows DLL with an exported <code>DllMain</code> |
| <code>shellcode_bin.zig</code> | Creates a suspended process and injects shellcode with <code>VirtualAllocEx</code>/<code>CreateRemoteThread</code>. |
| <code>suspended_thread_injection.nim</code> | Shellcode execution via suspended thread injection |
I recommend downloading Zig for different CPU architectures directly from Zig's official download page, available at https://ziglang.org/download/. In certain cases within this project, third-party libraries are employed.
Cross Compiling
See the cross-compilation section in the <a>Zig compiler usage guide</a>, for a lot more details.
Cross compiling to Windows from MacOs/Nix: <code>zig build-exe -target x86_64-windows src.zig</code>
Interfacing with C/C++
Explore the remarkable <a>Integration with C</a> section in the Zig documentation.
Here's <code>MessageBox</code> example
```zig
const std = @import("std");
const win = std.os.windows;
const user32 = win.user32;
const WINAPI = win.WINAPI;
const HWND = win.HWND;
const LPCSTR = win.LPCSTR;
const UINT = win.UINT;
extern "user32" fn MessageBoxA(hWnd: ?HWND, lpText: LPCSTR, lpCaption: LPCSTR, uType: UINT) callconv(WINAPI) i32;
pub fn main() void {
_ = MessageBoxA(null, "Hello World!", "Zig", 0);
}
```
Creating Windows DLLs with an exported <code>DllMain</code>
As you can see, the code in the example is already very close to what C code looks like, just use <code>export</code> keyword.
Example:
```zig
const std = @import("std");
const win = std.os.windows;
const WINAPI = win.WINAPI;
const HINSTANCE = win.HINSTANCE;
const DWORD = win.DWORD;
const LPVOID = win.LPVOID;
const BOOL = win.BOOL;
const HWND = win.HWND;
const LPCSTR = win.LPCSTR;
const UINT = win.UINT;
const DLL_PROCESS_ATTACH: DWORD = 1;
const DLL_THREAD_ATTACH: DWORD = 2;
const DLL_THREAD_DETACH: DWORD = 3;
const DLL_PROCESS_DETACH: DWORD = 0;
extern "user32" fn MessageBoxA(hWnd: ?HWND, lpText: LPCSTR, lpCaption: LPCSTR, uType: UINT) callconv(WINAPI) i32;
pub export fn _DllMainCRTStartup(hinstDLL: HINSTANCE, fdwReason: DWORD, lpReserved: LPVOID) BOOL {
_ = lpReserved;
_ = hinstDLL;
switch (fdwReason) {
DLL_PROCESS_ATTACH => {
_ = MessageBoxA(null, "Hello World!", "Zig", 0);
},
DLL_THREAD_ATTACH => {},
DLL_THREAD_DETACH => {},
DLL_PROCESS_DETACH => {},
else => {},
}
return 1;
}
```
To compile:
<code>//To make a static library
zig build-lib test.zig -target x86_64-windows
//To make a shared library
zig build-lib test.zig -dynamic -target x86_64-windows</code>
Optimizing executables for size
Taken from the <a>Build Mode</a>
For the biggest size decrease use the following flags <code>-O ReleaseSmall -fstrip -fsingle-threaded</code>
Opsec Considerations
Most samples are compiled in this mode <code>zig build-exe src.zig -O ReleaseSmall -fstrip -fsingle-threaded -target x86_64-windows</code>
Aside from a few specific NT functions found in the import table, I have not been able to find any other significant features that would indicate that they were coded in Zig.
Converting C code to Zig
Zig offers the functionality to convert C code to Zig code through the command <code>zig translate-c</code>. I haven't personally experimented with this feature yet.
Language Bridges
Regarding Python modules or Java JNI integration, I haven't had the opportunity to test these aspects yet.
References:
<ul>
<li>https://github.com/kristoff-it/zig-cuckoofilter/</li>
<li>https://github.com/ziglang/zig/issues/5795</li>
<li>https://lists.sr.ht/~andrewrk/ziglang/%20%3CCACZYt3T8jACL+3Z_NMW8yYvcJ+5oyP%3Dh1s2HHdDL_VxYQH5rzQ%40mail.gmail.com%3E</li>
</ul>
Debugging
You can utilize the functions within the <code>std.debug</code> namespace to display the call stack. Currently, there is limited IDE support for debugging Zig. If you're using VSCode, you can try the <code>webfreak.debug</code> extension. For more information on debugging Zig with VSCode, you can refer to the following links:
- <a>Reddit post: Debugging Zig in VSCode</a>
- <a>Dev.to article: Debugging Zig with VS Code</a>
These resources should provide you with additional details on setting up and using the webfreak.debug extension for Zig debugging in VSCode.
Setting up a dev environment
<a>VSCode</a> provides an official Zig extension <code>ziglang.vscode-zig</code> to enhance Zig language support, offering more comprehensive functionality compared to earlier extensions such as <code>tiehuis.zig</code> and <code>lorenzopirro.zig-snippets</code>.
The link to the <a>Zig Tools</a> page on the Zig website will likely provide further information on various tools and resources available for Zig development, including debugging tools and extensions.
Interesting Zig libraries
<ul>
<li>https://github.com/GoNZooo/zig-win32</li>
<li>https://github.com/Vexu/routez</li>
<li>https://github.com/ducdetronquito/requestz</li>
<li>https://github.com/ducdetronquito/h11</li>
<li>https://github.com/ducdetronquito/http</li>
<li>https://github.com/MasterQ32/zig-network</li>
<li>https://github.com/lithdew/pike</li>
<li>https://github.com/Hejsil/zig-clap</li>
<li>https://github.com/Vexu/bog</li>
<li>https://github.com/tiehuis/zig-regex</li>
<li>https://github.com/alexnask/interface.zig</li>
<li>https://github.com/marler8997/zig-os-windows</li>
<li>https://github.com/nrdmn/awesome-zig</li>
</ul>
Zig for implant dev links
<ul>
<li>https://github.com/Sobeston/injector</li>
</ul>
Comparison of Zig and Nim
| | Zig | Nim |
| ---- | ---- | ---- |
| Syntax Styles | Rust-like | Python-like |
| Backend | LLVM or Self-hosted | C Compiler or Self-Hosted |
| Code Generate | Support in future | Supported |
| Standard Library | General | Numerous |
| Memory Management | Manual | Multi-paradigm GC |
| FFI | <em>Directly</em> | Support |
| Translate C to <em>ThisLang</em> | Official | Third-Party |
| Package Manager | Official Package Manager as of Zig 0.11 | Nimble |
| Cross Compile | Convenient | Convenient |
| Learning Curve | Intermediate | Easy |
| Community Resources | Growing | Rich |
Summary
In conclusion, I am not currently inclined to choose Zig as my primary language for offensive purposes. I've also explored alternative languages like <a>Vlang</a>, but I haven't initiated practical experimentation with them yet. Comparatively, Nim offers superior community resources and more comprehensible documentation than Zig. While attempting to achieve similar outcomes, deciphering Zig's documentation proved to be a challenging endeavor. The manual memory management aspect may not be particularly user-friendly for those without professional development experience. It's possible that as Zig evolves and stabilizes in the future, I might be more inclined to employ it for specific development tasks within penetration testing.
<em>P.S.: I am not a professional developer; this project is presented solely from the viewpoint of a penetration testing engineer. The opinions expressed above are my own. Please do correct me if you find any errors.</em>
Contributors
<a>
</a> | []
|
https://avatars.githubusercontent.com/u/65570835?v=4 | zlm | ziglibs/zlm | 2020-05-30T21:03:20Z | Zig linear mathemathics | master | 6 | 209 | 37 | 209 | https://api.github.com/repos/ziglibs/zlm/tags | MIT | [
"game-math",
"linear-algebra",
"opengl-math",
"zig",
"zig-package",
"ziglang"
]
| 92 | false | 2025-05-20T10:10:54Z | true | true | 0.11.0 | github | []
| zlm
Zig linear mathemathics library.
Current provides the following types:
<ul>
<li><code>Vec2</code></li>
<li><code>Vec3</code></li>
<li><code>Vec4</code></li>
<li><code>Mat2</code></li>
<li><code>Mat3</code></li>
<li><code>Mat4</code></li>
</ul>
The library is currently built around the OpenGL coordinate system and is fully generic on the basic data type.
Example
```zig
const math = @import("zlm");
// Use this namespace to get access to a Vec3 with f16 fields instead of f32
const math_f16 = math.SpecializeOn(f16);
/// Accelerate the given velocity <code>v</code> by <code>a</code> over <code>t</code>.
fn accelerate(v: math.Vec3, a: math.Vec3, t: f32) math.Vec3 {
return v.add(a.scale(t));
}
``` | [
"https://github.com/Darkfllame/Zig3D",
"https://github.com/JadonBelair/voxel_renderer"
]
|
https://avatars.githubusercontent.com/u/265903?v=4 | interface.zig | alexnask/interface.zig | 2020-05-05T10:44:45Z | Dynamic dispatch for zig made easy | master | 4 | 177 | 15 | 177 | https://api.github.com/repos/alexnask/interface.zig/tags | MIT | [
"dynamic-dispatch",
"zig",
"zig-library",
"zig-package"
]
| 39 | false | 2025-05-20T09:53:04Z | false | false | unknown | github | []
| Zig Interfaces
Easy solution for all your zig dynamic dispatch needs!
Features
<ul>
<li>Fully decoupled interfaces and implementations</li>
<li>Control over the storage/ownership of interface objects</li>
<li>Comptime support (including comptime-only interfaces)</li>
<li>Async function partial support (blocking on <a>#4621</a>)</li>
<li>Optional function support</li>
<li>Support for manually written vtables</li>
</ul>
Example
```zig
const interface = @import("interface.zig");
const Interface = interface.Interface;
const SelfType = interface.SelfType;
// Let us create a Reader interface.
// We wrap it in our own struct to make function calls more natural.
const Reader = struct {
pub const ReadError = error { CouldNotRead };
<code>const IFace = Interface(struct {
// Our interface requires a single non optional, non-const read function.
read: fn (*SelfType, buf: []u8) ReadError!usize,
}, interface.Storage.NonOwning); // This is a non owning interface, similar to Rust dyn traits.
iface: IFace,
// Wrap the interface's init, since the interface is non owning it requires no allocator argument.
pub fn init(impl_ptr: var) Reader {
return .{ .iface = try IFace.init(.{impl_ptr}) };
}
// Wrap the read function call
pub fn read(self: *Reader, buf: []u8) ReadError!usize {
return self.iface.call("read", .{buf});
}
// Define additional, non-dynamic functions!
pub fn readAll(self: *Self, buf: []u8) ReadError!usize {
var index: usize = 0;
while (index != buf.len) {
const partial_amt = try self.read(buffer[index..]);
if (partial_amt == 0) return index;
index += partial_amt;
}
return index;
}
</code>
};
// Let's create an example reader
const ExampleReader = struct {
state: u8,
<code>// Note that this reader cannot return an error, the return type
// of our implementation functions only needs to coerce to the
// interface's function return type.
pub fn read(self: ExampleReader, buf: []u8) usize {
for (buf) |*c| {
c.* = self.state;
}
return buf.len;
}
</code>
};
test "Use our reader interface!" {
var example_reader = ExampleReader{ .state=42 };
<code>var reader = Reader.init(&example_reader);
var buf: [100]u8 = undefined;
_ = reader.read(&buf) catch unreachable;
</code>
}
```
See examples.zig for more examples. | []
|
https://avatars.githubusercontent.com/u/4252848?v=4 | apple_pie | Luukdegram/apple_pie | 2020-06-06T17:14:54Z | Basic HTTP server implementation in Zig | master | 14 | 164 | 21 | 164 | https://api.github.com/repos/Luukdegram/apple_pie/tags | MIT | [
"http",
"http-server",
"server",
"zig",
"ziglang"
]
| 308 | false | 2025-04-06T18:32:46Z | true | false | unknown | github | []
| Apple Pie
Apple pie is a HTTP Server implementation in <a>Zig</a>. The initial goal is to offer full support for http versions 1.0 and 1.1 with 2.0 and further planned at a later stage. With Apple Pie I'd like to offer a library that contains all features you'd expect from a server, while still remaining performant. Rather than hiding complexity, I want to expose its functionality so users can replace and/or expand upon to fit their needs.
Roadmap
<ul>
<li>HTTP 1.1 spec (fully) implemented</li>
</ul>
Features
<ul>
<li>Crossplatform support</li>
<li>Extensive routing (see the <a>router</a> example) built in</li>
<li>Allows for both async and blocking I/O using Zig's std event loop</li>
</ul>
Example
A very basic implementation would be as follow:
```zig
const std = @import("std");
const http = @import("apple_pie");
// use evented mode for event loop support
pub const io_mode = .evented;
// optional root constant to define max stack buffer size per request
pub const buffer_size: usize = 4096;
// optional root constant to define max header size per request
pub const request_buffer_size: usize = 4096;
/// Context variable, accessible by all handlers, allowing to access data objects
/// without requiring them to be global. Thread-safety must be handled by the user.
const Context = struct {
data: []const u8,
};
pub fn main() !void {
var gpa = std.heap.GeneralPurposeAllocator(.{}){};
defer _ = gpa.deinit();
<code>const my_context: Context = .{ .data = "Hello, world!" };
try http.listenAndServe(
gpa.allocator(),
try std.net.Address.parseIp("127.0.0.1", 8080),
my_context,
index,
);
</code>
}
fn index(ctx: Context, response: *http.Response, request: http.Request) !void {
_ = request;
try response.writer().print("{s}", .{ctx.data});
}
```
More examples can be found in the <a>examples</a> folder.
Building
Apple Pie is being developed on Zig's master branch and tries to keep up-to-date with its latest development.
To build Apple Pie a simple
<code>zig build</code> will suffice.
To build any of the examples, use the following:
<code>zig build example -Dexample=<example_name></code>
it will appear in <code>zig-out/bin/example_name</code> | []
|
https://avatars.githubusercontent.com/u/745333?v=4 | rayray | mkeeter/rayray | 2021-01-01T18:59:27Z | A tiny GPU raytracer, using Zig and WebGPU | master | 0 | 154 | 8 | 154 | https://api.github.com/repos/mkeeter/rayray/tags | - | [
"glsl",
"gpu",
"raytracing",
"webgpu",
"zig"
]
| 617 | false | 2025-05-08T20:58:42Z | true | false | unknown | github | []
| rayray
A tiny GPU raytracer!
(more details on the <a>project homepage</a>)
Features
<ul>
<li>Diffuse, metal, and glass materials</li>
<li>The only three shapes that matter:<ul>
<li>Spheres</li>
<li>Planes (both infinite and finite)</li>
<li>Cylinders (both infinite and capped)</li>
</ul>
</li>
<li>Any shape can be a light!</li>
<li>Antialiasing with sub-pixel sampling</li>
<li>Will <strong>crash your entire computer</strong> if you render too many rays per frame
(thanks, GPU drivers)</li>
</ul>
Implementation
<ul>
<li>Built on the bones of <a>Futureproof</a></li>
<li>Written in <a>Zig</a></li>
<li>Using <a>WebGPU</a> for graphics
via <a><code>wgpu-native</code></a></li>
<li>Shaders compiled from GLSL to SPIR-V with <a><code>shaderc</code></a></li>
<li>Minimal GUI using <a>Dear ImGUI</a>,
with a custom <a>Zig + WebGPU backend</a></li>
<li>Vaguely based on <a><em>Ray Tracing in One Weekend</em></a>,
with a data-driven design to run on the GPU.</li>
</ul>
Project status
This is a personal / toy project,
and I don't plan to support it on anything other than my laptop
(macOS 10.13, <code>zig-macos-x86_64-0.8.0-dev.1125</code>,
and <code>wgpu-native</code> built from source).
I'm unlikely to fix any issues,
although I will optimistically merge small-to-medium PRs that fix bugs
or add support for more platforms.
That being said, I'm generally friendly,
so feel free to open issues and ask questions;
just don't set your expectations too high!
If you'd like to add major features, please fork the project;
I'd be happy to link to any forks which achieve critical momemtum!
License
Licensed under either of
<ul>
<li><a>Apache License, Version 2.0</a></li>
<li><a>MIT license</a></li>
</ul>
at your option.
Contribution
Unless you explicitly state otherwise, any contribution intentionally submitted
for inclusion in the work by you, as defined in the Apache-2.0 license, shall be
dual licensed as above, without any additional terms or conditions. | []
|
https://avatars.githubusercontent.com/u/124872?v=4 | witx-codegen | jedisct1/witx-codegen | 2020-04-21T22:02:36Z | WITX code and documentation generator for AssemblyScript, Zig, Rust and more. | master | 1 | 140 | 14 | 140 | https://api.github.com/repos/jedisct1/witx-codegen/tags | MIT | [
"assemblyscript",
"code-generator",
"interface-types",
"wasm",
"webassembly",
"wit",
"witx",
"zig"
]
| 425 | false | 2025-04-06T01:52:23Z | false | false | unknown | github | []
|
<a></a>
WITX-CodeGen: A WITX code and documentation generator
WITX is a way to describe types and function interfaces for WebAssembly modules.
From this, code generators can produce code to access data, call or implement functions from different languages using the same layout and calling conventions.
WITX-CodeGen doesn't do transformations when functions are called. Instead, it exposes types that have the same layout in all languages, like a zero-copy serialization format. Data can thus be easily shared between guests and hosts without any overhead.
The generated code is compatible with the WebAssembly standard APIs (<a>WASI</a>).
This tool uses the next (as on June 9th, 2021) revision of the format definition, that will eventually be required for interface types.
<code>witx-codegen</code> is currently written in Rust, but it is totally language-agnostic. It is also compatible with all WebAssembly runtimes. The generated code is optimized for simplicity and readability.
The tool can also produce different documentation formats.
<code>witx-codegen</code> supersedes <code>as-witx</code>, <code>zig-witx</code>, <code>witx-docgen</code>, <code>witx-overview-docgen</code> and <code>witx-generate-raw</code>.
Installation
<ul>
<li>Via <code>cargo</code>:</li>
</ul>
<code>sh
cargo install witx-codegen</code>
<ul>
<li>Precompiled binaries: tarballs and Debian/Ubuntu packages are available <a>here</a>.</li>
</ul>
Usage
```text
WITX code generator for WebAssembly guest modules
USAGE:
witx-codegen [FLAGS] [OPTIONS] ...
FLAGS:
-h, --help Prints help information
-H, --skip-header Do not generate a header
-I, --skip-imports Ignores imported types and functions
-V, --version Prints version information
OPTIONS:
-m, --module-name
Set the module name to use instead of reading it from the witx file
<code>-o, --output <output_file> Output file, or - for the standard output
-t, --output-type <output_type>
Output type. One in: {assemblyscript, zig, rust, overview, markdown}
[default: assemblyscript]
</code>
ARGS:
... WITX files
```
Backends
<ul>
<li>[X] Markdown documentation (<a>example</a>)</li>
<li>[X] API Overview (<a>example</a>)</li>
<li>[X] AssemblyScript (<a>example</a>)</li>
<li>[X] Zig (<a>example</a>)</li>
<li>[X] Rust (<a>example</a>)</li>
<li>[X] C++ (<a>example</a>) - Experimental</li>
<li>[ ] TinyGo</li>
<li>[ ] Swift</li>
<li>[ ] HTML documentation</li>
</ul>
Support for additional languages is more than welcome!
Example inputs
See the <a><code>tests</code></a> folder for examples of WITX input files.
Other input formats may also be eventually supported, as well as extensions to produce more structured documentation.
WITX format
Basic types
<code>bool</code>, <code>char</code>, <code>u8</code>, <code>u16</code>, <code>u32</code>, <code>u64</code>, <code>s8</code>, <code>s16</code>, <code>s32</code>, <code>s64</code>
Other types
<ul>
<li><code>string</code>: a read-only string.</li>
<li><code>(in-buffer u8)</code>: a read-only buffer whose elements are of type <code>u8</code>.</li>
<li><code>(out-buffer u8)</code>: a buffer whose elements are of type <code>u8</code>.</li>
<li><code>(@witx const_pointer u8)</code>: a read-only <code>u8</code> pointer.</li>
<li><code>(@witx pointer u8)</code>: a <code>u8</code> pointer.</li>
<li><code>(@witx usize)</code>: an object size.</li>
</ul>
Type aliases
<ul>
<li><code>(typename $status_code u16)</code></li>
<li><code>(typename $size (@witx usize))</code></li>
</ul>
Note that returned values from function must all be aliases, not raw types.
Handles
Handles are opaque references to objects managed by the host.
In order to use handles, a "resource" has to be declared:
<code>(resource $http_handle)</code>
A "resource" represent a group of handles. The same resource can be shared by all handle types from the same module.
Each handle type can then be declared as aliases:
<code>(typename $query (handle $http_handle))
(typename $response_handle (handle $http_handle))</code>
Constants
<code>(typename $big_int u64)
(@witx const $big_int $zero 0)
(@witx const $big_int $a_hundred 100)
(@witx const $big_int $a_big_value 0xff00000000000000)
(@witx const $big_int $a_bigger_value 0xffffffffffffffff)</code>
Structures
<code>(typename $example_structure
(record
(field $first_member bool)
(field $second_member u8)
(field $third_member string)
)
)</code>
Structures that only contain booleans are encoded as bit sets.
Tuples
<code>(typename $test_tuple (tuple $test_bool $test_medium_int $big_int))</code>
Tagged unions
<code>(typename $test_tagged_union
(variant (@witx tag u16)
(case $first_choice u8)
(case $second_choice string)
(case $third_choice f32)
(case $empty_choice)
)
)</code>
This defines a union with a tag representing the active member. The example above generates a structure equivalent to:
<code>zig
struct {
tag: u16,
member: union {
first_choice: u8,
second_choice: string,
third_choice: f32,
empty_choice: (),
}
}</code>
Imports
Import some aliases, or all of them, from <code>common.witx</code>:
<code>(use $some_type, $some_other_type from $common)
(use * from $common)</code>
Modules
Only one module can be present in a file, whose name must match the module name. A module is defined as follows:
<code>(module $module_name
...
)</code>
It contains everything: types, handles, functions and imports.
Functions
<code>(@interface func (export "symmetric_key_generate")
(param $algorithm string)
(param $options $opt_options)
(result $error (expected $symmetric_key (error $crypto_errno)))
)</code>
This declares a <code>symmetric_key_generate</code> function, with two input parameters (<code>algorithm</code> and <code>options</code> of type <code>string</code> and <code>opt_options</code>).
The function returns an error code of type <code>$crypto_errno</code>. Or, if no error occurred, the function returns a value of type <code>$symmetric_key</code>.
In Rust, an equivalent function would be:
<code>rust
fn symmetric_key_generate(algorithm: &str, options: OptOptions)
-> Result<SymmetricKey, CryptoErrno>;</code>
Returning multiple values:
<code>(@interface func (export "symmetric_key_id")
(param $key $symmetric_key)
(param $key_id (@witx pointer u8))
(param $key_id_max_len $size)
(result $error (expected (tuple $size $version) (error $crypto_errno)))
)</code>
The function returns either an error, or two values, of type <code>$size</code> and <code>$version</code>.
The above example is eauivalent to a declaration like that one in Rust:
<code>rust
fn symmetric_key_id(key: SymmetricKey, key_id: *mut u8, key_id_max_len: usize)
-> Result<(Size, Version), CryptoErrno>;</code> | []
|
https://avatars.githubusercontent.com/u/1915?v=4 | koino | kivikakk/koino | 2020-08-12T07:24:47Z | CommonMark + GFM compatible Markdown parser and renderer | main | 7 | 139 | 13 | 139 | https://api.github.com/repos/kivikakk/koino/tags | MIT | [
"commonmark",
"markdown",
"zig"
]
| 241 | false | 2025-04-27T12:24:16Z | true | true | 0.14.0 | github | [
{
"commit": "711afa05416d1d1512bccf798a332be494d08f5f.tar.gz",
"name": "zunicode",
"tar_url": "https://github.com/kivikakk/zunicode/archive/711afa05416d1d1512bccf798a332be494d08f5f.tar.gz.tar.gz",
"type": "remote",
"url": "https://github.com/kivikakk/zunicode"
},
{
"commit": "a4e784da8399c51d5eeb5783e6a485b960d5c1f9",
"name": "clap",
"tar_url": "https://github.com/Hejsil/zig-clap/archive/a4e784da8399c51d5eeb5783e6a485b960d5c1f9.tar.gz",
"type": "remote",
"url": "https://github.com/Hejsil/zig-clap"
},
{
"commit": "00b62bc8bea7da75ba61f56555ea6cbaf0dc4e26",
"name": "libpcre_zig",
"tar_url": "https://github.com/kivikakk/libpcre.zig/archive/00b62bc8bea7da75ba61f56555ea6cbaf0dc4e26.tar.gz",
"type": "remote",
"url": "https://github.com/kivikakk/libpcre.zig"
},
{
"commit": "8bb5aad18f17724c5195f1e6f3a637e951bbcb07",
"name": "htmlentities_zig",
"tar_url": "https://github.com/kivikakk/htmlentities.zig/archive/8bb5aad18f17724c5195f1e6f3a637e951bbcb07.tar.gz",
"type": "remote",
"url": "https://github.com/kivikakk/htmlentities.zig"
}
]
| <a>koino</a>
Zig port of <a>Comrak</a>. Maintains 100% spec-compatibility with <a>GitHub Flavored Markdown</a>.
Getting started
Using koino as a library
<ul>
<li>Get Zig 0.12 https://ziglang.org/</li>
<li>Using Zig 0.13? See <a><code>zig-0.13.0</code></a> branch.</li>
<li>Start a new project with <code>zig init-exe</code> / <code>zig init-lib</code></li>
<li>
Add koino via the zig package manager:
<code>console
$ zig fetch --save https://github.com/kivikakk/koino/archive/<commit hash>.tar.gz</code>
</li>
<li>
Add the following to your <code>build.zig</code>'s <code>build</code> function:
<code>zig
const koino_pkg = b.dependency("koino", .{ .optimize = optimize, .target = target });
exe.root_module.addImport("koino", koino_pkg.module("koino"));</code>
</li>
<li>
Have a look at the bottom of <a><code>parser.zig</code></a> to see some test usage.
</li>
</ul>
Using it as a CLI executable
<ul>
<li>Clone this repository:
<code>console
$ git clone https://github.com/kivikakk/koino</code></li>
<li>Build
<code>console
$ zig build</code></li>
<li>Use <code>./zig-out/bin/koino</code></li>
</ul>
For development purposes
<ul>
<li>
Clone this repository with submodules for the <code>cmark-gfm</code> dependency:
<code>console
$ git clone --recurse-submodules https://github.com/kivikakk/koino
$ cd koino</code>
</li>
<li>
Build and run the spec suite.
</li>
</ul>
<code>console
$ zig build test
$ make spec</code>
Usage
Command line:
```console
$ koino --help
Usage: koino [-hu] [-e ...] [--smart]
Options:
-h, --help Display this help and exit
-u, --unsafe Render raw HTML and dangerous URLs
-e, --extension ... Enable an extension. (table,strikethrough,autolink,tagfilter)
--smart Use smart punctuation.
```
Library:
Documentation is TODO — see <a>LoLa</a> for an example of use. Note also the <a><code>build.zig</code></a> declaration. | [
"https://github.com/BitlyTwiser/zlog",
"https://github.com/Vemahk/zig-http-test"
]
|
https://avatars.githubusercontent.com/u/63115601?v=4 | pike | lithdew/pike | 2020-09-28T09:41:06Z | Async I/O for Zig | master | 13 | 136 | 8 | 136 | https://api.github.com/repos/lithdew/pike/tags | MIT | [
"async",
"epoll",
"io",
"iocp",
"kqueue",
"linux",
"mac",
"networking",
"signal",
"tcp",
"udp",
"windows",
"zig"
]
| 192 | false | 2025-05-01T23:05:19Z | false | false | unknown | github | []
| pike
A minimal cross-platform high-performance async I/O library written in <a>Zig</a>.
Features
<br/><input type='checkbox' class='w-4 h-4 text-green-500 bg-gray-100 border-gray-300 rounded focus:ring-blue-500 dark:focus:ring-blue-600 dark:ring-offset-gray-800 focus:ring-2 dark:bg-gray-700 dark:border-gray-600' checked disabled></input> Reactor/proactor-based I/O notification support
<br/><input type='checkbox' class='w-4 h-4 text-green-500 bg-gray-100 border-gray-300 rounded focus:ring-blue-500 dark:focus:ring-blue-600 dark:ring-offset-gray-800 focus:ring-2 dark:bg-gray-700 dark:border-gray-600' checked disabled></input> epoll (linux)
<br/><input type='checkbox' class='w-4 h-4 text-green-500 bg-gray-100 border-gray-300 rounded focus:ring-blue-500 dark:focus:ring-blue-600 dark:ring-offset-gray-800 focus:ring-2 dark:bg-gray-700 dark:border-gray-600' checked disabled></input> kqueue (darwin)
<br/><input type='checkbox' class='w-4 h-4 text-green-500 bg-gray-100 border-gray-300 rounded focus:ring-blue-500 dark:focus:ring-blue-600 dark:ring-offset-gray-800 focus:ring-2 dark:bg-gray-700 dark:border-gray-600' checked disabled></input> i/o completion ports (windows)
<br/><input type='checkbox' class='w-4 h-4 text-green-500 bg-gray-100 border-gray-300 rounded focus:ring-blue-500 dark:focus:ring-blue-600 dark:ring-offset-gray-800 focus:ring-2 dark:bg-gray-700 dark:border-gray-600' checked disabled></input> Async POSIX socket support
<br/><input type='checkbox' class='w-4 h-4 text-green-500 bg-gray-100 border-gray-300 rounded focus:ring-blue-500 dark:focus:ring-blue-600 dark:ring-offset-gray-800 focus:ring-2 dark:bg-gray-700 dark:border-gray-600' checked disabled></input> <code>bind</code>, <code>listen</code>, <code>connect</code>, <code>accept</code>
<br/><input type='checkbox' class='w-4 h-4 text-green-500 bg-gray-100 border-gray-300 rounded focus:ring-blue-500 dark:focus:ring-blue-600 dark:ring-offset-gray-800 focus:ring-2 dark:bg-gray-700 dark:border-gray-600' checked disabled></input> <code>read</code>, <code>recv</code>, <code>recvFrom</code>
<br/><input type='checkbox' class='w-4 h-4 text-green-500 bg-gray-100 border-gray-300 rounded focus:ring-blue-500 dark:focus:ring-blue-600 dark:ring-offset-gray-800 focus:ring-2 dark:bg-gray-700 dark:border-gray-600' checked disabled></input> <code>write</code>, <code>send</code>, <code>sendTo</code>
<br/><input type='checkbox' class='w-4 h-4 text-green-500 bg-gray-100 border-gray-300 rounded focus:ring-blue-500 dark:focus:ring-blue-600 dark:ring-offset-gray-800 focus:ring-2 dark:bg-gray-700 dark:border-gray-600' checked disabled></input> get/set socket options
<br/><input type='checkbox' class='w-4 h-4 text-green-500 bg-gray-100 border-gray-300 rounded focus:ring-blue-500 dark:focus:ring-blue-600 dark:ring-offset-gray-800 focus:ring-2 dark:bg-gray-700 dark:border-gray-600' checked disabled></input> Async Windows socket support
<br/><input type='checkbox' class='w-4 h-4 text-green-500 bg-gray-100 border-gray-300 rounded focus:ring-blue-500 dark:focus:ring-blue-600 dark:ring-offset-gray-800 focus:ring-2 dark:bg-gray-700 dark:border-gray-600' checked disabled></input> <code>bind</code>, <code>listen</code>, <code>connect</code>, <code>accept</code>
<br/><input type='checkbox' class='w-4 h-4 text-green-500 bg-gray-100 border-gray-300 rounded focus:ring-blue-500 dark:focus:ring-blue-600 dark:ring-offset-gray-800 focus:ring-2 dark:bg-gray-700 dark:border-gray-600' checked disabled></input> <code>read</code>, <code>recv</code>, <code>recvFrom</code>
<br/><input type='checkbox' class='w-4 h-4 text-green-500 bg-gray-100 border-gray-300 rounded focus:ring-blue-500 dark:focus:ring-blue-600 dark:ring-offset-gray-800 focus:ring-2 dark:bg-gray-700 dark:border-gray-600' checked disabled></input> <code>write</code>, <code>send</code>, <code>sendTo</code>
<br/><input type='checkbox' class='w-4 h-4 text-green-500 bg-gray-100 border-gray-300 rounded focus:ring-blue-500 dark:focus:ring-blue-600 dark:ring-offset-gray-800 focus:ring-2 dark:bg-gray-700 dark:border-gray-600' checked disabled></input> get/set socket options
<br/><input type='checkbox' class='w-4 h-4 text-green-500 bg-gray-100 border-gray-300 rounded focus:ring-blue-500 dark:focus:ring-blue-600 dark:ring-offset-gray-800 focus:ring-2 dark:bg-gray-700 dark:border-gray-600' checked disabled></input> Async signal support
<br/><input type='checkbox' class='w-4 h-4 text-green-500 bg-gray-100 border-gray-300 rounded focus:ring-blue-500 dark:focus:ring-blue-600 dark:ring-offset-gray-800 focus:ring-2 dark:bg-gray-700 dark:border-gray-600' checked disabled></input> signalfd for epoll (linux)
<br/><input type='checkbox' class='w-4 h-4 text-green-500 bg-gray-100 border-gray-300 rounded focus:ring-blue-500 dark:focus:ring-blue-600 dark:ring-offset-gray-800 focus:ring-2 dark:bg-gray-700 dark:border-gray-600' checked disabled></input> EVFILT_SIGNAL for kqueue (darwin)
<br/><input type='checkbox' class='w-4 h-4 text-green-500 bg-gray-100 border-gray-300 rounded focus:ring-blue-500 dark:focus:ring-blue-600 dark:ring-offset-gray-800 focus:ring-2 dark:bg-gray-700 dark:border-gray-600' checked disabled></input> SetConsoleCtrlHandler for i/o completion ports (windows)
<br/><input type='checkbox' class='w-4 h-4 text-green-500 bg-gray-100 border-gray-300 rounded focus:ring-blue-500 dark:focus:ring-blue-600 dark:ring-offset-gray-800 focus:ring-2 dark:bg-gray-700 dark:border-gray-600' checked disabled></input> Async event support
<br/><input type='checkbox' class='w-4 h-4 text-green-500 bg-gray-100 border-gray-300 rounded focus:ring-blue-500 dark:focus:ring-blue-600 dark:ring-offset-gray-800 focus:ring-2 dark:bg-gray-700 dark:border-gray-600' checked disabled></input> sigaction (posix)
<br/><input type='checkbox' class='w-4 h-4 text-green-500 bg-gray-100 border-gray-300 rounded focus:ring-blue-500 dark:focus:ring-blue-600 dark:ring-offset-gray-800 focus:ring-2 dark:bg-gray-700 dark:border-gray-600' checked disabled></input> SetConsoleCtrlHandler (windows)
Design
Notifier
A <code>Notifier</code> notifies of the completion of I/O events, or of the read/write-readiness of registered file descriptors/handles.
Should a <code>Notifier</code> report the completion of I/O events, it is designated to wrap around a proactor-based I/O notification layer in the operating system such as I/O completion ports on Windows.
Should a <code>Notifier</code> report the read/write-readiness of registered file descriptors/handles, it is designated to wrap around a reactor-based I/O notification layer in the operating system such as epoll on Linux, or kqueue on Darwin-based operating systems.
The <code>Notifier</code>'s purpose is to drive the execution of asynchronous I/O syscalls upon the notification of a reactor/proactor-based I/O event by dispatching suspended asynchronous function frames to be resumed by a thread pool/scheduler (e.g. <a>kprotty/zap</a>).
Handle
A <code>Handle</code>'s implementation is specific to a <code>Notifier</code> implementation, though overall wraps around and represents a file descriptor/handle in a program.
Subject to the <code>Notifier</code> implementation a <code>Handle</code>'s implementation falls under, state required to drive asynchronous I/O syscalls through a <code>Handle</code> is kept inside a <code>Handle</code>.
An example would be an intrusive linked list of suspended asynchronous function frames that are to be resumed upon the recipient of a notification that a file descriptor/handle is ready to be written to/read from. | []
|
https://avatars.githubusercontent.com/u/265903?v=4 | ctregex.zig | alexnask/ctregex.zig | 2020-06-22T22:19:33Z | Compile time regular expressions in zig | master | 5 | 133 | 15 | 133 | https://api.github.com/repos/alexnask/ctregex.zig/tags | - | [
"compile-time",
"regex",
"zig",
"zig-library",
"zig-package"
]
| 143 | false | 2025-05-06T00:15:46Z | true | false | unknown | github | []
| Zig compile time regular expressions
Generating fast code since 2020
Features
<ul>
<li>Comptime regular expression compilation</li>
<li>Comptime and runtime matching</li>
<li>UTF8, UTF16le, ASCII, codepoint array support</li>
<li>Captures (with named <code>(:<name>...)</code> support)</li>
<li><code>|</code>, <code>*</code>, <code>+</code>, <code>?</code>, <code>(:?...)</code>, <code>[...]</code>, <code>[^...]</code>, <code>{N}</code>, <code>{min,}</code>, <code>{min,max}</code></li>
<li>'\d', '\s' character classes</li>
</ul>
TODO
<ul>
<li>Faster generated code using DFAs when possible</li>
<li>search, findAll, etc.</li>
<li>More character classes</li>
<li>More features (backreferences etc.)</li>
</ul>
Example
```zig
test "runtime matching" {
@setEvalBranchQuota(1250);
// The encoding is utf8 by default, you can use .ascii, .utf16le, .codepoint here instead.
if (try match("(?def|abc)([😇ω])+", .{.encoding = .utf8}, "abc😇ωωωωω")) |res| {
std.debug.warn("Test: {}, 1: {}\n", .{ res.capture("test"), res.captures[1] });
}
}
test "comptime matching" {
@setEvalBranchQuota(2700);
if (comptime try match("(?def|abc)([😇ω])+", .{}, "abc😇ωωωωω")) |res| {
@compileError("Test: " ++ res.capture("test").? ++ ", 1: " ++ res.captures[1].?);
}
}
```
See tests.zig for more examples.
<a>Small benchmark with ctregex, PCRE2</a> | []
|
https://avatars.githubusercontent.com/u/9960268?v=4 | requestz | ducdetronquito/requestz | 2020-07-07T11:37:34Z | HTTP client for Zig 🦎 | master | 5 | 117 | 13 | 117 | https://api.github.com/repos/ducdetronquito/requestz/tags | 0BSD | [
"http",
"zig"
]
| 40 | false | 2025-04-16T08:59:44Z | true | false | unknown | github | []
| Requestz
An HTTP client inspired by <a>httpx</a> and <a>ureq</a>.
<a></a> <a></a> <a></a>
⚠️ I'm currently renovating an old house which does not allow me to work on <a>requestz</a>, <a>h11</a> and <a>http</a> anymore. Feel free to fork or borrow some ideas if there are any good ones :)
Installation
<em>requestz</em> is available on <a>astrolabe.pm</a> via <a>gyro</a>
<code>gyro add ducdetronquito/requestz</code>
Usage
Send a GET request
```zig
const client = @import("requestz.zig").Client;
var client = try Client.init(std.testing.allocator);
defer client.deinit();
var response = try client.get("http://httpbin.org/get", .{});
defer response.deinit();
```
Send a request with headers
```zig
const Headers = @import("http").Headers;
var headers = Headers.init(std.testing.allocator);
defer headers.deinit();
try headers.append("Gotta-go", "Fast!");
var response = try client.get("http://httpbin.org/get", .{ .headers = headers.items() });
defer response.deinit();
```
Send a request with compile-time headers
```zig
var headers = .{
.{"Gotta-go", "Fast!"}
};
var response = try client.get("http://httpbin.org/get", .{ .headers = headers });
defer response.deinit();
```
Send binary data along with a POST request
```zig
var response = try client.post("http://httpbin.org/post", .{ .content = "Gotta go fast!" });
defer response.deinit();
var tree = try response.json();
defer tree.deinit();
```
Stream a response
```zig
var response = try client.stream(.Get, "http://httpbin.org/", .{});
defer response.deinit();
while(true) {
var buffer: [4096]u8 = undefined;
var bytesRead = try response.read(&buffer);
if (bytesRead == 0) {
break;
}
std.debug.print("{}", .{buffer[0..bytesRead]});
}
```
Other standard HTTP method shortcuts:
- <code>client.connect</code>
- <code>client.delete</code>
- <code>client.head</code>
- <code>client.options</code>
- <code>client.patch</code>
- <code>client.put</code>
- <code>client.trace</code>
Dependencies
<ul>
<li><a>h11</a></li>
<li><a>http</a></li>
<li><a>iguanaTLS</a></li>
<li><a>zig-network</a></li>
</ul>
License
<em>requestz</em> is released under the <a>BSD Zero clause license</a>. 🎉🍻 | []
|
https://avatars.githubusercontent.com/u/694081?v=4 | SpeedTests | jabbalaci/SpeedTests | 2020-06-22T07:37:25Z | comparing the execution speeds of various programming languages | master | 1 | 111 | 39 | 111 | https://api.github.com/repos/jabbalaci/SpeedTests/tags | MIT | [
"benchmark",
"c",
"clang",
"cpp",
"csharp",
"d",
"dart",
"go",
"haskell",
"hyperfine",
"java",
"kotlin",
"linux",
"lua",
"nim",
"polyglot",
"pypy3",
"python3",
"rust",
"zig"
]
| 25,851 | false | 2025-05-18T12:48:06Z | false | false | unknown | github | []
| Speed Tests
When I learn a new programming language, I always implement the
Münchausen numbers problem in the given language. The problem is
simple but it includes a lot of computations, thus it gives an
idea of the execution speed of a language.
Münchausen numbers
A <a>Münchausen number</a>
is a number equal to the sum of its digits raised to each digit's power.
For instance, 3435 is a Münchausen number because
33+44+33+55 = 3435.
00 is not well-defined, thus we'll consider 00=0.
In this case there are four Münchausen numbers: 0, 1, 3435, and 438579088.
Exercise
Write a program that finds all the Münchausen numbers. We know that the largest
Münchausen number is less than 440 million.
Updates
Dates are in <code>yyyy-month</code> format.
<strong>2025-April:</strong> Python 3 with Rust removed. Common LISP updated. C3 added.
<strong>2025-March:</strong> Nim was updated to version 2.2.2. C# was updated to version 9.0.
Forth was added. Racket got an improved implementation. Lua updated. PHP updated. Nelua was added.
Implementations
In the implementations I tried to use the same (simple) algorithm in order
to make the comparisons as fair as possible.
All the tests were run on my home desktop machine (Intel Core i7-4771 CPU @ 3.50GHz with 8 CPU cores)
using Manjaro Linux. Execution times are wall-clock times and they are measured with
<a>hyperfine</a> (warmup runs: 1, benchmarked runs: 2).
The following implementations were received in the form of pull requests:
<ul>
<li>Clojure, Common LISP, Crystal, D, FASM, Forth, Fortran, Haskell, JavaScript, Lua, Mojo,
NASM, OCaml, Pascal, Perl, PHP, Python 3 with Numba, Racket,
Ruby, Scala 3, Scheme, Swift, Toit, V, Zig</li>
</ul>
Thanks for the contributions!
If you know how to make something faster, let me know!
Languages are listed in alphabetical order.
The size of the EXE files can be further reduced with the command <code>strip -s</code>. If it's
applicable, then the stripped EXE size is also shown in the table.
Below, you can find <strong>single-threaded</strong> implemetations. We also have
some <strong>multi-threaded</strong> implementations, <a>see here</a>.
C
<ul>
<li>gcc (GCC) 13.2.1 20230801</li>
<li>clang version 16.0.6</li>
<li>Benchmark date: 2024-02-05 [yyyy-mm-dd]</li>
</ul>
| Compilation | Runtime (sec) | EXE (bytes) | stripped EXE (bytes) |
|-----|:---:|:---:|:---:|
| <code>gcc -O3 main.c -o main -lm</code> | 3.893 ± 0.01 | 15,560 | 14,408 |
| <code>gcc -O2 main.c -o main -lm</code> | 3.892 ± 0.001 | 15,560 | 14,408 |
| <code>clang -O3 main.c -o main -lm</code> | 2.684 ± 0.013 | 15,528 | 14,416 |
| <code>clang -O2 main.c -o main -lm</code> | 2.672 ± 0.001 | 15,528 | 14,416 |
Notes:
* No real difference between the switches <code>-O2</code> and <code>-O3</code>.
It's enough to use <code>-O2</code>.
* clang is better in this case
<a>see source</a>
C++
<ul>
<li>g++ (GCC) 13.2.1 20230801</li>
<li>clang version 16.0.6</li>
<li>Benchmark date: 2024-02-05 [yyyy-mm-dd]</li>
</ul>
| Compilation | Runtime (sec) | EXE (bytes) | stripped EXE (bytes) |
|-----|:---:|:---:|:---:|
| <code>g++ -O3 --std=c++2a main.cpp -o main</code> | 3.865 ± 0.01 | 15,936 | 14,432 |
| <code>g++ -O2 --std=c++2a main.cpp -o main</code> | 3.849 ± 0.012 | 15,936 | 14,432 |
| <code>clang++ -O3 --std=c++2a main.cpp -o main</code> | 2.913 ± 0.01 | 15,904 | 14,440 |
| <code>clang++ -O2 --std=c++2a main.cpp -o main</code> | 2.827 ± 0.015 | 15,904 | 14,440 |
Notes:
* No big difference between the switches <code>-O2</code> and <code>-O3</code>.
Using <code>-O2</code> is even better.
* clang is better in this case
<a>see source</a>
C
<ul>
<li>dotnet 9.0.102</li>
<li>Benchmark date: 2025-03-02 [yyyy-mm-dd]</li>
</ul>
| Compilation | Runtime (sec) | EXE (bytes) | -- |
|-----|:---:|:---:|:---:|
| <code>dotnet publish -o dist -c Release</code> | 5.064 ± 0.01 | 77,736 | -- |
Notes:
* Similar performance to Java.
* 0.6 seconds faster than .NET 8.0.
<a>see source</a>
C3
<ul>
<li>C3 Compiler Version: 0.7.0</li>
<li>Benchmark date: 2025-04-29 [yyyy-mm-dd]</li>
</ul>
| Compilation | Runtime (sec) | EXE (bytes) | stripped EXE (bytes) |
|-----|:---:|:---:|:---:|
| <code>c3c compile -O5 -g0 main.c3</code> | 3.125 ± 0.01 | 110,752 | 90,920 |
Notes:
* Similar performance to C.
* More info about the language: https://c3-lang.org
<a>see source</a>
Clojure
<ul>
<li>Clojure CLI version 1.12.0.1479</li>
<li>Benchmark date: 2024-10-08 [yyyy-mm-dd]</li>
</ul>
| Execution | Runtime (sec) | compiled / transpiled output size (bytes) | -- |
|-----|:---:|:---:|:---:|
| <code>clj -M -m main</code> | 5.631 ± 0.112 | -- | -- |
| <code>mkdir classes && java -cp `clj -Spath` main</code> | 5.339 ± 0.101 | -- | -- |
<a>see source</a>
Notes:
* A bit slower than Java.
Codon
<ul>
<li>codon 0.15.5</li>
<li>Benchmark date: 2023-04-02 [yyyy-mm-dd]</li>
</ul>
| Compilation | Runtime (sec) | EXE (bytes) | stripped EXE (bytes) |
|-----|:---:|:---:|:---:|
| <code>codon build -release main.py</code> | 5.369 ± 0.006 | 28,400 | 26,864 |
Notes:
* Codon is a high-performance Python compiler that compiles Python code
to native machine code without any runtime overhead.
* It's a bit faster than C#!
* The code is unchanged Python code. No type annotations are needed.
See https://github.com/exaloop/codon for more information about this compiler.
<a>see source</a>
Common LISP
<ul>
<li>GNU CLISP 2.49.93+ (2018-02-18) (built on root2 [65.108.105.205])</li>
<li>SBCL 2.5.1</li>
<li>Benchmark date: 2025-04-10 [yyyy-mm-dd]</li>
</ul>
| Execution | Runtime (sec) | -- | -- |
|-----|:---:|:---:|:---:|
| <code>clisp -C main2.cl</code> | 517.914 ± 1.032 | -- | -- |
| <code>clisp -C main.cl</code> | 322.324 ± 0.98 | -- | -- |
| <code>sbcl --script main.cl</code> | 7.277 ± 0.003 | -- | -- |
| <code>sbcl --script main2.cl</code> | 4.897 ± 0.007 | -- | -- |
Notes:
* <code>clisp</code> is very slow. Even worse than Python. And without the
<code>-C</code> switch, it's ten times slower.
* With <code>sbcl</code>, you can get excellent performance.
<a>see source</a>
Crystal
<ul>
<li>Crystal 1.13.2 (2024-09-08); LLVM: 18.1.8; Default target: x86_64-pc-linux-gnu</li>
<li>Benchmark date: 2024-10-13 [yyyy-mm-dd]</li>
</ul>
| Compilation | Runtime (sec) | EXE (bytes) | stripped EXE (bytes) |
|-----|:---:|:---:|:---:|
| <code>crystal build --release main.cr</code> | 4.237 ± 0.077 | 807,432 | 273,424 |
Notes:
* The runtime is very good, similar to Go.
* The source code is almost identical to the Ruby source code.
* The build time is also good. In a previous version (2022) it was painfully slow.
See https://crystal-lang.org for more info about this language.
<a>see source</a>
D
<ul>
<li>DMD64 D Compiler v2.100.0</li>
<li>LDC - the LLVM D compiler (1.29.0)</li>
<li>Benchmark date: 2022-07-28 [yyyy-mm-dd]</li>
</ul>
| Compilation | Runtime (sec) | EXE (bytes) | stripped EXE (bytes) |
|-----|:---:|:---:|:---:|
| <code>dmd -release -O main.d</code> | 9.987 ± 0.045 | 993,816 | 712,504 |
| <code>ldc2 -release -O main.d</code> | 3.089 ± 0.008 | 34,584 | 23,008 |
Notes:
* the runtime is comparable to C/C++
* the official compiler <code>dmd</code> is slow
* <code>ldc2</code> is the best in this case
<a>see source</a>
Dart
<ul>
<li>Dart SDK version: 2.17.6 (stable) (Tue Jul 12 12:54:37 2022 +0200) on "linux_x64"</li>
<li>Node.js v18.6.0</li>
<li>Benchmark date: 2022-07-28 [yyyy-mm-dd]</li>
</ul>
| Execution | Runtime (sec) | compiled / transpiled output size (bytes) | -- |
|-----|:---:|:---:|:---:|
| <code>dart main.dart</code> | 23.909 ± 0.581 | -- | -- |
| <code>dart compile js main.dart -O2 -m -o main.js && node main.js</code> | 10.509 ± 0.032 | 31,684 | -- |
| <code>dart compile exe main.dart -o main && ./main</code> | 8.377 ± 0.009 | 5,925,856 | -- |
(<code>*</code>): in the first case, the Dart code is executed as a script
Notes:
* If you execute it as a script (JIT), it's slow.
* If you compile to native code (AOT), it's fast (though slower than Java/C#).
* stripping damaged the EXE file
<a>see source</a>
Elixir
<ul>
<li>Erlang/OTP 24 [erts-12.3] [source] [64-bit] [smp:8:8] [ds:8:8:10] [async-threads:1] [jit]; Elixir 1.13.2 (compiled with Erlang/OTP 24)</li>
<li>Benchmark date: 2022-07-28 [yyyy-mm-dd]</li>
</ul>
| Execution | Runtime (sec) | -- | -- |
|-----|:---:|:---:|:---:|
| <code>elixir main.exs</code> | 227.963 ± 0.543 | -- | -- |
| <code>elixirc munchausen.ex && elixir caller.exs</code> | 217.528 ± 0.762 | -- | -- |
Notes:
* Elixir doesn't excel in CPU-intensive tasks.
* In the second case, the modules were compiled to <code>.beam</code> files. However, it
didn't make the program much faster. The difference is very small.
<a>see source</a>
FASM
<ul>
<li>flat assembler version 1.73.30</li>
<li>Benchmark date: 2022-07-28 [yyyy-mm-dd]</li>
</ul>
| Compilation | Runtime (sec) | EXE (bytes) | stripped EXE (bytes) |
|-----|:---:|:---:|:---:|
| <code># FASM x64, see v1 in Makefile</code> | 15.792 ± 0.018 | 532 | 532 |
| <code># FASM x86, see v2 in Makefile</code> | 15.207 ± 0.023 | 444 | 444 |
Note: no difference between the 32-bit and 64-bit versions.
See https://en.wikipedia.org/wiki/FASM for more info about FASM.
<a>see source</a>
Forth
<ul>
<li>gforth 0.7.3</li>
<li>Benchmark date: 2025-03-02 [yyyy-mm-dd]</li>
</ul>
| Execution | Runtime (sec) | -- | -- |
|-----|:---:|:---:|:---:|
| <code>gforth-fast main.fs</code> | 73.734 ± 0.034 | -- | -- |
<a>see source</a>
Fortran
<ul>
<li>GNU Fortran (GCC) 12.1.0</li>
<li>Benchmark date: 2022-07-28 [yyyy-mm-dd]</li>
</ul>
| Compilation | Runtime (sec) | EXE (bytes) | stripped EXE (bytes) |
|-----|:---:|:---:|:---:|
| <code>gfortran -O2 main.f08 -o main</code> | 3.884 ± 0.054 | 21,016 | 14,456 |
Note: its speed is comparable to C.
<a>see source</a>
Go
<ul>
<li>go version go1.23.1 linux/amd64</li>
<li>Benchmark date: 2024-10-08 [yyyy-mm-dd]</li>
</ul>
| Compilation | Runtime (sec) | EXE (bytes) | stripped EXE (bytes) |
|-----|:---:|:---:|:---:|
| <code># using int, see v1 in Makefile</code> | 4.122 ± 0.034 | 2,137,820 | 1,391,192 |
| <code># using uint and uint32, see v2 in Makefile</code> | 3.5 ± 0.045 | 2,137,756 | 1,391,192 |
Notes:
* The speed is between C and Java (slower than C, faster than Java).
* Using uint and uint32, you can get better performance.
* The EXE is quite big.
<a>see source</a>
Haskell
<ul>
<li>The Glorious Glasgow Haskell Compilation System, version 8.10.7</li>
<li>Benchmark date: 2022-07-28 [yyyy-mm-dd]</li>
</ul>
| Compilation | Runtime (sec) | EXE (bytes) | stripped EXE (bytes) |
|-----|:---:|:---:|:---:|
| <code># basic, see v1 in Makefile</code> | 93.816 ± 0.043 | 3,175,704 | 754,008 |
| <code># optimized, see v2 in Makefile</code> | 3.517 ± 0.009 | 6,324,936 | 3,183,648 |
Notes:
* The performance of the optimized version is comparable to C.
* However, when you compile the optimized version for the first time,
the compilation is very slow.
<a>see source</a>
Java
<ul>
<li>openjdk version "21.0.4" 2024-07-16</li>
<li>Benchmark date: 2024-10-08 [yyyy-mm-dd]</li>
</ul>
| Execution | Runtime (sec) | Binary size (bytes) | -- |
|-----|:---:|:---:|:---:|
| <code>javac Main.java && java Main</code> | 5.003 ± 0.002 | 1,027 | -- |
(<code>*</code>): the binary size is the size of the <code>.class</code> file
Note: very good performance.
<a>see source</a>
JavaScript
<ul>
<li>Node.js v22.8.0</li>
<li>Benchmark date: 2024-10-08 [yyyy-mm-dd]</li>
</ul>
| Execution | Runtime (sec) | -- | -- |
|-----|:---:|:---:|:---:|
| <code>node main1.js</code> | 17.789 ± 0.009 | -- | -- |
| <code>node main2.js</code> | 6.819 ± 0.001 | -- | -- |
Notes:
* <code>main1.js</code> is a straightforward implementation
* <code>main2.js</code> is an improved implementation, using
a more optimal cache array size
<a>see source</a>
Julia
<ul>
<li>julia version 1.10.0</li>
<li>Benchmark date: 2024-02-07 [yyyy-mm-dd]</li>
</ul>
| Execution | Runtime (sec) | -- | -- |
|-----|:---:|:---:|:---:|
| <code>julia --startup=no main.jl</code> | 3.656 ± 0.006 | -- | -- |
Note: excellent performance, almost like C.
See https://julialang.org for more info about this language.
<a>see source</a>
Kotlin
<ul>
<li>Kotlin version 2.0.20-release-360 (JRE 21.0.4+7)</li>
<li>openjdk version "21.0.4" 2024-07-16</li>
<li>Benchmark date: 2024-10-08 [yyyy-mm-dd]</li>
</ul>
| Execution | Runtime (sec) | JAR size (bytes) | -- |
|-----|:---:|:---:|:---:|
| <code>kotlinc main.kt -include-runtime -d main.jar && java -jar main.jar</code> | 5.092 ± 0.004 | 4,826,841 | -- |
Note: same performance as Java.
<a>see source</a>
Lua
<ul>
<li>Lua 5.4.7 Copyright (C) 1994-2024 Lua.org, PUC-Rio</li>
<li>LuaJIT 2.1.1736781742 -- Copyright (C) 2005-2025 Mike Pall. https://luajit.org/</li>
<li>Benchmark date: 2025-03-16 [yyyy-mm-dd]</li>
</ul>
| Compilation | Runtime (sec) | -- | -- |
|-----|:---:|:---:|:---:|
| <code>lua main1.lua</code> | 112.412 ± 0.03 | -- | -- |
| <code>luajit main1.lua</code> | 16.854 ± 0.013 | -- | -- |
| <code>luajit main2_goto.lua</code> | 15.737 ± 0.007 | -- | -- |
Notes:
* LuaJIT is a Just-In-Time Compiler for Lua.
The language evolved and it contains an integer division operator (<code>//</code>), but LuaJIT
doesn't understand it.
* The Lua code ran much faster than the Python 3 (CPython) code.
* LuaJIT is fast. Its performance is similar to PyPy3 (even a little bit faster).
<a>see source</a>
Mojo
<ul>
<li>mojo 24.5.0 (e8aacb95)</li>
<li>Benchmark date: 2024-10-21 [yyyy-mm-dd]</li>
</ul>
| Compilation | Runtime (sec) | EXE (bytes) | stripped EXE (bytes) |
|-----|:---:|:---:|:---:|
| <code># using Int, see v1 in Makefile</code> | 3.844 ± 0.011 | 1,160,400 | 302,952 |
| <code># using UInt32, see v2 in Makefile</code> | 3.125 ± 0.043 | 1,160,400 | 302,952 |
Notes:
* The execution speed of v1 is very impressive. It's like C with gcc.
* The source code is very similar to Python, though not completely identical.
* Using <code>UInt32</code> makes it even faster. v2 is one of the fastest solutions here.
See https://www.modular.com/mojo for more info about Mojo.
<a>see source</a>
NASM
<ul>
<li>NASM version 2.15.05 compiled on Sep 24 2020</li>
<li>Benchmark date: 2022-07-28 [yyyy-mm-dd]</li>
</ul>
| Compilation | Runtime (sec) | EXE (bytes) | stripped EXE (bytes) |
|-----|:---:|:---:|:---:|
| <code># NASM x86, see v2 in Makefile</code> | 15.19 ± 0.012 | 9,228 | 8,428 |
| <code># NASM x64, see v1 in Makefile</code> | 15.186 ± 0.034 | 9,656 | 8,552 |
Note: no difference between the 32-bit and 64-bit versions.
See https://en.wikipedia.org/wiki/Netwide_Assembler for more info about NASM.
<a>see source</a>
Nelua
<ul>
<li>Nelua 0.2.0-dev</li>
<li>Benchmark date: 2025-03-27 [yyyy-mm-dd]</li>
</ul>
| Compilation | Runtime (sec) | EXE (bytes) | stripped EXE (bytes) |
|-----|:---:|:---:|:---:|
| <code>nelua main.nelua --release -o main</code> | 3.519 ± 0.02 | 15,704 | 14,432 |
| <code>nelua main.nelua --release --cc=clang -o main</code> | 3.215 ± 0.011 | 15,616 | 14,432 |
Notes:
* excellent performance (comparable to C/C++)
* it's faster with clang
* its syntax and semantics are similar to Lua
* see https://nelua.io for more info about this language
<a>see source</a>
Nim Tests #1
<ul>
<li>Nim Compiler Version 2.2.2 [Linux: amd64]</li>
<li>gcc (GCC) 14.2.1 20250128</li>
<li>clang version 19.1.7</li>
<li>Benchmark date: 2025-03-02 [yyyy-mm-dd]</li>
</ul>
| Compilation | Runtime (sec) | EXE (bytes) | stripped EXE (bytes) |
|-----|:---:|:---:|:---:|
| <code>nim c -d:release main.nim</code> | 3.773 ± 0.017 | 73,696 | 63,936 |
| <code>nim c --cc:clang -d:release main.nim</code> | 3.645 ± 0.014 | 57,440 | 47,608 |
| <code>nim c --cc:clang -d:danger main.nim</code> | 3.41 ± 0.021 | 42,808 | 35,152 |
| <code>nim c -d:danger main.nim</code> | 3.098 ± 0.022 | 54,808 | 47,328 |
(<code>*</code>): if <code>--cc:clang</code> is missing, then the default <code>gcc</code> was used
Notes:
* excellent performance, comparable to C
* danger mode gave some performance boost
* In release mode, there isn't much difference between gcc and clang.
* In danger mode, gcc performs better.
<a>see source</a>
Nim Tests #2
<ul>
<li>Nim Compiler Version 2.2.2 [Linux: amd64]</li>
<li>gcc (GCC) 14.2.1 20250128</li>
<li>clang version 19.1.7</li>
<li>Benchmark date: 2025-03-02 [yyyy-mm-dd]</li>
</ul>
| Compilation | Runtime (sec) | EXE (bytes) | stripped EXE (bytes) |
|-----|:---:|:---:|:---:|
| <code># using int32, see v3 in Makefile</code> | 3.728 ± 0.02 | 57,440 | 47,608 |
| <code># using int64, see v2 in Makefile</code> | 3.644 ± 0.023 | 57,440 | 47,608 |
| <code># using int, see v1 in Makefile</code> | 3.623 ± 0.001 | 57,440 | 47,608 |
| <code># using uint64, see v5 in Makefile</code> | 3.427 ± 0.033 | 57,496 | 47,608 |
| <code># using uint32, see v4 in Makefile</code> | 3.248 ± 0.026 | 57,496 | 47,608 |
Here, we used the compiler options <code>--cc:clang -d:release</code>
everywhere and tested the different integer data types.
Notes:
* In Nim, the size of <code>int</code> is platform-dependent, i.e. it's 64-bit long on
a 64 bit system. Thus, on a 64 bit system, there is no difference between
using int and int64 (that is, v1 and v2 are equivalent).
* There's a small difference between int / int64 (signed) and uint64 (unsigned).
uint64 is a bit faster.
* int32 (v3) was slower than int64, and uint32 (v4) was faster than uint64 (v5)
* To sum up: you can use int, but if you need some performance gain, try uint32 too.
Avoid int32.
<a>see source</a>
OCaml
<ul>
<li>ocamlopt 5.1.0</li>
<li>Benchmark date: 2024-02-05 [yyyy-mm-dd]</li>
</ul>
| Compilation | Runtime (sec) | EXE (bytes) | stripped EXE (bytes) |
|-----|:---:|:---:|:---:|
| <code>ocamlopt -unsafe -O3 -o main -rounds 10 main.ml</code> | 8.18 ± 0.001 | 1,086,200 | 902,232 |
<a>see source</a>
Odin
<ul>
<li>odin version dev-2024-10-nightly</li>
<li>Benchmark date: 2024-10-13 [yyyy-mm-dd]</li>
</ul>
| Compilation | Runtime (sec) | EXE (bytes) | stripped EXE (bytes) |
|-----|:---:|:---:|:---:|
| <code>odin build . -no-bounds-check -disable-assert -o:speed</code> | 3.536 ± 0.338 | 151,704 | 145,616 |
See https://odin-lang.org for more info about this language.
Notes:
* Very good performance, comparable to C.
* A previous version (2022) was slower, so Odin has improved a lot.
<a>see source</a>
Pascal
<ul>
<li>Free Pascal Compiler version 3.2.2-r0d122c49 [2025/01/02] for x86_64</li>
<li>Benchmark date: 2025-01-11 [yyyy-mm-dd]</li>
</ul>
| Compilation | Runtime (sec) | EXE (bytes) | stripped EXE (bytes) |
|-----|:---:|:---:|:---:|
| <code># see v1 in Makefile</code> | 17.391 ± 0.009 | 531,056 | 531,056 |
| <code># see v2 in Makefile</code> | 5.828 ± 0.024 | 531,056 | 531,056 |
Notes:
* Using signed integer (<code>LongInt</code> in v1) is a bit slower than using unsigned integer (<code>UInt32</code> in v2).
* With <code>UInt32</code>, <code>DivMod()</code> is slow. Using separate <code>div</code> and <code>mod</code> operations gives better results.
* However, with <code>LongInt</code>, it's the opposite. <code>DivMod()</code> is a better choice here.
* Strangely, <code>strip</code> didn't make the EXE any smaller.
<a>see source</a>
Perl
<ul>
<li>This is perl 5, version 38, subversion 1 (v5.38.1) built for x86_64-linux-thread-multi</li>
<li>Benchmark date: 2024-02-05 [yyyy-mm-dd]</li>
</ul>
| Execution | Runtime (sec) | -- | -- |
|-----|:---:|:---:|:---:|
| <code>perl main.pl</code> | 494.71 ± 4.649 | -- | -- |
| <code>perl -Minteger main.pl</code> | 423.805 ± 2.471 | -- | -- |
<a>see source</a>
Notes:
* This is the slowest solution. It's even slower than Python.
PHP
<ul>
<li>PHP 8.4.4 (cli) (built: Feb 11 2025 18:24:50) (NTS)</li>
<li>Benchmark date: 2025-03-16 [yyyy-mm-dd]</li>
</ul>
| Execution | Runtime (sec) | -- | -- |
|-----|:---:|:---:|:---:|
| <code>php main.php</code> | 133.232 ± 0.113 | -- | -- |
<a>see source</a>
Notes:
* Faster than Python 3
Python 3
<ul>
<li>Python 3.13.1</li>
<li>Python 3.10.14 (39dc8d3c85a7, Aug 30 2024, 08:27:45) [PyPy 7.3.17 with GCC 14.2.1 20240805]</li>
<li>Benchmark date: 2025-02-07 [yyyy-mm-dd]</li>
</ul>
| Execution | Runtime (sec) | -- | -- |
|-----|:---:|:---:|:---:|
| <code>python3 main.py</code> | 313.333 ± 8.03 | -- | -- |
| <code>pypy3 main.py</code> | 19.911 ± 0.054 | -- | -- |
Notes:
* Python 3.12 was 257 seconds. Version 3.13 got 56 seconds slower.
It seems Python 3 gets slower with every new version :(
* Python 3.11 was 233 seconds. Version 3.12 got 20+ seconds slower.
* PyPy3 is fast and comparable to LuaJIT
<a>see source</a>
Python 3 with mypyc
<ul>
<li>Python 3.10.5</li>
<li>mypy 0.971 (compiled: no)</li>
<li>Benchmark date: 2022-08-12 [yyyy-mm-dd]</li>
</ul>
| Execution | Runtime (sec) | .so (bytes) | stripped .so (bytes) |
|-----|:---:|:---:|:---:|
| <code>mypyc main.py && ./start_v3.sh</code> | 80.481 ± 0.574 | 183,992 | 92,824 |
Notes:
* <code>mypyc</code> can compile a module. This way, the program can be 4 to 5 times faster.
<a>see source</a>
Python 3 with Nim
<ul>
<li>Python 3.10.5</li>
<li>Nim Compiler Version 1.6.6 [Linux: amd64]</li>
<li>Benchmark date: 2022-08-13 [yyyy-mm-dd]</li>
</ul>
| Execution | Runtime (sec) | -- | -- |
|-----|:---:|:---:|:---:|
| <code>./start_v1.sh</code> | 46.772 ± 0.203 | -- | -- |
Notes:
* When you start it for the first time, it'll compile the Nim code
as a shared library. Thus the first run may be slower.
* The real work is done in Nim. The Nim code is compiled as a shared library.
The Python code just calls a function implemented in Nim.
<a>see source</a>
Python 3 with Numba
<ul>
<li>Python 3.11.6</li>
<li>numba 0.58.1</li>
<li>numpy 1.26.3</li>
<li>Benchmark date: 2024-02-07 [yyyy-mm-dd]</li>
</ul>
| Execution | Runtime (sec) | -- | -- |
|-----|:---:|:---:|:---:|
| <code>python3 main.py</code> | 5.526 ± 0.435 | -- | -- |
Notes:
* Numba is an open source JIT compiler that translates a subset of Python and NumPy code into fast machine code. More info here: https://numba.pydata.org
* The performance is excellent (similar to Java's).
* Almost equivalent to the original Python 3 source code.
* This implementation uses a numpy array for the cache.
<a>see source</a>
Racket
<ul>
<li>Welcome to Racket v8.15 [cs].</li>
<li>Benchmark date: 2025-03-16 [yyyy-mm-dd]</li>
</ul>
| Execution | Runtime (sec) | -- | -- |
|-----|:---:|:---:|:---:|
| <code>racket main1.rkt</code> | 107.486 ± 0.5 | -- | -- |
| <code>racket main2.rkt</code> | 43.847 ± 1.932 | -- | -- |
See https://racket-lang.org for more info about this language.
Notes:
* <code>main1.js</code> is a straightforward implementation
* <code>main2.js</code> is an improved implementation that uses type-specific procedures
<a>see source</a>
Ruby
<ul>
<li>ruby 3.0.4p208 (2022-04-12 revision 3fa771dded) [x86_64-linux]</li>
<li>Benchmark date: 2022-07-30 [yyyy-mm-dd]</li>
</ul>
| Execution | Runtime (sec) | -- | -- |
|-----|:---:|:---:|:---:|
| <code>ruby main.rb</code> | 199.632 ± 3.2 | -- | -- |
| <code>ruby --jit main.rb</code> | 75.863 ± 1.174 | -- | -- |
Notes:
* much faster than Python 3
* When run in JIT mode, the performance is the same as Python's
mypyc variant (where mypyc compiles a module).
* PyPy3 is 3-4 times faster than the JIT mode.
<a>see source</a>
Rust
<ul>
<li>rustc 1.62.1 (e092d0b6b 2022-07-16)</li>
<li>Benchmark date: 2022-07-28 [yyyy-mm-dd]</li>
</ul>
| Compilation | Runtime (sec) | EXE (bytes) | stripped EXE (bytes) |
|-----|:---:|:---:|:---:|
| <code>cargo build --release</code> | 2.936 ± 0.078 | 3,839,048 | 317,752 |
Notes:
* excellent performance (comparable to C/C++)
* The EXE is very big (almost 4 MB). However, if you strip the EXE,
the size becomes acceptable.
<a>see source</a>
Scala 3
<ul>
<li>Scala compiler version 3.6.0 -- Copyright 2002-2024, LAMP/EPFL</li>
<li>openjdk version "21.0.4" 2024-07-16</li>
<li>Benchmark date: 2024-10-20 [yyyy-mm-dd]</li>
</ul>
| Execution | Runtime (sec) | JAR size (bytes) | -- |
|-----|:---:|:---:|:---:|
| <code>scalac main.scala -d main.jar && scala main.jar</code> | 5.378 ± 0.015 | 5,782 | -- |
Notes:
* a bit slower than Java, a bit faster than C# (.NET 8)
* same performance as Clojure
<a>see source</a>
Scheme
<ul>
<li>chez 9.5.8</li>
<li>guile (GNU Guile) 2.2.7</li>
<li>gambitc v4.9.4</li>
<li>stalin 0.11</li>
<li>Benchmark date: 2022-09-18 [yyyy-mm-dd]</li>
</ul>
| Execution | Runtime (sec) | EXE (bytes) | -- |
|-----|:---:|:---:|:---:|
| <code>guile -s main.scm</code> | 148.423 ± 1.773 | -- | -- |
| <code>chez --compile-imported-libraries --optimize-level 3 -q --script main.scm</code> | 69.826 ± 0.387 | -- | -- |
| <code>gambitc -:debug=pqQ0 -exe -cc-options '-O3' main.scm && ./main</code> | 21.718 ± 0.229 | 9,098,392 | -- |
| <code>stalin -architecture amd64 -s -On -Ot -Ob -Om -Or -dC -dH -dP\ && ./main</code> | 4.599 ± 0.017 | 25,472 | -- |
| <code>stalin -architecture amd64 -s -On -Ot -Ob -Om -Or -dC -dH -dP\ && ./main</code> | 4.012 ± 0.014 | 25,512 | -- |
Note: stalin's performance is close to C.
<a>see source</a>
Swift
<ul>
<li>Swift version 5.9.2 (swift-5.9.2-RELEASE)</li>
<li>Benchmark date: 2024-02-05 [yyyy-mm-dd]</li>
</ul>
| Compilation | Runtime (sec) | EXE (bytes) | stripped EXE (bytes) |
|-----|:---:|:---:|:---:|
| <code>swiftc -Ounchecked main.swift</code> | 3.335 ± 0.004 | 15,832 | 11,984 |
Note: the performance is similar to C++.
<a>see source</a>
Toit
<ul>
<li>Toit version: v2.0.0-alpha.74</li>
<li>Benchmark date: 2023-04-02 [yyyy-mm-dd]</li>
</ul>
| Execution | Runtime (sec) | EXE (bytes) | -- |
|-----|:---:|:---:|:---:|
| <code>toit.run main.toit</code> | 120.263 ± 0.069 | -- | -- |
| <code>toit.compile -O2 -o main main.toit && ./main</code> | 118.63 ± 0.774 | 1,254,784 | 1,254,784 |
Notes:
* The runtime of <code>toit.run</code> and <code>toit.compile</code> is the same. I'm not sure,
but I think <code>toit.run</code> compiles to a temp. folder and starts the program from there.
* <code>toit.compile</code> must produce a stripped EXE. Stripping the EXE explicitly didn't change
the file size.
* see https://toitlang.org for more info about this language
<a>see source</a>
V
<ul>
<li>V 0.3.0 82db1e4</li>
<li>Benchmark date: 2022-07-28 [yyyy-mm-dd]</li>
</ul>
| Compilation | Runtime (sec) | EXE (bytes) | stripped EXE (bytes) |
|-----|:---:|:---:|:---:|
| <code>v -prod main.v</code> | 4.056 ± 0.004 | 209,392 | 187,728 |
| <code>v -cc clang -prod main.v</code> | 3.936 ± 0.018 | 212,720 | 191,736 |
By default, it uses GCC.
Notes:
* its speed is comparable to C
* see https://vlang.io for more info about this language
<a>see source</a>
Zig
<ul>
<li>zig 0.11.0</li>
<li>Benchmark date: 2024-02-07 [yyyy-mm-dd]</li>
</ul>
| Compilation | Runtime (sec) | EXE (bytes) | stripped EXE (bytes) |
|-----|:---:|:---:|:---:|
| <code>zig build-exe -OReleaseFast src/main.zig</code> | 2.975 ± 0.037 | 1,721,168 | 170,968 |
Notes:
* excellent performance (comparable to C/C++)
* see https://ziglang.org for more info about this language
<a>see source</a> | []
|
https://avatars.githubusercontent.com/u/6756180?v=4 | qml_zig | kassane/qml_zig | 2020-12-19T17:33:55Z | QML bindings for the Zig programming language | main | 2 | 108 | 4 | 108 | https://api.github.com/repos/kassane/qml_zig/tags | Apache-2.0 | [
"qml-bindings",
"qml-zig",
"zig",
"zig-package",
"ziglang"
]
| 1,696 | false | 2025-05-19T12:28:46Z | true | true | 0.14.0 | github | [
{
"commit": "56cb910b368ad0f8ef1f18ef52d46ab8136ca5d6",
"name": "dotherside",
"tar_url": "https://github.com/filcuc/dotherside/archive/56cb910b368ad0f8ef1f18ef52d46ab8136ca5d6.tar.gz",
"type": "remote",
"url": "https://github.com/filcuc/dotherside"
}
]
| QML-zig
Bindings are based on <a>DOtherSide</a> C bindings for QML Library is mostly feature-compliant with other bindings based on the library, but lacks some minor features and has quite a few bugs.
Preview
Build - Steps
Requirements
All software required for building.
<ul>
<li>Qt 5.15 or higher</li>
<li>Zig v0.14.0 or master</li>
<li>CMake v3.2 or higher (DOtherSide build)</li>
</ul>
Question
Works on Qt6?
Maybe, check <a>DOtherSide</a> support!!
Instructions
~~~bash
Clone repo
git clone --recursive https://github.com/kassane/qml_zig
Open folder
cd qml_zig
build DOtherSide
zig build cmake
Build
zig build ExampleName -Doptimize=ReleaseSafe|-Doptimize=ReleaseFast|-Doptimize=ReleaseSmall
~~~
Examples
<code>zig build Animated</code> - Run an Animated Box
<code>zig build Hello</code> - Hello World, with Menu and Clickable Button
<code>zig build Cells</code> - Cells example from QML Tute, click a color to change the text
<code>zig build Button</code> - Button with 2-way comms to the Zig code
<code>zig build Layouts</code> - Layouts examples
<code>zig build Splits</code> - Splitview example
<code>zig build Tables</code> - Tableview example
Work in Progres Examples
<code>zig build Particle</code> - Particle system example
- Needs QObject wrapper working yet, to pass zig objects to the QML side
Status
<ul>
<li>Basic initialization and execution</li>
<li>More Examples - thanks <a>@zigster64</a>!</li>
<li>Providing properties to QML files</li>
</ul>
TODO
<br/><input type='checkbox' class='w-4 h-4 text-blue-600 bg-gray-100 border-gray-300 rounded focus:ring-blue-500 dark:focus:ring-blue-600 dark:ring-offset-gray-800 focus:ring-2 dark:bg-gray-700 dark:border-gray-600' disabled></input> QAbstractListModels
<br/><input type='checkbox' class='w-4 h-4 text-blue-600 bg-gray-100 border-gray-300 rounded focus:ring-blue-500 dark:focus:ring-blue-600 dark:ring-offset-gray-800 focus:ring-2 dark:bg-gray-700 dark:border-gray-600' disabled></input> QObject - <strong>working progress</strong>
<br/><input type='checkbox' class='w-4 h-4 text-blue-600 bg-gray-100 border-gray-300 rounded focus:ring-blue-500 dark:focus:ring-blue-600 dark:ring-offset-gray-800 focus:ring-2 dark:bg-gray-700 dark:border-gray-600' disabled></input> QStyle | []
|
https://avatars.githubusercontent.com/u/3932972?v=4 | zig-opengl | ikskuh/zig-opengl | 2020-11-29T22:35:28Z | OpenGL binding generator based on the opengl registry | master | 3 | 108 | 15 | 108 | https://api.github.com/repos/ikskuh/zig-opengl/tags | EUPL-1.2 | [
"gamedev",
"opengl",
"opengl-es",
"opengl-loader",
"zig",
"zig-package",
"ziglang"
]
| 824 | false | 2025-05-12T22:45:53Z | false | false | unknown | github | []
| Zig OpenGL Binding
This is a pragmatic binding to different OpenGL versions.
It uses the official <a>OpenGL Registry</a> by Khronos to generate the Zig code.
Right now, it does minimal adjustments like removing the <code>gl</code> prefix from functions or the <code>GL_</code> prefix from constants. Everything else is the same as the C API.
There is a single non-OpenGL function exported:
<code>zig
pub fn load(load_ctx: anytype, get_proc_address: fn(@TypeOf(load_ctx), [:0]const u8) ?*FunctionPointer) !void {</code>
This function will load all OpenGL entry points with the help of <code>get_proc_address</code>. It receives the <code>load_ctx</code> as well as the function name.
<strong>NOTE:</strong> Please do not reference <code>zig-opengl</code> as a submodule or a package. Generate a binding and copy the output of that into your repository and update the file on demand. The OpenGL Registry is just too huge to be used conveniently.
Cloning submodules is required, so use <code>--recursive</code>:
<code>bash
git clone --recursive https://github.com/ikskuh/zig-opengl.git</code>
Example
This example uses <a>ZWL</a> by @Aransentin.
```zig
const zwl = @import("zwl");
const Platform = zwl.Platform(…);
pub fn initAndDraw(window: Platform.Window) !void {
try gl.load(window.platform, Platform.getOpenGlProcAddress);
while(true) {
gl.clearColor(1, 0, 1, 1);
gl.clear(gl.COLOR_BUFFER_BIT);
<code>try window.present();
</code>
}
}
```
Usage with mach-glfw
There is an example of <code>mach-glfw</code> + <code>zig-opengl</code> usage available here: https://github.com/hexops/mach-glfw-opengl-example
Pregenerated Loaders
This repository contains pre-generated bindings for all extension-free OpenGL versions.
Generating your own loader
From source
To generate your own loader, you have to clone this repository and build the generator with <code>dotnet</code>:
<code>sh-session
user@machine:~/zig-opengl$ dotnet run
Usage: generator <registry> <result> <api_version> [<extension>] [<extension>] ...
user@machine:~/zig-opengl$ dotnet run OpenGL-Registry/xml/gl.xml gl3v3.zig GL_VERSION_3_3
Final API has 344 commands and 818 enums types.
user@machine:~/zig-opengl$</code>
<code>sh-session
dotnet run \
OpenGL-Registry/xml/gl.xml \ # path to the opengl registry
my_binding.zig \ # path to the generated file
GL_VERSION_3_3 \ # feature level, options listed below
… # Add your extensions here, each as a single arg. Or let them out, you don't need extensions</code>
Possible feature levels (at the time of writing) are:
<ul>
<li><code>GL_VERSION_1_0</code></li>
<li><code>GL_VERSION_1_1</code></li>
<li><code>GL_VERSION_1_2</code></li>
<li><code>GL_VERSION_1_3</code></li>
<li><code>GL_VERSION_1_4</code></li>
<li><code>GL_VERSION_1_5</code></li>
<li><code>GL_VERSION_2_0</code></li>
<li><code>GL_VERSION_2_1</code></li>
<li><code>GL_VERSION_3_0</code></li>
<li><code>GL_VERSION_3_1</code></li>
<li><code>GL_VERSION_3_2</code></li>
<li><code>GL_VERSION_3_3</code></li>
<li><code>GL_VERSION_4_0</code></li>
<li><code>GL_VERSION_4_1</code></li>
<li><code>GL_VERSION_4_2</code></li>
<li><code>GL_VERSION_4_3</code></li>
<li><code>GL_VERSION_4_4</code></li>
<li><code>GL_VERSION_4_5</code></li>
<li><code>GL_VERSION_4_6</code></li>
<li><code>GL_VERSION_ES_CM_1_0</code></li>
<li><code>GL_ES_VERSION_2_0</code></li>
<li><code>GL_ES_VERSION_3_0</code></li>
<li><code>GL_ES_VERSION_3_1</code></li>
<li><code>GL_ES_VERSION_3_2</code></li>
<li><code>GL_SC_VERSION_2_0</code></li>
</ul>
Contribution
This library uses a small C# script that generates the Zig bindings. It is located in <code>src/Generator.cs</code>
What is missing right now?
<ul>
<li>Option to specify <code>core</code> or <code>compatibility</code> profile.</li>
</ul> | []
|
https://avatars.githubusercontent.com/u/65570835?v=4 | repository | ziglibs/repository | 2020-10-03T11:20:40Z | A community-maintained repository of zig packages | main | 5 | 108 | 21 | 108 | https://api.github.com/repos/ziglibs/repository/tags | MIT | [
"zig"
]
| 204 | false | 2025-05-22T03:25:09Z | true | false | unknown | github | []
| Zig Package Repository
This is one community-maintained repository of zig packages.
Contributions
If you have an actively maintained package, feel free to create a PR that adds your package to the repository! If you feel like it, you're also free to add other peoples packages!
Adding new packages
The repo provides a convenience tool to create new packages. Just run <code>zig build add</code> to get a prompt for package informations. The tool will verify that the entered information is vaguely correct and follows the format rules, also checks if a package with that name already exists and if the tags are all valid.
Verification
This repository will use the CI to verify if all PRs keep the database consistent. If you want to locally test this before doing the PR, just call <code>zig build verify</code> in the root folder.
Repository structure
The repository contains two major data sets: <em>packages</em> and <em>tags</em>.
<em>Tags</em> are just groups of packages, each package can have zero or more tags assigned. <em>Packages</em> are basically a link to <em>any</em> git repository paired with a root source file which is required for the package to be imported.
<code>packages/</code>
A folder containing a single file per package. Each file is a json file following this structure:
<code>json
{
"author": "<author>",
"description": "<description>",
"git": "<url>",
"root_file": "<path>",
"tags": [
"<tag>", "<tag>"
]
}</code>
The fields have the following meaning:
- <code>author</code> is the name (or nickname) of the package author
- <code>description</code> is a short description of the package
- <code>git</code> is a path to the git repository where the package can be fetched
- <code>root_file</code> is an absolute path in unix style (path segments separated by <code>/</code>) to the root file of the package. This is what should be used for <code>std.build.Pkg.path</code>
- <code>tags</code> is an array of strings where each item is the name of a tag in the folder <code>tags/</code>. Tags are identified by their file name (without extension) and will group the packages
<code>tags/</code>
A folder containing a single file per tag. Each file is a json file following this structure:
<code>json
{
"description": "<text>"
}</code>
The fields have the following meaning:
- <code>description</code> is a short description of what kind of packages can be found in this group.
<code>tools/</code>
This folder contains the sources of the verification tools and other nice things. | []
|
https://avatars.githubusercontent.com/u/13420428?v=4 | zglfw | IridescenceTech/zglfw | 2020-09-17T18:03:48Z | A thin, idiomatic wrapper for GLFW. Written in Zig, for Zig! | master | 0 | 104 | 14 | 104 | https://api.github.com/repos/IridescenceTech/zglfw/tags | NOASSERTION | [
"glfw",
"opengl",
"zig",
"zig-package"
]
| 380 | false | 2025-05-19T05:33:30Z | true | true | 0.14.0 | github | []
| zGLFW
A thin, idiomatic wrapper for GLFW. Written in Zig, for Zig!
Why write a wrapper?
While Zig is PERFECTLY capable of simply <code>@cImport</code>ing glfw3.h and using it in your application, I think it lacks a lot of cleanliness and succinctness that can be expressed with Zig. I decided to write this wrapper to provide GLFW with a nicer interface, error handling options, and quality of life changes (for example <code>[]const u8</code> instead of <code>[*c]const u8</code>). It also uses nicely named constants in place of <code>#define</code>s.
zGLFW is NOT 100% tested. I am happy to fix any errors that may arise, and I will accept contributions! Errors that arise from GLFW will be printed to <code>stderr</code>.
Examples
```zig
const std = @import("std");
const glfw = @import("glfw");
pub fn main() !void {
var major: i32 = 0;
var minor: i32 = 0;
var rev: i32 = 0;
<code>glfw.getVersion(&major, &minor, &rev);
std.debug.print("GLFW {}.{}.{}\n", .{ major, minor, rev });
//Example of something that fails with GLFW_NOT_INITIALIZED - but will continue with execution
//var monitor: ?*glfw.Monitor = glfw.getPrimaryMonitor();
try glfw.init();
defer glfw.terminate();
std.debug.print("GLFW Init Succeeded.\n", .{});
var window: *glfw.Window = try glfw.createWindow(800, 640, "Hello World", null, null);
defer glfw.destroyWindow(window);
while (!glfw.windowShouldClose(window)) {
if (glfw.getKey(window, glfw.KeyEscape) == glfw.Press) {
glfw.setWindowShouldClose(window, true);
}
glfw.pollEvents();
}
</code>
}
```
Documentation
I would suggest you look into the <code>glfw.zig</code> file themselves, as most of the changes are simple syntactically, but I have made some comments in cases where it may be different than you expect. Obviously <a>GLFW's Documentation</a> should cover most things that you want to know. | []
|
https://avatars.githubusercontent.com/u/9960268?v=4 | h11 | ducdetronquito/h11 | 2020-03-28T12:22:04Z | I/O agnostic HTTP/1.1 implementation for Zig 🦎 | master | 2 | 104 | 8 | 104 | https://api.github.com/repos/ducdetronquito/h11/tags | 0BSD | [
"http",
"io-free",
"parser",
"zig"
]
| 197 | false | 2025-04-27T23:22:10Z | true | false | unknown | github | []
| h11
<a></a> <a></a> <a></a>
I/O free state machine implementation of the HTTP/1.1 protocol.
Inspired by the amazing work of <a>python-hyper</a>.
⚠️ I'm currently renovating an old house which does not allow me to work on <a>requestz</a>, <a>h11</a> and <a>http</a> anymore. Feel free to fork or borrow some ideas if there are any good ones :)
Installation
<em>h11</em> is available on <a>astrolabe.pm</a> via <a>gyro</a>
<code>gyro add ducdetronquito/h11</code>
Dependencies
<ul>
<li><a>http</a></li>
</ul>
License
<em>h11</em> is released under the <a>BSD Zero clause license</a>. 🎉🍻 | []
|
https://avatars.githubusercontent.com/u/32400794?v=4 | zig-wlroots | swaywm/zig-wlroots | 2020-10-12T19:44:02Z | [mirror] Zig bindings for wlroots | master | 0 | 101 | 32 | 101 | https://api.github.com/repos/swaywm/zig-wlroots/tags | MIT | [
"bindings",
"wayland",
"wlroots",
"zig"
]
| 508 | false | 2025-05-01T10:12:36Z | true | true | 0.14.0 | github | [
{
"commit": "v0.3.0.tar.gz",
"name": "pixman",
"tar_url": "https://codeberg.org/ifreund/zig-pixman/archive/v0.3.0.tar.gz.tar.gz",
"type": "remote",
"url": "https://codeberg.org/ifreund/zig-pixman"
},
{
"commit": "v0.3.0.tar.gz",
"name": "wayland",
"tar_url": "https://codeberg.org/ifreund/zig-wayland/archive/v0.3.0.tar.gz.tar.gz",
"type": "remote",
"url": "https://codeberg.org/ifreund/zig-wayland"
},
{
"commit": "v0.3.0.tar.gz",
"name": "xkbcommon",
"tar_url": "https://codeberg.org/ifreund/zig-xkbcommon/archive/v0.3.0.tar.gz.tar.gz",
"type": "remote",
"url": "https://codeberg.org/ifreund/zig-xkbcommon"
}
]
| zig-wlroots
Idiomatic <a>Zig</a> bindings for
<a>wlroots</a>.
The main repository is on <a>codeberg</a>,
which is where the issue tracker may be found and where contributions are accepted.
Read-only mirrors exist on <a>sourcehut</a>
and <a>github</a>.
Completion status
Large parts of the wlroots API are fully bound, more than enough for the
<a>river</a> Wayland compositor to use these bindings.
At this stage, I only personally add bindings for new parts of the
wlroots API as required by river. If your project requires some
part of the wlroots API not yet bound please open an issue or pull
request on <a>codeberg</a>.
Dependencies
<ul>
<li><a>zig</a> 0.14</li>
<li><a>wlroots</a> 0.18</li>
<li><a>zig-wayland</a></li>
<li><a>zig-xkbcommon</a></li>
<li><a>zig-pixman</a></li>
</ul>
Usage
See <a>tinywl.zig</a> for an example compositor using zig-wlroots and an example
of how to integrate zig-wlroots and its dependencies into your build.zig.
See the C headers of wlroots for documentation.
Versioning
zig-wlroots versions have the form <code>major.minor.revision</code> where major and minor
are the major and minor version numbers of the compatible wlroots release. The
revision number is incremented for every zig-wlroots release compatible with a
given wlroots release. Breaking changes and bugfixes may occur with only a
revision version bump. The required Zig version may be updated with a revision
version bump.
For example, zig-wlroots <code>0.16.42</code> would be compatible with wlroots 0.16, the 42
indicating that there were 42 zig-wlroots releases since the initial wlroots 0.16
compatible zig-wlroots release.
For unreleased versions, the <code>-dev</code> suffix is used (e.g. <code>0.1.0-dev</code>).
License
zig-wlroots is released under the MIT (expat) license. The contents of the tinywl directory
are not part of zig-wlroots and are released under the Zero Clause BSD license. | [
"https://github.com/riverwm/river"
]
|
https://avatars.githubusercontent.com/u/12723818?v=4 | zig-wayland | ifreund/zig-wayland | 2020-09-13T21:27:03Z | [mirror] Zig wayland scanner and libwayland bindings | master | 2 | 100 | 28 | 100 | https://api.github.com/repos/ifreund/zig-wayland/tags | MIT | [
"wayland",
"zig"
]
| 470 | false | 2025-04-30T01:18:43Z | true | true | 0.14.0 | github | []
| zig-wayland
Zig 0.14 bindings and protocol scanner for libwayland.
The main repository is on <a>codeberg</a>,
which is where the issue tracker may be found and where contributions are accepted.
Read-only mirrors exist on <a>sourcehut</a>
and <a>github</a>.
Usage
A <code>Scanner</code> interface is provided which you may integrate with your <code>build.zig</code>:
```zig
const std = @import("std");
const Build = std.Build;
const Scanner = @import("wayland").Scanner;
pub fn build(b: *Build) !void {
const target = b.standardTargetOptions(.{});
const optimize = b.standardOptimizeOption(.{});
<code>const scanner = Scanner.create(b, .{});
const wayland = b.createModule(.{ .root_source_file = scanner.result });
scanner.addSystemProtocol("stable/xdg-shell/xdg-shell.xml");
scanner.addSystemProtocol("staging/ext-session-lock/ext-session-lock-v1.xml");
scanner.addCustomProtocol(b.path("protocol/private_foobar.xml"));
// Pass the maximum version implemented by your wayland server or client.
// Requests, events, enums, etc. from newer versions will not be generated,
// ensuring forwards compatibility with newer protocol xml.
// This will also generate code for interfaces created using the provided
// global interface, in this example wl_keyboard, wl_pointer, xdg_surface,
// xdg_toplevel, etc. would be generated as well.
scanner.generate("wl_seat", 4);
scanner.generate("xdg_wm_base", 3);
scanner.generate("ext_session_lock_manager_v1", 1);
scanner.generate("private_foobar_manager", 1);
const exe = b.addExecutable(.{
.name = "foobar",
.root_source_file = .{ .path = "foobar.zig" },
.target = target,
.optimize = optimize,
});
exe.root_module.addImport("wayland", wayland);
exe.linkLibC();
exe.linkSystemLibrary("wayland-client");
b.installArtifact(exe);
</code>
}
```
Then, you may import the provided module in your project:
<code>zig
const wayland = @import("wayland");
const wl = wayland.client.wl;</code>
There is an example project using zig-wayland here in the
<a>example/hello</a> directory of this repository.
Note that zig-wayland does not currently do extensive verification of Wayland
protocol xml or provide good error messages if protocol xml is invalid. It is
recommend to use <code>wayland-scanner --strict</code> to debug protocol xml instead.
Versioning
For now, zig-wayland versions are of the form <code>0.major.patch</code>. A major version
bump indicates a zig-wayland release that breaks API or requires a newer Zig
version to build. A patch version bump indicates a zig-wayland release that is
fully backwards compatible.
For unreleased versions, the <code>-dev</code> suffix is used (e.g. <code>0.1.0-dev</code>).
The version of zig-wayland currently has no direct relation to the upstream
libwayland version supported.
Breaking changes in zig-wayland's API will be necessary until a stable Zig 1.0
version is released, at which point I plan to switch to a new versioning scheme
and start the version numbers with <code>1</code> instead of <code>0</code>.
License
zig-wayland is released under the MIT (expat) license.
The contents of the hello-zig-wayland directory are not part of zig-wayland and are released under the Zero Clause BSD license. | [
"https://github.com/riverwm/river",
"https://github.com/tomcur/tarn"
]
|
https://avatars.githubusercontent.com/u/69380057?v=4 | Zig-PSP | zPSP-Dev/Zig-PSP | 2020-07-30T20:32:10Z | A project to bring the Zig Programming Language to the Sony PlayStation Portable! | master | 1 | 99 | 8 | 99 | https://api.github.com/repos/zPSP-Dev/Zig-PSP/tags | NOASSERTION | [
"psp",
"psp-sdk",
"zig",
"zig-package"
]
| 3,746 | false | 2025-05-13T19:30:18Z | true | true | 0.14.0 | github | [
{
"commit": "b5fbd5e13a7925def1810a40dbda4954755aa2f0",
"name": "zPBPTool",
"tar_url": "https://github.com/zPSP-Dev/zPBPTool/archive/b5fbd5e13a7925def1810a40dbda4954755aa2f0.tar.gz",
"type": "remote",
"url": "https://github.com/zPSP-Dev/zPBPTool"
},
{
"commit": "cda98b6f5fa970e42eed596c557a8bd328537a14",
"name": "zSFOTool",
"tar_url": "https://github.com/zPSP-Dev/zSFOTool/archive/cda98b6f5fa970e42eed596c557a8bd328537a14.tar.gz",
"type": "remote",
"url": "https://github.com/zPSP-Dev/zSFOTool"
},
{
"commit": "836d9cd94809071996cc788b429961f128de843e",
"name": "libzpsp",
"tar_url": "https://github.com/zPSP-Dev/libzpsp/archive/836d9cd94809071996cc788b429961f128de843e.tar.gz",
"type": "remote",
"url": "https://github.com/zPSP-Dev/libzpsp"
}
]
| Zig-PSP
A project to bring Zig to the Sony PlayStation Portable
Why Zig on the PSP?
In the PSP programming community, many libraries, tools, and other features are written in C or C++, which as we know has its problems with writing clean, reusable, and high quality code. Given that the core objectives of Zig as a language are to allow us to create well-designed and reusable software, Zig seems like a perfect fit for integrating older PSP libraries while striving to develop higher quality software!
Special Thanks
Special thanks is given to the <a>Rust-PSP team</a> whose efforts influenced and helped to get this project off the ground. No harm is intended, and it's thanks to you Rustaceans that fellow Ziguanas can program for the PSP.
Usage
Currently, using Zig-PSP is rather straight forward - one must use the psp folder in their project's src folder in order to have the PSP's function definitions, alongside with some custom utilities I have created. One also must include the tools/ folder to use the post-build tools. To build a PSP app, use the included <code>build.zig</code> script to generate a PSP executable! (EBOOT.PBP / app.prx) This script is well commented for explanation and documentation.
For a main.zig file one should include something like:
```zig
const psp = @import("psp/utils/psp.zig");
comptime {
asm(psp.module_info("Zig PSP App", 0, 1, 0));
}
pub fn main() !void {
psp.utils.enableHBCB();
psp.debug.screenInit();
<code>psp.debug.print("Hello from Zig!");
</code>
}
```
A quick call to <code>zig build</code> will build your program and should emit an EBOOT.PBP and app.prx in your root. These are the two PSP executable formats - .prx for debugging, and .PBP for running normally.
One can run a .PBP file on their PSP (assuming CFW is installed) by adding their application to <code>PSP_DRIVE:/PSP/GAME/YourAppName/EBOOT.PBP</code> and it will be available under the Games->Memory Stick list in the PSP's XMB.
EBOOT Customization
In order to customize the EBOOT, one can look into the <code>build.zig</code> file and modify the constant fields to change their application icon, background, and even add animations or sounds to the EBOOT on the XMB screen.
Comparisons To C/C++
When comparing Zig code to C/C++, it would be rather apparent that by default, Zig is much smaller and tightly knit. LLVM is an excellent backend which produces some very small code, and Zig is an example of that. Without the weight of the entire C standard library needing to be imported, a simple naive Hello World, as seen above, generates in 10,195 bytes, compared to the C/C++ size of 68,098 bytes. That's an 85% reduction in size! With a few structural changes, as seen in <code>hello-min.zig</code> sample, that size can get down to 6,674 bytes! That's 90.2% smaller!
Hopefully in the future, one could reference track the functions used in the SDK for imports, and dynamically generate module import information. This way, the PSP applications could go as small as 3,200 bytes for a hello world! This repository is distributed as part of a template, allowing one to customize their module imports, meaning that full release applications built with small tweaks to the toolchain NIDS directory could result in extraordinarily small executables for release applications!
Documentation
Currently Zig-PSP does not include documentation of the PSPSDK in the SDK's .zig files - but rather they are <a>well documented in C</a>. It is planned to add documentation in the future to resolve this
Debugging
If one has an installed copy of the legacy PSPSDK, one can use PSPLink - a USB debugging software, to connect their PSP to their computer and run debugging functions on the application. With legacy PSPSDK, you'll also have access to psp-gdb, a PSP-specific version of GDB to use as well. PSP-GDB with Zig is untested at the moment, but in theory should work. | []
|
https://avatars.githubusercontent.com/u/65322356?v=4 | zpm | zigtools/zpm | 2020-05-21T01:21:42Z | Zig package manager helper | master | 0 | 97 | 10 | 97 | https://api.github.com/repos/zigtools/zpm/tags | - | [
"zig",
"ziglang"
]
| 179 | false | 2025-05-16T17:19:29Z | true | true | unknown | github | []
| ZPM Next Generation
<blockquote>
This project is vaporware right now. If you feel the urge to implement it, go ahead!
</blockquote>
Usage Examples
<code>sh-session
[user@host] ~ $ zpm add-index zig.pm https://index.zig.pm/api/v1/
[user@host] ~ $</code>
```sh-session
[user@host] ~ $ zpm search network
masterq32/network 1.0.0 @ zig.pm
A smallest-common-subset of socket functions for crossplatform networking, TCP & UDP
marler8997/ziget 1.2.3 @ zig.pm
Zig library/tool to request network assets
[user@host] ~ $
```
```sh-session
[user@host] ~ $ zpm add masterq32/network
Adding masterq32/network... [/]
Done.
Use this code to add the dependency to your project:
<code>const network_dep = b.dependency("masterq32/network", .{});
const network_mod = network_dep.module("network");
</code>
[user@host] ~ $
```
```sh-session
[user@host] ~ $ zpm update --auto
Updating 2 dependencies... [/]
<code>masterq32/network 1.0.0 => 1.0.5
masterq32/args 1.4.5 => 1.9.2
</code>
[user@host] ~ $
```
```sh-session
[user@host] ~ $ zpm update --auto --major
Updating 1 dependency... [/]
<code>masterq32/network 1.0.0 => 2.1.7
</code>
[user@host] ~ $
```
```sh-session
[user@host] ~ $ zpm update
Updating 1 dependency... [/]
<code>masterq32/network 1.0.0 => 2.1.7 [yN]
</code>
```
<code>sh-session
[user@host] ~ $ zpm package
path: /home/user/.cache/zpm/bundles/network.tar.xz
hash: 1220a1f050f3a67785cbe68283b252f02f72885eea80d6a9e1856b02cd66deaf1492</code>
<code>sh-session
[user@host] ~ $ zpm push
Uploading masterq32/network to zig.pm... [/]
[user@host] ~ $</code>
<code>build.zig.zon</code> Extension
```zig
.{
.name = "network", // this is displayed after the user name
.version = "1.2.3", // this is displayed in the search
.dependencies = .{
.inner = .{
.url = "…",
.hash = "…",
<code> .index = "zig.pm", // which index was used to fetch
.package_name = "masterq32/inner", // what is the package named there
.package_version = "0.9.3", // which version was installed last
},
},
// Where can we fetch our packages?
.package_indices = .{
.@"zig.pm" = .{
.base_url = "https://index.zig.pm/api/v1/",
},
},
</code>
}
```
Package Index Format
<code>/index.json</code>
Describes the root of a package index.
Should be served with a backend that supports <code>index.json?search=<query>&sort=<key></code> with <code><key></code> being one of the fields of an entry of <code>packages</code> and <code><query></code> should be able to do a full text search.
```json
{
"last_update": {
"unix": "1714076768",
"iso": "2024-04-25T20:26:08.690159"
},
"packages": [
{
"name": "masterq32/network",
"short_desc": "A smallest-common-subset of socket functions for crossplatform networking, TCP & UDP",
<code> "zig_version": "0.12.0",
"pkg_version": "0.11.0-43-ge107f8d11",
"pkg_hash": "12203149d62eb94d919582cfd2482a4abd14b7908a69928ec0fe2724969388a2ad01",
"pkg_url": "https://downloads.zig.pm/packages/masterq32/network/0.11.0-43-ge107f8d11.tar.xz",
"pkg_metadata": "https://downloads.zig.pm/packages/masterq32/network.json"
},
…
]
</code>
}
```
<code>metadata.json</code>
This file is served under the url provided at <code>pkg_metadata</code> and describes a package more in-depth including
all published versions and some generic package metadata.
<code>json
{
"package_name": "masterq32/network",
"description": "A smallest-common-subset of socket functions for crossplatform networking, TCP & UDP",
"versions": {
"0.11.0-43-ge107f8d11": {
"package": {
"hash": "12200466d72927f83a1e427d04d15e7ab71ab735ae6f175b6dee22bde2d64bab34a3",
"url": "https://downloads.zig.pm/packages/masterq32/network/0.11.0-43-ge107f8d11.tar.xz",
"files": [
"LICENSE",
"build.zig",
"build.zig.zon",
"src/network.zig"
]
},
"created": {
"unix": "1714076768",
"iso": "2024-04-25T20:26:08.690159"
},
"archive": {
"size": "218662",
"sha256sum": "786101a5548c7f5687a2f401c9b011badd734b68051c600d6a2a0e31b0bf7629"
},
"dependencies": {
"inner": {
"name": "masterq32/inner",
"version": "0.9.3"
},
},
}
}
}</code> | []
|
https://avatars.githubusercontent.com/u/9960268?v=4 | http | ducdetronquito/http | 2020-09-20T08:54:37Z | HTTP core types for Zig 🦴 | master | 3 | 96 | 7 | 96 | https://api.github.com/repos/ducdetronquito/http/tags | 0BSD | [
"http",
"zig"
]
| 69 | false | 2024-12-09T12:36:55Z | true | false | unknown | github | []
| HTTP
HTTP core types for Zig inspired by Rust <a>http</a>.
<a></a> <a></a> <a></a>
⚠️ I'm currently renovating an old house which does not allow me to work on <a>requestz</a>, <a>h11</a> and <a>http</a> anymore. Feel free to fork or borrow some ideas if there are any good ones :)
Installation
<em>http</em> is available on <a>astrolabe.pm</a> via <a>gyro</a>
<code>gyro add ducdetronquito/http</code>
Usage
Create an HTTP request
```zig
const Request = @import("http").Request;
const std = @import("std");
var request = try Request.builder(std.testing.allocator)
.get("https://ziglang.org/")
.header("GOTTA-GO", "FAST")
.body("");
defer request.deinit();
```
Create an HTTP response
```zig
const Response = @import("http").Request;
const StatusCode = @import("http").StatusCode;
const std = @import("std");
var response = try Response.builder(std.testing.allocator)
.status(.Ok)
.header("GOTTA-GO", "FAST")
.body("");
defer response.deinit();
```
API Reference
Structures
<code>Headers</code>
An HTTP header list
<code>zig
// The default constructor
fn init(allocator: *Allocator) Headers</code>
<code>zig
// Add a header name and value
fn append(self: *Headers, name: []const u8, value: []const u8) !void</code>
<code>zig
// Retrieve the first matching header
fn get(self: Headers, name: []const u8) ?Header</code>
<code>zig
// Retrieve a list of matching headers
fn list(self: Headers, name: []const u8) ![]Header</code>
<code>zig
// Retrieve the number of headers
fn len(self: Headers) usize</code>
<code>zig
// Retrieve all headers
fn items(self: Headers) []Header</code>
Header issues are tracked here: <a>#2</a>
<code>Request</code>
An HTTP request object produced by the request builder.
<code>zig
const Request = struct {
method: Method,
uri: Uri,
version: Version,
headers: Headers,
body: []const u8,
};</code>
<code>zig
// The default constructor to start building a request
fn builder(allocator: *Allocator) RequestBuilder</code>
<code>zig
// Release the memory allocated by the headers
fn deinit(self: *Request) void</code>
<code>RequestBuilder</code>
The request builder.
<code>zig
// The default constructor
default(allocator: *Allocator) RequestBuilder</code>
<code>zig
// Set the request's payload.
// This function returns the final request objet or a potential error
// collected during the build steps
fn body(self: *RequestBuilder, value: []const u8) RequestError!Request</code>
<code>zig
// Shortcut to define a CONNECT request to the provided URI
fn connect(self: *RequestBuilder, _uri: []const u8) *RequestBuilder</code>
<code>zig
// Shortcut to define a DELETE request to the provided URI
fn delete(self: *RequestBuilder, _uri: []const u8) *RequestBuilder</code>
<code>zig
// Shortcut to define a GET request to the provided URI
fn get(self: *RequestBuilder, _uri: []const u8) *RequestBuilder</code>
<code>zig
// Shortcut to define an HEAD request to the provided URI
fn head(self: *RequestBuilder, _uri: []const u8) *RequestBuilder</code>
<code>zig
// Set a request header name and value
fn header(self: *RequestBuilder, name: []const u8, value: []const u8) *RequestBuilder</code>
<code>zig
// Set the request's method
fn method(self: *RequestBuilder, value: Method) *RequestBuilder</code>
<code>zig
// Shortcut to define an OPTIONS request to the provided URI
fn options(self: *RequestBuilder, _uri: []const u8) *RequestBuilder</code>
<code>zig
// Shortcut to define a PATCH request to the provided URI
fn patch(self: *RequestBuilder, _uri: []const u8) *RequestBuilder</code>
<code>zig
// Shortcut to define a POST request to the provided URI
fn post(self: *RequestBuilder, _uri: []const u8) *RequestBuilder</code>
<code>zig
// Shortcut to define a PUT request to the provided URI
fn put(self: *RequestBuilder, _uri: []const u8) *RequestBuilder</code>
<code>zig
// Shortcut to define a TRACE request to the provided URI
fn trace(self: *RequestBuilder, _uri: []const u8) *RequestBuilder</code>
<code>zig
// Set the request's URI
fn uri(self: *RequestBuilder, value: []const u8) *RequestBuilder</code>
<code>zig
// Set the request's protocol version
fn version(self: *RequestBuilder, value: Version) *RequestBuilder</code>
<code>Response</code>
An HTTP response object produced by the response builder.
<code>zig
const Response = struct {
status: StatusCode,
version: Version,
headers: Headers,
body: []const u8,
};</code>
<code>zig
// The default constructor to start building a response
fn builder(allocator: *Allocator) ResponseBuilder</code>
<code>ResponseBuilder</code>
The response builder.
<code>zig
// The default constructor
default(allocator: *Allocator) ResponseBuilder</code>
<code>zig
// Set the response's payload.
// This function returns the final response objet or a potential error
// collected during the build steps
fn body(self: *ResponseBuilder, value: []const u8) ResponseError!Response</code>
<code>zig
// Set a response header name and value
fn header(self: *ResponseBuilder, name: []const u8, value: []const u8) *ResponseBuilder</code>
<code>zig
// Set the response's status code
fn status(self: *ResponseBuilder, value: StatusCode) *ResponseBuilder</code>
<code>zig
// Set the response's protocol version
fn version(self: *ResponseBuilder, value: Version) *ResponseBuilder</code>
<code>Uri</code>
A valid URI object
<a>Read more</a>
Enumerations
<code>Method</code>
The available request methods.
<ul>
<li>Connect</li>
<li>Custom</li>
<li>Delete</li>
<li>Get</li>
<li>Head</li>
<li>Options</li>
<li>Patch</li>
<li>Post</li>
<li>Put</li>
<li>Trace</li>
</ul>
<code>StatusCode</code>
The available response status codes.
A lot; the list is available on <a>MDN</a>.
<code>Version</code>
The available protocol versions.
<ul>
<li>Http09</li>
<li>Http10</li>
<li>Http11</li>
<li>Http2</li>
<li>Http3</li>
</ul>
Errors
<code>HeadersError</code>
<ul>
<li>OutOfMemory</li>
<li>Invalid</li>
</ul>
<code>RequestError</code>
<ul>
<li>OutOfMemory</li>
<li>UriRequired</li>
<li><a>URI errors</a></li>
</ul>
<code>ResponseError</code>
<ul>
<li>OutOfMemory</li>
</ul>
License
<em>http</em> is released under the <a>BSD Zero clause license</a>. 🎉🍻
The URI parser is a fork of Vexu's <a>zuri</a> under the MIT License. | [
"https://github.com/zigster64/zchat"
]
|
https://avatars.githubusercontent.com/u/124872?v=4 | zigly | jedisct1/zigly | 2020-11-17T18:24:22Z | The easiest way to write services for Fastly's Compute@Edge in Zig. | master | 0 | 89 | 2 | 89 | https://api.github.com/repos/jedisct1/zigly/tags | Apache-2.0 | [
"fastly",
"webassembly",
"zig",
"zig-library",
"zig-package"
]
| 125 | false | 2025-05-11T02:38:24Z | true | true | unknown | github | []
|
The easiest way to write Fastly Compute services in Zig.
<ul>
<li><a></a></li>
<li><a>What is Fastly Compute?</a></li>
<li><a>What is Zigly?</a></li>
<li><a>Usage</a><ul>
<li><a>Example application</a></li>
<li><a>Adding Zigly as a dependency</a></li>
<li><a>A minimal WebAssembly program</a></li>
<li><a>Testing Fastly Compute modules</a></li>
<li><a>Using Zigly</a></li>
<li><a>Hello world!</a></li>
<li><a>Inspecting incoming requests</a></li>
<li><a>Making HTTP queries</a></li>
<li><a>Cache override</a></li>
<li><a>Pipes</a></li>
<li><a>Proxying</a></li>
<li><a>Redirects</a></li>
<li><a>Response decompression</a></li>
<li><a>Dictionaries</a></li>
<li><a>Logging</a></li>
</ul>
</li>
<li><a>Deployment to Fastly's platform</a></li>
</ul>
What is Fastly Compute?
<a>Fastly Compute</a> is <a>Fastly</a>'s service to run custom code directly on CDN nodes.
The service runs anything that can be compiled to WebAssembly, and exports a convenient set of functions to interact with the platform.
What is Zigly?
Zigly is a library that makes it easy to write Fastly Compute modules in <a>Zig</a>.
Beyond the functions exported by the Fastly platform, Zigly will eventually include additional utility functions (cookie manipulation, JWT tokens, tracing...) to make application development as simple as possible.
Zigly is written for Zig 0.12.x.
Usage
Example application
Check out the <code>example</code> directory.
This contains an example Fastly application that relays all incoming traffic to a backend server, with transparent caching.
If you just want to use Fastly as a CDN, this is all you need!
Adding Zigly as a dependency
Add the dependency to your project:
<code>sh
zig fetch --save=zigly https://github.com/jedisct1/zigly/archive/refs/tags/0.1.9.tar.gz</code>
And the following to your <code>build.zig</code> file:
<code>zig
const zigly = b.dependency("zigly", .{
.target = target,
.optimize = optimize,
});
exe.root_module.addImport("zigly", zigly.module("zigly"));
exe.linkLibrary(zigly.artifact("zigly"));</code>
The <code>zigly</code> structure can be imported in your application with:
<code>zig
const zigly = @import("zigly");</code>
A minimal WebAssembly program
```zig
const std = @import("std");
pub fn main() !void
std.debug.print("Hello from WebAssembly and Zig!\n", .{});
}
```
The program can be compiled with (replace <code>example.zig</code> with the source file name):
<code>sh
zig build-exe -target wasm32-wasi example.zig</code>
Happy with the result? Add <code>-Doptimize=ReleaseSmall</code> or <code>-Doptimize=ReleaseFast</code> to get very small or very fast module:
<code>sh
zig build-exe -target wasm32-wasi -Doptimize=ReleaseSmall example.zig</code>
The example above should not compile to more than 411 bytes.
If you are using a build file instead, define the target as <code>wasm32-wasi</code> in the <code>build.zig</code> file:
<code>zig
const target = b.standardTargetOptions(.{ .default_target = .{ .cpu_arch = .wasm32, .os_tag = .wasi } });</code>
...and build with <code>zig build -Doptimize=ReleaseSmall</code> or <code>-Doptimize=ReleaseFast</code> to get optimized modules.
Testing Fastly Compute modules
The easiest way to test the resulting modules is to use <a>Viceroy</a>, a reimplementation of the Fastly API that runs locally.
Using Zigly
Hello world!
<code>zig
const downstream = try zigly.downstream();
var response = downstream.response;
try response.body.writeAll("Hello world!");
try response.finish();</code>
<code>downstream()</code> returns a type representing the initial connection, from a client to the proxy.
That type includes <code>response</code>, that can be used to send a response, as well as <code>request</code>, that can be used to inspect the incoming request.
Every function call may fail with an error from the <code>FastlyError</code> set.
Slightly more complicated example:
```zig
const downstream = try zigly.downstream();
var response = downstream.response;
response.setStatus(201);
response.headers.set("X-Example", "Header");
try response.body.writeAll("Partial");
try response.flush();
try response.body.writeAll("Response");
try response.finish();
var logger = Logger.open("logging_endpoint");
logger.write("Operation sucessful!");
```
Note that calling <code>finish()</code> is always required in order to actually send a response to the client.
But realistically, most responses will either be simple redirects:
<code>zig
var downstream = try zigly.downstream();
try downstream.redirect(302, "https://www.perdu.com");</code>
or responding directly from the cache, proxying to the origin if the cached entry is nonexistent or expired:
<code>zig
var downstream = try zigly.downstream();
try downstream.proxy("google", "www.google.com");</code>
Inspecting incoming requests
Applications can read the body of an incoming requests as well as other informations such as the headers:
<code>zig
const request = downstream.request;
const user_agent = try request.headers.get(allocator, "user-agent");
if (request.isPost()) {
// method is POST, read the body until the end, up to 1000000 bytes
const body = try request.body.readAll(allocator, 1000000);
}</code>
As usual in Zig, memory allocations are never hidden, and applications can choose the allocator they want to use for individual function calls.
Making HTTP queries
Making HTTP queries is easy:
<code>zig
var query = try zigly.Request.new("GET", "https://example.com");
var response = try query.send("backend");
const body = try response.body.readAll(allocator, 0);</code>
Arbitrary headers can be added the the outgoing <code>query</code>:
<code>zig
try query.headers.set("X-Custom-Header", "Custom value");</code>
Body content can also be pushed, even as chunks:
<code>zig
try query.body.write("X");
try query.body.write("Y");
try query.body.close();</code>
And the resulting <code>response</code> contains <code>headers</code> and <code>body</code> properties, that can be inspected the same way as a downstream query.
Cache override
Caching can be disabled or configured on a per-query basis with <code>setCachingPolicy()</code>:
<code>zig
try query.setCachingPolicy(.{ .serve_stale = 600, .pci = true });</code>
Attributes include:
<ul>
<li><code>no_cache</code></li>
<li><code>ttl</code></li>
<li><code>serve_stale</code></li>
<li><code>pci</code></li>
<li><code>surrogate_key</code></li>
</ul>
Pipes
With <code>pipe()</code>, the response sent to a client can be a direct copy of another response. The application will then act as a proxy, optionally also copying the original status and headers.
<code>zig
var query = try zigly.Request.new("GET", "https://google.com");
var upstream_response = try query.send("google");
const downstream = try zigly.downstream();
try downstream.response.pipe(&upstream_response, true, true);</code>
Proxying
Proxying is even easier to use than pipes when a query should be sent unmodified (with the exception of the <code>Host</code> header) to the origin:
<code>zig
var downstream = try zigly.downstream();
try downstream.proxy("google", "www.google.com");</code>
The second parameter is optional. If <code>null</code>, the original <code>Host</code> header will not be modified.
Redirects
Redirecting the client to another address can be done with a single function call on the downstream object:
<code>zig
const downstream = try zigly.downstream();
try downstream.redirect(302, "https://www.perdu.com");</code>
Response decompression
By default, responses are left as-is. Which means that if compression (<code>Content-Encoding</code>) was accepted by the client, the response can be compressed.
Calling <code>setAutoDecompressResponse(true)</code> on a <code>Request</code> object configures the Fastly Compute runtime to decompress gzip-encoded responses before streaming them to the application.
Dictionaries
<code>zig
const dict = try zigly.Dictionary.open("name");
const value = try dict.get(allocator, "key");</code>
Logging
<code>zig
const logger = try zigly.Logger.open("endpoint);
try logger.write("Log entry");</code>
Deployment to Fastly's platform
The <code>fastly</code> command-line tool only supports compilation of Rust and AssemblyScript at the moment.
However, it can still be used to upload pre-compiled code written in other languages, including Zig.
<ol>
<li>Create a new project:</li>
</ol>
<code>sh
fastly compute init</code>
For the language, select <code>Other (pre-compiled WASM binary)</code>.
<ol>
<li>Add a build script:</li>
</ol>
Add the following lines to the fastly.toml file:
<code>toml
[scripts]
build = "zig build -Doptimize=ReleaseSmall -Dtarget=wasm32-wasi && mkdir -p bin && cp zig-out/bin/*.wasm bin/main.wasm"</code>
<ol>
<li>Compile and package the Fastly Compute module:</li>
</ol>
<code>sh
fastly compute build</code>
<ol>
<li>Test locally</li>
</ol>
<code>sh
fastly compute serve</code>
<ol>
<li>Deploy!</li>
</ol>
<code>sh
fastly compute deploy</code>
In order to deploy new versions, repeat steps 3 and 5. | []
|
https://avatars.githubusercontent.com/u/39484230?v=4 | didot | zenith391/didot | 2020-09-12T08:24:09Z | Zig 3D game engine. | master | 1 | 88 | 1 | 88 | https://api.github.com/repos/zenith391/didot/tags | MIT | [
"game-engine",
"game-engine-3d",
"high-level",
"high-level-api",
"zig"
]
| 40,010 | false | 2025-05-09T06:05:37Z | true | false | unknown | github | []
| Didot
A Zig 3D game engine.
Introduction
Didot is a multi-threaded 3D game engine programmed in Zig and aimed at high-level constructs: you manipulate game objects and meshes instead of OpenGL calls and batches.
It improves developers life by splitting the engine into multiple modules in order to have easier porting to other platforms. For example, you can change the windowing module from <code>didot-glfw</code> to <code>didot-x11</code> to use Xlib instead of depending on GLFW without any change to your game's code, as porting (except for shaders) is transparent to the developer's code.
Installation
Prerequisites:
- Zig compiler (<code>master</code> branch, didot is currently tested with commit <code>0aef1fa</code>)
You only need to launch your terminal and execute those commands in an empty directory:
<code>sh
git clone https://github.com/zenith391/didot
zig init-exe</code>
And then, change the resulting <code>build.zig</code> file looks like this:
```zig
const didot = @import("didot/build.zig");
const Builder = @import("std").build.Builder;
pub fn build(b: *Builder) void {
// ...
exe.setBuildMode(mode);
try didot.addEngineToExe(exe, .{
.prefix = "didot/"
});
exe.install();
// ...
}
```
Using Didot
Showing a cube:
```zig
const std = @import("std");
const zlm = @import("zlm");
usingnamespace @import("didot-graphics");
usingnamespace @import("didot-objects");
usingnamespace @import("didot-app");
const Vec3 = zlm.Vec3;
const Allocator = std.mem.Allocator;
fn init(allocator: <em>Allocator, app: </em>Application) !void {
var shader = try ShaderProgram.create(@embedFile("vert.glsl"), @embedFile("frag.glsl"));
<code>var camera = try GameObject.createObject(allocator, null);
camera.getComponent(Transform).?.* = .{
.position = Vec3.new(1.5, 1.5, -0.5),
.rotation = Vec3.new(-120.0, -15.0, 0).toRadians()
};
try camera.addComponent(Camera { .shader = shader });
try app.scene.add(camera);
var cube = try GameObject.createObject(allocator, "Mesh/Cube");
cube.getComponent(Transform).?.position = Vec3.new(-1.2, 0.75, -3);
try app.scene.add(cube);
</code>
}
pub fn main() !void {
var gp = std.heap.GeneralPurposeAllocator(.{}) {};
const allocator = &gp.allocator;
<code>var scene = try Scene.create(allocator, null);
comptime var systems = Systems {};
var app = Application(systems) {
.title = "Test Cube",
.initFn = init
};
try app.run(allocator, scene);
</code>
}
```
And to make that into a textured cube, only a few lines are necessary:
<code>zig
try scene.assetManager.put("Texture/Grass", try TextureAsset.init2D(allocator, "assets/textures/grass.png", "png"));
var material = Material { .texturePath = "Texture/Grass" };
cube.material = material;</code>
First line loads <code>assets/textures/grass.png</code> to <code>Texture/Grass</code>.
Second line creates a Material with the <code>Texture/Grass</code> texture.
Third line links the cube to the newly created Material.
You can also look at the <a>example</a> to see how to make camera movement or load models from OBJ files or even load scenes from JSON files.
Systems (currently):
```zig
fn exampleSystem(query: Query(.{*Transform})) !void {
var iterator = query.iterator();
while (iterator.next()) |o| {
std.log.info("Someone's at position {} !", .{o.transform.position});
}
}
pub fn main() !void {
// ...
comptime var systems = Systems {};
systems.addSystem(exampleSystem);
var app = Application(systems) {
.title = "Test Cube",
.initFn = init
};
try app.run(allocator, scene);
}
```
<a>API reference</a>
Features
<ul>
<li><a>Scene editor</a></li>
<li>Assets manager</li>
<li>OpenGL backend</li>
<li>Shaders</li>
<li>Meshes</li>
<li>Materials</li>
<li>Textures</li>
<li>Windowing</li>
<li>GLFW backend</li>
<li>X11 backend</li>
<li>Model loader</li>
<li>OBJ files</li>
<li>Image loader</li>
<li>BMP files</li>
<li>PNG files</li>
<li>Application system for easier use</li>
<li>Game objects system</li>
</ul> | []
|
https://avatars.githubusercontent.com/u/29983540?v=4 | hzzp | truemedian/hzzp | 2020-06-14T17:12:00Z | null | master | 0 | 87 | 10 | 87 | https://api.github.com/repos/truemedian/hzzp/tags | MIT | [
"http",
"zig"
]
| 14,333 | false | 2025-04-15T22:05:17Z | true | false | unknown | github | []
| hzzp
<a></a>
<a></a>
<a></a>
A I/O agnostic HTTP/1.1 parser and encoder for Zig.
Features
<ul>
<li>Performs no allocations during parsing or encoding, uses a single buffer for all parsing.</li>
<li>Relatively simple to use.</li>
<li>Works with any Reader and Writer.</li>
</ul>
Notes
<ul>
<li>hzzp does <strong>not</strong> buffer either reads or writes, if you prefer the performance boost such buffering provides, you must
provide your own buffered Reader and Writers.</li>
</ul>
Examples
<strong>Coming Soon...</strong> | []
|
https://avatars.githubusercontent.com/u/124872?v=4 | zig-charm | jedisct1/zig-charm | 2020-10-27T17:32:21Z | A Zig version of the Charm crypto library. | main | 0 | 85 | 6 | 85 | https://api.github.com/repos/jedisct1/zig-charm/tags | MIT | [
"charm",
"crypto",
"cryptography",
"lightweight",
"xoodoo",
"zig",
"zig-package",
"ziglang"
]
| 22 | false | 2025-05-12T18:44:59Z | true | true | 0.14.0 | github | []
| charm
A tiny, self-contained cryptography library, implementing authenticated encryption and keyed hashing.
Charm was especially designed for memory-constrained devices, but can also be used to add encryption support to WebAssembly modules with minimal overhead.
Any number of hashing and authenticated encryption operations can be freely chained using a single rolling state.
In this mode, each authentication tag authenticates the whole transcript since the beginning of the session.
The <a>original implementation</a> was written in C and is used by the <a>dsvpn</a> VPN software.
This is a port to the <a>Zig</a> language. It is fully compatible with the C version.
Usage
Setting up a session
Charm requires a 256-bit key, and, if the key is reused for different sessions, a unique session identifier (<code>nonce</code>):
```zig
var key: [Charm.key_length]u8 = undefined;
std.crypto.random.bytes(&key);
var charm = Charm.new(key, null);
```
Hashing
<code>zig
const h = charm.hash("data");</code>
Authenticated encryption
Encryption
<code>zig
const tag = charm.encrypt(msg[0..]);</code>
Encrypts <code>msg</code> in-place and returns a 128-bit authentication tag.
Decryption
Starting from the same state as the one used for encryption:
<code>zig
try charm.decrypt(msg[0..], tag);</code>
Returns <code>error.AuthenticationFailed</code> if the authentication tag is invalid for the given message and the previous transcript.
Security guarantees
128-bit security, no practical limits on the size and length of messages.
Other implementations:
<ul>
<li><a>charm</a> original implementation in C.</li>
<li><a>charm.js</a> a JavaScript (TypeScript) implementation.</li>
<li><a>go-charm</a> a Go implementation.</li>
</ul> | []
|
https://avatars.githubusercontent.com/u/65570835?v=4 | ansi_term | ziglibs/ansi_term | 2020-07-27T21:04:27Z | Zig library for dealing with ANSI terminals | master | 4 | 84 | 8 | 84 | https://api.github.com/repos/ziglibs/ansi_term/tags | MIT | [
"ansi-terminal",
"zig",
"zig-package",
"ziglang"
]
| 65 | false | 2025-05-21T04:09:14Z | true | true | 0.14.0 | github | []
| ansi_term
Zig library for dealing with ANSI Terminals (escape codes, styles, etc.)
<blockquote>
<span class="bg-green-100 text-green-800 text-xs font-medium me-2 px-2.5 py-0.5 rounded dark:bg-green-900 dark:text-green-300">IMPORTANT</span>
This library was renamed from <code>ansi-term</code>, now using an underscore
</blockquote>
This was originally code which was extracted from
<a>lscolors</a> for use in
other zig libraries. More features have been added since.
<code>ansi_term</code> is designed to work with Zig 0.14.0.
Documentation
Automatically generated documentation for the project
can be found at https://ziglibs.github.io/ansi_term/.
Note that autodoc is currently in beta; the website may be broken or incomplete. | [
"https://github.com/joachimschmidt557/zig-termbox",
"https://github.com/neurocyte/zat",
"https://github.com/ziglibs/lscolors"
]
|
https://avatars.githubusercontent.com/u/84904715?v=4 | wasmtime-zig | zigwasm/wasmtime-zig | 2020-05-14T17:44:48Z | Zig embedding of Wasmtime | main | 4 | 84 | 9 | 84 | https://api.github.com/repos/zigwasm/wasmtime-zig/tags | Apache-2.0 | [
"wasi",
"wasm",
"wasmtime",
"zig",
"zig-library"
]
| 65 | false | 2025-05-02T07:01:22Z | true | false | unknown | github | []
| wasmtime-zig
<a></a>
<a></a>
Zig embedding of <a>Wasmtime</a>
Disclaimer
This is a very much work-in-progress library so drastic changes to the API are anything
but expected, and things might just not work as expected yet.
Building
To build this library, you will need Zig nightly 0.8.0, as well as [<code>gyro</code>] package manager.
This library consumes the C API of the Wasmtime project which you can download with every release of
Wasmtime. It relies on version <code>v0.24.0</code> of Wasmtime and you need it to build tests and examples.
You can download the library from <a>here</a>.
After you unpack it, if you installed the lib in path that is not your system search path for lld,
you can add the installed path to the build command using the following flag
<code>gyro build --search-prefix=<path-to-libwasmtime></code>
Running examples
<code>simple.zig</code>
The <code>simple.zig</code> example is equivalent to [<code>hello.c</code>] example in Wasmtime. You can run it with
<code>gyro build run -Dexample=simple</code>
Optionally, if you installed <code>libwasmtime</code> into some custom path, you can tell zig where to find it
with
<code>gyro build run -Dexample=simple --search-prefix=<path-to-libwasmtime></code> | []
|
https://avatars.githubusercontent.com/u/8798829?v=4 | zig-header-gen | suirad/zig-header-gen | 2020-07-09T23:31:09Z | Automatically generate headers/bindings for other languages from Zig code | master | 4 | 80 | 12 | 80 | https://api.github.com/repos/suirad/zig-header-gen/tags | MIT | [
"binding-generator",
"build",
"c",
"comptime",
"cpp",
"golang",
"header-generator",
"nim",
"python",
"rust",
"zig",
"zig-library"
]
| 80 | false | 2025-03-31T15:34:08Z | true | false | unknown | github | []
| HeaderGen
<code>HeaderGen</code> automatically generates headers/bindings for other languages given
Zig code with exported functions/types
Here are the following supported language binding outputs:
<br/><input type='checkbox' class='w-4 h-4 text-green-500 bg-gray-100 border-gray-300 rounded focus:ring-blue-500 dark:focus:ring-blue-600 dark:ring-offset-gray-800 focus:ring-2 dark:bg-gray-700 dark:border-gray-600' checked disabled></input> C Bindings
<br/><input type='checkbox' class='w-4 h-4 text-green-500 bg-gray-100 border-gray-300 rounded focus:ring-blue-500 dark:focus:ring-blue-600 dark:ring-offset-gray-800 focus:ring-2 dark:bg-gray-700 dark:border-gray-600' checked disabled></input> Python Bindings
<br/><input type='checkbox' class='w-4 h-4 text-blue-600 bg-gray-100 border-gray-300 rounded focus:ring-blue-500 dark:focus:ring-blue-600 dark:ring-offset-gray-800 focus:ring-2 dark:bg-gray-700 dark:border-gray-600' disabled></input> Rust Bindings
<br/><input type='checkbox' class='w-4 h-4 text-blue-600 bg-gray-100 border-gray-300 rounded focus:ring-blue-500 dark:focus:ring-blue-600 dark:ring-offset-gray-800 focus:ring-2 dark:bg-gray-700 dark:border-gray-600' disabled></input> Go Bindings
<br/><input type='checkbox' class='w-4 h-4 text-blue-600 bg-gray-100 border-gray-300 rounded focus:ring-blue-500 dark:focus:ring-blue-600 dark:ring-offset-gray-800 focus:ring-2 dark:bg-gray-700 dark:border-gray-600' disabled></input> Nim Bindings
Here are the following supported Zig language features:
<br/><input type='checkbox' class='w-4 h-4 text-green-500 bg-gray-100 border-gray-300 rounded focus:ring-blue-500 dark:focus:ring-blue-600 dark:ring-offset-gray-800 focus:ring-2 dark:bg-gray-700 dark:border-gray-600' checked disabled></input> Extern Functions
<br/><input type='checkbox' class='w-4 h-4 text-green-500 bg-gray-100 border-gray-300 rounded focus:ring-blue-500 dark:focus:ring-blue-600 dark:ring-offset-gray-800 focus:ring-2 dark:bg-gray-700 dark:border-gray-600' checked disabled></input> Extern Structs
<br/><input type='checkbox' class='w-4 h-4 text-green-500 bg-gray-100 border-gray-300 rounded focus:ring-blue-500 dark:focus:ring-blue-600 dark:ring-offset-gray-800 focus:ring-2 dark:bg-gray-700 dark:border-gray-600' checked disabled></input> Extern Unions
<br/><input type='checkbox' class='w-4 h-4 text-green-500 bg-gray-100 border-gray-300 rounded focus:ring-blue-500 dark:focus:ring-blue-600 dark:ring-offset-gray-800 focus:ring-2 dark:bg-gray-700 dark:border-gray-600' checked disabled></input> Extern Enums
Getting started
Given the following Zig code as the file <code>src/fancylib.zig</code> and using the C generator:
```zig
const std = @import("std");
export fn print_msg(msg_ptr: ?[*]const u8, len: usize) bool {
if (msg_ptr) |raw_msg| {
const msg = raw_msg[0 .. len - 1];
std.debug.print("Msg is: {}", .{msg});
return true;
}
return false;
}
const Internal = struct {
a: u64,
};
const External = extern struct {
b: u64,
c: [100]u8,
};
export fn use_internal_and_external(i: ?<em>Internal, e: ?</em>External) void {
// do things...
}
```
You will receive the following C header in <code>headers/fancylib.h</code>:
```c
ifndef _fancylib_H
define _fancylib_H
include
include
include
typedef struct External {
uint64_t b;
uint8_t c[100];
} External_t;
bool print_msg(uint8_t* arg0, size_t arg1);
void use_internal_and_external(void<em> arg0, External_t</em> arg1);
endif
```
Usage Notes
<ul>
<li>Copy from this repo <code>header_gen.zig</code> and the folder <code>generators</code>;
drop them next to your <code>build.zig</code></li>
<li>See the <code>build.zig</code> in this repo for an example of integration</li>
</ul> | []
|
https://avatars.githubusercontent.com/u/80392719?v=4 | serial | ZigEmbeddedGroup/serial | 2020-04-19T18:45:34Z | Serial port configuration library for Zig | master | 6 | 77 | 22 | 77 | https://api.github.com/repos/ZigEmbeddedGroup/serial/tags | MIT | [
"serial",
"serial-port",
"uart",
"zig",
"zig-package",
"ziglang"
]
| 81 | false | 2025-04-26T07:06:44Z | true | true | 0.14.0 | github | []
| Zig Serial Port Library
Library for configuring and listing serial ports.
Features
<ul>
<li>Basic serial port configuration</li>
<li>Baud Rate</li>
<li>Parity (none, even, odd, mark, space)</li>
<li>Stop Bits (one, two)</li>
<li>Handshake (none, hardware, software)</li>
<li>Byte Size (5, 6, 7, 8)</li>
<li>Flush serial port send/receive buffers</li>
<li>List available serial ports</li>
<li>API: supports Windows, Linux and Mac</li>
</ul>
Example
```zig
// Port configuration.
// Serial ports are just files, \.\COM1 for COM1 on Windows:
var serial = try std.fs.cwd().openFile("\\.\COM1", .{ .mode = .read_write }) ;
defer serial.close();
try zig_serial.configureSerialPort(serial, zig_serial.SerialConfig{
.baud_rate = 19200,
.word_size = 8,
.parity = .none,
.stop_bits = .one,
.handshake = .none,
});
```
Usage
Library integration
Integrate the library in your project via the Zig package manager:
<ul>
<li>add <code>serial</code> to your <code>.zig.zon</code> file by providing the URL to the archive of a tag or specific commit of the library</li>
<li>to update the hash, run <code>zig fetch --save [URL/to/tag/or/commit.tar.gz]</code></li>
</ul>
Running tests
The <code>build.zig</code> file contains a test step that can be called with <code>zig build test</code>. Note that this requires a serial port to be available on the system;
<ul>
<li>Linux: <code>/dev/ttyUSB0</code></li>
<li>Mac: <code>/dev/cu.usbmodem101</code></li>
<li>Windows: <code>COM3</code></li>
</ul>
Building the examples
You can build the examples from the <code>./examples</code> directory by calling <code>zig build examples</code>. Binaries will be generated in <code>./zig-out/bin</code> by default.
<ul>
<li>Note that the <code>list_port_info</code> example currently only works on Windows</li>
</ul>
Building the documentation
You can generate the documentation by running <code>zig build docs</code>.
After that you can browse it by:
<ol>
<li>starting the web server. For example, by running <code>python -m http.server 8000 zig-out/docs</code></li>
<li>reading the docs from your browser at <code>http://127.0.0.1:8000</code></li>
</ol> | [
"https://github.com/Harry-Heath/micro",
"https://github.com/Strum355/wdnas-exporter",
"https://github.com/ringtailsoftware/commy"
]
|
https://avatars.githubusercontent.com/u/13735?v=4 | libopaque | stef/libopaque | 2020-11-15T19:29:07Z | c implementation of the OPAQUE protocol with bindings for python, php, ruby, lua, zig, java, erlang, golang, js and SASL. also supports a threshold variants based on 2hashdh and 3hashtdh | master | 4 | 76 | 11 | 76 | https://api.github.com/repos/stef/libopaque/tags | LGPL-3.0 | [
"ake",
"authenticated-key-exchange",
"erlang",
"go",
"golang",
"ietf-cfrg",
"java",
"javascript",
"js",
"libsodium",
"lua",
"opaque",
"password",
"password-ake",
"php",
"python",
"ruby",
"sasl",
"sasl-mech",
"zig"
]
| 4,585 | false | 2025-04-19T06:35:12Z | false | false | unknown | github | []
| libopaque
This library implements the OPAQUE protocol as proposed in the IRTF
CFRG draft at https://github.com/cfrg/draft-irtf-cfrg-opaque.
It comes with bindings for js, php7, ruby, java, erlang, lua, python, go and
SASL. There are also a 3rd party bindings for:
- <a>dart</a>
- rust <a>libopaque-sys</a> + <a>opaqueoxide</a>
Some more information about OPAQUE can be found in a series of blogposts:
<ul>
<li><a>OPAQUE</a></li>
<li><a>Why and how to use OPAQUE for user authentication</a></li>
<li><a>opaque demo</a></li>
</ul>
There is a <a>live demo</a> between a
python/flask backend and a js/html frontend.
Dependencies
libopaque depends on libsodium<a>1</a> and on liboprf<a>2</a>
Both must be installed to use libopaque.
The OPAQUE Protocol
The OPAQUE protocol is an asymmetric password-authenticated
key-exchange. Essentially it allows a client to establish a shared
secret with a server based on only having a password. The client
doesn't need to store any state. The protocol has two phases:
<ul>
<li>In the initialization phase a client registers with the server.</li>
<li>In the AKE phase the client and server establish a shared secret.</li>
</ul>
The initialization only needs to be executed once, the key-exchange
can be executed as many times as necessary.
The following sections provide an abstract overview of the various
steps and their inputs and outputs, this is to provide an
understanding of the protocol. The various language bindings have -
language-specific - slightly different APIs in the way the
input/output parameters are provided to the functions, see details in
the READMEs of the bindings sub-directories.
Initialization
The original paper and the IRTF CFRG draft differ, in the original
paper a one-step registration is specified which allows the server
during initialization to inspect the password of the client in
cleartext. This allows the server to enforce password sanity rules
(e.g. not being listed in hacked user databases), however this also
implies that the client has to trust the server with this
password. The IRTF CFRG draft doesn't specify this registration,
instead it specifies a four-step protocol which results in exactly the
same result being stored on the server, without the client ever
exposing the password to the server.
One-step registration revealing password to server
Before calling the registration function the server should check the
strength of the password by obeying <a>NIST SP 800-63-3b</a>) and if insufficient reject the registration.
The registration function takes the following parameters:
<ul>
<li>the client password</li>
<li>the optional long-term server private key skS</li>
<li>the IDs</li>
</ul>
The result of the registration is a record that the server should
store to be provided to the client in the key-exchange
phase. Additionally an <code>export_key</code> is also generated which can be used
to encrypt additional data that can be decrypted by the client in the
key-exchange phase. Where and how this additional <code>export_key</code> encrypted
data is stored and how it is retrieved by the client is out of scope
of the protocol, for example this could be used to store additional
keys, personal data, or other sensitive client state.
Password Privacy Preserving registration
This registration is a four step protocol which results in exactly the
same outcome as the one-step variant, without the server learning the
client password. It is recommended to have the client do a password
strength according to NIST SP 800-63-3b check before engaging in the
following protocol.
The following steps are executed, starting with the client:
<ol>
<li>client: sec, req = CreateRegistrationRequest(pwd)</li>
</ol>
The outputs in the first step are
<ul>
<li>a sensitive client context <code>sec</code> that is needed in step 3, this should
be kept secret as it also contains the plaintext password.</li>
<li>
and request <code>req</code> that should be sent to the server, this request
does not need to be encrypted (it is already).
</li>
<li>
server: ssec, resp = CreateRegistrationResponse(req, skS)
</li>
</ul>
In the second step the server takes the request and an optional
long-term server private key skS. In case no skS is supplied a
user-specific long-term server keypair is generated. The output of this step is:
<ul>
<li>a sensitive server context <code>ssec</code>, which must be kept secret and secure
until step 4 of this registration protocol.</li>
<li>
a response, which needs to be sent back to the client, this
response does not need to be encrypted (it is already).
</li>
<li>
client: recU, export_key = FinalizeRequest(sec, resp, ids)
</li>
</ul>
In the third step the client takes its context from step 1, the
servers response from step 2, and the IDs of the server and client to
assemble a record stub <code>recU</code> and an <code>export_key</code>. In case the client
wishes to (and the server supports it) to encrypt and store additional
data at the server, it uses the <code>export_key</code> to encrypt it and sends
it over to the server together with the record stub. The record stub
might or might not be needed to be encrypted, depending on the OPAQUE
envelope configuration.
<ol>
<li>server: rec = StoreUserRecord(ssec, recU, rec)</li>
</ol>
In the last - fourth - step of the registration protocol, the server
receives the record stub <code>recU</code> from the client step 3, it's own
sensitive context <code>ssec</code> from step 2. These parameters are used to
complete the record stub into a full record <code>rec</code>, which then the
server must store for later retrieval.
The key-exchange
The key-exchange is a three-step protocol with an optional fourth step
for explicit client authentication:
<ol>
<li>client: sec, req = CreateCredentialRequest(pwd)</li>
</ol>
The client initiates a key-exchange taking the password as input and
outputting a sensitive client context <code>sec</code> which should be kept
secret until step 3 of this protocol. This step also produces a
request <code>req</code> - which doesn't need to be encrypted (it is already) -
to be passed to the server executing step 2:
<ol>
<li>server: resp, sk, ssec = CreateCredentialResponse(req, rec, ids, context)</li>
</ol>
The server receives a request from the client, retrieves record
belonging to the client, the IDs of itself and the client, and
a context string. Based on these inputs the server produces:
<ul>
<li>a response <code>resp</code> which needs to be sent to client,</li>
<li>its own copy of the shared key produced by the key-exchange, and</li>
<li>
a sensitive context <code>ssec</code> which it needs to protect until the optional step 4.
</li>
<li>
client: sk, authU, export_key, ids = RecoverCredentials(resp, sec, context, ids)
</li>
</ul>
The client receives the servers response <code>resp</code>, and
- takes its own sensitive context <code>sec</code> from step 1.,
- in case the envelope configuration has set the servers public key
set to not-packaged the servers public key,
- a context string,
- the ids of the server and client.
Processing all these inputs results in:
- the shared secret key produced by the key exchange, which must be
the same as what the server has,
- an authentication token <code>authU</code> which can be sent to the server in
case the optional fourth step of the protocol is needed to
explicitly authenticate the client to the server.
- and finally the client also computes the <code>export_key</code> which was
used to encrypt additional data during the registration phase.
<ol>
<li>optionally server: UserAuth(ssec, authU)</li>
</ol>
This step is not needed in case the shared key is used for example to
set up an encrypted channel between the server and client. Otherwise
the <code>authU</code> token is sent to the server, which using its previously
stored sensitive context <code>ssec</code> verifies that the client has indeed
computed the same shared secret as a result of the key-exchange and
thus explicitly authenticating the client.
Installing
Install <code>libsodium-dev</code> and <code>pkgconf</code> using your operating system's package
manager.
Building everything should (hopefully) be quite simple afterwards:
<code>git submodule update --init --recursive --remote
cd src
make</code>
OPAQUE API
The API is described in the header file:
<a><code>src/opaque.h</code></a>.
The library implements the OPAQUE protocol with the following deviations from
the original paper:
<ol>
<li>It does not implement any persistence/lookup functionality.</li>
<li>Instead of HMQV (which is patented), it implements a Triple-DH.</li>
<li>It implements "user iterated hashing" from page 29 of the paper.</li>
<li>It additionally implements a variant where U secrets never hit S
unprotected.</li>
</ol>
For more information, see the
<a>IRTF CFRG specification</a>,
the <a>original paper</a>
and the
<a><code>src/tests/opaque-test.c</code></a>
example file.
OPAQUE Parameters
Currently all parameters are hardcoded, but there is nothing stopping you from
setting stronger values for the password hash.
The Curve
This OPAQUE implementation is based on libsodium's ristretto25519 curve. This
means currently all keys are 32 bytes long.
Other Crypto Building Blocks
This OPAQUE implementation relies on libsodium as a dependency to provide all
other cryptographic primitives:
<ul>
<li><code>crypto_pwhash</code><a>3</a> uses the Argon2 function with
<code>crypto_pwhash_OPSLIMIT_INTERACTIVE</code> and
<code>crypto_pwhash_MEMLIMIT_INTERACTIVE</code> as security parameters.</li>
<li><code>randombytes</code> attempts to use the cryptographic random source of
the underlying operating system<a>4</a>.</li>
</ul>
Debugging
To aid in debugging and testing, there are two macros available:
| Macro | Description |
| ---------- | ------------------------------------------------- |
| <code>TRACE</code> | outputs extra information to stderr for debugging |
| <code>NORANDOM</code> | removes randomness for deterministic results |
To use these macros, specify the <code>DEFINES</code> Makefile variable when calling
<code>make</code>:
<code>$ make DEFINES='-DTRACE -DNORANDOM' clean libopaque.so tests
$ LD_LIBRARY_PATH=. ./tests/opaque-test</code>
As a shortcut, calling <code>make debug</code> also sets these variables. This code block
is equivalent to the one above:
<code>$ make clean debug
$ LD_LIBRARY_PATH=. ./tests/opaque-test</code>
Credits
This project was funded through the NGI0 PET Fund, a fund established
by NLnet with financial support from the European Commission's Next
Generation Internet programme, under the aegis of DG Communications
Networks, Content and Technology under grant agreement No 825310. | []
|
https://avatars.githubusercontent.com/u/475017?v=4 | dos.zig | jayschwa/dos.zig | 2020-09-07T23:42:05Z | Create DOS programs with Zig | main | 0 | 76 | 4 | 76 | https://api.github.com/repos/jayschwa/dos.zig/tags | MIT | [
"dos",
"retrocomputing",
"zig"
]
| 77 | false | 2025-02-04T03:19:17Z | true | false | unknown | github | []
| <strong>Note</strong>: <a>Zig 0.12.0 removed "bring your own OS" support</a>
from the standard library. This project will remain paused on Zig 0.11.0 until
a newer Zig release reintroduces BYOS support.
DOS SDK for Zig
Write and cross-compile <a>DOS</a> programs with the
<a>Zig programming language</a>. Programs run in 32-bit
<a>protected mode</a> and require a
resident <a>DPMI host</a>.
<a>CWSDPMI</a> is bundled with the executable
for environments that do not have DPMI available.
To comply with the <a>CWSDPMI license</a>,
published programs must provide notice to users that they have the right to
receive the source code and/or binary updates for CWSDPMI. Distributors should
indicate a site for the source in their documentation.
This package is in a primordial state. It is a minimal demonstration of how to
create a simple DOS program with Zig. Only basic file/terminal input/output are
working, and does not include proper error handling. It will require hacking if
you wish to adapt it for your own needs.
Quick Start
Install:
<ul>
<li><a>Zig</a> (version 0.11.0)</li>
<li><a>DOSBox</a></li>
</ul>
Setup submodules:
<ul>
<li>Run the command <code>git submodule init && git submodule update</code></li>
</ul>
Add DOSBox to the path:
<ul>
<li>Mac: Add <code>export PATH="$PATH:/applications/dosbox.app/contents/macos/"</code> to your <code>~/.zshrc</code>.</li>
<li>Windows: https://stackoverflow.com/questions/9546324/adding-a-directory-to-the-path-environment-variable-in-windows</li>
</ul>
Run:
<code>sh
zig build run</code>
Design
There are five main components of this package:
<ul>
<li><a>DOS API</a> wrappers call the 16-bit
real mode interrupt 21 routines (via DPMI) and implement operating system
interfaces for the Zig standard library.</li>
<li><a>DPMI API</a> wrappers manage extended
memory blocks and segments.</li>
<li>A custom <a>linker script</a>
produces <a>DJGPP COFF</a> executables.</li>
<li>The <a>CWSDPMI</a> stub loader enters
protected mode and runs the COFF executable attached to it.</li>
<li>A small demo program exercises all of the above.</li>
</ul>
Roadmap
<ul>
<li>Proper error handling.</li>
<li>Parse environment data (command, variables) and hook into standard library abstractions.</li>
<li>Implement <code>mprotect</code> for stack guard and zero pages.</li>
<li>Implement a <code>page_allocator</code> for the standard library.</li>
<li>Add graphical demo program.</li>
</ul>
Questions and Answers
Can I just target 16-bit real mode rather than require DPMI?
It is technically possible, but not a goal of this package. Zig (via LLVM) can
generate "16-bit" code using the <code>code16</code> ABI target. In reality, this code is
often 32-bit instructions with added prefixes that override the address or
operand size. Using <code>code16</code> actually produces <em>larger</em> binaries. Additionally,
the oldest CPU that can be targeted is an Intel 80386, which supports 32-bit
protected mode. It's guaranteed to be there and has a lot of advantages, so we
might as well use it.
Why not integrate with an existing DOS toolchain like DJGPP?
This was attempted and had mixed results. DJGPP's object format (COFF) is
subtly different from the one produced by modern toolchains such as Zig. Crude
conversion scripts had to be used to get them to work together and it was not
robust. While it would be nice to leverage DJGPP's C library, it ultimately
felt like more trouble than it was worth. Not relying on a separate toolchain
will make things easier in the long run. | []
|
https://avatars.githubusercontent.com/u/3759175?v=4 | ziter | Hejsil/ziter | 2020-11-04T18:10:36Z | The missing iterators for Zig | master | 1 | 76 | 2 | 76 | https://api.github.com/repos/Hejsil/ziter/tags | MIT | [
"functional",
"iterator",
"iterator-library",
"iterators",
"zig",
"zig-library",
"zig-package"
]
| 133 | false | 2025-05-08T07:11:00Z | true | true | 0.14.0 | github | []
| ziter
An iterator library for zig inspired by the iterators in the Rust standard libary.
```zig
const iter = @import("ziter");
const std = @import("std");
test "ascii" {
const ascii_digits = iter.range(u8, 0, 255)
.filter({}, iter.void_ctx(std.ascii.isDigit));
<code>const ascii_alpha = try iter.range(u8, 0, 255)
.filter({}, iter.void_ctx(std.ascii.isAlphabetic))
.collect_no_allocator(std.BoundedArray(u8, 255){});
try iter.expectEqual(iter.deref("0123456789"), ascii_digits);
try std.testing.expectEqualStrings(
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz",
ascii_alpha.slice(),
);
</code>
}
test "Fibonacci" {
const fib = Fibonacci{};
<code>const fib_sum_first_5 = fib.take(5).sum(usize);
const fib_first_alphabetic = fib.map({}, to_u8)
.find({}, iter.void_ctx(std.ascii.isAlphabetic));
try std.testing.expectEqual(@as(usize, 7), fib_sum_first_5);
try std.testing.expectEqual(@as(?u8, 'Y'), fib_first_alphabetic);
</code>
}
pub const Fibonacci = struct {
c: usize = 0,
n: usize = 1,
<code>pub fn next(it: *@This()) ?usize {
const curr = it.c;
it.c = it.n;
it.n = curr + it.n;
return curr;
}
pub usingnamespace iter;
</code>
};
fn to_u8(_: void, item: usize) u8 {
return @truncate(item);
}
``` | []
|
https://avatars.githubusercontent.com/u/124872?v=4 | zig-minisign | jedisct1/zig-minisign | 2020-12-05T21:33:09Z | Minisign reimplemented in Zig. | main | 2 | 70 | 7 | 70 | https://api.github.com/repos/jedisct1/zig-minisign/tags | NOASSERTION | [
"crypto",
"minisign",
"signatures",
"zig",
"zig-package"
]
| 115 | false | 2025-05-12T19:38:29Z | true | true | 0.14.0 | github | []
| zig-minisign
A Zig implementation of <a>Minisign</a>.
<code>minizign</code> was primarily designed to verify signatures, although signing is likely to be implemented next.
Compilation
Requires the current <code>master</code> version of <a>Zig</a>.
Compile with:
<code>sh
zig build -Doptimize=ReleaseSmall</code>
for a size-optimized version, or
<code>sh
zig build -Doptimize=ReleaseFast</code>
for a speed-optimized version.
Usage
<code>text
Usage:
-h, --help Display this help and exit
-p, --publickey-path <PATH> Public key path to a file
-P, --publickey <STRING> Public key, as a BASE64-encoded string
-l, --legacy Accept legacy signatures
-m, --input <PATH> Input file
-q, --quiet Quiet mode
-V, --verify Verify
-C, --convert Convert the given public key to SSH format</code>
Example
Verify <code>public-resolvers.md</code> using <code>public-resolvers.md.minisig</code> and the public key file <code>minisig.pub</code>:
<code>sh
minizign -p minisign.pub -Vm public-resolvers.md</code>
Verify <code>public-resolvers.md</code> by directly providing the public key on the command-line:
<code>sh
minizign -P RWQf6LRCGA9i53mlYecO4IzT51TGPpvWucNSCh1CBM0QTaLn73Y7GFO3 -Vm public-resolvers.md</code>
SSH-encoded public keys
<code>minizign</code> can encode public keys in SSH format, so that they can be uploaded to GitHub:
<code>sh
minizign -p minisign.pub -C</code>
<code>text
ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIHmlYecO4IzT51TGPpvWucNSCh1CBM0QTaLn73Y7GFO3 minisign key E7620F1842B4E81F</code>
GitHub makes public SSH keys available at <code>https://github.com/<username>.keys</code>.
SSH-encoded keys can be loaded by <code>minizign</code> the same way as native keys, with <code>-p <key file></code>. They will be automatically recognized as such.
Features
<code>minizign</code> supports prehashing (which can be forced if you know this is how the signature was created), has zero dependencies and can be cross-compiled to anything that Zig can cross-compile to, including WebAssembly. | []
|
https://avatars.githubusercontent.com/u/27973237?v=4 | shell-completions | ziglang/shell-completions | 2020-12-29T21:47:29Z | Shell completions for the Zig compiler. | master | 6 | 67 | 19 | 67 | https://api.github.com/repos/ziglang/shell-completions/tags | MIT | [
"completion",
"shell",
"zig",
"zsh"
]
| 33 | false | 2025-05-09T03:04:07Z | false | false | unknown | github | []
| shell-completions
Shell completions for the <a>Zig compiler</a>.
Installation for zsh
The <code>_zig</code> file needs to be included in your <code>$fpath</code>. This can be achieved in two ways:
1. Move the <code>_zig</code> file to one of the folders listed in <code>$fpath</code>. You can list these folders with <code>print -l $fpath</code>.
2. Add the folder containing <code>_zig</code> to the <code>$fpath</code>. This can be achieved by adding <code>fpath=(/path/to/this/repo/shell-completions $fpath)</code> to your <code>~/.zshrc</code> file (to update the current terminal run <code>source ~/.zshrc</code>).
Once the <code>$fpath</code> variable is updated, run <code>compinit</code> to rebuild <code>~/.zcompdump</code>.
Installation for Oh My Zsh
<ol>
<li>Clone the plugin as <code>zig-shell-completions</code></li>
</ol>
<code>sh
git clone https://github.com/ziglang/shell-completions $ZSH/custom/plugins/zig-shell-completions</code>
<ol>
<li>Add the plugin <code>zig-shell-completions</code> to <code>$plugin</code></li>
</ol>
<code>sh
plugins+=(zig-shell-completions)</code>
Installation for bash
<code>sh
curl -LO "https://raw.githubusercontent.com/ziglang/shell-completions/master/_zig.bash"
echo ". $PWD/_zig.bash" >> ~/.bashrc</code> | []
|
https://avatars.githubusercontent.com/u/37966791?v=4 | zfltk | MoAlyousef/zfltk | 2021-01-19T16:04:08Z | Zig bindings for the FLTK gui library | main | 5 | 66 | 8 | 66 | https://api.github.com/repos/MoAlyousef/zfltk/tags | MIT | [
"fltk",
"gui",
"zig",
"zig-package"
]
| 9,454 | false | 2025-05-19T08:21:33Z | true | true | unknown | github | []
| zfltk
A Zig wrapper for the FLTK gui library.
Running the examples
<code>git clone https://github.com/MoAlyousef/zfltk --recurse-submodules
cd zfltk
zig build run-simple
zig build run-capi
zig build run-editor
zig build run-input
zig build run-image
zig build run-mixed</code>
Usage
Until an official Zig package manager is published, the easiest way to use the library is to add it as a subdirectory to your project, either via git submodules or git clone:
<code>git submodule add https://github.com/moalyousef/zfltk
cd zfltk
git checkout pre_zpm
cd ..
git submodule update --init --recursive</code>
then you will need a build.zig file as follows:
```zig
const std = @import("std");
const Sdk = @import("zfltk/sdk.zig");
const Builder = std.build.Builder;
pub fn build(b: *Builder) !void {
const target = b.standardTargetOptions(.{});
const mode = b.standardReleaseOptions();
const sdk = Sdk.init(b);
const exe = b.addExecutable("main", "src/main.zig");
exe.addPackagePath("zfltk", "zfltk/src/zfltk.zig");
exe.setTarget(target);
exe.setBuildMode(mode);
try sdk.link("zfltk", exe); // takes the sdk path
exe.install();
<code>const run_cmd = exe.run();
run_cmd.step.dependOn(b.getInstallStep());
if (b.args) |args| {
run_cmd.addArgs(args);
}
const run_step = b.step("run", "Run the app");
run_step.dependOn(&run_cmd.step);
</code>
}
<code>Then you can run:</code>
zig build run
```
Dependencies
This repo tracks cfltk, the C bindings to FLTK. It (along with FLTK) is statically linked to your application.
This requires CMake (and Ninja on Windows) as a build system, and is only required once.
<ul>
<li>Windows: No dependencies.</li>
<li>MacOS: No dependencies.</li>
<li>Linux: X11 and OpenGL development headers need to be installed for development. The libraries themselves are available on linux distros with a graphical user interface.</li>
</ul>
For Debian-based GUI distributions, that means running:
<code>sudo apt-get install libx11-dev libxext-dev libxft-dev libxinerama-dev libxcursor-dev libxrender-dev libxfixes-dev libpango1.0-dev libpng-dev libgl1-mesa-dev libglu1-mesa-dev</code>
For RHEL-based GUI distributions, that means running:
<code>sudo yum groupinstall "X Software Development" && yum install pango-devel libXinerama-devel libpng-devel libstdc++-static</code>
For Arch-based GUI distributions, that means running:
<code>sudo pacman -S libx11 libxext libxft libxinerama libxcursor libxrender libxfixes libpng pango cairo libgl mesa --needed</code>
For Alpine linux:
<code>apk add pango-dev fontconfig-dev libxinerama-dev libxfixes-dev libxcursor-dev libpng-dev mesa-gl</code>
For nixos:
<code>nix-shell --packages rustc cmake git gcc xorg.libXext xorg.libXft xorg.libXinerama xorg.libXcursor xorg.libXrender xorg.libXfixes libcerf pango cairo libGL mesa pkg-config</code>
API
Using the Zig wrapper (under development):
```zig
const zfltk = @import("zfltk");
const app = zfltk.app;
const Window = zfltk.Window;
const Button = zfltk.Button;
const Box = zfltk.Box;
const Color = zfltk.enums.Color;
fn butCb(but: <em>Button(.normal), data: ?</em>anyopaque) void {
var box = Box.fromRaw(data.?);
<code>box.setLabel("Hello World!");
but.setColor(Color.fromName(.cyan));
</code>
}
pub fn main() !void {
try app.init();
app.setScheme(.gtk);
<code>var win = try Window.init(.{
.w = 400,
.h = 300,
.label = "Hello",
});
var but = try Button(.normal).init(.{
.x = 160,
.y = 220,
.w = 80,
.h = 40,
.label = "Click me!",
});
var box = try Box.init(.{
.x = 10,
.y = 10,
.w = 380,
.h = 180,
.boxtype = .up,
});
box.setLabelFont(.courier);
box.setLabelSize(18);
win.group().end();
win.widget().show();
but.setCallbackEx(butCb, box);
try app.run();
</code>
}
<code>The messaging api can also be used:</code>zig
const zfltk = @import("zfltk");
const app = zfltk.app;
const Widget = zfltk.Widget;
const Window = zfltk.Window;
const Button = zfltk.Button;
const Box = zfltk.Box;
const enums = zfltk.enums;
pub const Message = enum(usize) {
// Can't begin with Zero!
first = 1,
second,
};
pub fn main() !void {
try app.init();
app.setScheme(.gtk);
<code>var win = try Window.init(.{
.w = 400,
.h = 300,
.label = "Hello",
});
var but1 = try Button(.normal).init(.{
.x = 100,
.y = 220,
.w = 80,
.h = 40,
.label = "Button 1",
});
var but2 = try Button(.normal).init(.{
.x = 200,
.y = 220,
.w = 80,
.h = 40,
.label = "Button 2",
});
var mybox = try Box.init(.{
.x = 10,
.y = 10,
.w = 380,
.h = 180,
.boxtype = .up,
});
mybox.setLabelFont(.courier);
mybox.setLabelSize(18);
win.group().end();
win.show();
but1.emit(Message, .first);
but2.emit(Message, .second);
while (app.wait()) {
if (app.recv(Message)) |msg| switch (msg) {
.first => mybox.setLabel("Button 1 Clicked!"),
.second => mybox.setLabel("Button 2 Clicked!"),
};
}
</code>
}
```
Using the C Api directly:
```zig
const c = @cImport({
@cInclude("cfl.h"); // Fl_run
@cInclude("cfl_enums.h"); // Fl_Color_*
@cInclude("cfl_button.h"); // Fl_Button
@cInclude("cfl_box.h"); // Fl_Box
@cInclude("cfl_window.h"); // Fl_Window
});
pub fn butCb(w: ?<em>c.Fl_Widget, data: ?</em>anyopaque) callconv(.C) void {
c.Fl_Box_set_label(@ptrCast(?<em>c.Fl_Box, data), "Hello World!");
c.Fl_Button_set_color(@ptrCast(?</em>c.Fl_Button, w), c.Fl_Color_Cyan);
}
pub fn main() void {
c.Fl_set_scheme("gtk+");
var win = c.Fl_Window_new(100, 100, 400, 300, "Hello");
var but = c.Fl_Button_new(160, 220, 80, 40, "Click me!");
var box = c.Fl_Box_new(10, 10, 380, 180, "");
c.Fl_Window_end(win);
c.Fl_Window_show(win);
c.Fl_Button_set_callback(but, butCb, box);
_ = c.Fl_run();
}
```
You can also mix and match for any missing functionalities in the Zig wrapper (see examples/mixed.zig)
| []
|
https://avatars.githubusercontent.com/u/70730202?v=4 | Hidamari | HidamariProject/Hidamari | 2020-09-04T00:53:06Z | Modern operating system aimed at running WebAssembly code. | master | 0 | 64 | 2 | 64 | https://api.github.com/repos/HidamariProject/Hidamari/tags | BSD-3-Clause | [
"kernel",
"operating-system",
"wasm",
"webassembly",
"zig"
]
| 3,348 | false | 2024-07-01T12:21:18Z | true | false | unknown | github | []
| The Hidamari Project
(C) 2020 Ronsor Labs.
Introduction
This is an operating system primarily geared at running WebAssembly code that uses functions conforming to the WASI specifications.
All main components are included in this repository, including the kernel, drivers, and userspace applications.
TODO:
<ol>
<li>Finish implementing WASI APIs.</li>
<li>Clean up all the TODOs in code.</li>
<li>Fix security issues.</li>
<li>Exit UEFI boot services at some point.</li>
<li>GUI</li>
<li>Networking</li>
<li>Audio</li>
<li>Many more things.</li>
</ol>
Building and running.
This is pretty simple. Clone the repo and run <code>zig build</code>. The kernel will be built as <code>output/efi/boot/bootx64.efi</code> and you
can test in QEMU using <code>sh scripts/invoke-qemu.sh</code>. | []
|
https://avatars.githubusercontent.com/u/29983540?v=4 | zfetch | truemedian/zfetch | 2020-12-29T00:33:51Z | null | master | 0 | 60 | 8 | 60 | https://api.github.com/repos/truemedian/zfetch/tags | MIT | [
"http",
"zig"
]
| 100 | false | 2024-10-25T07:03:59Z | true | false | unknown | github | []
| Notice
This package is deprecated and archived for the foreseeable future due to the zig master being an ever changing target
and my lack of time to address and fix things that have changed. Those looking for a similar experience should look
at <a>haze/zelda</a>.
zfetch
<a></a>
<a></a>
<a></a>
A HTTP request library for Zig with HTTPS support.
Features
<ul>
<li>HTTPS support, including trust handling (provided by <a>iguanaTLS</a>)</li>
<li>A relatively simple interface.</li>
</ul>
Notes
<ul>
<li>Passing <code>null</code> as the <code>trust_chain</code> in Request.init will tell zfetch to <strong>not check server certificates</strong>. If you do
not trust your connection, please provide a iguanaTLS x509 certificate chain.</li>
<li>zfetch only does rudimentary checks to ensure functions are called in the right order. These are nowhere near enough
to prevent you from doing so, please call the functions in the order they are intended to be called in.</li>
</ul>
Adding zfetch as a package
Gyro
```zzz
gyro.zzz
...
deps:
truemedian/zfetch: ^0.1.1
...
```
Zigmod
```yaml
zig.mod
...
dependencies:
- type: git
path: https://github.com/truemedian/zfetch
...
```
Submodules
<blockquote>
Assuming zfetch is <strong>recursively</strong> checked out at <code>libs/zfetch</code>
</blockquote>
```zig
// build.zig
const zfetch = @import("libs/zfetch/build.zig");
...
exe.addPackage(zfetch.getPackage(b, "libs/zfetch"));
...
```
Examples
see <a>examples</a>.
<strong>More Coming Soon...?</strong> | []
|
https://avatars.githubusercontent.com/u/8798829?v=4 | adma | suirad/adma | 2020-06-17T04:11:37Z | A general purpose, multithreaded capable slab allocator for Zig | master | 0 | 60 | 1 | 60 | https://api.github.com/repos/suirad/adma/tags | MIT | [
"allocator",
"general-purpose",
"slab-allocator",
"zig",
"zig-lang",
"zig-library"
]
| 21 | false | 2025-04-01T22:21:13Z | true | false | unknown | github | []
| A.D.M.A - Acronyms Dont Mean Anything
Adma is a general purpose allocator for zig with the following features:
<br/><input type='checkbox' class='w-4 h-4 text-green-500 bg-gray-100 border-gray-300 rounded focus:ring-blue-500 dark:focus:ring-blue-600 dark:ring-offset-gray-800 focus:ring-2 dark:bg-gray-700 dark:border-gray-600' checked disabled></input> <a>Slab Allocation strategy</a>
<br/><input type='checkbox' class='w-4 h-4 text-green-500 bg-gray-100 border-gray-300 rounded focus:ring-blue-500 dark:focus:ring-blue-600 dark:ring-offset-gray-800 focus:ring-2 dark:bg-gray-700 dark:border-gray-600' checked disabled></input> Optimized for rapid small memory allocation/releasing
<br/><input type='checkbox' class='w-4 h-4 text-green-500 bg-gray-100 border-gray-300 rounded focus:ring-blue-500 dark:focus:ring-blue-600 dark:ring-offset-gray-800 focus:ring-2 dark:bg-gray-700 dark:border-gray-600' checked disabled></input> Reuse of OS provided allocations
<br/><input type='checkbox' class='w-4 h-4 text-green-500 bg-gray-100 border-gray-300 rounded focus:ring-blue-500 dark:focus:ring-blue-600 dark:ring-offset-gray-800 focus:ring-2 dark:bg-gray-700 dark:border-gray-600' checked disabled></input> Non-Blocking allocation & free within a thread
<br/><input type='checkbox' class='w-4 h-4 text-green-500 bg-gray-100 border-gray-300 rounded focus:ring-blue-500 dark:focus:ring-blue-600 dark:ring-offset-gray-800 focus:ring-2 dark:bg-gray-700 dark:border-gray-600' checked disabled></input> Multithreaded Capable
<br/><input type='checkbox' class='w-4 h-4 text-green-500 bg-gray-100 border-gray-300 rounded focus:ring-blue-500 dark:focus:ring-blue-600 dark:ring-offset-gray-800 focus:ring-2 dark:bg-gray-700 dark:border-gray-600' checked disabled></input> Automatic feature reduction for single threaded use
<br/><input type='checkbox' class='w-4 h-4 text-green-500 bg-gray-100 border-gray-300 rounded focus:ring-blue-500 dark:focus:ring-blue-600 dark:ring-offset-gray-800 focus:ring-2 dark:bg-gray-700 dark:border-gray-600' checked disabled></input> Safe freeing of memory sent to a different thread
Getting started
In Zig:
```zig
const adma = @Import("adma");
pub fn example() !void {
// .initWith using a c allocator
//const adma_ref = try adma.AdmaAllocator.initWith(std.heap.c_allocator, 0);
<code>// .init defaults to using std.heap.page_allocator underneath for ease of use
const adma_ref = adma.AdmaAllocator.init();
defer adma_ref.deinit();
const allocator = &adma_ref.allocator;
var buf = try allocator.alloc(u8, 100);
defer allocator.free(buf);
</code>
}
```
Usage Notes
<ul>
<li>If using adma in a multithreaded context, ensure you <code>AdmaAllocator.init/deinit</code>
in every thread; not pass the allocator pointer to the additional thread</li>
<li>If using for zig prior to the big allocation interface change, see the branch
called <code>pre-allocator-revamp</code></li>
</ul> | []
|
https://avatars.githubusercontent.com/u/24529384?v=4 | zig-sfml-wrapper | Guigui220D/zig-sfml-wrapper | 2020-10-29T16:25:03Z | A zig wrapper for csfml | main | 9 | 57 | 9 | 57 | https://api.github.com/repos/Guigui220D/zig-sfml-wrapper/tags | NOASSERTION | [
"binding",
"csfml",
"sfml",
"wrapper",
"zig",
"zig-package"
]
| 7,523 | false | 2025-05-21T00:42:59Z | true | true | unknown | github | []
| Zig <a>SFML</a> Wrapper
A pretty interface to use CSFML in a way that looks Object-Oriented in zig!
What this is
This is a wrapper for CSFML. Theres no problem importing CSFML in Zig, but the resulting code can be a little bit messy.
My goal is to make things close enough to SFML, with nice methods.
This currently for Zig 0.12 (should work with 0.13) and CSFML 2.6.1.
Adding to your project
Add using Zig's package manager like so: <code>zig fetch --save https://github.com/Guigui220D/zig-sfml-wrapper/archive/d5272051a937c8a3756bb96eab8276b76a271de4.tar.gz</code> (replace the commit hash if you want an other version).
Add this to your exe compile in <code>build.zig</code>:
```zig
const sfml = @import("sfml"); // AT THE TOP OF THE FILE
exe.root_module.addImport("sfml", b.dependency("sfml", .{}).module("sfml"));
sfml.link(exe);
```
<blockquote>
<strong>Note:</strong> Your project must know the location of the CSFML2.6.1 include, lib, and binaries directories for successful building and running. For more information, please refer to the wiki 👇
</blockquote>
Check the <a>wiki</a> for more details on how to compile your project or the examples.
Small example
This is a small example of how you use this sfml wrapper:
```zig
//! This is a translation of the c++ code the sfml website gives you to test if SFML works
//! for instance, in this page: https://www.sfml-dev.org/tutorials/2.6/start-vc.php
const sf = struct {
const sfml = @import("sfml");
usingnamespace sfml;
usingnamespace sfml.graphics;
};
pub fn main() !void {
var window = try sf.RenderWindow.createDefault(.{ .x = 200, .y = 200 }, "SFML works!");
defer window.destroy();
<code>var shape = try sf.CircleShape.create(100.0);
defer shape.destroy();
shape.setFillColor(sf.Color.Green);
while (window.isOpen()) {
while (window.pollEvent()) |event| {
if (event == .closed)
window.close();
}
window.clear(sf.Color.Black);
window.draw(shape, null);
window.display();
}
</code>
}
```
Projects made with this wrapper
Feel free to add your project to this list!
<ul>
<li><a>Pong clone I made</a></li>
<li><a>Minez</a> an arcade looking minecraft inspired mining game</li>
<li><a>quran-warsh</a> a desktop quran app</li>
</ul>
How much is done
Most of the classes are wrapped and you should be able to write games with this wrapper.
The network module is a recent addition and does not contain all classes yet (HTTP, FTP, ...).
Threads are not available yet. | []
|
https://avatars.githubusercontent.com/u/473672?v=4 | nfd-zig | fabioarnold/nfd-zig | 2020-12-27T19:12:22Z | OS-native file dialogs on Linux, macOS and Windows | master | 1 | 55 | 13 | 55 | https://api.github.com/repos/fabioarnold/nfd-zig/tags | MIT | [
"file-dialog",
"native",
"zig",
"zig-package"
]
| 184 | false | 2025-05-20T18:15:07Z | true | false | unknown | github | []
| nfd-zig
<code>nfd-zig</code> is a Zig binding to the library <a>nativefiledialog</a> which provides a convenient cross-platform interface to opening file dialogs on Linux, macOS and Windows.
This library has been tested on Windows 10, macOS 11.1 and Linux.
Usage
You can run a demo with <code>zig build run</code>. The demo's source is in <code>src/demo.zig</code>.
If you want to add the library to your own project...
<ul>
<li>Add the <code>nfd</code> dependency to your <code>build.zig.zon</code>
<code>zig
.{
.dependencies = .{
.nfd = .{ .path = "libs/nfd-zig" }, // Assuming nfd-zig is available in the local directory. Use .url otherwise.
}
}</code></li>
<li>Add the import in your <code>build.zig</code>:
<code>zig
const nfd = b.dependency("nfd", .{});
const nfd_mod = nfd.module("nfd");
exe.root_module.addImport("nfd", nfd_mod);</code></li>
</ul>
Screenshot
| []
|
https://avatars.githubusercontent.com/u/27973237?v=4 | fetch-them-macos-headers | ziglang/fetch-them-macos-headers | 2020-10-20T16:33:48Z | A utility for fetching minimal macOS libc headers | main | 0 | 53 | 10 | 53 | https://api.github.com/repos/ziglang/fetch-them-macos-headers/tags | MIT | [
"macos",
"zig"
]
| 3,123 | false | 2025-05-21T08:27:38Z | true | false | unknown | github | []
| fetch-them-macos-headers
A deprecated project that was used to collect macOS system header files.
The new workflow is here: https://github.com/ziglang/zig/wiki/Updating-libc#darwin | []
|
https://avatars.githubusercontent.com/u/65570835?v=4 | zinput | ziglibs/zinput | 2020-05-24T19:22:58Z | A Zig command-line input library! | master | 4 | 50 | 6 | 50 | https://api.github.com/repos/ziglibs/zinput/tags | - | [
"zig",
"zig-package",
"ziglang"
]
| 26 | false | 2025-01-18T16:24:54Z | true | false | unknown | github | []
| zinput
A Zig command-line input library!
<ul>
<li><a>zinput</a><ul>
<li><a>Usage</a></li>
</ul>
</li>
</ul>
Usage
```zig
const zinput = @import("zinput");
const my_string = try zinput.askString(allocator, "I need a string!", 128);
defer allocator.free(my_string);
```
Check out the test in <code>main.zig</code> for an example! | []
|
https://avatars.githubusercontent.com/u/80545079?v=4 | Kiragine | MeKaLu/Kiragine | 2020-09-10T19:24:46Z | Game engine written in zig, no external dependencies required! | master | 1 | 49 | 0 | 49 | https://api.github.com/repos/MeKaLu/Kiragine/tags | NOASSERTION | [
"game-engine",
"open-source",
"zig"
]
| 7,354 | false | 2025-04-19T06:40:31Z | true | false | unknown | github | []
| Kiragine
I am now working on another engine, i hope it'll be the successor of this engine. It has the same fundamentals but slightly different approach. I won't make you wait longer than a month or two until it's ready to release, once it release i'll put a link here and archive this repository.
Edit: <a>New engine, this is discontinued</a>
Game engine written in zig, compatible with <strong>master branch</strong>.
<strong>No external dependencies</strong> required!
Get started <a>now</a>
<a>Documentation</a>
Project goals
<br/><input type='checkbox' class='w-4 h-4 text-green-500 bg-gray-100 border-gray-300 rounded focus:ring-blue-500 dark:focus:ring-blue-600 dark:ring-offset-gray-800 focus:ring-2 dark:bg-gray-700 dark:border-gray-600' checked disabled></input> Single window operations
<br/><input type='checkbox' class='w-4 h-4 text-green-500 bg-gray-100 border-gray-300 rounded focus:ring-blue-500 dark:focus:ring-blue-600 dark:ring-offset-gray-800 focus:ring-2 dark:bg-gray-700 dark:border-gray-600' checked disabled></input> Input management
<br/><input type='checkbox' class='w-4 h-4 text-green-500 bg-gray-100 border-gray-300 rounded focus:ring-blue-500 dark:focus:ring-blue-600 dark:ring-offset-gray-800 focus:ring-2 dark:bg-gray-700 dark:border-gray-600' checked disabled></input> Simple ecs
<br/><input type='checkbox' class='w-4 h-4 text-blue-600 bg-gray-100 border-gray-300 rounded focus:ring-blue-500 dark:focus:ring-blue-600 dark:ring-offset-gray-800 focus:ring-2 dark:bg-gray-700 dark:border-gray-600' disabled></input> Asset manager
<br/><input type='checkbox' class='w-4 h-4 text-blue-600 bg-gray-100 border-gray-300 rounded focus:ring-blue-500 dark:focus:ring-blue-600 dark:ring-offset-gray-800 focus:ring-2 dark:bg-gray-700 dark:border-gray-600' disabled></input> 2D Renderer:
<br/><input type='checkbox' class='w-4 h-4 text-green-500 bg-gray-100 border-gray-300 rounded focus:ring-blue-500 dark:focus:ring-blue-600 dark:ring-offset-gray-800 focus:ring-2 dark:bg-gray-700 dark:border-gray-600' checked disabled></input> Flipbook
<br/><input type='checkbox' class='w-4 h-4 text-green-500 bg-gray-100 border-gray-300 rounded focus:ring-blue-500 dark:focus:ring-blue-600 dark:ring-offset-gray-800 focus:ring-2 dark:bg-gray-700 dark:border-gray-600' checked disabled></input> Camera
<br/><input type='checkbox' class='w-4 h-4 text-green-500 bg-gray-100 border-gray-300 rounded focus:ring-blue-500 dark:focus:ring-blue-600 dark:ring-offset-gray-800 focus:ring-2 dark:bg-gray-700 dark:border-gray-600' checked disabled></input> Shape drawing
<br/><input type='checkbox' class='w-4 h-4 text-green-500 bg-gray-100 border-gray-300 rounded focus:ring-blue-500 dark:focus:ring-blue-600 dark:ring-offset-gray-800 focus:ring-2 dark:bg-gray-700 dark:border-gray-600' checked disabled></input> Texture drawing
<br/><input type='checkbox' class='w-4 h-4 text-blue-600 bg-gray-100 border-gray-300 rounded focus:ring-blue-500 dark:focus:ring-blue-600 dark:ring-offset-gray-800 focus:ring-2 dark:bg-gray-700 dark:border-gray-600' disabled></input> Text drawing
<br/><input type='checkbox' class='w-4 h-4 text-blue-600 bg-gray-100 border-gray-300 rounded focus:ring-blue-500 dark:focus:ring-blue-600 dark:ring-offset-gray-800 focus:ring-2 dark:bg-gray-700 dark:border-gray-600' disabled></input> GUI system
<br/><input type='checkbox' class='w-4 h-4 text-blue-600 bg-gray-100 border-gray-300 rounded focus:ring-blue-500 dark:focus:ring-blue-600 dark:ring-offset-gray-800 focus:ring-2 dark:bg-gray-700 dark:border-gray-600' disabled></input> Vulkan implementation
<br/><input type='checkbox' class='w-4 h-4 text-blue-600 bg-gray-100 border-gray-300 rounded focus:ring-blue-500 dark:focus:ring-blue-600 dark:ring-offset-gray-800 focus:ring-2 dark:bg-gray-700 dark:border-gray-600' disabled></input> Audio
<br/><input type='checkbox' class='w-4 h-4 text-blue-600 bg-gray-100 border-gray-300 rounded focus:ring-blue-500 dark:focus:ring-blue-600 dark:ring-offset-gray-800 focus:ring-2 dark:bg-gray-700 dark:border-gray-600' disabled></input> Android support
<br/><input type='checkbox' class='w-4 h-4 text-blue-600 bg-gray-100 border-gray-300 rounded focus:ring-blue-500 dark:focus:ring-blue-600 dark:ring-offset-gray-800 focus:ring-2 dark:bg-gray-700 dark:border-gray-600' disabled></input> Optional: scripting language
<br/><input type='checkbox' class='w-4 h-4 text-blue-600 bg-gray-100 border-gray-300 rounded focus:ring-blue-500 dark:focus:ring-blue-600 dark:ring-offset-gray-800 focus:ring-2 dark:bg-gray-700 dark:border-gray-600' disabled></input> Optional: advanced integrated ecs
<br/><input type='checkbox' class='w-4 h-4 text-blue-600 bg-gray-100 border-gray-300 rounded focus:ring-blue-500 dark:focus:ring-blue-600 dark:ring-offset-gray-800 focus:ring-2 dark:bg-gray-700 dark:border-gray-600' disabled></input> Optional: splash screen
About release cycle
<ul>
<li>Versioning: major.minor.patch</li>
<li>Every x.x.3 creates a new minor, which becomes x.(x + 1).0</li>
<li>Again every x.3.x creates a new major, which becomes (x + 1).0.x</li>
<li>When a minor gets created, there will be a new release</li>
<li>When a new version comes, it'll comitted as x.x.x source update</li>
</ul> | []
|
https://avatars.githubusercontent.com/u/1519747?v=4 | zacho | kubkon/zacho | 2020-08-26T19:38:17Z | Zig's Mach-O parser | master | 0 | 44 | 4 | 44 | https://api.github.com/repos/kubkon/zacho/tags | MIT | [
"zig",
"zig-package"
]
| 198 | false | 2025-05-10T11:12:03Z | true | true | unknown | github | [
{
"commit": "b9a7c13bef81b32d2df0ccc78994001c795ef805.tar.gz",
"name": "zigkit",
"tar_url": "https://github.com/kubkon/ZigKit/archive/b9a7c13bef81b32d2df0ccc78994001c795ef805.tar.gz.tar.gz",
"type": "remote",
"url": "https://github.com/kubkon/ZigKit"
}
]
| zacho
...or Zig's Mach-O parser. This project started off as a dummy scratchpad for reinforcing my
understanding of the Mach-O file format while I was working on the Zig's stage2 Mach-O linker
(I still am working on it, in case anyone was asking).
My current vision for <code>zacho</code> is for it to be a cross-platform version of <code>otool</code> and <code>pagestuff</code>
macOS utilities. These seem to be very useful when battling the Darwin kernel and <code>dyld</code> when those
refuse to load your hand-crafter binary, or you just like looking at Mach-O dissected output.
Usage
```
Usage: zacho [options] file
General options:
-c, --code-signature Print the contents of code signature (if any)
-d, --dyld-info Print the contents of dyld rebase and bind opcodes
-e, --exports-trie Print export trie (if any)
-h, --header Print the Mach-O header
-i, --indirect-symbol-table Print the indirect symbol table
-l, --load-commands Print load commands
-r, --relocations Print relocation entries (if any)
-s, --symbol-table Print the symbol table
-u, --unwind-info Print the contents of (compact) unwind info section (if any)
-v, --verbose Print more detailed info for each flag
--archive-index Print archive index (if any)
--string-table Print the string table
--data-in-code Print data-in-code entries (if any)
--hex-dump=[name] Dump section contents as bytes
--string-dump=[name] Dump section contents as strings
--verify-memory-layout Print virtual memory layout and verify there is no overlap
--help Display this help and exit
```
Building from source
Building from source requires <a>Zig 0.14</a>.
<code>$ git clone https://github.com/kubkon/zacho.git
$ zig build</code> | []
|
https://avatars.githubusercontent.com/u/39384757?v=4 | zss | chadwain/zss | 2020-11-19T04:48:40Z | zss is a CSS layout engine and renderer, written in Zig. | master | 0 | 42 | 2 | 42 | https://api.github.com/repos/chadwain/zss/tags | NOASSERTION | [
"css",
"zig",
"zss"
]
| 2,702 | false | 2025-05-19T22:22:41Z | true | true | unknown | github | [
{
"commit": "a0f4771122f7db10f8b8cf574c1a1fa4d5d7fbed",
"name": "harfbuzz",
"tar_url": "https://github.com/chadwain/harfbuzz/archive/a0f4771122f7db10f8b8cf574c1a1fa4d5d7fbed.tar.gz",
"type": "remote",
"url": "https://github.com/chadwain/harfbuzz"
},
{
"commit": "53c75bf06c40f763608fe2230a1a7f33e45a86eb",
"name": "zgl",
"tar_url": "https://github.com/chadwain/zgl/archive/53c75bf06c40f763608fe2230a1a7f33e45a86eb.tar.gz",
"type": "remote",
"url": "https://github.com/chadwain/zgl"
},
{
"commit": "7e098bf6be568cb8bd659397c2d5c291893095bc",
"name": "zigimg",
"tar_url": "https://github.com/TUSF/zigimg/archive/7e098bf6be568cb8bd659397c2d5c291893095bc.tar.gz",
"type": "remote",
"url": "https://github.com/TUSF/zigimg"
}
]
| zss
zss is a <a>CSS</a> layout engine and document renderer, written in <a>Zig</a>.
Building zss
To build zss, simply run <code>zig build --help</code> to see your options.
zss uses version 0.14 of the zig compiler.
Standards Implemented
In general, zss tries to implement the standards contained in <a>CSS Snapshot 2023</a>.
| Module | Level | Progress |
| ------ | ----- | ----- |
| CSS Level 2 | 2.2 | Partial |
| Syntax | 3 | Partial |
| Selectors | 3 | Partial |
| Cascading and Inheritance | 4 | Partial |
| Backgrounds and Borders | 3 | Partial |
| Values and Units | 3 | Partial |
| Namespaces | 3 | Partial |
License
See <a>LICENSE.md</a> for detailed licensing information. | []
|
https://avatars.githubusercontent.com/u/4252848?v=4 | luf | Luukdegram/luf | 2020-09-01T14:47:36Z | Statically typed, embeddable, scripting language written in Zig. | master | 8 | 40 | 4 | 40 | https://api.github.com/repos/Luukdegram/luf/tags | MIT | [
"embeddable",
"embeddable-scripting-language",
"language",
"luf",
"scripting-language",
"statically-typed",
"zig",
"ziglang"
]
| 976 | false | 2025-05-06T00:16:08Z | true | false | unknown | github | []
| Luf
Luf is a statically typed embeddable scripting language written in <a>Zig</a>.
The goal of this project is to create a simple, expressive scripting language that can be used to implement new ideas. As most of it is experimental, I would currently not recommend this for any serious use.
Resources
<ul>
<li><a>Examples</a></li>
<li><a>Documentation</a></li>
<li><a>Building from source</a></li>
<li><a>Contributing</a></li>
<li><a>Editor Support</a></li>
</ul>
Building from source
<a></a>
<a></a> <a></a>
I try to keep up with the latest version of Zig to be able to use all of its features (and bug fixes).
Currently, you'll need atleast version 0.8.0-dev.2641+55811d8da to build Luf.
Building
To build Luf as a static library, execute the following Zig command:
<code>zig build</code>
Tests
Currently all tests are written in Zig, but there's plans to also write behavioural tests in Luf.
To run all tests, execute the following command:
<code>zig build test</code>
Editor support
Currently there's support for syntax highlighting for vscode, which can be found <a>here</a>. | []
|
https://avatars.githubusercontent.com/u/12176994?v=4 | zig-vst | schroffl/zig-vst | 2020-07-04T23:11:35Z | Aims to provide high- and low-level utilites for building VST 2.4 plugins with Zig | master | 1 | 40 | 1 | 40 | https://api.github.com/repos/schroffl/zig-vst/tags | MIT | [
"vst",
"zig"
]
| 2,200 | false | 2025-03-14T15:01:53Z | true | false | unknown | github | []
| zig-vst
Aims to provide high- and low-level utilites for building VST 2.4 plugins with Zig.
It's too early for any documentation, so it's still TODO.
Hot Reloading
Not very mature yet, but here's a demo:
| []
|
https://avatars.githubusercontent.com/u/29983540?v=4 | wz | truemedian/wz | 2020-07-04T23:03:57Z | null | master | 0 | 38 | 7 | 38 | https://api.github.com/repos/truemedian/wz/tags | MIT | [
"websocket",
"zig"
]
| 75 | false | 2024-10-01T21:26:28Z | true | false | unknown | github | []
| wz
<a></a>
<a></a>
<a></a>
An I/O agnostic WebSocket 1.3 library for Zig.
Currently untested, contributions towards a test suite are appreciated.
Features
<ul>
<li>Performs no allocations, uses a single buffer for all parsing.</li>
<li>Works with any Reader and Writer.</li>
</ul>
Notes
<ul>
<li>wz does <strong>not</strong> buffer either reads or writes, if you prefer the performance boost such buffering provides, you must
provide your own buffered Reader and Writers.</li>
</ul>
Examples
<strong>Coming Soon...</strong> | []
|
https://avatars.githubusercontent.com/u/63115601?v=4 | snow | lithdew/snow | 2020-12-05T14:03:29Z | A small, fast, cross-platform, async Zig networking framework built on top of lithdew/pike. | master | 2 | 38 | 3 | 38 | https://api.github.com/repos/lithdew/snow/tags | MIT | [
"async",
"networking",
"pike",
"tcp",
"zig"
]
| 94 | false | 2024-08-31T21:01:41Z | true | false | unknown | github | []
| snow
A small, fast, cross-platform, async Zig networking framework built on top of <a>lithdew/pike</a>.
It automatically handles:
1. buffering/framing data coming in and out of a socket,
2. managing the lifecycle of incoming / outgoing connections, and
3. representing a singular <code>Client</code> / <code>Server</code> as a bounded adaptive pool of outgoing / incoming connections.
It also allows you to specify:
1. how messages are framed (<code>\n</code> suffixed to each message, message length prefixed to each message, etc.),
2. a sequence of steps to be performed before successfully establishing a connection (a handshake protocol), and
3. an upper bound to the maximum number of connections a <code>Client</code> / <code>Server</code> may pool in total.
Usage
In your <code>build.zig</code>:
```zig
const std = @import("std");
const Builder = std.build.Builder;
const pkgs = struct {
const pike = std.build.Pkg{
.name = "pike",
.path = "pike/pike.zig",
};
<code>const snow = std.build.Pkg{
.name = "snow",
.path = "snow/snow.zig",
.dependencies = &[_]std.build.Pkg{
pike,
}
};
</code>
};
pub fn build(b: *Builder) void {
// Given a build step...
step.addPackage(pkgs.pike);
step.addPackage(pkgs.snow);
}
```
Protocol
Applications written with <em>snow</em> provide a <code>Protocol</code> implementation which specifies how message are encoded / decoded into frames.
Helpers (<code>io.Reader</code> / <code>io.Writer</code>) are provided to assist developers in specifying how frame encoding / decoding is to be performed.
Given a <code>Protocol</code> implementation, a <code>Client</code> / <code>Server</code> may be instantiated.
Here is an example of a <code>Protocol</code> that frames messages based on an End-of-Line character ('\n') suffixed at the end of each message:
```zig
const std = @import("std");
const snow = @import("snow");
const mem = std.mem;
const Protocol = struct {
const Self = @This();
<code>// This gets called right before a connection is marked to be successfully established!
//
// Unlike the rest of the callbacks below, 'socket' is a raw 'pike.Socket'. Feel free to
// read / write as much data as you wish, or to return an error to prevent a connection
// from being marked as being successfully established.
//
// Rather than 'void', snow.Options.context_type may be set and returned from 'handshake'
// to bootstrap a connection with additional fields and methods under 'socket.context'.
pub fn handshake(self: *Self, comptime side: snow.Side, socket: anytype) !void {
return {};
}
// This gets called before a connection is closed!
pub fn close(self: *Self, comptime side: snow.Side, socket: anytype) void {
return {};
}
// This gets called when a connection's resources is ready to be de-allocated!
//
// A slice of remaining items in the socket's write queue is passed to purge() to be
// optionally deallocated.
pub fn purge(self: *Self, comptime side: snow.Side, socket: anytype, items: []const []const u8) void {
return {};
}
// This gets called when data is ready to be read from a connection!
pub fn read(self: *Self, comptime side: snow.Side, socket: anytype, reader: anytype) !void {
while (true) {
const line = try reader.readLine();
defer reader.shift(line.len);
// Do something with the frame here!
}
}
// This gets called when data is queued and ready to be encoded and written to
// a connection!
//
// Rather than '[]const u8', custom message types may be set to be queuable to the
// connections write queue by setting snow.Options.message_type.
pub fn write(self: *Self, comptime side: snow.Side, socket: anytype, writer: anytype, items: [][]const u8) !void {
for (items) |message| {
if (mem.indexOfScalar(u8, message, '\n') != null) {
return error.UnexpectedDelimiter;
}
const frame = try writer.peek(message.len + 1);
mem.copy(u8, frame[0..message.len], message);
frame[message.len..][0] = '\n';
}
try writer.flush();
}
</code>
};
```
Client
A <code>Client</code> comprises of a bounded adaptive pool of outgoing connections that are to be connected to a single IPv4/IPv6 endpoint.
When writing a message to an endpoint with a <code>Client</code>, a connection is initially grabbed from the pool. The message is then queued to be written to the connection's underlying socket.
A policy is specified for selecting which connection to grab from a <code>Client</code>'s pool. The policy goes as follows:
There exists a configurable maximum number of connections that may belong to a <code>Client</code>'s pool (defaulting to 16). If all existing connections in a <code>Client</code>'s pool contain queued messages that have yet to be flushed and written, a new connection is created and registered to the pool up to a maximum number of connections.
If the pool's maximum number of connections limit is reached, the connection in the pool with the smallest number of queued messages is returned. Otherwise, a new connection is created and registered to the pool and returned.
Server
A <code>Server</code> comprises of a bounded adaptive pool of incoming connections accepted from a single bounded IPv4/IPv6 endpoint. There exists a configurable maximum number of connections that may belong to a <code>Server</code>'s pool (defaulting to 128).
Should an incoming connection be established and the pool underlying a <code>Server</code> appears to be full, the connection will be declined and de-initialized.
Socket
All sockets comprise of two coroutines: a reader coroutine, and a writer coroutine. The reader and writer coroutine are responsible for framing and buffering messages received from / written to a single socket instance, and for executing logic specified under a <code>Protocol</code> implementation.
An interesting detail to note is that the writer coroutine is entirely lock-free.
Performance
<em>snow</em> was written with performance in mind: zero heap allocations occur in all hot paths. Heap allocations only ever occur when establishing a new incoming / outgoing connection.
All other underlying components are stack-allocated and recycled as much as possible. | []
|
https://avatars.githubusercontent.com/u/47629329?v=4 | zig-debian | dryzig/zig-debian | 2020-06-02T05:04:31Z | Packaging the Zig programming language for Debian and Ubuntu. | master | 9 | 35 | 5 | 35 | https://api.github.com/repos/dryzig/zig-debian/tags | Unlicense | [
"apt-get",
"apt-repository",
"debian",
"ubuntu",
"zig",
"ziglang"
]
| 9 | false | 2025-02-10T02:07:00Z | false | false | unknown | github | []
| Zig for Debian and Ubuntu
This repository contains instructions for installing the <a>Zig</a> programming
language and toolchain on the Ubuntu and Debian operating systems, as well
as the [<code>debuild</code>][] configuration for building the corresponding binary
packages from the <a>upstream tarballs</a>.
Distributions
Currently, x86-64 (aka AMD64) binary packages are available for all recent
Ubuntu and Debian releases:
| Distribution | Alias | AMD64 |
| :--------------- | :------- | :---- |
| Ubuntu 20.10 | Groovy | ✔ |
| Ubuntu 20.04 LTS | Focal | ✔ |
| Ubuntu 19.10 | Eoan | ✔ |
| Ubuntu 18.04 LTS | Bionic | ✔ |
| Debian 11 | Bullseye | ✔ |
| Debian 10 | Buster | ✔ |
| Debian unstable | Sid | ✔ |
Installation
Installation from an APT repository
Once you've completed the <a>repository configuration</a> (see
further below), installation is as easy as the familiar:
<code>bash
$ sudo apt install zig</code>
Installation from a downloaded .DEB package file
Alternatively, you can just download the latest [<code>.deb</code>][] file and install
that directly with [<code>dpkg</code>][]:
```bash
$ wget https://github.com/dryzig/zig-debian/releases/download/0.6.0-1/zig_0.6.0-1_amd64.deb
$ sudo dpkg -i zig_0.6.0-1_amd64.deb
```
Configuration
Configure PGP Signing Keys
<code>bash
$ sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 379CE192D401AB61</code>
Configuration on Ubuntu
Configure on Ubuntu 20.10 (Groovy)
<code>bash
$ echo 'deb https://dl.bintray.com/dryzig/zig-ubuntu groovy main' | sudo tee -a /etc/apt/sources.list
$ sudo apt update</code>
Configure on Ubuntu 20.04 LTS (Focal)
<code>bash
$ echo 'deb https://dl.bintray.com/dryzig/zig-ubuntu focal main' | sudo tee -a /etc/apt/sources.list
$ sudo apt update</code>
Configure on Ubuntu 19.10 (Eoan)
<code>bash
$ echo 'deb https://dl.bintray.com/dryzig/zig-ubuntu eoan main' | sudo tee -a /etc/apt/sources.list
$ sudo apt update</code>
Configure on Ubuntu 18.04 LTS (Bionic)
<code>bash
$ echo 'deb https://dl.bintray.com/dryzig/zig-ubuntu bionic main' | sudo tee -a /etc/apt/sources.list
$ sudo apt update</code>
Configuration on Debian
Configure on Debian 11 (Bullseye)
<code>bash
$ echo 'deb https://dl.bintray.com/dryzig/zig-debian bullseye main' | sudo tee -a /etc/apt/sources.list
$ sudo apt update</code>
Configure on Debian 10 (Buster)
<code>bash
$ echo 'deb https://dl.bintray.com/dryzig/zig-debian buster main' | sudo tee -a /etc/apt/sources.list
$ sudo apt update</code>
Maintenance
Building <code>zig_0.6.0-1_amd64.deb</code>
<code>bash
$ wget https://ziglang.org/download/0.6.0/zig-linux-x86_64-0.6.0.tar.xz
$ tar xvf zig-linux-x86_64-0.6.0.tar.xz</code>
<code>bash
$ ln -s zig-linux-x86_64-0.6.0 zig-0.6.0
$ tar cJhf zig_0.6.0.orig.tar.xz zig-0.6.0</code>
<code>bash
$ cd zig-0.6.0
$ git clone https://github.com/dryzig/zig-debian.git debian
$ debuild</code> | []
|
https://avatars.githubusercontent.com/u/65570835?v=4 | funzig | ziglibs/funzig | 2020-07-30T18:35:43Z | Fun functional functionality for Zig! | master | 0 | 35 | 0 | 35 | https://api.github.com/repos/ziglibs/funzig/tags | MIT | [
"zig",
"zig-library"
]
| 23 | false | 2025-02-08T09:31:10Z | false | false | unknown | github | []
|
Functional Zig features!
Table of Contents
<ul>
<li><a>Functions</a></li>
</ul>
Functions
Here's a list of the functions implemented by funzig, in order of addition:
<ul>
<li><code>pipe</code></li>
<li><code>reduce</code></li>
<li><code>map</code></li>
<li><code>find</code></li>
</ul>
For usage information, check out the tests in all the files <code>src</code>! | []
|
https://avatars.githubusercontent.com/u/2567177?v=4 | foxwhale | malcolmstill/foxwhale | 2020-04-26T16:38:03Z | A Wayland compositor written in Zig | master | 19 | 34 | 0 | 34 | https://api.github.com/repos/malcolmstill/foxwhale/tags | MIT | [
"wayland",
"zig",
"ziglang"
]
| 1,230 | false | 2025-03-26T02:38:05Z | true | true | unknown | github | [
{
"commit": "b37fcaaef4bbad39bff217af03e4cac9e030b74d.tar.gz",
"name": "foxwhale_gen",
"tar_url": "https://github.com/malcolmstill/foxwhale-gen/archive/b37fcaaef4bbad39bff217af03e4cac9e030b74d.tar.gz.tar.gz",
"type": "remote",
"url": "https://github.com/malcolmstill/foxwhale-gen"
},
{
"commit": null,
"name": "foxwhale_epoll",
"tar_url": null,
"type": "relative",
"url": "foxwhale-epoll"
},
{
"commit": null,
"name": "foxwhale_pool",
"tar_url": null,
"type": "relative",
"url": "foxwhale-pool"
},
{
"commit": null,
"name": "foxwhale_subset_pool",
"tar_url": null,
"type": "relative",
"url": "foxwhale-subset-pool"
},
{
"commit": null,
"name": "foxwhale_iterable_pool",
"tar_url": null,
"type": "relative",
"url": "foxwhale-iterable-pool"
},
{
"commit": null,
"name": "foxwhale_wayland",
"tar_url": null,
"type": "relative",
"url": "foxwhale-wayland"
},
{
"commit": null,
"name": "foxwhale_backend",
"tar_url": null,
"type": "relative",
"url": "foxwhale-backend"
},
{
"commit": null,
"name": "foxwhale_animation",
"tar_url": null,
"type": "relative",
"url": "foxwhale-animation"
},
{
"commit": null,
"name": "foxwhale_ease",
"tar_url": null,
"type": "relative",
"url": "foxwhale-ease"
}
]
| 404 | []
|
https://avatars.githubusercontent.com/u/2326560?v=4 | zig-riscv-embedded | nmeum/zig-riscv-embedded | 2020-04-11T21:14:10Z | Experimental Zig-based CoAP node for the HiFive1 RISC-V board | master | 0 | 33 | 4 | 33 | https://api.github.com/repos/nmeum/zig-riscv-embedded/tags | AGPL-3.0 | [
"bare-metal",
"coap",
"coap-server",
"embedded",
"hifive1",
"risc-v",
"riscv",
"zig"
]
| 255 | false | 2024-09-12T03:08:13Z | true | false | unknown | github | []
| zig-riscv-embedded
Experimental <a>Zig</a>-based <a>CoAP</a> node for the <a>HiFive1</a> RISC-V board.
Status
This repository is intended to provide a simple sample application for
experimenting with the Zig programming language on freestanding RISC-V.
The application targets the <a>SiFive FE310-G000</a> or more
specifically the <a>HiFive 1</a>. While possible to run the
application on "real hardware", it can also be run using QEMU. In both
cases it is possible to toggle an LED using <a>CoAP</a> over
<a>SLIP</a>.
CoAP over SLIP
To experiment with external dependencies in Zig, this application
provides a very bare bone implementation of <a>CoAP</a> using
<a>zoap</a>. Since implementing an entire UDP/IP stack from
scratch is out-of-scope, this repository transports CoAP packets
directly over <a>SLIP</a>.
Unfortunately, the QFN48 package of the FE310-G000 (as used by the
HiFive1) does not support the UART1. For this reason, the application
multiplexes diagnostic messages and CoAP frames over the same UART
(UART0) using <a>Slipmux</a>. For this purpose, a Go-based
multiplexer for the development system is available in the <code>./slipmux</code>
subdirectory.
Dependencies
For building the software and the associated Slipmux tooling, the
following software is required:
<ul>
<li>Zig <code>0.9.1</code></li>
<li><a>Go</a> for compiling the <code>./slipmux</code> tool</li>
<li>A CoAP client, e.g. <code>coap-client(1)</code> from <a>libcoap</a></li>
<li>QEMU (<code>qemu-system-riscv32</code>) for emulating a HiFive1 (optional)</li>
</ul>
For flashing to real hardware, the following software is required:
<ul>
<li><a>riscv-openocd</a></li>
<li><a>GDB</a> with 32-bit RISC-V support</li>
</ul>
Building
The Zig build system is used for building the application, the
configuration is available in <code>build.zig</code>. To build the application run:
<code>$ zig build
</code>
This will create a freestanding RISC-V ELF binary <code>zig-out/bin/main</code>.
If the image should be booted on real hardware, building in the
<code>ReleaseSmall</code> <a>build mode</a> may be desirable:
<code>$ zig build -Drelease-small
</code>
Furthermore, the Slipmux multiplexer needs to be compiled using the
following commands in order to receive diagnostic messages from the
device and send CoAP messages to the device:
<code>$ cd slipmux && go build -trimpath
</code>
Booting in QEMU
In order to simulate a serial device, which can be used with the
<code>./slipmux</code> tool, QEMU must be started as follows:
<code>$ qemu-system-riscv32 -M sifive_e -nographic -kernel zig-out/bin/main -serial pty
</code>
QEMU will print the allocated PTY path to standard output. In a separate
terminal the <code>./slipmux</code> tool can then be started as follows:
<code>$ ./slipmux/slipmux :2342 <PTY allocated by QEMU>
</code>
This will create a UDP Socket on <code>localhost:2342</code>, CoAP packets send to
this socket are converted into Slipmux CoAP frames and forwarded to the
emulated HiFive1 over the allocated PTY. CoAP packets can be send using
any CoAP client, e.g. using <code>coap-client(1)</code> from <a>libcoap</a>:
<code>$ coap-client -N -m put coap://[::1]:2342/on
$ coap-client -N -m put coap://[::1]:2342/off
</code>
In QEMU, this will cause debug messages to appear in the terminal window
were <code>./slipmux</code> is running. On real hardware, it will also cause the
red LED to be toggled.
Booting on real hardware
The binary can be flashed to real hardware using OpenOCD and gdb. For
this purpose, a shell script is provided. In order to flash a compiled
binary run the following command:
<code>$ ./flash
</code>
After flashing the device, interactions through CoAP are possible using
the instructions given for QEMU above. However, with real hardware
<code>./slipmux</code> needs to be passed the TTY device for the HiFive1 (i.e.
<code>/dev/ttyUSB0</code>).
To debug errors on real hardware start OpenOCD using <code>openocd -f
openocd.cfg</code>. In a separate terminal start a gdb version with RISC-V
support (e.g. <a>gdb-multiarch</a>) as follows:
<code>$ gdb-multiarch -ex 'target extended-remote :3333' zig-out/bin/main
</code>
Development
A pre-commit git hook for checking if files are properly formated is
provided in <code>.githooks</code>. It can be activated using:
<code>$ git config --local core.hooksPath .githooks
</code>
License
The application uses slightly modified linker scripts and assembler
startup code copied from the <a>RIOT</a> operating system. Unless
otherwise noted code written by myself is licensed under
<code>AGPL-3.0-or-later</code>. Refer to the license headers of the different files
for more information. | []
|
https://avatars.githubusercontent.com/u/63115601?v=4 | hello | lithdew/hello | 2020-11-17T15:04:49Z | Multi-threaded cross-platform HTTP/1.1 web server example in Zig. | master | 1 | 33 | 1 | 33 | https://api.github.com/repos/lithdew/hello/tags | - | [
"async",
"cross-platform",
"http-server",
"zig"
]
| 7 | false | 2025-01-08T03:21:48Z | false | false | unknown | github | []
| hello
Multi-threaded cross-platform HTTP/1.1 web server example in <a>Zig</a> using <a>lithdew/pike</a> and <a>kprotty/zap</a>.
Warning
This example is barebones and <em>highly experimental</em>. Linux and Mac has been extensively tested, with Windows only being barely supported.
<a>pike</a> does not yet support cancellation of pending I/O operations on Windows, which causes this example to fail spontaneously should one initiate a graceful shutdown on Windows.
Setup
This example requires a nightly version of Zig. Make sure that port 9000 is available.
<code>git clone --recurse-submodules https://github.com/lithdew/hello
cd hello && zig run hello.zig</code>
Benchmarks
```
$ cat /proc/cpuinfo | grep 'model name' | uniq
model name : Intel(R) Core(TM) i7-7700HQ CPU @ 2.80GHz
$ wrk -t12 -c100 -d30s http://127.0.0.1:9000
Running 30s test @ http://127.0.0.1:9000
12 threads and 100 connections
Thread Stats Avg Stdev Max +/- Stdev
Latency 417.19us 0.90ms 30.21ms 96.78%
Req/Sec 26.86k 3.31k 39.72k 73.08%
9629837 requests in 30.04s, 459.19MB read
Requests/sec: 320538.80
Transfer/sec: 15.28MB
``` | []
|
https://avatars.githubusercontent.com/u/3932972?v=4 | zig-bearssl | ikskuh/zig-bearssl | 2020-05-21T00:42:45Z | A BearSSL binding for Zig | master | 1 | 32 | 11 | 32 | https://api.github.com/repos/ikskuh/zig-bearssl/tags | MIT | [
"bearssl",
"ssl",
"tls",
"zig",
"zig-package",
"ziglang"
]
| 1,061 | false | 2025-04-29T13:25:50Z | true | true | unknown | github | []
| zig-bearssl
A <a>BearSSL</a> binding for Zig, providing primitive (and probably unsafe, i'm no SSL expert) bindings for SSL and TLS connections to generic zig code. | [
"https://github.com/ikskuh/gurl"
]
|
https://avatars.githubusercontent.com/u/2665334?v=4 | zig-snappy | gsquire/zig-snappy | 2020-09-07T23:25:50Z | Snappy compression for Zig | master | 1 | 32 | 3 | 32 | https://api.github.com/repos/gsquire/zig-snappy/tags | MIT | [
"compression",
"snappy",
"zig"
]
| 27 | false | 2025-04-05T18:41:32Z | false | false | unknown | github | []
| zig-snappy
<a></a>
This is a rough translation of Go's <a>snappy</a> library for Zig. It
only supports the block format. The streaming format may be added in the future.
Caveat
Expect some sharp edges. This is my first time writing Zig! I would greatly appreciate any issues
or pull requests to improve the code, write tests, or just critique in general.
Roadmap
<ul>
<li>More robust tests</li>
<li>Fuzzing</li>
</ul>
Usage
See the <a>binary</a> in the repository.
License
MIT | []
|
https://avatars.githubusercontent.com/u/3932972?v=4 | ZTT | ikskuh/ZTT | 2021-02-06T08:04:04Z | Precompiled Zig text template engine | master | 0 | 32 | 4 | 32 | https://api.github.com/repos/ikskuh/ZTT/tags | Zlib | [
"template-engine",
"text-templating-engine",
"zig",
"zig-package",
"ziglang"
]
| 13 | false | 2025-04-08T13:17:56Z | true | false | unknown | github | []
| Zig Text Templates
This project implements a template generator for Zig that works similar to how PHP works.
It allows you to mix plain text and Zig code to generate automatic text files.
Consider the following example:
<code>``zig
<#
// This tag let's you import global statements available to the</code>render()` function
const std = @import("std");
>
Zig Text Template
The following syntax inserts <code>ctx.intro</code> formattet with the format string <code>{s:-^10}</code>.
<= ctx.intro : {s:-^10} =>
The list has the following <= ctx.list.len => items:
<code>- <= item.name : {s} => *(weight <= item.weight : {d:.1} => kg)*
</code>
You can pass arbitrary format strings and expressions to the direct formatter:
- <= "hello:world" : {s} =>
- <= (10 + 20 * 30) =>
- <= std.math.log10(10 + 20 * 30) =>
Note that for using a <code>:</code> inside the format expression itself, use braces to encapsulate the items.
```
This was inspired by both <a>PHP</a> and <a>Microsofts T4</a> engine.
Usage
Each generated template will yield a <code>zig</code> file which exports a function called <code>render</code>:
<code>zig
pub fn render(stream: anytype, ctx: anytype) !void {
…
}</code>
This function must be invoked with a <code>std.io.Writer</code> for the first argument and <em>any</em> value for the second argument. <code>ctx</code> is meant to pass information from the caller to the template engine to allow dynamic content generation.
To generate templates in your build script, just run the executable with <code>FileSource</code>s.
<code>zig
< TO BE DONE ></code>
For a full example, see <code>build.zig</code> and the <code>example</code> folder.
Syntax
The syntax knows these constructs:
<ul>
<li><code><? … ?></code> will paste everything between the start and end sigil verbatim into the <code>render</code> function code. This can be used to generate loops, conditions, ...</li>
<li><code><= expr => will print a default-formatted (</code>{}`) expression into the stream.</li>
<li><code><= expr : format =></code> will behave similar to the default-formatted version, but you can specify your own format string in <code>format</code>. This accepts any format string that <code>std.fmt.format</code> accepts for the type of <code>expr</code>.</li>
<li><code><# … #></code> will paste everything between the start and end sigil verbatim into the global scope of the Zig code. This can be used to create custom functions or exports.</li>
</ul>
Note that both <code><# … #></code> and <code><? … ?></code> will swallow a directly following line break, while <code><= … =></code> will not. This makes writing templates more intuitive. | []
|
https://avatars.githubusercontent.com/u/1915?v=4 | libpcre.zig | kivikakk/libpcre.zig | 2020-08-20T04:03:56Z | Zig bindings to libpcre | main | 0 | 31 | 6 | 31 | https://api.github.com/repos/kivikakk/libpcre.zig/tags | MIT | [
"pcre",
"regular-expression",
"zig"
]
| 49 | false | 2025-03-30T00:47:11Z | true | true | 0.14.0 | github | [
{
"commit": "6a08aa250b3ca1deea5fbc5f696bb4e25ac2da90.tar.gz",
"name": "pcre",
"tar_url": "https://github.com/kivikakk/pcre-8.45/archive/6a08aa250b3ca1deea5fbc5f696bb4e25ac2da90.tar.gz.tar.gz",
"type": "remote",
"url": "https://github.com/kivikakk/pcre-8.45"
}
]
| <a>libpcre.zig</a>
Use via the zig package manager (Zig v0.12+):
<code>sh
$ zig fetch --save https://github.com/kivikakk/libpcre.zig/archive/<commit hash>.tar.gz</code>
Then add the following to <code>build.zig</code> (a source build of <code>pcre</code> will be linked against automatically):
<code>zig
const pcre_pkg = b.dependency("libpcre.zig", .{ .optimize = optimize, .target = target });
const pcre_mod = pcre_pkg.module("libpcre");
exe.root_module.addImport("pcre", pcre_mod);</code>
To link against the system <code>libpcre</code>, add the <code>system_library</code> build option like this:
Note, only the following systems support this mode:
* Linux: <code>apt install pkg-config libpcre3-dev</code>
* macOS: <code>brew install pkg-config pcre</code>
* ~~Windows: install <a>vcpkg</a>, <code>vcpkg integrate install</code>, <code>vcpkg install pcre --triplet x64-windows-static</code>~~
Zig doesn't have vcpkg integration any more. Suggestions welcome!
<code>zig
const pcre_pkg = b.dependency("libpcre.zig", .{ .optimize = optimize, .target = target, .system_library = "true" });</code> | []
|
https://avatars.githubusercontent.com/u/15308111?v=4 | comptime_hash_map | Vexu/comptime_hash_map | 2020-06-27T17:56:20Z | A statically initiated HashMap | master | 0 | 27 | 4 | 27 | https://api.github.com/repos/Vexu/comptime_hash_map/tags | MIT | [
"compile-time",
"zig",
"zig-library",
"zig-package"
]
| 11 | false | 2025-03-10T12:26:19Z | true | true | unknown | github | []
| Comptime HashMap
A statically initiated HashMap, originally a pull request to the Zig std lib <a>#5359</a>.
Installation
Build for Zig <code>0.13.0</code>.
<code>sh
zig fetch --save git+https://github.com/Vexu/comptime_hash_map</code>
In your <code>build.zig</code>:
<code>zig
const chm = b.dependency("comptime_hash_map", .{});
exe.root_module.addImport("comptime_hash_map", chm.module("comptime_hash_map"));</code>
In your <code>exe</code> module:
<code>zig
const chm = @import("comptime_hash_map");</code> | []
|
https://avatars.githubusercontent.com/u/65570835?v=4 | string-searching | ziglibs/string-searching | 2020-05-05T11:39:10Z | String(not limited to []const u8)-searching algorithms in zig | master | 1 | 25 | 0 | 25 | https://api.github.com/repos/ziglibs/string-searching/tags | MIT | [
"bitap-algorithm",
"boyer-moore",
"zig",
"zig-package",
"ziglang"
]
| 40 | false | 2025-05-08T07:36:41Z | true | false | unknown | github | []
| string-searching
Implementation of some string-search algorithms in
<a>zig</a>. Compatible with zig 0.13.0.
Boyer-Moore string searching
Ported from the implementation in the Go standard library:
<a>strings/search.go</a>.
Bitap algorithm
Inspired by the code on the <a>Wikipedia
article</a>. | []
|
https://avatars.githubusercontent.com/u/71220004?v=4 | iotmonitor | mqttiotstuff/iotmonitor | 2020-04-12T12:21:38Z | PainLess, Monitor and State server for iot mqtt devices, and software agents. This daemon permit to maintain the execution of constellations of mqtt devices and associated agents | master | 2 | 24 | 1 | 24 | https://api.github.com/repos/mqttiotstuff/iotmonitor/tags | Apache-2.0 | [
"agents",
"healthcheck",
"iot",
"iot-device",
"monitor",
"monitoring",
"mqtt",
"server",
"state",
"zig"
]
| 355 | false | 2025-03-04T16:27:49Z | true | false | unknown | github | []
| IOTMonitor project
IotMonitor is an effortless and lightweight mqtt monitoring for devices (things) and agents on Linux.
IotMonitor aims to solve the "always up" problem of large IOT devices and agents system. This project is successfully used every day for running smart home automation system.
Considering large and longlived running mqtt systems can hardly rely only on monolytics plateforms, the reality is always composite as some agents or functionalities increase with time. Diversity also occurs in running several programming languages implementation for agents.
This project offers a simple command line, as in *nix system, to monitor MQTT device or agents system. MQTT based communication devices (IOT) and agents are watched, and alerts are emitted if devices or agents are not responding any more. Declared software agents are restarted by iotmonitor when crashed.
In the behaviour, once the mqtt topics associated to a thing or agent is declared, IotMonitor records and restore given MQTT "states topics" as they go and recover. It helps reinstalling IOT things state, to avoid lots of administration tasks.
IotMonitor use a TOML config file. Each device has an independent configured communication message time out. When the device stop communication on this topic, the iotmonitor publish a specific monitoring failure topic for the lots device, with the latest contact timestamp. This topic is labelled :
<code>home/monitoring/expire/[device_name]
</code>
This topic can then be displayed or alerted to inform that the device or agent is not working properly.
This project is based on C Paho MQTT client library, use leveldb as state database.
Running the project on linux
Using Nix
Install Nix, <a>https://nixos.org/download.html</a>
then, using the following <code>shell.nix</code> file,
```
{ nixpkgs ? , iotstuff ? import (fetchTarball
"https://github.com/mqttiotstuff/nix-iotstuff-repo/archive/9b12720.tar.gz")
{ } }:
iotstuff.pkgs.mkShell rec { buildInputs = [ iotstuff.iotmonitor ]; }
```
run :
<code>nix-shell shell.nix</code>
or : (with the shell.nix in the folder)
<code>nix-shell</code>
Using Nix Flake
<code> nix run git+https://github.com/mqttiotstuff/iotmonitor?submodules=1
</code>
build with flake :
<code> git clone --recursive https://github.com/mqttiotstuff/iotmonitor
nix build "git+file://$(pwd)?submodules=1"
</code>
Using docker,
<a>see README in docker subfolder, for details and construct the image</a>
launch the container from image :
<code>bash
docker run --rm -d -u $(id --user) -v `pwd`:/config iotmonitor</code>
From scratch
for building the project, the following elements are needed :
<ul>
<li>leveldb library (used for storing stated)</li>
<li>C compiler (builds essentials)</li>
<li>cmake</li>
<li>zig : 0.9.1</li>
</ul>
then launch the following commands :
```bash
git clone --recursive https://github.com/frett27/iotmonitor
cd iotmonitor
cd paho.mqtt.c
cmake -DPAHO_BUILD_STATIC=true .
make
cd ..
mkdir bin
zig build -Dcpu=baseline -Dtarget=native-native-gnu
```
Configuration File
The configuration is defined in the <code>config.toml</code> TOML file, (see an example in the root directory)
A global Mqtt broker configuration section is defined using a heading <code>[mqtt]</code>
the following parameters are found :
<code>toml
[mqtt]
serverAddress="tcp://localhost:1883"
baseTopic="home/monitoring"
user=""
password=""</code>
An optional clientid can also be specified to change the mqtt clientid, a default "iotmonitor" is provided
Device declaration
In the configuration toml file, each device is declared in a section using a "device_" prefix
in the section : the following elements can be found :
<code>toml
[device_esp04]
watchTimeOut=60
helloTopic="home/esp04"
watchTopics="home/esp04/sensors/#"
stateTopics="home/esp04/actuators/#"</code>
<ul>
<li><code>watchTimeOut</code> : watch dog for alive state, when the timeout is reached without and interactions on watchTopics, then iotmonitor trigger an expire message for the device</li>
<li><code>helloTopic</code> : the topic to observe to welcome the device. This topic trigger the state recovering for the device and agents. IotMonitor, resend the previous stored <code>stateTopics</code>, the content of the helloTopic is not used (every first mqtt topic can be used to restore state)</li>
<li><code>watchTopics</code> : the topic pattern to observe to know the device is alive</li>
<li><code>stateTopics</code> : list of topics for recording the states and reset them as they are welcomed</li>
</ul>
Agents declarations
Agents are declared using an "agent_" prefix in the section. Agents are devices with an associated command line (<code>exec</code> config key) that trigger the start of the software agent. IotMonitor checks periodically if the process is running, and relaunch it if needed.
<code>toml
[agent_ledboxdaemon]
exec="source ~/mqttagents/p3/bin/activate;cd ~/mqttagents/mqtt-agent-ledbox;python3 ledboxdaemon.py"
watchTopics="home/agents/ledbox/#"</code>
IotMonitor running the processes identify the process using a specific bash command line containing an IOTMONITOR tag, which is recognized to detect if the process is running. Monitored processes are detached from the iotmonitor process, avoiding to relaunch the whole system in the case of restarting the <code>iotmonitor</code> process.
Agents may also have <code>helloTopic</code>, <code>stateTopics</code> and <code>watchTimeOut</code> as previously described.
State restoration for things and agents
At startup OR when the <code>helloTopic</code> is fired, iotmonitor fire the previousely recorded states on mqtt, this permit the device (things), to take it's previoulsy state, as if it has not been stopped.. All mqtt recorded states (<code>stateTopics</code>) are backuped by iotmonitor in a leveldb database.
For practical reasons, this permit to centralize the state, and restore them when an iot device has rebooted. If used this functionnality, reduce the need to implement a cold state storage for each agent or device. Starting or stopping iotmonitor, redefine the state for all elements.
Monitoring iotmonitor :-)
IotMonitor publish a counter on the <code>home/monitoring/up</code> topic every seconds. One can then monitor the iotmonitor externally.
The counter is resetted at each startup.
Credits
<ul>
<li>zig-toml : for zig toml parser</li>
<li>paho eclipse mqtt c library</li>
<li>levedb database</li>
<li>routez : for http server integration</li>
</ul> | []
|
https://avatars.githubusercontent.com/u/12070598?v=4 | zata | rvcas/zata | 2020-03-22T21:38:58Z | Common Data Structures and Algorithms for Learning Zig | main | 0 | 24 | 2 | 24 | https://api.github.com/repos/rvcas/zata/tags | MIT | [
"data-structures",
"learning",
"learning-zig",
"zig"
]
| 23 | false | 2025-01-17T00:36:22Z | true | false | unknown | github | []
| zata
Common and simple data structures for learning zig.
Requirements
You'll need <a target="_blank">zig</a> to play with this.
You can find instructions to install it here: <a target="_blank">click me</a>
Running
```sh
git clone [email protected]:10factory/zata.git
cd zata
zig build test
```
Implemented
<ul>
<li>Linked List</li>
</ul> | []
|
https://avatars.githubusercontent.com/u/65570835?v=4 | painterz | ziglibs/painterz | 2020-07-16T09:35:41Z | Low-level implementation of different painting primitives (lines, rectangles, ...) without specialization on a certain draw target | master | 1 | 23 | 1 | 23 | https://api.github.com/repos/ziglibs/painterz/tags | MIT | [
"2d-graphics",
"canvas",
"graphics",
"painting",
"zig",
"zig-package",
"ziglang"
]
| 24 | false | 2025-03-21T04:33:13Z | true | true | unknown | github | []
| painterz
The idea of this library is to provide platform-independent, embedded-feasible implementations of several drawing primitives.
The library exports a generic <code>Canvas</code> type which is specialized on a <code>setPixel</code> function that will put pixels of type <code>Color</code> onto a <code>Framebuffer</code>.
It's currently not possible or planned to do blending, but alpha test could be implemented by ignoring certain color values in the <code>setPixel</code> function.
Usage Example
See <a><code>src/example.zig</code></a> for a full usage example.
```zig
const Pixel = packed struct {
r: u8, g: u8, b: u8, a: u8
};
const Framebuffer = struct {
buffer: []Pixel,
<code>fn setPixel(fb: @This(), x: isize, y: isize, c: Pixel) void {
if (x < 0 or y < 0) return;
if (x >= 100 or y >= 100) return;
fb.buffer[100 * std.math.absCast(y) + std.math.absCast(x)] = c;
}
</code>
};
var canvas = painterz.Canvas(Framebuffer, Pixel, Framebuffer.setPixel).init(Framebuffer{
.buffer = …,
});
canvas.drawLine(100, 120, 110, 90, Pixel{
.r = 0xFF,
.g = 0x00,
.b = 0xFF,
.a = 0xFF,
});
``` | []
|
https://avatars.githubusercontent.com/u/3759175?v=4 | aniz | Hejsil/aniz | 2021-01-02T15:36:06Z | A program for keeping a local list of anime you have watched | master | 0 | 22 | 1 | 22 | https://api.github.com/repos/Hejsil/aniz/tags | MIT | [
"anime",
"anime-list",
"cli",
"database",
"zig"
]
| 260 | false | 2025-05-07T13:47:11Z | true | true | 0.14.0 | github | [
{
"commit": "4d0e84cd8844c0672e0cbe247a3130750c9e0f27.tar.gz",
"name": "datetime",
"tar_url": "https://github.com/frmdstryr/zig-datetime/archive/4d0e84cd8844c0672e0cbe247a3130750c9e0f27.tar.gz.tar.gz",
"type": "remote",
"url": "https://github.com/frmdstryr/zig-datetime"
},
{
"commit": "aa24df42183ad415d10bc0a33e6238c437fc0f59.tar.gz",
"name": "folders",
"tar_url": "https://github.com/ziglibs/known-folders/archive/aa24df42183ad415d10bc0a33e6238c437fc0f59.tar.gz.tar.gz",
"type": "remote",
"url": "https://github.com/ziglibs/known-folders"
}
]
| aniz
aniz is a program for keeping a local list of anime you have watched.
Example
```sh
$ # First, an anime database needs to be downloaded.
$ # Run this once a week to have the latest database at all time.
$ aniz database download
$ # Search for an anime in the database
$ aniz database -s 'Attack on titan' | head -n1
tv 2013 spring 25 Shingeki no Kyojin https://anidb.net/anime/9541 https://cdn.myanimelist.net/images/anime/10/47347.jpg
$ # Add one or more animes to your list
$ aniz list plan-to-watch \
https://anidb.net/anime/9541 \
https://anilist.co/anime/11981 \
https://kitsu.io/anime/7929
$ # Show your list
$ aniz list
2023-04-19 p 0 0 Shingeki no Kyojin https://anidb.net/anime/9541
2023-04-19 p 0 0 RWBY https://kitsu.io/anime/7929
2023-04-19 p 0 0 Mahou Shoujo Madoka★Magica Movie 3: Hangyaku no Monogatari https://anilist.co/anime/11981
$ # Watch an episode
$ aniz list watch-episode https://kitsu.io/anime/7929
$ aniz list
2023-04-19 w 1 0 RWBY https://kitsu.io/anime/7929
2023-04-19 p 0 0 Shingeki no Kyojin https://anidb.net/anime/9541
2023-04-19 p 0 0 Mahou Shoujo Madoka★Magica Movie 3: Hangyaku no Monogatari https://anilist.co/anime/11981
$ # Complete show
$ aniz list complete https://anidb.net/anime/9541
$ aniz list
2023-04-19 w 1 0 RWBY https://kitsu.io/anime/7929
2023-04-19 p 0 0 Mahou Shoujo Madoka★Magica Movie 3: Hangyaku no Monogatari https://anilist.co/anime/11981
2023-04-19 c 25 1 Shingeki no Kyojin https://anidb.net/anime/9541
``` | []
|
https://avatars.githubusercontent.com/u/4252848?v=4 | ctradix | Luukdegram/ctradix | 2020-10-06T19:18:27Z | Comptime radix tree in Zig | master | 0 | 22 | 2 | 22 | https://api.github.com/repos/Luukdegram/ctradix/tags | MIT | [
"compiletime",
"comptime",
"radix",
"radix-tree",
"zig",
"ziglang"
]
| 31 | false | 2025-01-22T19:13:34Z | true | false | unknown | github | []
|
ctradix
Comptime radix trie implemented in <a>Zig</a>.
This library was experimental to see how feasible it is to implement a comptime radix trie
where all data is known at compile time. The main use case for this library is to be used
within <a>apple_pie</a> for routing support.
The implementation is based on Hashicorp's <a>implementation</a>.
For a fast, adaptive radix tree implementation in Zig I'd recommend <a>art.zig</a>.
Example
```zig
comptime var radix = RadixTree(u32){};
comptime _ = radix.insert("foo", 1);
comptime _ = radix.insert("bar", 2);
const foo = radix.get("foo");
const bar = radix.getLongestPrefix("barfoo");
std.log.info("{}", .{foo}); //1
std.log.info("{}", .{bar}); //2
```
Benchmarks
To run the benchmarks, run <code>zig build bench</code>. Note that the benchmark is always ran as ReleaseFast.
edit build.zig if you want to enable other build modes as well.
Searches for 300 words, 50.000 times for 3 instances
<code>StringHashMap 0177ms 0175ms 0175ms
StringArrayHashMap 0228ms 0241ms 0241ms
RadixTree 0393ms 0389ms 0392ms</code> | []
|
https://avatars.githubusercontent.com/u/5048090?v=4 | zig-cairo | jackdbd/zig-cairo | 2021-01-12T23:44:55Z | 🪲 zig-idiomatic wrapper for cairo | main | 17 | 21 | 5 | 21 | https://api.github.com/repos/jackdbd/zig-cairo/tags | NOASSERTION | [
"cairo",
"graphics",
"wrapper",
"zig"
]
| 926 | false | 2025-03-18T11:29:36Z | true | false | unknown | github | []
| zig-cairo
<a></a>
Thin wrapper for the <a>cairo</a> 2D graphics library.
Tested on Zig version <strong>0.9.1</strong>.
🚧 Very much a work in progress... 🚧
Naming convention
As suggested in the <a>cairo Appendix</a>, the type names and method names of the original C library were changed to follow the <a>Zig Style Guide</a>. For example, a method like <code>cairo_set_source(cr, source)</code> in cairo becomes <code>cr.setSource(source)</code> in zig-cairo.
Installation
Clone the repo and jump into it:
<code>sh
git clone [email protected]:jackdbd/zig-cairo.git
cd zig-cairo</code>
In order to use this library and run the examples you will need zig version <strong>0.9.1</strong>. You can get it using <a>zigup</a>:
<code>sh
zigup fetch 0.9.1
zigup 0.9.1</code>
You will also need <a>cairo</a>, <a>pango</a>, <a>pangocairo</a>, <a>xcb</a>, and <a>xvfb</a> if you want to run some tests/examples in a virtual framebuffer. See <a>this script</a>.
Examples
You can find many examples in the <a>examples directory</a>.
Run <code>zig build --help</code> to see all the compilation targets.
Most examples generate a PNG. Here I use <a>feh</a> to view the generated file:
<code>sh
zig build rounded_rectangle && feh examples/generated/rounded_rectangle.png
zig build spirograph && feh examples/generated/spirograph.png
zig build text_extents && feh examples/generated/text_extents.png</code>
A few examples generate a SVG:
<code>sh
zig build surface_svg && inkscape examples/generated/test-image.svg</code>
Some other examples don't generate any image file. This one opens a window and renders cairo graphics inside of it (using a cairo <a>XCB</a> surface):
<code>sh
zig build surface_xcb</code>
If you installed <a>XVFB</a> you can also run this example in a virtual framebuffer:
<code>sh
xvfb-run --server-args="-screen 0 1024x768x24" zig build surface_xcb</code>
Tests
```sh
run all tests, in all modes (debug, release-fast, release-safe, release-small)
zig build test
run all tests, only in debug mode
zig build test-debug
``` | []
|
https://avatars.githubusercontent.com/u/5464072?v=4 | zig-ansi | nektro/zig-ansi | 2020-12-09T19:24:11Z | ANSI utilities for CLI usage in Zig. | master | 2 | 21 | 1 | 21 | https://api.github.com/repos/nektro/zig-ansi/tags | MIT | [
"zig",
"zig-package"
]
| 19 | false | 2025-05-21T20:33:19Z | true | false | unknown | github | []
| zig-ansi
<a></a>
<a></a>
<a></a>
<a></a>
<a></a>
ANSI utilities for CLI usage in Zig.
Zig
<ul>
<li>https://ziglang.org/</li>
<li>https://github.com/ziglang/zig</li>
<li>https://github.com/ziglang/zig/wiki/Community</li>
</ul>
Getting Started
Using https://github.com/nektro/zigmod, add a <code>git</code> type with a path of <code>https://github.com/nektro/zig-ansi</code>.
Usage
See <code>src/main.zig</code> or do <code>zig build run</code> to see examples.
See <code>src/lib.zig</code> for source code. | []
|
https://avatars.githubusercontent.com/u/11783095?v=4 | ilo_license_key | nrdmn/ilo_license_key | 2020-05-14T20:44:28Z | iLO license key library | master | 0 | 21 | 4 | 21 | https://api.github.com/repos/nrdmn/ilo_license_key/tags | - | [
"ilo",
"keygen",
"zig"
]
| 2 | false | 2025-05-14T17:14:15Z | true | false | unknown | github | []
| HP iLO license key validation library
This library validates HP iLO license keys. This is most definitely not a
keygen, but if you want to understand how license keys are constructed,
have a look at the unit tests. | []
|
https://avatars.githubusercontent.com/u/936155?v=4 | zig-csv | beho/zig-csv | 2020-12-31T15:31:40Z | Low-level CSV parser library for Zig language. | main | 1 | 18 | 4 | 18 | https://api.github.com/repos/beho/zig-csv/tags | MIT | [
"csv",
"zig"
]
| 41 | false | 2024-12-01T08:39:58Z | true | true | 0.13.0 | github | []
| zig-csv
Low-level CSV parser library for <a>Zig language</a>. Each non-empty line in input is parsed as one or more tokens of type <code>field</code>, followed by <code>row_end</code>.
<em>This library was conceived as Zig learning project and it was not used by me in production software.</em>
Features
<ul>
<li>Reads UTF-8 files.</li>
<li>Provides iterator interface to stream of tokens.</li>
<li>Handles quoted fields in which column/row separator can be used. Quote itself can be used in field by doubling it (e.g. <code>"This is quote: ""."</code>)</li>
<li>Configurable column separator (default <code>,</code>), row separator (<code>\n</code>) and quote (<code>"</code>).</li>
<li><strong>Currently only single byte characters.</strong></li>
<li>Parser does not allocate – caller provides a buffer that parser operates in. <strong>Buffer must be longer than a longest field in input.</strong></li>
</ul>
Example
Following code reads CSV tokens from a file while very naively printing them as table to standard output.
```zig
const std = @import("std");
const csv = @import("csv");
pub fn main() anyerror!void {
var arena = std.heap.ArenaAllocator.init(std.heap.page_allocator);
defer arena.deinit();
<code>const allocator = &arena.allocator;
var buffer = try allocator.alloc(u8, 4096);
const args = try std.process.argsAlloc(allocator);
defer std.process.argsFree(allocator, args);
if (args.len != 2) {
std.log.warn("Single arg is expected", .{});
std.process.exit(1);
}
const file = try std.fs.cwd().openFile(args[1], .{});
defer file.close();
var csv_tokenizer = try csv.CsvTokenizer(std.fs.File.Reader).init(file.reader(), buffer, .{});
const stdout = std.io.getStdOut().writer();
while (try csv_tokenizer.next()) |token| {
switch (token) {
.field => |val| {
try stdout.writeAll(val);
try stdout.writeAll("\t");
},
.row_end => {
try stdout.writeAll("\n");
},
}
}
</code>
}
``` | []
|
https://avatars.githubusercontent.com/u/3952805?v=4 | zig-bgfx-sdl2 | LakeByTheWoods/zig-bgfx-sdl2 | 2020-09-15T09:27:09Z | Minimal zig project to get bgfx running with sdl2 | master | 2 | 18 | 6 | 18 | https://api.github.com/repos/LakeByTheWoods/zig-bgfx-sdl2/tags | MIT | [
"bgfx",
"sdl2",
"zig",
"ziglang"
]
| 5 | false | 2025-01-24T17:07:51Z | true | false | unknown | github | []
| zig-bgfx-sdl2
Minimal zig project to get bgfx running with sdl2
SDL2 needs to be intalled on your system so that zig build can find it
To build and run:
<code>zig build fetch
zig build run</code> | []
|
https://avatars.githubusercontent.com/u/2859122?v=4 | mogwai | kooparse/mogwai | 2020-11-04T15:49:44Z | Graphic utility used to manipulate objects in 3D for scene editing (commonly called Gizmo). | master | 1 | 18 | 0 | 18 | https://api.github.com/repos/kooparse/mogwai/tags | - | [
"game-engine",
"gamedev",
"gizmo",
"graphics-engine",
"scene-editor",
"zig"
]
| 978 | false | 2025-05-09T06:05:54Z | true | false | unknown | github | []
| Mogwai
Graphic utility used to manipulate objects in 3D for scene editing (commonly called Gizmo).
It's a straightforward and simple Gizmo, all the manipulation is computed in this library
while it gives you all the verticies for your renderer; At the end,
you'll get a decomposed matrix (three vec3 for translation/rotation/scale).
This library uses only <a>zalgebra</a> and the <code>std</code>!
Examples
```zig
usingnamespace @import("mogwai");
pub fn main () void {
var gizmo = Mogwai(.{
.screen_width = 800,
.screen_height = 600,
.snap_axis = 0.5,
.snap_angle = 5
});
// Get all vertices for your renderer.
const xy_panel = gizmo.meshes.move_panels.xy;
const yz_panel = gizmo.meshes.move_panels.yz
// See https://github.com/kooparse/mogwai/blob/master/exemples/_glfw_opengl.zig#L62-L73
// for all meshes.
// Mode is an enum containing all different modes
// for the gizmo (move, rotate, scale, none).
var gizmo_mode = Mode.Move;
while(true) {
// After pulling cursor state and positions:
gizmo.setCursor(pos_x, pos_y, is_pressed);
// After updating the view matrix (camera moving...).
gizmo.setCamera(view, proj);
<code>// You just have to pass a mode and the model matrix from the
// selected object from your scene.
if (gizmo.manipulate(target_model_matrix, gizmo_mode)) |result| {
switch (result.mode) {
Mode.Move => {
target.transform.position = result.position;
},
Mode.Rotate => {
target.transform.rotation = result.rotation.extractRotation();
},
Mode.Scale => {
target.transform.scale = result.scale;
},
else => {},
}
}
// Draw all the meshes
your_renderer.draw(&yz_panel, gizmo.is_hover(GizmoItem.PanelYZ));
</code>
}
}
```
See https://github.com/kooparse/mogwai/blob/master/exemples/_glfw_opengl.zig for a real exemple.
Documentation
Config
Field | Type | Description
------------ | ------------- | -------------
screen_width | i32 | Width of the screen (required)
screen_height | i32 | Height of the screen (required)
dpi | i32 | Pixel ratio of your monitor
snap | ?f32 | Snap when dragging gizmo, value is equals to floor factor
arcball_radius | f32 | Radius of the rotation circles
arcball_thickness | f32 | Width of the rotation circle borders
panel_size| f32 | The width/height of panels
panel_offset| f32 | Offset of the panels from the origin position
panel_width| f32 | Plans width for panels
axis_length | f32 | Length of arrows
axis_size | f32 | The width/height of arrows
scale_box_size | f32 | Size of the scaler boxes
Contributing to the project
Don’t be shy about shooting any questions you may have. If you are a beginner/junior, don’t hesitate, I will always encourage you. It’s a safe place here. Also, I would be very happy to receive any kind of pull requests, you will have (at least) some feedback/guidance rapidly.
Behind screens, there are human beings, living any sort of story. So be always kind and respectful, because we all sheer to learn new things.
Thanks
This project is inspired by <a>tinygizmo</a> and <a>ImGuizmo</a>. | []
|
https://avatars.githubusercontent.com/u/53614543?v=4 | zitertools | zerobsv/zitertools | 2020-10-18T06:26:26Z | An improved version of the existing python itertools library that I created for Zig. | main | 0 | 17 | 0 | 17 | https://api.github.com/repos/zerobsv/zitertools/tags | MIT | [
"filter",
"iterator",
"itertools",
"itertools-library",
"python",
"zig"
]
| 1,517 | false | 2025-01-27T17:15:58Z | true | false | unknown | github | []
| Zig itertools
<a></a>
<a></a>
This is an attempt to port the itertools library from python to zig, in order to introduce a functional
paradigm to the language. Maintains efficiency by reducing temporary allocations, and moving through
slices using an iterator. The library also includes some constructs such as map, filter and reduce which
are part of the python builtin library which are essential for functional programming.
And of course, their compile time counterparts!
Suggestions and contributions are welcome.
NOTE: De-initializing the iterator is the responsibility of the user.
Generic Iterator
Iterators
Min
Max
Reduce
Map
Filter
Accumulate
Dropwhile
Filterfalse
Compress
Takewhile
Combinatoric Iterators
Powerset
Permutations
Lexicographically ordered
Efficient: Heap's method
Combinations
Generate from permutations
Twiddle
Product
Note: The library does not support generators yet
Sources
<a>itertools</a>
Martin Heinz, <a>Tour of Python Itertools</a>
MITx: 6.00.2x
Sedgewick R, Permutation Generation Methods, Princeton University
<a>ctregex</a> by Alex Naskos | []
|
https://avatars.githubusercontent.com/u/2286349?v=4 | zig-x86_64 | leecannon/zig-x86_64 | 2020-07-25T14:44:59Z | Support for x86_64 specific instructions (e.g. TLB flush), registers (e.g. control registers), and structures (e.g. page tables) | master | 0 | 17 | 2 | 17 | https://api.github.com/repos/leecannon/zig-x86_64/tags | MIT | [
"osdev",
"x86",
"x86-64",
"zig",
"zig-library",
"zig-package",
"ziglang"
]
| 307 | false | 2025-03-26T01:57:10Z | true | false | unknown | github | []
| zig-x86_64
<a></a>
<strong>I don't use this library anymore. I made this as a port of the rust crate but over time I have come to dislike the API.</strong>
<strong>As written it does not support self-hosted so will probably be deleted with the release of zig 0.11</strong>
This repo contains various functionality required to make an x86_64 kernel (following <a>Writing an OS in Rust</a>)
It is mainly a zig reimplementation of the rust crate <a>x86_64</a>.
It includes a few additonal types in the <code>x86_64.additional</code> namespace:
<ul>
<li><code>SerialPort</code> - Serial port type, mainly for debug output</li>
<li><code>SimplePic</code> - Reimplementation of <a>pic8259_simple</a></li>
</ul>
How to get
Gyro
<code>gyro add leecannon/x86_64</code>
Zigmod
<code>zigmod aq add 1/leecannon/x86_64</code>
Git
Submodule
<code>git submodule add https://github.com/leecannon/zig-x86_64 zig-x86_64</code>
Clone
<code>git clone https://github.com/leecannon/zig-x86_64</code> | []
|
https://avatars.githubusercontent.com/u/3932972?v=4 | gurl | ikskuh/gurl | 2020-05-13T23:17:54Z | A curl-like cli application to interact with Gemini sites. | master | 2 | 17 | 3 | 17 | https://api.github.com/repos/ikskuh/gurl/tags | MIT | [
"gemini",
"zig",
"ziglang"
]
| 97 | false | 2025-01-15T01:45:27Z | true | true | unknown | github | [
{
"commit": "bb2eced8ddf28114b3a1ff761c2d80b90b1a61e2.tar.gz",
"name": "zig-args",
"tar_url": "https://github.com/MasterQ32/zig-args/archive/bb2eced8ddf28114b3a1ff761c2d80b90b1a61e2.tar.gz.tar.gz",
"type": "remote",
"url": "https://github.com/MasterQ32/zig-args"
},
{
"commit": "fa75e1bc672952efa0cf06160bbd942b47f6d59b.tar.gz",
"name": "known-folders",
"tar_url": "https://github.com/ziglibs/known-folders/archive/fa75e1bc672952efa0cf06160bbd942b47f6d59b.tar.gz.tar.gz",
"type": "remote",
"url": "https://github.com/ziglibs/known-folders"
},
{
"commit": "830821a8736ca1bf7662b9c5fec9bfe9f0066ad3.tar.gz",
"name": "zig-network",
"tar_url": "https://github.com/MasterQ32/zig-network/archive/830821a8736ca1bf7662b9c5fec9bfe9f0066ad3.tar.gz.tar.gz",
"type": "remote",
"url": "https://github.com/MasterQ32/zig-network"
},
{
"commit": "42cac648593ce784944769dba52343871ac7824c.tar.gz",
"name": "zig-bearssl",
"tar_url": "https://github.com/MasterQ32/zig-bearssl/archive/42cac648593ce784944769dba52343871ac7824c.tar.gz.tar.gz",
"type": "remote",
"url": "https://github.com/MasterQ32/zig-bearssl"
}
]
| 👧 gurl
A <a>Gemini</a> command line interface similar to <a>curl</a> written in <a>Zig</a>.
Project State
<br/><input type='checkbox' class='w-4 h-4 text-green-500 bg-gray-100 border-gray-300 rounded focus:ring-blue-500 dark:focus:ring-blue-600 dark:ring-offset-gray-800 focus:ring-2 dark:bg-gray-700 dark:border-gray-600' checked disabled></input> Successful TLS 1.2 handshake
<br/><input type='checkbox' class='w-4 h-4 text-green-500 bg-gray-100 border-gray-300 rounded focus:ring-blue-500 dark:focus:ring-blue-600 dark:ring-offset-gray-800 focus:ring-2 dark:bg-gray-700 dark:border-gray-600' checked disabled></input> Successful GET request header exchange
<br/><input type='checkbox' class='w-4 h-4 text-green-500 bg-gray-100 border-gray-300 rounded focus:ring-blue-500 dark:focus:ring-blue-600 dark:ring-offset-gray-800 focus:ring-2 dark:bg-gray-700 dark:border-gray-600' checked disabled></input> Successful body download
<br/><input type='checkbox' class='w-4 h-4 text-green-500 bg-gray-100 border-gray-300 rounded focus:ring-blue-500 dark:focus:ring-blue-600 dark:ring-offset-gray-800 focus:ring-2 dark:bg-gray-700 dark:border-gray-600' checked disabled></input> header parsing
<br/><input type='checkbox' class='w-4 h-4 text-green-500 bg-gray-100 border-gray-300 rounded focus:ring-blue-500 dark:focus:ring-blue-600 dark:ring-offset-gray-800 focus:ring-2 dark:bg-gray-700 dark:border-gray-600' checked disabled></input> URL parser
<br/><input type='checkbox' class='w-4 h-4 text-green-500 bg-gray-100 border-gray-300 rounded focus:ring-blue-500 dark:focus:ring-blue-600 dark:ring-offset-gray-800 focus:ring-2 dark:bg-gray-700 dark:border-gray-600' checked disabled></input> DNS resolving
<br/><input type='checkbox' class='w-4 h-4 text-blue-600 bg-gray-100 border-gray-300 rounded focus:ring-blue-500 dark:focus:ring-blue-600 dark:ring-offset-gray-800 focus:ring-2 dark:bg-gray-700 dark:border-gray-600' disabled></input> MIME parsing
<br/><input type='checkbox' class='w-4 h-4 text-blue-600 bg-gray-100 border-gray-300 rounded focus:ring-blue-500 dark:focus:ring-blue-600 dark:ring-offset-gray-800 focus:ring-2 dark:bg-gray-700 dark:border-gray-600' disabled></input> All of the correct heading handling
<br/><input type='checkbox' class='w-4 h-4 text-green-500 bg-gray-100 border-gray-300 rounded focus:ring-blue-500 dark:focus:ring-blue-600 dark:ring-offset-gray-800 focus:ring-2 dark:bg-gray-700 dark:border-gray-600' checked disabled></input> Follow absolute redirects
<br/><input type='checkbox' class='w-4 h-4 text-blue-600 bg-gray-100 border-gray-300 rounded focus:ring-blue-500 dark:focus:ring-blue-600 dark:ring-offset-gray-800 focus:ring-2 dark:bg-gray-700 dark:border-gray-600' disabled></input> Follow relative redirects
<br/><input type='checkbox' class='w-4 h-4 text-blue-600 bg-gray-100 border-gray-300 rounded focus:ring-blue-500 dark:focus:ring-blue-600 dark:ring-offset-gray-800 focus:ring-2 dark:bg-gray-700 dark:border-gray-600' disabled></input> Pretty-printing and guidance messages for failed requests
<br/><input type='checkbox' class='w-4 h-4 text-blue-600 bg-gray-100 border-gray-300 rounded focus:ring-blue-500 dark:focus:ring-blue-600 dark:ring-offset-gray-800 focus:ring-2 dark:bg-gray-700 dark:border-gray-600' disabled></input> TOFU (trust on first use) for SSL connections
<br/><input type='checkbox' class='w-4 h-4 text-green-500 bg-gray-100 border-gray-300 rounded focus:ring-blue-500 dark:focus:ring-blue-600 dark:ring-offset-gray-800 focus:ring-2 dark:bg-gray-700 dark:border-gray-600' checked disabled></input> Implement primitive TOFU (store public key, not certificate)
<br/><input type='checkbox' class='w-4 h-4 text-blue-600 bg-gray-100 border-gray-300 rounded focus:ring-blue-500 dark:focus:ring-blue-600 dark:ring-offset-gray-800 focus:ring-2 dark:bg-gray-700 dark:border-gray-600' disabled></input> Implement correct TOFU (trust on first use) for SSL connections
<br/><input type='checkbox' class='w-4 h-4 text-blue-600 bg-gray-100 border-gray-300 rounded focus:ring-blue-500 dark:focus:ring-blue-600 dark:ring-offset-gray-800 focus:ring-2 dark:bg-gray-700 dark:border-gray-600' disabled></input> Client certificates
<br/><input type='checkbox' class='w-4 h-4 text-blue-600 bg-gray-100 border-gray-300 rounded focus:ring-blue-500 dark:focus:ring-blue-600 dark:ring-offset-gray-800 focus:ring-2 dark:bg-gray-700 dark:border-gray-600' disabled></input> temporary cert
<br/><input type='checkbox' class='w-4 h-4 text-blue-600 bg-gray-100 border-gray-300 rounded focus:ring-blue-500 dark:focus:ring-blue-600 dark:ring-offset-gray-800 focus:ring-2 dark:bg-gray-700 dark:border-gray-600' disabled></input> permanent cert
<br/><input type='checkbox' class='w-4 h-4 text-green-500 bg-gray-100 border-gray-300 rounded focus:ring-blue-500 dark:focus:ring-blue-600 dark:ring-offset-gray-800 focus:ring-2 dark:bg-gray-700 dark:border-gray-600' checked disabled></input> Use <a>XDG directories</a>
<br/><input type='checkbox' class='w-4 h-4 text-blue-600 bg-gray-100 border-gray-300 rounded focus:ring-blue-500 dark:focus:ring-blue-600 dark:ring-offset-gray-800 focus:ring-2 dark:bg-gray-700 dark:border-gray-600' disabled></input> Implement windows port
<br/><input type='checkbox' class='w-4 h-4 text-green-500 bg-gray-100 border-gray-300 rounded focus:ring-blue-500 dark:focus:ring-blue-600 dark:ring-offset-gray-800 focus:ring-2 dark:bg-gray-700 dark:border-gray-600' checked disabled></input> Port <code>zig-network</code> to windows
<br/><input type='checkbox' class='w-4 h-4 text-green-500 bg-gray-100 border-gray-300 rounded focus:ring-blue-500 dark:focus:ring-blue-600 dark:ring-offset-gray-800 focus:ring-2 dark:bg-gray-700 dark:border-gray-600' checked disabled></input> Implement correct config directory locating for windows
<br/><input type='checkbox' class='w-4 h-4 text-blue-600 bg-gray-100 border-gray-300 rounded focus:ring-blue-500 dark:focus:ring-blue-600 dark:ring-offset-gray-800 focus:ring-2 dark:bg-gray-700 dark:border-gray-600' disabled></input> Trust Anchor support for windows
Dependencies
<ul>
<li><a>Zig 0.6.0</a> or newer</li>
<li><a>BearSSL</a> (provided as submodule)</li>
<li><a>zig-network</a> (provided as submodule)</li>
</ul>
Build Instructions
<ol>
<li>Refresh submodules (<code>git submodule init</code>, <code>git submodule update</code>)</li>
<li>Build gurl (<code>zig build</code>)</li>
<li>Run <code>./zig-cache/bin/gurl</code> </li>
</ol>
Design Considerations
Give the user control over their system and make configuration easy.
Certificate Trust
<ul>
<li>accept any certificate</li>
<li>auto-accept the cert on first use (TOFU)</li>
<li>use CAs or ask user on first sight (TOFU+CA)</li>
<li>always ask on first sight (interactive TOFU)</li>
<li>auto-accept when first seen in a session (TOFU, no disk usage)</li>
<li>always ask when first seen in a session (interactive TOFU, no disk usage)</li>
</ul>
Future Plans
Correctly adhere to XDG standards and use <code>xdg-open</code>
TOFU Notes
Current implementation just stores the public key of the server and
not the certificate with fingerprint and everything
<blockquote>
That certificate's fingerprint and expiry date are saved in a
persistent database (like the .known_hosts file for SSH), associated
with the server's hostname.
</blockquote>
Client Certificate Process
<ul>
<li>Wait for specification update</li>
</ul>
Tools
Connect with OpenSSL:
<code>openssl s_client --connect domain.name -quiet -verify_quiet</code>
Dump DER certificate information:
<code>openssl x509 -in trust-store/mozz.us/cert-1.der -inform der -text</code>
Convert DER to PEM:
<code>openssl x509 -inform der -in trust-store/gemini.conman.org/cert-0.der -out conman.pem</code> | []
|
https://avatars.githubusercontent.com/u/3932972?v=4 | spu-mark-ii | ikskuh/spu-mark-ii | 2020-04-19T14:10:00Z | CPU and home computer project | master | 2 | 17 | 1 | 17 | https://api.github.com/repos/ikskuh/spu-mark-ii/tags | MIT | [
"assembler",
"cpu",
"spu-mark-ii",
"zig",
"ziglang"
]
| 30,654 | false | 2023-09-28T18:51:53Z | true | false | unknown | github | []
| The SPU Mark II Project
A project that focuses on the development and improvement of the <em>SPU Mark II</em> instruction
set architecture.
Another focus is development and creation of a concrete implementation of the CPU in VHDL
as well as building a small "home computer" around an FPGA board similar to other computers
from the 80ies.
SPU Mark II
The SPU Mark II is a 16 bit <em>RISC</em>ish cpu that uses the <a>stack machine</a>
approach instead of a <a>register machine</a> approach.
The instrution set is documented in <a>documentation/isa.md</a>.
Short feature list:
- Highly flexible instruction set
- Conditional instructions instead of special conditional jumps or movs
- Optional hardware multiplication/division units (WIP)
- Optional interrupt handling (WIP)
To get a feel for the instruction set, here's a small example for a <code>void puts(char*str)</code> function:
```asm
puts:
bpget ; function prologue
spget
bpset
<code>get 2 ; fetch arg 1
</code>
puts_loop:
ld8 [i0:peek] [f:yes]
[ex:nonzero] st8 0x4000 ; Use MMIO for text output
[ex:nonzero] add 1
[ex:nonzero] jmp puts_loop
pop
<code>bpget ; function epilogue
spset
bpset
ret
</code>
```
Ashet Home Computer
The <em>Ashet Home Computer</em> is a computer built on top of the <em>SPU Mark II</em> cpu and
provides a small environment to use the cpu.
Planned Features
<ul>
<li><a>MMU</a></li>
<li>Video Output (either FBAS or VGA)</li>
<li>Audio Output (signed 16 bit PCM)</li>
<li>SD Card Storage</li>
<li>Keyboard Interface</li>
<li>Joystick Port (C64 style)</li>
<li>UART interface</li>
</ul>
Current Memory Map
Note that this memory map right now does not utilize the MMU, so bus width is 16 bit.
| Range | Function |
|---------------------|--------------------|
| <code>0x0000</code> … <code>0x3FFF</code> | Builtin ROM |
| <code>0x4000</code> … <code>0x4FFF</code> | UART Interface |
| <code>0x6000</code> … <code>0x60FF</code> | 256 byte fast RAM |
| <code>0x6100</code> … <code>0x7FFF</code> | <em>Unmapped</em> |
| <code>0x8000</code> … <code>0xFFFF</code> | 32k byte slow RAM | | []
|
https://avatars.githubusercontent.com/u/12723818?v=4 | zig-xkbcommon | ifreund/zig-xkbcommon | 2020-10-14T21:56:33Z | [mirror] Zig bindings for xkbcommon | master | 0 | 16 | 3 | 16 | https://api.github.com/repos/ifreund/zig-xkbcommon/tags | MIT | [
"xkbcommon",
"zig"
]
| 78 | false | 2025-03-07T09:40:41Z | true | true | 0.14.0 | github | []
| zig-xkbcommon
<a>zig</a> 0.14 bindings for
<a>xkbcommon</a> that are a little
nicer to use than the output of <code>zig translate-c</code>.
The main repository is on <a>codeberg</a>,
which is where the issue tracker may be found and where contributions are accepted.
Read-only mirrors exist on <a>sourcehut</a>
and <a>github</a>.
Versioning
For now, zig-xkbcommon versions are of the form <code>0.major.patch</code>. A major version
bump indicates a zig-xkbcommon release that breaks API or requires a newer Zig
version to build. A patch version bump indicates a zig-xkbcommon release that is
fully backwards compatible.
For unreleased versions, the <code>-dev</code> suffix is used (e.g. <code>0.1.0-dev</code>).
The version of zig-xkbcommon currently has no direct relation to the upstream
xkbcommon version supported.
Breaking changes in zig-xkbcommon's API will be necessary until a stable Zig 1.0
version is released, at which point I plan to switch to a new versioning scheme
and start the version numbers with <code>1</code> instead of <code>0</code>. | [
"https://github.com/riverwm/river"
]
|
https://avatars.githubusercontent.com/u/4959032?v=4 | msgpack-zig | oleggator/msgpack-zig | 2020-07-11T17:05:57Z | MessagePack for Zig | master | 1 | 16 | 0 | 16 | https://api.github.com/repos/oleggator/msgpack-zig/tags | MIT | [
"messagepack",
"msgpack",
"zig"
]
| 50 | false | 2024-05-20T15:58:43Z | true | false | unknown | github | []
| MessagePack for Zig
Based on <a>github.com/tarantool/msgpuck</a>.
Stream API implementation progress
| Type | Encoding | Decoding |
|-------------------------|:-----------------------:|:--------:|
| generic | :white_check_mark: | |
| int (7-64 bit) | :white_check_mark: | |
| comptime int (7-64 bit) | :white_check_mark: | |
| float (32, 64 bit) | :white_check_mark: | |
| comptime float (64 bit) | :white_check_mark: | |
| bool | :white_check_mark: | |
| Optional | :white_check_mark: | |
| Struct | :white_check_mark: | |
| Pointer | :ballot_box_with_check: | |
| Map | :ballot_box_with_check: | |
| Array | :white_check_mark: | |
| Slice | :white_check_mark: | |
| Many | :white_check_mark: | |
| string | :white_check_mark: | |
| binary | :white_check_mark: | |
| extension | :white_check_mark: | |
| nil | :white_check_mark: | |
<ul>
<li>:white_check_mark: - implemented with unit tests</li>
<li>:ballot_box_with_check: - implemented without unit tests</li>
</ul> | []
|
https://avatars.githubusercontent.com/u/1059144?v=4 | zig.run | jlauman/zig.run | 2021-01-16T15:18:57Z | Run and play with Zig source code. | main | 0 | 16 | 1 | 16 | https://api.github.com/repos/jlauman/zig.run/tags | MIT | [
"playground",
"zig"
]
| 456 | false | 2025-02-12T05:43:10Z | false | false | unknown | github | []
| zig.run
<a>Run and play</a> with <a>Zig</a> source code.
Refer to the <a>wiki</a> for using zig.run as a snippet runner or service. | []
|
https://avatars.githubusercontent.com/u/4929546?v=4 | advent-of-code | pomadchin/advent-of-code | 2021-12-01T12:37:32Z | Advent of Code written in different languages. | main | 0 | 4 | 0 | 4 | https://api.github.com/repos/pomadchin/advent-of-code/tags | MIT | [
"advent-of-code",
"rust",
"scala",
"zig"
]
| 737 | false | 2025-05-08T22:17:42Z | false | false | unknown | github | []
| Advent of Code
<a></a>
<a>Advent of Code</a> written in different languages.
Scala 2021
There also exists an alternative <a>feature/rec-schemes</a> branch to practice <a>recursion schemes</a> using <a>Droste</a>
Encryption
All input files should be encrypted; i.e.:
```bash
single file
$ gpg --batch --passphrase "$GPG_PASSPHRASE_INPUTS" --symmetric --cipher-algo AES256 file.txt
multiple files
for file in $year/rust/src/<em>/</em>.txt; do
gpg --batch --passphrase "$GPG_PASSPHRASE_INPUTS" --symmetric --cipher-algo AES256 "$file"
done
```
Decription is done via a GitHub Actions step. | []
|
https://avatars.githubusercontent.com/u/10657551?v=4 | lamia | Black-Cat/lamia | 2021-06-19T07:14:52Z | Small sdf editor | master | 34 | 4 | 0 | 4 | https://api.github.com/repos/Black-Cat/lamia/tags | - | [
"3d",
"sdf",
"zig"
]
| 428 | false | 2025-04-12T14:12:58Z | true | false | unknown | github | []
| lamia
Small sdf editor
uses <a>nyancore</a>
Requirements
<ul>
<li>zig 0.11</li>
<li>Vulkan SDK (for developing, optional)</li>
</ul>
How to build?
Clone repository with all submodules
<code>git clone --recurse-submodules [email protected]:Black-Cat/lamia.git</code>
Cross compilation is available
Release for windows is build with <code>zig build -Dtarget=x86_64-windows-gnu -Drelease-fast=true</code>
Linux
<code>zig build</code>
Windows
<code>zig build -Dtarget=x86_64-windows-gnu</code>
If you develop vulkan code, it is recomended to use <code>-Dvulkan-validation=true</code> flag. It requires installed vulkand sdk with correct environment variables. Enabling this option will turn on vulkan validation layers.
You can enable tracing with <code>-Denable-tracing=true</code> and connect with tracy v0.8.
Hot to run?
Linux
<code>zig build run</code>
Windows
<code>zig build -Dtarget=x86_64-windows-gnu run</code>
It is also possible to pass path to scene that will be opened on the application start
```
zig build run -- ../scene.ls
or
./zig-out/bin/lamia ../scene.ls
```
Feedback
Create an issue here, or send email to iblackcatw(at)gmail.com or discord <code>Black Cat!#5337</code> | []
|
https://avatars.githubusercontent.com/u/3759175?v=4 | ston | Hejsil/ston | 2021-06-13T13:48:03Z | The Streaming Text Object Notation | master | 0 | 4 | 0 | 4 | https://api.github.com/repos/Hejsil/ston/tags | MIT | [
"deserialization",
"parser",
"serialization",
"zig",
"zig-library"
]
| 83 | false | 2024-09-13T12:54:21Z | false | false | unknown | github | []
| <code>ston</code> - Streaming Text Object Notation
A simple text format for streaming objects in a line based format.
Grammar
```
Lines <- Line<em>
Line <- Suffix</em> '=' VALUE '\n'
Suffix
<- '.' FIELD
/ '[' INDEX ']'
INDEX <- [^]\n]<em>
FIELD <- [^=.[\n]</em>
VALUE <- [^\n]*
```
Examples (json vs ston)
<code>json
{
"bool": true,
"int": 2,
"float": 1.1,
"string": "string",
"array": [ 1, 2, 3 ],
"nest": {
"int": 2,
"string": "string"
}
}</code>
<code>.bool=true
.int=2
.float=1.1
.string=string
.array[0]=1
.array[1]=2
.array[2]=3
.nest.int=2
.nest.string=string</code> | []
|
https://avatars.githubusercontent.com/u/473672?v=4 | hello-webgl | fabioarnold/hello-webgl | 2021-04-06T19:12:00Z | Hello WebGL in Zig | master | 0 | 4 | 1 | 4 | https://api.github.com/repos/fabioarnold/hello-webgl/tags | - | [
"webgl",
"webgl2",
"zig",
"ziglang"
]
| 285 | false | 2024-11-12T02:31:17Z | true | true | unknown | github | [
{
"commit": "27013efdea89e6f9b838b088e916fe7e55a828fa.tar.gz",
"name": "zalgebra",
"tar_url": "https://github.com/kooparse/zalgebra/archive/27013efdea89e6f9b838b088e916fe7e55a828fa.tar.gz.tar.gz",
"type": "remote",
"url": "https://github.com/kooparse/zalgebra"
}
]
| Hello WebGL in Zig
Build and run in your browser
```bash
fetch the source and build
git clone https://github.com/fabioarnold/hello-webgl
cd hello-webgl
zig build
run a local http server
python3 -m http.server
open http://localhost:8000 in your browser
``` | []
|
https://avatars.githubusercontent.com/u/8948701?v=4 | openbsd-ziglibc | semarie/openbsd-ziglibc | 2021-11-08T18:56:06Z | build a ZIG_LIBC environment for Zig, targeting OpenBSD | main | 0 | 4 | 1 | 4 | https://api.github.com/repos/semarie/openbsd-ziglibc/tags | ISC | [
"openbsd",
"zig"
]
| 4 | false | 2025-04-18T20:31:35Z | false | false | unknown | github | []
| OpenBSD ZIG_LIBC support
Simple shell script to build a <code>ZIG_LIBC</code> environment for <a>Zig</a> targeting <a>OpenBSD</a>.
Usage
<code>$ ./build-ziglibc.sh
usage: ./build-ziglibc.sh url output-dir</code>
<ul>
<li><em>url</em> : URL pointing to OpenBSD sets.</li>
</ul>
Typical url to use: https://cdn.openbsd.org/pub/OpenBSD/<em>version</em>/<em>platform</em>/
Please note that OpenBSD officially support only the two last
released versions. Snapshots url is also valid for targeting
-current, but be aware that it is a moving target.
Refer to <a>supported platforms</a>
list from OpenBSD site web for the name used.
<ul>
<li><em>output-dir</em> : where to put the environment.</li>
</ul>
Prefer absolute path: it will be used in generated <code>libc.conf</code> file.
The directory will be created.
Examples of url
<ul>
<li>OpenBSD 6.9 <a>amd64</a> (x86_64 on Linux world)</li>
</ul>
https://cdn.openbsd.org/pub/OpenBSD/6.9/amd64/
<ul>
<li>OpenBSD -current <a>i386</a></li>
</ul>
https://cdn.openbsd.org/pub/OpenBSD/snapshots/i386/
Use the environment
<code>$ ZIG_LIBC=path/to/amd64/libc.conf zig build-exe -target x86_64-openbsd -o tests/helloz tests/hello.zig
$ ZIG_LIBC=path/to/amd64/libc.conf zig cc -target x86_64-openbsd -o tests/helloc tests/hello.c</code>
Make shell wrapper
For easy use of crosscompilation, you could create a shell wrapper
named <code>x86_64-openbsd-cc</code>:
```
!/bin/sh
exec env ZIG_LIBC=path/to/amd64/libc.conf zig cc -target x86_64-openbsd "$@"
```
And do the same for <code>x86_64-openbsd-c++</code>, <code>x86_64-openbsd-ar</code>, … | []
|
https://avatars.githubusercontent.com/u/10657551?v=4 | nyancore | Black-Cat/nyancore | 2021-05-07T06:26:12Z | Small lib for my projects | master | 0 | 4 | 0 | 4 | https://api.github.com/repos/Black-Cat/nyancore/tags | MIT | [
"zig"
]
| 17,879 | false | 2025-04-12T14:11:06Z | true | false | unknown | github | []
| nyancore
Small lib for my personal projects
used in <a>lamia</a> sdf editor
Awesome libs used in this project
<ul>
<li>Dear ImGUI (with cImGui interface)</li>
<li>enet</li>
<li>glfw</li>
<li>glslang</li>
<li>tracy</li>
<li>vulkan-zig</li>
</ul>
Math implementation is based on cglm implementation
Tracing
If you have enabled tracing, add zone tracing code
```zig
const tracy = @import("tracy.zig");
var zone: tracy.Zone = tracy.Zone.start_color_from_file(@src(), null);
defer zone.end();
```
Different start functions control how color for zone is choosen. You can choose your own with <code>0xRRGGBB</code>
Frames are automaticaly traced in <code>Application</code> main loop
Use tracy v0.8 to connect to application | []
|
https://avatars.githubusercontent.com/u/40190339?v=4 | Wireworld | daneelsan/Wireworld | 2022-01-04T05:51:10Z | Wireworld: a Turing-complete cellular automaton suited for simulating logic gates and other real-world computer elements | master | 0 | 4 | 1 | 4 | https://api.github.com/repos/daneelsan/Wireworld/tags | - | [
"c",
"wireworld",
"wolfram-language",
"zig"
]
| 1,407 | false | 2025-03-10T04:28:12Z | true | false | unknown | github | []
| Wireworld
Wireworld is a Turing-complete cellular automaton first proposed by Brian Silverman in 1987 suited for simulating logic gates and other real-world computer elements.
Installation
Install the paclet (version <code>1.0.0</code>) from github releases:
<code>Mathematica
PacletInstall["https://github.com/daneelsan/Wireworld/releases/download/v1.0.0/Wireworld-1.0.0.paclet"]</code>
Usage
Load the Wireworld` package:
<code>Mathematica
Needs["Wireworld`"]</code>
Wireworld symbols:
<code>Mathematica
In[]:= Names["Wireworld`*"]
Out[]= {
"WireworldDraw",
"WireworldEvolve",
"WireworldPlot",
"WireworldStateQ",
"$WireworldFunctionRule",
"$WireworldNumberRule",
"$WireworldRule"
}</code>
Open the documentation of the <code>WireworldEvolve</code> function:
<code>Mathematica
NotebookOpen[Information[WireworldEvolve, "Documentation"]["Local"]]</code>
Examples
A Clock Generator
A period 12 electron clock generator:
```Mathematica
In[]:= state = {
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 3, 3, 3, 0, 3, 2, 1, 3, 3, 0, 0, 0},
{0, 3, 0, 0, 0, 3, 0, 0, 0, 0, 0, 3, 0, 0},
{0, 3, 0, 0, 0, 3, 0, 0, 0, 0, 0, 3, 0, 0},
{0, 3, 0, 0, 0, 2, 0, 0, 0, 0, 0, 3, 0, 0},
{0, 0, 3, 3, 1, 0, 0, 0, 0, 0, 0, 3, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 0, 0}
};
In[]:= ListAnimate[WireworldPlot /@ WireworldEvolve[state, 11]]
```
The Diode
A diode allows electrons to flow in only one direction:
```Mathematica
In[]:= state = {
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{3, 3, 2, 1, 3, 3, 3, 3, 2, 1, 3, 0, 3, 3, 2, 1, 3, 3, 3, 3, 2},
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{3, 3, 2, 1, 3, 3, 3, 3, 2, 0, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3},
{0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
};
In[]:= ListAnimate[WireworldPlot /@ WireworldEvolve[state, 8]]
```
The OR gate
Two clock generators sending electrons into an OR gate:
```Mathematica
In[]:= state = {
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 3, 3, 3, 3, 3, 3, 2, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 3, 0, 0, 0, 0, 0, 0, 0, 0, 3, 3, 3, 3, 2, 1, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 3, 3, 3, 1, 2, 3, 3, 3, 0, 0, 0, 0, 0, 0, 3, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 3, 3, 3, 3, 2, 1, 3},
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 2, 1, 3, 3, 3, 3, 2, 1, 0, 0, 0, 0, 0, 0, 3, 0, 0, 0, 0, 0, 0},
{0, 0, 3, 0, 0, 0, 0, 0, 0, 0, 0, 3, 3, 3, 3, 3, 3, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 3, 3, 3, 3, 3, 3, 3, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
};
In[]:= ListAnimate[WireworldPlot /@ WireworldEvolve[state, 20]]
```
Wolfram Paclet Repository
A copy of the lastest released paclet is in the Wolfram Paclet Repository (WPR):
https://resources.wolframcloud.com/PacletRepository/resources/DanielS/Wireworld/
Build
<ol>
<li>Build the <code>Wireworld</code> paclet using the <code>build_paclet.wls</code> wolframscript:</li>
</ol>
<code>sh
./scripts/build_paclet.wls</code>
The paclet will be placed under the <code>build</code> directory:
<code>sh
ls build/*.paclet # build/Wireworld-1.0.0.paclet</code>
<ol>
<li>Install the built paclet:</li>
</ol>
<code>Mathematica
PacletInstall["./build/Wireworld-1.0.0.paclet"]</code>
Build libWireworld
The <code>LibraryLink</code> library <code>libWireworld</code> contains the low-level functions <code>Wireworld`Library`WireworldStepImmutable</code> and <code>Wireworld`Library`WireworldStepMutable</code>. There are two ways to build it:
build_library.wls
Run <code>scripts/build_library.wls</code>:
<code>sh
./scripts/build_library.wls</code>
The library will be stored in <code>LibraryResources/$SystemID/</code>:
<code>sh
ls LibraryResources/MacOSX-ARM64 # libWireworld.dylib</code>
Note: this script only builds the library for your builtin <code>$SystemID</code>.
zig build
Use <code>zig build</code> (https://ziglang.org) to build the library:
<code>sh
zig version # 0.14.0
zig build</code>
The library will be stored in <code>LibraryResources/$SystemID/</code>:
<code>sh
ls LibraryResources/MacOSX-ARM64 # libWireworld.dylib</code>
One can also cross compile specifying the target:
<code>sh
zig build -Dtarget=x86_64-linux
ls LibraryResources/Linux-x86-64 # libWireworld.so</code>
The mapping between <code>zig targets</code> and <code>$SystemID</code> is:
<code>Mathematica
{
"Linux-x86-64" -> "x86_64-linux",
"MacOSX-x86-64" -> "x86_64-macos",
"Windows-x86-64" -> "x86_64-windows",
"MacOSX-ARM64" -> "aarch64-macos",
}</code>
Note: other targets will be stored in <code>zig-out/lib</code>.
The build configuration is specified in <code>build.zig</code>. If necessary, change the location of the Wolfram libraries and headers:
<code>zig
lib.addIncludeDir(...);
lib.addLibPath(...);</code> | []
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.