Ziggit Blog

Ziggit Blog

@ziggit-blog

Publisher

83

Posts

Posts by Ziggit Blog

An edge case for Io.Dir.realpath*() functions

An edge case for Io.Dir.realpath*() functions

Hi everyone, This was the topic that finally motivated my first post here. Not to try and litigate it, but try and understand it, and perhaps ask what to do about an edge case if the long considered removal were to be accepted one day. I’m pretty new to Zig, but feel I’ve gotten pretty far. I’v...

0
Partial workaround for missing `decls` param to `@Struct`

Partial workaround for missing `decls` param to `@Struct`

I just had plain c.sdl* functions and I decided that I want to strip them to sdl.* Gnerally it is just about trying to find a way to create decls for comptime generated struct (As a probably a lot of people tried: example1, example2). And I found one way! In zig you can do following: // It is...

Ziggit Blog Ziggit Blog · Rust ·
0
Pride Meetup - Portland OR

Pride Meetup - Portland OR

I know there are a few of us in Portland, and pride is this weekend. Anyone want to meet up for lunch on Sunday after the parade? If nobody suggests an alternative, my default plan is Veggie Grill @ 1PM since it’s easy and near the festival/parade route. I’m open to suggestions though, I rarely...

0
[Roc] How Our Rust-to-Zig Rewrite is Going

[Roc] How Our Rust-to-Zig Rewrite is Going

Richard’s style of writing is less similar to mine than Andrew’s or Mitchell’s: he reads as a bit more generous and takes time to say things that I might just leave to a reader to notice. Excellent move, to move up this blog post ahead of the 0.1.0 announcement, given current events 😉 Anyway,...

Ziggit Blog Ziggit Blog · Rust ·
0
How to deal with `undefined` buffers in ReleaseSafe mode

How to deal with `undefined` buffers in ReleaseSafe mode

I’d really like to use ReleaseSafe builds by default, but I keep finding them unreasonably slow. A common source of slowdowns is var large_buf: [N]u8 = undefined. If you have something like that in the hot path, it has meaningful impact. I’ve seen some other thread that memset is not actually as...

Ziggit Blog Ziggit Blog · Rust ·
0
std.Io.{Reader,Writer} and positional reads/writes

std.Io.{Reader,Writer} and positional reads/writes

I currently try to implement an fs for which I require positional reads/writes. For testing purposes I would like to have the implementation only take *std.Io.Reader and *std.Io.Writer instead of an *std.Io.File, but I noticed that the interfaces don’t expose positional reads/writes, not even se...

Ziggit Blog Ziggit Blog · Rust ·
0
Embed binary data at compile time

Embed binary data at compile time

Hey 🙂 this is my first Post and also my first attempts at metaprogramming. For my Project im working on, i needed some icons and found them in the form of SVGs. Because i want this project to be small and minimal, and because i need the icons the whole time the Program is running, i want to em...

Ziggit Blog Ziggit Blog · Rust ·
0
Parsing ZON with optional fields

Parsing ZON with optional fields

Hello, i would like to write zon in such a way that, i could omit struct fields and their value would default to whatever code i write for them example // when i parse this, i check if the optional bool is present in the zon. // if not, default it to "false" const Foo = struct { required_int...

0
Railroad Diagrams

Railroad Diagrams

Railroad It’s a railroad diagram generator that comes with a live server for editing. This all started as a search for a way to add railroad diagrams to https://ziggy-lang.io and ended up in a small rabbit hole. I’ll soon add this to Zine to let authors place a diagram source in their cont...

0
Vendoring Zig Compiler as Library

Vendoring Zig Compiler as Library

Hi all, I’ve been working on a node editor using Vulkan and Wayland. I am playing around with creating my own version of MaxMSP, which is a node editor that can be used essentially to create sound graphs where each node is a source, a filter, etc. It is often used for prototyping, but also for o...

0
A question on a switch of a comptime known value

A question on a switch of a comptime known value

this is a function from my vector library, it sets the X axis of a vector (the first element in a SIMD vector) to the provided value. question is: how would the compiler handles this given that dimensions is a comptime_int and so it is comptime known, would it make a copy of the function for eac...

Ziggit Blog Ziggit Blog · Rust ·
0
Testing a command line argument parser

Testing a command line argument parser

I wrote a small command line argument parser and I would now like to test it. The parser takes a std.process.Args.Iterator for initialization like so: const args: std.process.Args = .{ .vector = &.{ "--asdf", "--qwerty", "--", "-abc", "waow", "woah", "hmmm" }, }; var iter: ArgsIterator = .in...

0
Zero Sugar Added Jam: the Zig gamejam!

Zero Sugar Added Jam: the Zig gamejam!

Zero Sugar Added A zig-only game jam, with a unique gimmick for each jam, focused on limiting you in fun ways! A couple of months ago, me, @evaleek and @Sietse2202 decided we wanted to host a zig gamejam to show our love for the language, game development, and the community! As said above, the...

Ziggit Blog Ziggit Blog · Rust ·
0
Mass delete your cached files!

Mass delete your cached files!

decache Have you ever thought to yourself: “Gosh dang it, all these .zig-cache directories are taking up so much space on my disk, but I have so many projects it would take AGES to clean them all up! What ever could I do?” decache lets you easily clean up all directories that match a pattern,...

0
Segmentation fault on `shrinkToLen`

Segmentation fault on `shrinkToLen`

Hello, i am having an issue where i am getting seg fault on a seemingly random spot of the code. using a step debugger, the path to crash is -> array_list.zig 1142:26 -> allocator.zig 360:18 -> allocator.zig 448:5 -> compiler_rt.zig 684:14 Segmentation fault at address 0x7f0d40580000 lib/std/m...

Ziggit Blog Ziggit Blog · Rust ·
0
Using build.zig as a library

Using build.zig as a library

I am writing an application that needs, at runtime, to download resources from the internet and pre-process them. But I want to skip the work on subsequent launches. This seems exactly the problem solved by build.zig. Is there a nice way to re-use that in my application? The brute-force would be...

Ziggit Blog Ziggit Blog · Rust ·
0
Runtime Array creation

Runtime Array creation

Hi, recently ive been having to create runtime arrays where i have some data to iterate over and append it to an array, and although i have a way that works (and even think is the proper/accepted way) One of my usecases: create an array of the cli arguments. Solution: pub fn argsToArray(gpa: st...

Ziggit Blog Ziggit Blog · Rust ·
0
Custom tagging

Custom tagging

Is there are feature on this site so that I could add custom tags to users? For example: It would be nice to be able to add a note to people to say what project they’re working on (if they’ve shared it). That way I’m not relying on my memory to realise “Oh, that’s the one that’s working on a che...

0
Run step with elevated priviledges

Run step with elevated priviledges

I have am making an application that requires CAP_NET_RAW. I would like to include a convenience run step so I can change my current workflow: zig build sudo zig-out/bin/gatorcat --log-level err dc --ifname enx00e04c68006a --recv-timeout-us 50000 --config-file eni.zon to this: zig build run --...

Ziggit Blog Ziggit Blog · DevOps ·
0
C import overflows

C import overflows

Trying to port one of my projects to 0.16 but getting a failure on C import: src/main.zig:986:12: error: C import failed const tb = @cImport({ thread 111408 panic: integer overflow /usr/local/lib/zig/std/zig/ErrorBundle.zig:218:27: 0x123d049 in renderErrorMessage (build) s...

Ziggit Blog Ziggit Blog · C/C++ ·
0
Static Maps

Static Maps

I need to create a map with amino acids as keys and values that represent their mass (f32). Amino acids, the building blocks of proteins, are represented by a single capital letter–there are just 20 of them. I created the working solution below that uses string keys, but is there something simila...

Ziggit Blog Ziggit Blog · Rust ·
0
Minimal zig-ts-mode for emacs

Minimal zig-ts-mode for emacs

https://codeberg.org/krl/zig-ts-mode Hello all fellow emacsians, i have made a minimalist ts mode for emacs that i have been running for a while now. The other zig-ts-modes i have found have either been incomplete or outdated, as well as containing a lot of stuff that i don’t need and/or unders...

0
Logging !?Entry errors and continuing

Logging !?Entry errors and continuing

I’ve been writing a small program (that I’m hoping to showcase soon!) that needs to walk a directory tree to do its job. The basic code I want to write is as follows: while (walker.next()) |ok| { const entry = ok orelse break; // walker is finished // do stuff with entry... } else |err|...

0
Threaded and Evented coexistence

Threaded and Evented coexistence

Just to clean mess in my head. Let’s suppose that we have two “execution contexts”: under Io.Threaded under Io.Evented And shared struct with Io.Mutex used guard As far as I understand the way of safely access to this struct is use “neitral” 3rd Io - std.Io.Threaded.global_single_thr...

0
The Three-Io Problem

The Three-Io Problem

Just to clean mess in my head. Let’s suppose that we have two “execution contexts”: under Io.Threaded under Io.Evented And shared struct with Io.Mutex used guard As far as I understand the way of safely access to this struct is use “neitral” 3rd Io - std.Io.Threaded.global_single_thr...

0
`deinit` `.empty` MultiArrayList

`deinit` `.empty` MultiArrayList

Hello, I was wondering how MultiArrayList.deinit interacts with a MultiArrayList obtained with .empty? I see empty is defined as follows: pub const empty: Self = .{ .bytes = undefined, .len = 0, .capacity = 0, }; … and deinit as follows: /// <SNIP> fn allocatedBytes(self: Self) []a...

Ziggit Blog Ziggit Blog · Rust ·
0
Simd operation for combining multiple u64 values

Simd operation for combining multiple u64 values

I have (almost) never done anything with simd operations. Time to play around with it. When I want to bitwise combine the following (chess) struct would that be a good candidate for simd (instead of ‘manually’ combine all fields with another Threats struct)? Operations like and, or, xor. Or so...

Ziggit Blog Ziggit Blog · Rust ·
0
Playing with zig and assembly

Playing with zig and assembly

assembly-zig I spent some time learning assembly and took the opportunity to do so while also trying to interact with Zig code from assembly and vice-versa. I learned a lot about calling conventions, X86 assembly, Zig – at the time 0.16.0 wasn’t tagged yet so I also got to experiment with the...

Ziggit Blog Ziggit Blog · Assembly · Rust ·
0
Diagnostics (again)

Diagnostics (again)

I finally hit a scenario where i need dynamic error messages to be shown to an end user for binary decoder i am busy with. This naturally led me to discover the diagnostics pattern, which I see has been discussed a few times on this forum. The idea made a lot of sense and I looked at some example...

0
Wssup - simple WebSocket client library

Wssup - simple WebSocket client library

wssup - simple WebSocket client library Hi Ziggit! A couple of months ago I was writing a NetworkTables client in Zig and needed a WebSocket client library (the standard library only has WebSocket server support). So I used karlseguin’s websocket.zig, but I didn’t like it because of how bulky...

0
Ignore dependency build.zig.zon `paths` in build script

Ignore dependency build.zig.zon `paths` in build script

I’m trying to include licenses / readmes from my dependencies in my project, as well as bundle dependency source code with my releases to comply with copyleft licenses (Im statically compiling to a lone executable). However, some of my dependencies exclude their readme/license from their build.zi...

Ziggit Blog Ziggit Blog · Rust ·
0
Using freetype c in zig

Using freetype c in zig

const std = @import("std"); const Io = std.Io; const pow = std.math.pow; const gl = @cImport({ @cDefine("GLAD_GL_IMPLEMENTATION", ""); @cInclude("glad/gl.h"); @cDefine("GLFW_INCLUDE_NONE", ""); @cInclude("GLFW/glfw3.h"); @cInclude("GL/gl.h"); }); const ftp = @cImport({ @cI...

Ziggit Blog Ziggit Blog · Rust ·
0
Lobsters Interview with mitchellh

Lobsters Interview with mitchellh

I found this a nice antidote to the emotionally charged Zig news cycle of the last 24 hours. a lot to love, but this line made me smile: Zig is just getting better and better. They focus a lot on compilation tooling and even removed language features to improve compilation speed, mind blowing....

0
Zig Asset Bundler

Zig Asset Bundler

Zig Asset Bundler Compress and embed directories into your Zig executable. This is a first initial release, I plan to use it in Zine because the Zine executable needs to contain all the assets that are part of the template website you get when you run zine init. As the readme says, I would l...

Ziggit Blog Ziggit Blog · Rust ·
0