macos: don't assume that all macOS major versions are simple numeric values

This commit is contained in:
Tyler Wilding 2025-01-11 12:43:36 -05:00
parent 434484e5b5
commit 0a6fdb0412
No known key found for this signature in database
GPG Key ID: E294CCB423D02CF2
3 changed files with 10 additions and 5 deletions

View File

@ -2,6 +2,7 @@
#include "common/common_types.h"
#include "common/log/log.h"
#include "common/util/string_util.h"
#ifdef __APPLE__
#include <stdio.h>
@ -112,7 +113,7 @@ CpuInfo& get_cpu_info() {
return gCpuInfo;
}
std::optional<double> get_macos_version() {
std::optional<double> get_macos_major_version() {
#ifndef __APPLE__
return {};
#else
@ -124,7 +125,11 @@ std::optional<double> get_macos_version() {
return {};
}
try {
return std::stod(buffer);
std::string macos_major_version = buffer;
if (str_util::contains(buffer, ".")) {
macos_major_version = str_util::split_string(macos_major_version, ".")[0];
}
return std::stod(macos_major_version);
} catch (std::exception& e) {
lg::error("Error occured when attempting to convert sysctl value {} to number", buffer);
return {};

View File

@ -18,4 +18,4 @@ struct CpuInfo {
CpuInfo& get_cpu_info();
std::optional<double> get_macos_version();
std::optional<double> get_macos_major_version();

View File

@ -182,8 +182,8 @@ int main(int argc, char** argv) {
// Check if we are on a modern enough version of macOS so that AVX can be
// emulated via rosetta
#ifdef __APPLE__
auto macos_version = get_macos_version();
if (macos_version < 15.0) {
auto macos_major_version = get_macos_major_version();
if (macos_major_version < 15.0) {
lg::info(
"Your CPU does not support AVX. But the newer version of Rosetta supports it, update to "
"atleast Sequoia to run OpenGOAL!");