#Check if target is posix

1 messages · Page 1 of 1 (latest)

tight lagoon
#

I've got some functions that should run depending on if the platform is posix or not. Is the way to do this to check if target is not windows or wasi? Feels like I could be missing some targets. Or if more were added in the future my code wouldn't work properly

wanton lion
#

you can use

const builtin = @import("builtin");

// somewhere else
if (builtin.target == .windows) ...```
Note its not the same as `std.builtin` but a generated file that fills in the `std.Target` struct
#

how you do the rest is up to you, it would make sense to check in build.zig and simply include correct files as a lib which have the same interface for your functions.

The other is to have it in one file that uses comptime to check the OS but that might be confusing

tight lagoon
#

Yeah, I'm aware I can check os like that. That's what I'm currently doing. Just seemed fragile to check for windows and wasi, so I was hoping for a better solution

switch (builtin.os.tag) {
    .windows, .wasi => nonPosixPath,
    else => posixPath,
};```
feral river