Commit 3ad9349f09
Changed files (1)
std
std/os/windows.zig
@@ -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,