Support all operating systems, even hobby OSes, with a "bring your own OS layer" in the std lib #3784
Labels
accepted
This proposal is planned.
os-bring-your-own
The "Bring Your Own Operating System" abstraction layer
proposal
This issue suggests modifications. If it also has the "accepted" label then it is planned.
standard library
This issue involves writing Zig code for the standard library.
Milestone
The
std.Target.Os
enum recognizes the following operating systems:This list is the list of targets that LLVM supports + zen (a hobby OS not maintained for over 1 year) + UEFI.
It doesn't make sense to put every hobby OS into this list, but it does make sense to support them! It should be possible for people to take advantage of Zig's cross platform abstractions without having to get support for their hobby OS upstreamed into Zig.
I propose to do this with 2 things:
other
tag tostd.Target.Os
pub fn main()
)This allows hobby OS developers to maintain a zig package that makes the zig standard library support their OS. Application developers could use it like this:
Next, standard library abstractions will detect when they should utilize this. If the operating system is POSIX compliant, then many things will Just Work. For example,
std.os.read
is currently defined like this:system
in this refers to:Here we would change
else => struct{},
to look for@import("root").os
if it was provided. With this modification, as long as the OS package defined all the constants (such asfd_t
andEISDIR
), thenstd.os.write
would end up calling the write function from the hobby OS package, and everything Just Works.Some abstractions may not work so smoothly; in this case there could be code that looks something like this:
Really, the check for the "other" OS isn't even necessary. Allowing applications to override fundamental OS functions could be useful on any operating system.
With this proposal implemented, Zig would have very near first class support for all operating systems. The main difference between upstream-recognized OSes and "other" OSes would be where the support is maintained - upstream zig std lib, or in a third party "OS layer" package.
cc @pixelherodev
The text was updated successfully, but these errors were encountered: