Make stage2 start.zig work on Windows

This commit is contained in:
Martin Wickham
2021-09-01 14:32:02 -05:00
parent 3b09262c12
commit d6e87da47b

View File

@@ -28,6 +28,8 @@ comptime {
if (@typeInfo(@TypeOf(root.main)).Fn.calling_convention != .C) {
@export(main2, .{ .name = "main" });
}
} else if (builtin.stage2_os == .windows) {
@export(wWinMainCRTStartup2, .{ .name = "wWinMainCRTStartup" });
} else {
if (!@hasDecl(root, "_start")) {
@export(_start2, .{ .name = "_start" });
@@ -96,6 +98,11 @@ fn callMain2() noreturn {
exit2(0);
}
fn wWinMainCRTStartup2() callconv(.C) noreturn {
root.main();
exit2(0);
}
fn exit2(code: usize) noreturn {
switch (native_os) {
.linux => switch (builtin.stage2_arch) {
@@ -148,11 +155,16 @@ fn exit2(code: usize) noreturn {
},
else => @compileError("TODO"),
},
.windows => {
ExitProcess(@truncate(u32, code));
},
else => @compileError("TODO"),
}
unreachable;
}
extern "kernel32" fn ExitProcess(exit_code: u32) callconv(.C) noreturn;
////////////////////////////////////////////////////////////////////////////////
fn _DllMainCRTStartup(