windows: initial support for zig build test

Makes progress getting "zig build test" to work on windows.  Mostly
fixed issues around build configuration and added some branches throughout
the Zig code to return/throw errors for unimplemented parts.

I also added an initial implementation for getting the home dir.
This commit is contained in:
Jonathan Marler
2023-09-14 02:34:43 -06:00
parent e213a93fe3
commit a2e881ff4e
9 changed files with 89 additions and 24 deletions

View File

@@ -122,6 +122,9 @@ pub fn start(self: *Command, alloc: Allocator) !void {
else
@compileError("missing env vars");
if (builtin.os.tag == .windows)
@panic("start not implemented on windows");
// Fork
const pid = try std.os.fork();
if (pid != 0) {
@@ -187,6 +190,9 @@ fn setupFd(src: File.Handle, target: i32) !void {
/// Wait for the command to exit and return information about how it exited.
pub fn wait(self: Command, block: bool) !Exit {
if (builtin.os.tag == .windows)
@panic("wait not implemented on windows");
const res = if (block) std.os.waitpid(self.pid.?, 0) else res: {
// We specify NOHANG because its not our fault if the process we launch
// for the tty doesn't properly waitpid its children. We don't want
@@ -255,7 +261,7 @@ pub fn expandPath(alloc: Allocator, cmd: []const u8) !?[]u8 {
};
defer f.close();
const stat = try f.stat();
if (stat.kind != .directory and stat.mode & 0o0111 != 0) {
if (stat.kind != .directory and isExecutable(stat.mode)) {
return try alloc.dupe(u8, full_path);
}
}
@@ -265,6 +271,11 @@ pub fn expandPath(alloc: Allocator, cmd: []const u8) !?[]u8 {
return null;
}
fn isExecutable(mode: std.fs.File.Mode) bool {
if (builtin.os.tag == .windows) return true;
return mode & 0o0111 != 0;
}
test "expandPath: env" {
const path = (try expandPath(testing.allocator, "env")).?;
defer testing.allocator.free(path);