zig

fork of https://codeberg.org/ziglang/zig
Log | Files | Refs | README | LICENSE

commit 3ad9349f09e5afdacd64b8ab257ae1d09859f48a (tree)
parent 0d84d52e37923aab3c7f44b20b1490d6c0fbaac5
Author: Andrew Kelley <andrew@ziglang.org>
Date:   Fri,  5 Jul 2019 14:08:56 -0400

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.

Diffstat:
Mstd/os/windows.zig | 27+++++++++++++++++++++++++++
1 file changed, 27 insertions(+), 0 deletions(-)

diff --git a/std/os/windows.zig b/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,