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