std: Fix detection of Linux kernel version

master
LemonBoy 2020-03-10 12:16:56 +01:00 committed by Andrew Kelley
parent 675f01f176
commit 3e93dce0a1
2 changed files with 15 additions and 8 deletions

View File

@ -1296,12 +1296,12 @@ pub const io_uring_files_update = struct {
};
pub const utsname = extern struct {
sysname: [65]u8,
nodename: [65]u8,
release: [65]u8,
version: [65]u8,
machine: [65]u8,
domainname: [65]u8,
sysname: [64:0]u8,
nodename: [64:0]u8,
release: [64:0]u8,
version: [64:0]u8,
machine: [64:0]u8,
domainname: [64:0]u8,
};
pub const HOST_NAME_MAX = 64;

View File

@ -201,8 +201,15 @@ pub const NativeTargetInfo = struct {
switch (Target.current.os.tag) {
.linux => {
const uts = std.os.uname();
const release = mem.toSliceConst(u8, @ptrCast([*:0]const u8, &uts.release));
if (std.builtin.Version.parse(release)) |ver| {
const release = mem.toSliceConst(u8, &uts.release);
// The release field may have several other fields after the
// kernel version
const kernel_version = if (mem.indexOfScalar(u8, release, '-')) |pos|
release[0..pos]
else
release;
if (std.builtin.Version.parse(kernel_version)) |ver| {
os.version_range.linux.range.min = ver;
os.version_range.linux.range.max = ver;
} else |err| switch (err) {