| author | |
| committer | |
| log | 2922a483099a0a45d4cbaf2bc7c3b43fcebe4e77 |
| tree | 01c8aa5d1b3332a119baf57db2101a02fd5f5434 |
| parent | fc10c9c4ce40570d0abeda764f1bd76b3e79af61 |
3 files changed, 63 insertions(+), 37 deletions(-)
lib/std/target.zig+14| ... | @@ -109,6 +109,20 @@ pub const Target = struct { | ... | @@ -109,6 +109,20 @@ pub const Target = struct { |
| 109 | /// Latest Windows version that the Zig Standard Library is aware of | 109 | /// Latest Windows version that the Zig Standard Library is aware of |
| 110 | pub const latest = WindowsVersion.win10_20h1; | 110 | pub const latest = WindowsVersion.win10_20h1; |
| 111 | 111 | ||
| 112 | /// Compared against build numbers reported by the runtime to distinguish win10 versions, | ||
| 113 | /// where 0x0A000000 + index corresponds to the WindowsVersion u32 value. | ||
| 114 | pub const known_win10_build_numbers = [_]u32{ | ||
| 115 | 10240, //win10 | ||
| 116 | 10586, //win10_th2 | ||
| 117 | 14393, //win_rs1 | ||
| 118 | 15063, //win_rs2 | ||
| 119 | 16299, //win_rs3 | ||
| 120 | 17134, //win_rs4 | ||
| 121 | 17763, //win_rs5 | ||
| 122 | 18362, //win_19h1 | ||
| 123 | 19041, //win_20h1 | ||
| 124 | }; | ||
| 125 | |||
| 112 | pub const Range = struct { | 126 | pub const Range = struct { |
| 113 | min: WindowsVersion, | 127 | min: WindowsVersion, |
| 114 | max: WindowsVersion, | 128 | max: WindowsVersion, |
lib/std/zig/system.zig+4-37| ... | @@ -14,6 +14,7 @@ const process = std.process; | ... | @@ -14,6 +14,7 @@ const process = std.process; |
| 14 | const Target = std.Target; | 14 | const Target = std.Target; |
| 15 | const CrossTarget = std.zig.CrossTarget; | 15 | const CrossTarget = std.zig.CrossTarget; |
| 16 | const macos = @import("system/macos.zig"); | 16 | const macos = @import("system/macos.zig"); |
| 17 | pub const windows = @import("system/windows.zig"); | ||
| 17 | 18 | ||
| 18 | pub const getSDKPath = macos.getSDKPath; | 19 | pub const getSDKPath = macos.getSDKPath; |
| 19 | 20 | ||
| ... | @@ -249,43 +250,9 @@ pub const NativeTargetInfo = struct { | ... | @@ -249,43 +250,9 @@ pub const NativeTargetInfo = struct { |
| 249 | } | 250 | } |
| 250 | }, | 251 | }, |
| 251 | .windows => { | 252 | .windows => { |
| 252 | var version_info: std.os.windows.RTL_OSVERSIONINFOW = undefined; | 253 | const detected_version = windows.detectRuntimeVersion(); |
| 253 | version_info.dwOSVersionInfoSize = @sizeOf(@TypeOf(version_info)); | 254 | os.version_range.windows.min = detected_version; |
| 254 | 255 | os.version_range.windows.max = detected_version; | |
| 255 | switch (std.os.windows.ntdll.RtlGetVersion(&version_info)) { | ||
| 256 | .SUCCESS => {}, | ||
| 257 | else => unreachable, | ||
| 258 | } | ||
| 259 | |||
| 260 | // Starting from the system infos build a NTDDI-like version | ||
| 261 | // constant whose format is: | ||
| 262 | // B0 B1 B2 B3 | ||
| 263 | // `---` `` ``--> Sub-version (Starting from Windows 10 onwards) | ||
| 264 | // \ `--> Service pack (Always zero in the constants defined) | ||
| 265 | // `--> OS version (Major & minor) | ||
| 266 | const os_ver: u16 = @intCast(u16, version_info.dwMajorVersion & 0xff) << 8 | | ||
| 267 | @intCast(u16, version_info.dwMinorVersion & 0xff); | ||
| 268 | const sp_ver: u8 = 0; | ||
| 269 | const sub_ver: u8 = if (os_ver >= 0x0A00) subver: { | ||
| 270 | // There's no other way to obtain this info beside | ||
| 271 | // checking the build number against a known set of | ||
| 272 | // values | ||
| 273 | const known_build_numbers = [_]u32{ | ||
| 274 | 10240, 10586, 14393, 15063, 16299, 17134, 17763, | ||
| 275 | 18362, 19041, | ||
| 276 | }; | ||
| 277 | var last_idx: usize = 0; | ||
| 278 | for (known_build_numbers) |build, i| { | ||
| 279 | if (version_info.dwBuildNumber >= build) | ||
| 280 | last_idx = i; | ||
| 281 | } | ||
| 282 | break :subver @truncate(u8, last_idx); | ||
| 283 | } else 0; | ||
| 284 | |||
| 285 | const version: u32 = @as(u32, os_ver) << 16 | @as(u32, sp_ver) << 8 | sub_ver; | ||
| 286 | |||
| 287 | os.version_range.windows.max = @intToEnum(Target.Os.WindowsVersion, version); | ||
| 288 | os.version_range.windows.min = @intToEnum(Target.Os.WindowsVersion, version); | ||
| 289 | }, | 256 | }, |
| 290 | .macos => { | 257 | .macos => { |
| 291 | var scbuf: [32]u8 = undefined; | 258 | var scbuf: [32]u8 = undefined; |
lib/std/zig/system/windows.zig created+45| ... | @@ -0,0 +1,45 @@ | ||
| 1 | // SPDX-License-Identifier: MIT | ||
| 2 | // Copyright (c) 2015-2020 Zig Contributors | ||
| 3 | // This file is part of [zig](https://ziglang.org/), which is MIT licensed. | ||
| 4 | // The MIT license requires this copyright notice to be included in all copies | ||
| 5 | // and substantial portions of the software. | ||
| 6 | const std = @import("std"); | ||
| 7 | |||
| 8 | pub const WindowsVersion = std.Target.Os.WindowsVersion; | ||
| 9 | |||
| 10 | /// Returns the highest known WindowsVersion deduced from reported runtime information. | ||
| 11 | /// Discards information about in-between versions we don't differentiate. | ||
| 12 | pub fn detectRuntimeVersion() WindowsVersion { | ||
| 13 | var version_info: std.os.windows.RTL_OSVERSIONINFOW = undefined; | ||
| 14 | version_info.dwOSVersionInfoSize = @sizeOf(@TypeOf(version_info)); | ||
| 15 | |||
| 16 | switch (std.os.windows.ntdll.RtlGetVersion(&version_info)) { | ||
| 17 | .SUCCESS => {}, | ||
| 18 | else => unreachable, | ||
| 19 | } | ||
| 20 | |||
| 21 | // Starting from the system infos build a NTDDI-like version | ||
| 22 | // constant whose format is: | ||
| 23 | // B0 B1 B2 B3 | ||
| 24 | // `---` `` ``--> Sub-version (Starting from Windows 10 onwards) | ||
| 25 | // \ `--> Service pack (Always zero in the constants defined) | ||
| 26 | // `--> OS version (Major & minor) | ||
| 27 | const os_ver: u16 = @intCast(u16, version_info.dwMajorVersion & 0xff) << 8 | | ||
| 28 | @intCast(u16, version_info.dwMinorVersion & 0xff); | ||
| 29 | const sp_ver: u8 = 0; | ||
| 30 | const sub_ver: u8 = if (os_ver >= 0x0A00) subver: { | ||
| 31 | // There's no other way to obtain this info beside | ||
| 32 | // checking the build number against a known set of | ||
| 33 | // values | ||
| 34 | var last_idx: usize = 0; | ||
| 35 | for (WindowsVersion.known_win10_build_numbers) |build, i| { | ||
| 36 | if (version_info.dwBuildNumber >= build) | ||
| 37 | last_idx = i; | ||
| 38 | } | ||
| 39 | break :subver @truncate(u8, last_idx); | ||
| 40 | } else 0; | ||
| 41 | |||
| 42 | const version: u32 = @as(u32, os_ver) << 16 | @as(u16, sp_ver) << 8 | sub_ver; | ||
| 43 | |||
| 44 | return @intToEnum(WindowsVersion, version); | ||
| 45 | } | ||