I made a quick udp-based echo server to see if zig could fit some basic requirements for a project. I see a lot of examples online doing std.os.socket(..) or std.os.recvfrom(...).
In my editor (neovim), I end up having to do std.os.linux.socket(...). I’m wondering if there were any changes to how the os part of the standard library was namespaced? I’m assuming my lsp or plugin is issue, but wanted to check with you all first to see if there’s any ideas.
Hit by it too. Hard. All the constants too. Still running into code I don’t want to add anything to because I don’t want to have to redo everything on a recompile.
Best course of action for std.os replacement is to search for the function in the 0.12.0 documentation.
Some functions, like exit, have cross platform replacements: std.process.exit
If you cannot find the function elsewhere (at least std.process and std.fs), use the std.posix call.
If you decide to use a call in a different package, check the compatibility of the return value. std.os in 0.11.0 converts errno error codes in zig errors.
maybe std.posix should be std.unix since it is easier to build a compat layer for them and then have a std.windows. given mac’s unix heritage not sure where that fits. put linux, freebsd, etc under std.unix;
if you want cross platform you use std.fs and the like. If you want general unix and don’t care about windows, use std.unix. simiar for windows.
if you want to do something special but it isn’t supported by the zig layer you are probably writing to std.unix and std.windows with some comptime logic in your code.
if you want to do something highly specific (io_uring, kqueue, IOCP) yo are writing to std.unix.linux, std.unix.freebsd, std.windows.
that makes the most sense to me.
(if you want to have a very clean hierachy unix/windows go under std.os.unix/windows. std.os might just be code to test what os you are on, get defaults for them etc… but no platform specific code. that all goes under std.os).