Support Apple Silicon via Rosetta2 on MacOS Sequoia and Above (#3754)

This commit is contained in:
Tyler Wilding
2024-11-10 11:06:56 -05:00
committed by GitHub
parent e3efede029
commit f8058f2138
10 changed files with 120 additions and 17 deletions
+27
View File
@@ -3,6 +3,13 @@
#include "common/common_types.h"
#include "common/log/log.h"
#ifdef __APPLE__
#include <stdio.h>
#include <sys/sysctl.h>
#include <sys/types.h>
#endif
#ifdef _WIN32
// clang-format off
#define NOMINMAX
@@ -104,3 +111,23 @@ void setup_cpu_info() {
CpuInfo& get_cpu_info() {
return gCpuInfo;
}
std::optional<double> get_macos_version() {
#ifndef __APPLE__
return {};
#else
char buffer[128];
size_t bufferlen = 128;
auto ok = sysctlbyname("kern.osproductversion", &buffer, &bufferlen, NULL, 0);
if (ok != 0) {
lg::warn("Unable to check for `kern.osproductversion` to determine macOS version");
return {};
}
try {
return std::stod(buffer);
} catch (std::exception& e) {
lg::error("Error occured when attempting to convert sysctl value {} to number", buffer);
return {};
}
#endif
}