pub const WindowsVersion = enum(u32) Latest Windows version that the Zig Standard Library is aware of
Compared against build numbers reported by the runtime to distinguish win10 versions, where 0x0A000000 + index corresponds to the WindowsVersion u32 value.
pub inline fn isAtLeast(ver: WindowsVersion, min_ver: WindowsVersion) boolpub fn parse(str: []const u8) !WindowsVersionpub fn format(wv: WindowsVersion, w: *std.Io.Writer) std.Io.Writer.Error!voidThis function is defined to serialize a Zig source code representation of this type, that, when parsed, will deserialize into the same data.
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330 pub const WindowsVersion = enum(u32) {
nt4 = 0x04000000,
win2k = 0x05000000,
xp = 0x05010000,
ws2003 = 0x05020000,
vista = 0x06000000,
win7 = 0x06010000,
win8 = 0x06020000,
win8_1 = 0x06030000,
win10 = 0x0A000000, //aka win10_th1
win10_th2 = 0x0A000001,
win10_rs1 = 0x0A000002,
win10_rs2 = 0x0A000003,
win10_rs3 = 0x0A000004,
win10_rs4 = 0x0A000005,
win10_rs5 = 0x0A000006,
win10_19h1 = 0x0A000007,
win10_vb = 0x0A000008, //aka win10_19h2
win10_mn = 0x0A000009, //aka win10_20h1
win10_fe = 0x0A00000A, //aka win10_20h2
win10_co = 0x0A00000B, //aka win10_21h1
win10_ni = 0x0A00000C, //aka win10_21h2
win10_cu = 0x0A00000D, //aka win10_22h2
win11_zn = 0x0A00000E, //aka win11_21h2
win11_ga = 0x0A00000F, //aka win11_22h2
win11_ge = 0x0A000010, //aka win11_23h2
win11_dt = 0x0A000011, //aka win11_24h2
win11_br = 0x0A000012, //aka win11_25h2
win11_kr = 0x0A000013, //aka win11_26h1
_,
/// Latest Windows version that the Zig Standard Library is aware of
pub const latest = WindowsVersion.win11_kr;
/// Compared against build numbers reported by the runtime to distinguish win10 versions,
/// where 0x0A000000 + index corresponds to the WindowsVersion u32 value.
pub const known_win10_build_numbers = [_]u32{
10240, //win10 aka win10_th1
10586, //win10_th2
14393, //win10_rs1
15063, //win10_rs2
16299, //win10_rs3
17134, //win10_rs4
17763, //win10_rs5
18362, //win10_19h1
18363, //win10_vb aka win10_19h2
19041, //win10_mn aka win10_20h1
19042, //win10_fe aka win10_20h2
19043, //win10_co aka win10_21h1
19044, //win10_ni aka win10_21h2
19045, //win10_cu aka win10_22h2
22000, //win11_zn aka win11_21h2
22621, //win11_ga aka win11_22h2
22631, //win11_ge aka win11_23h2
26100, //win11_dt aka win11_24h2
26200, //win11_br aka win11_25h2
28000, //win11_kr aka win11_26h1
};
/// Returns whether the first version `ver` is newer (greater) than or equal to the second version `ver`.
pub inline fn isAtLeast(ver: WindowsVersion, min_ver: WindowsVersion) bool {
return @backingInt(ver) >= @backingInt(min_ver);
}
pub const Range = struct {
min: WindowsVersion,
max: WindowsVersion,
pub inline fn includesVersion(range: Range, ver: WindowsVersion) bool {
return @backingInt(ver) >= @backingInt(range.min) and
@backingInt(ver) <= @backingInt(range.max);
}
/// Checks if system is guaranteed to be at least `version` or older than `version`.
/// Returns `null` if a runtime check is required.
pub inline fn isAtLeast(range: Range, min_ver: WindowsVersion) ?bool {
if (@backingInt(range.min) >= @backingInt(min_ver)) return true;
if (@backingInt(range.max) < @backingInt(min_ver)) return false;
return null;
}
};
pub fn parse(str: []const u8) !WindowsVersion {
return std.meta.stringToEnum(WindowsVersion, str) orelse
@fromBackingInt(@intCast(std.fmt.parseInt(u32, str, 0) catch
return error.InvalidOperatingSystemVersion));
}
/// This function is defined to serialize a Zig source code representation of this
/// type, that, when parsed, will deserialize into the same data.
pub fn format(wv: WindowsVersion, w: *std.Io.Writer) std.Io.Writer.Error!void {
if (std.enums.tagName(WindowsVersion, wv)) |name| {
var vecs: [2][]const u8 = .{ ".", name };
return w.writeVecAll(&vecs);
} else {
return w.print("@enumFromInt(0x{X:0>8})", .{wv});
}
}
}
Based on NTDDI version constants from https://docs.microsoft.com/en-us/cpp/porting/modifying-winver-and-win32-winnt