Revive windows support.

It had been broken for a while due to a (now fixed) bug in zig and a couple other problems.
This commit is contained in:
IntegratedQuantum 2023-06-21 11:20:18 +02:00
parent b0a358f63c
commit bf3a01ad95
3 changed files with 42 additions and 8 deletions

View File

@ -59,14 +59,21 @@ pub fn build(b: *std.build.Builder) !void {
"portaudio/src/common/pa_trace.c",
}, &[_][]const u8{"-g", "-O3"});
if(target.getOsTag() == .windows) {
// TODO: Choose a host API
// windows:
exe.addCSourceFiles(&[_][]const u8 {"portaudio/src/os/win/pa_win_coinitialize.c", "portaudio/src/os/win/pa_win_hostapis.c", "portaudio/src/os/win/pa_win_util.c", "portaudio/src/os/win/pa_win_waveformat.c", "portaudio/src/os/win/pa_win_wdmks_utils.c", "portaudio/src/os/win/pa_x86_plain_converters.c", }, &[_][]const u8{"-g", "-O3", "-DPA_USE_WASAPI"});
exe.addIncludePath("portaudio/src/os/win");
exe.linkSystemLibrary("ole32");
exe.linkSystemLibrary("winmm");
exe.linkSystemLibrary("uuid");
// WASAPI:
exe.addCSourceFiles(&[_][]const u8 {"portaudio/src/hostapi/wasapi/pa_win_wasapi.c"}, &[_][]const u8{"-g", "-O3"});
} else if(target.getOsTag() == .linux) {
// unix:
exe.addCSourceFiles(&[_][]const u8 {"portaudio/src/os/unix/pa_unix_hostapis.c", "portaudio/src/os/unix/pa_unix_util.c"}, &[_][]const u8{"-g", "-O3", "-DPA_USE_ALSA"});
exe.addIncludePath("portaudio/src/os/unix");
// ALSA:
exe.addCSourceFiles(&[_][]const u8 {"portaudio/src/hostapi/alsa/pa_linux_alsa.c"}, &[_][]const u8{"-g", "-O3"});
exe.linkSystemLibrary("alsa");
exe.linkSystemLibrary("asound");
} else {
std.log.err("Unsupported target: {}\n", .{ target.getOsTag() });
}

View File

@ -60,14 +60,32 @@ const Socket = struct {
}
fn receive(self: Socket, buffer: []u8, timeout: i32, resultAddress: *Address) ![]u8 {
var pfd = [1]os.pollfd {
.{.fd = self.socketID, .events = os.POLL.IN, .revents = undefined},
};
var length = try os.poll(&pfd, timeout);
if(length == 0) return error.Timeout;
if(builtin.os.tag == .windows) { // Of course Windows always has it's own special thing.
var pfd = [1]os.pollfd {
.{.fd = self.socketID, .events = std.c.POLL.RDNORM | std.c.POLL.RDBAND, .revents = undefined},
};
const length = os.windows.ws2_32.WSAPoll(&pfd, pfd.len, timeout); // TODO: #16122
if (length == os.windows.ws2_32.SOCKET_ERROR) {
switch (os.windows.ws2_32.WSAGetLastError()) {
.WSANOTINITIALISED => unreachable,
.WSAENETDOWN => return error.NetworkSubsystemFailed,
.WSAENOBUFS => return error.SystemResources,
// TODO: handle more errors
else => |err| return os.windows.unexpectedWSAError(err),
}
} else if(length == 0) {
return error.Timeout;
}
} else {
var pfd = [1]os.pollfd {
.{.fd = self.socketID, .events = os.POLL.IN, .revents = undefined},
};
const length = try os.poll(&pfd, timeout);
if(length == 0) return error.Timeout; return error.Timeout;
}
var addr: os.sockaddr.in = undefined;
var addrLen: os.socklen_t = @sizeOf(os.sockaddr.in);
length = try os.recvfrom(self.socketID, buffer, 0, @ptrCast(*os.sockaddr, &addr), &addrLen);
const length = try os.recvfrom(self.socketID, buffer, 0, @ptrCast(*os.sockaddr, &addr), &addrLen);
resultAddress.ip = addr.addr;
resultAddress.port = @byteSwap(addr.port);
return buffer[0..length];

View File

@ -1,5 +1,6 @@
const std = @import("std");
const Allocator = std.mem.Allocator;
const builtin = @import("builtin");
const main = @import("main.zig");
@ -29,6 +30,14 @@ pub const Compression = struct {
while(try walker.next()) |entry| {
if(entry.kind == .file) {
var relPath = entry.path;
if(builtin.os.tag == .windows) { // I hate you
const copy = try main.threadAllocator.dupe(u8, relPath);
std.mem.replaceScalar(u8, copy, '\\', '/');
relPath = copy;
}
defer if(builtin.os.tag == .windows) {
main.threadAllocator.free(relPath);
};
var len: [4]u8 = undefined;
std.mem.writeIntBig(u32, &len, @intCast(u32, relPath.len));
_ = try comp.write(&len);