add std.os.windows.subsystem

The original issue that #2445 wanted to fix was solved in the previous
commit. However it also exposed the subsystem in the standard library,
which is still useful. So that's done in this commit, and #2445 can be
closed.
master
Andrew Kelley 2019-07-05 14:08:56 -04:00
parent 0d84d52e37
commit 3ad9349f09
No known key found for this signature in database
GPG Key ID: 7C5F548F728501A9
1 changed files with 27 additions and 0 deletions

View File

@ -20,6 +20,33 @@ pub const shell32 = @import("windows/shell32.zig");
pub usingnamespace @import("windows/bits.zig");
/// `builtin` is missing `subsystem` when the subsystem is automatically detected,
/// so Zig standard library has the subsystem detection logic here. This should generally be
/// used rather than `builtin.subsystem`.
/// On non-windows targets, this is `null`.
pub const subsystem: ?builtin.SubSystem = blk: {
if (@hasDecl(builtin, "subsystem")) break :blk builtin.subsystem;
switch (builtin.os) {
.windows => {
if (builtin.is_test) {
break :blk builtin.SubSystem.Console;
}
const root = @import("root");
if (@hasDecl(root, "WinMain") or
@hasDecl(root, "wWinMain") or
@hasDecl(root, "WinMainCRTStartup") or
@hasDecl(root, "wWinMainCRTStartup"))
{
break :blk builtin.SubSystem.Windows;
} else {
break :blk builtin.SubSystem.Console;
}
},
.uefi => break :blk builtin.SubSystem.EfiApplication,
else => break :blk null,
}
};
pub const CreateFileError = error{
SharingViolation,
PathAlreadyExists,