| ... | @@ -181,6 +181,7 @@ pub const NativeTargetInfo = struct { | ... | @@ -181,6 +181,7 @@ pub const NativeTargetInfo = struct { |
| 181 | ProcessFdQuotaExceeded, | 181 | ProcessFdQuotaExceeded, |
| 182 | SystemFdQuotaExceeded, | 182 | SystemFdQuotaExceeded, |
| 183 | DeviceBusy, | 183 | DeviceBusy, |
| | 184 | Unexpected, |
| 184 | }; | 185 | }; |
| 185 | | 186 | |
| 186 | /// Given a `CrossTarget`, which specifies in detail which parts of the target should be detected | 187 | /// Given a `CrossTarget`, which specifies in detail which parts of the target should be detected |
| ... | @@ -221,7 +222,44 @@ pub const NativeTargetInfo = struct { | ... | @@ -221,7 +222,44 @@ pub const NativeTargetInfo = struct { |
| 221 | } | 222 | } |
| 222 | }, | 223 | }, |
| 223 | .windows => { | 224 | .windows => { |
| 224 | // TODO Detect native operating system version. | 225 | var version_info: std.os.windows.RTL_OSVERSIONINFOW = undefined; |
| | 226 | version_info.dwOSVersionInfoSize = @sizeOf(@TypeOf(version_info)); |
| | 227 | |
| | 228 | const rc = std.os.windows.ntdll.RtlGetVersion(&version_info); |
| | 229 | switch (rc) { |
| | 230 | .SUCCESS => {}, |
| | 231 | else => return std.os.windows.unexpectedStatus(rc), |
| | 232 | } |
| | 233 | |
| | 234 | // Starting from the system infos build a NTDDI-like version |
| | 235 | // constant whose format is: |
| | 236 | // B0 B1 B2 B3 |
| | 237 | // `---` `` ``--> Sub-version (Starting from Windows 10 onwards) |
| | 238 | // \ `--> Service pack (Always zero in the constants defined) |
| | 239 | // `--> OS version (Major & minor) |
| | 240 | const os_ver: u16 = // |
| | 241 | @intCast(u16, version_info.dwMajorVersion & 0xff) << 8 | |
| | 242 | @intCast(u16, version_info.dwMinorVersion & 0xff); |
| | 243 | const sp_ver: u8 = 0; |
| | 244 | const sub_ver: u8 = if (os_ver >= 0xA000) subver: { |
| | 245 | // There's no other way to obtain this info beside |
| | 246 | // checking the build number against a known set of |
| | 247 | // values |
| | 248 | for ([_]u32{ |
| | 249 | 10240, 10586, 14393, 15063, 16299, 17134, 17763, |
| | 250 | 18362, 18363, |
| | 251 | }) |build, i| { |
| | 252 | if (version_info.dwBuildNumber < build) |
| | 253 | break :subver @truncate(u8, i); |
| | 254 | } |
| | 255 | // Unknown subversion, the OS is too new... |
| | 256 | break :subver 0; |
| | 257 | } else 0; |
| | 258 | |
| | 259 | const version: u32 = @as(u32, os_ver) << 16 | @as(u32, sp_ver) << 8 | sub_ver; |
| | 260 | |
| | 261 | os.version_range.windows.max = @intToEnum(Target.Os.WindowsVersion, version); |
| | 262 | os.version_range.windows.min = @intToEnum(Target.Os.WindowsVersion, version); |
| 225 | }, | 263 | }, |
| 226 | .macosx => { | 264 | .macosx => { |
| 227 | // TODO Detect native operating system version. | 265 | // TODO Detect native operating system version. |