Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix current CPU architecture detection with rosetta2 #11376

Merged
merged 2 commits into from
Nov 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 9 additions & 7 deletions src/common/utility.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -127,15 +127,10 @@ static QLatin1String platform()
QByteArray Utility::userAgentString()
{
return QStringLiteral("Mozilla/5.0 (%1) mirall/%2 (%3, %4-%5 ClientArchitecture: %6 OsArchitecture: %7)")
.arg(platform(),
OCC::Version::displayString(),
.arg(platform(), OCC::Version::displayString(),
// accessing the theme to fetch the string is rather difficult
// since this is only needed server-side to identify clients, the app name (as of 2.9, the short name) is good enough
qApp->applicationName(),
QSysInfo::productType(),
QSysInfo::kernelVersion(),
QSysInfo::buildCpuArchitecture(),
QSysInfo::currentCpuArchitecture())
qApp->applicationName(), QSysInfo::productType(), QSysInfo::kernelVersion(), QSysInfo::buildCpuArchitecture(), Utility::currentCpuArch())
.toLatin1();
}

Expand Down Expand Up @@ -622,6 +617,13 @@ QString Utility::formatRFC1123Date(const QDateTime &date)
return date.toUTC().toString(RFC1123PatternC());
}

#ifndef Q_OS_MAC
QString Utility::currentCpuArch()
{
return QSysInfo::currentCpuArchitecture();
}
#endif

} // namespace OCC

QDebug operator<<(QDebug debug, nanoseconds in)
Expand Down
3 changes: 3 additions & 0 deletions src/common/utility.h
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,9 @@ OCSYNC_EXPORT Q_DECLARE_LOGGING_CATEGORY(lcUtility)

OCSYNC_EXPORT QDateTime parseRFC1123Date(const QString &date);
OCSYNC_EXPORT QString formatRFC1123Date(const QDateTime &date);

// replacement for QSysInfo::currentCpuArchitecture() that respects macOS's rosetta2
OCSYNC_EXPORT QString currentCpuArch();
} // Utility namespace
/** @} */ // \addtogroup

Expand Down
21 changes: 21 additions & 0 deletions src/common/utility_mac.mm
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@
#import <Foundation/NSFileManager.h>
#import <Foundation/NSUserDefaults.h>

#include <sys/sysctl.h>

namespace OCC {

void Utility::setupFavLink(const QString &folder)
Expand Down Expand Up @@ -255,4 +257,23 @@
}
#endif

QString Utility::currentCpuArch()
{
static const QString rv = []() {
int ret = 0;
size_t size = sizeof(ret);

// ret will be 1 if the process is translated (most likely with rosetta2)
if (sysctlbyname("sysctl.proc_translated", &ret, &size, nullptr, 0) != -1) {
if (errno != ENOENT) {
return QStringLiteral("arm64");
}
}

return QSysInfo::currentCpuArchitecture();
}();

return rv;
}

} // namespace OCC
2 changes: 1 addition & 1 deletion src/gui/updater/updater.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ QUrlQuery Updater::getQueryParams()
query.addQueryItem(QStringLiteral("platform"), platform);
query.addQueryItem(QStringLiteral("oem"), theme->appName());
query.addQueryItem(QStringLiteral("buildArch"), QSysInfo::buildCpuArchitecture());
query.addQueryItem(QStringLiteral("currentArch"), QSysInfo::currentCpuArchitecture());
query.addQueryItem(QStringLiteral("currentArch"), Utility::currentCpuArch());

// client updater server is now aware of packaging format
// TODO: add packaging string for other supported platforms, too
Expand Down
3 changes: 2 additions & 1 deletion src/libsync/theme.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,8 @@ QString Theme::aboutVersions(Theme::VersionFormat format) const
gitUrl = gitSHA1(format) + br;
}
}
QStringList sysInfo = {QStringLiteral("OS: %1-%2").arg(QSysInfo::productType(), QSysInfo::kernelVersion())};
QStringList sysInfo = {QStringLiteral("OS: %1-%2 (build arch: %3, CPU arch: %4)")
.arg(QSysInfo::productType(), QSysInfo::kernelVersion(), QSysInfo::buildCpuArchitecture(), Utility::currentCpuArch())};
// may be called by both GUI and CLI, but we can display QPA only for the former
if (auto guiApp = qobject_cast<QGuiApplication *>(qApp)) {
sysInfo << QStringLiteral("QPA: %1").arg(guiApp->platformName());
Expand Down
Loading