diff options
author | Tor Arne Vestbø <tor.arne.vestbo@qt.io> | 2021-06-22 00:11:58 +0200 |
---|---|---|
committer | Tor Arne Vestbø <tor.arne.vestbo@qt.io> | 2021-07-13 11:18:23 +0000 |
commit | a71d725e46cf694867400be2bd079b699e62301a (patch) | |
tree | b5407788353a94bc6cfc0a508757dedf5fe54030 /src/libs/utils/hostosinfo.cpp | |
parent | 9cd97e940b8fb4eadd6d42eaee79835b34d1804b (diff) |
Add workarounds for running under Rosetta on macOS
When Qt Creator is built as an Intel binary, and runs on
an Apple Silicon (ARM) Mac, it will be run via the Rosetta
translation layer. This means any process spawned by QtC,
including qmake, CMake, and lldb, will launch as x86_64
binaries as well.
For qmake and CMake, this affects their default choice of
build architecture, resulting in x86_64 builds of user
applications. We want to produce native arm64 apps, even
if Qt Creator itself isn't one, so we explicitly detect
the situation, and if Qt has an arm64 slice, we default
to arm64 builds.
The logic of adding CONFIG+=x86_64 to the qmake step has
been disabled, as the assumption that a single qmake run
and build will produce only a single architecture does no
longer hold. The corresponding logic in Qt was removed
in 2015 (qtbase f58e95f098c8d78a5f2db7729606126fe093cbdf).
In the case of lldb, running it as an x86_64 binary fails
to attach to the running application. We work around this
by using the 'arch' tool to explicitly launch it as an
arm64 binary. This works for debugging both arm64 and
x86_64 applications.
Change-Id: I65cc0f600223990f25c76cef18d927895e551260
Reviewed-by: Eike Ziller <eike.ziller@qt.io>
Diffstat (limited to 'src/libs/utils/hostosinfo.cpp')
-rw-r--r-- | src/libs/utils/hostosinfo.cpp | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/src/libs/utils/hostosinfo.cpp b/src/libs/utils/hostosinfo.cpp index c5f313d5ce7..78ed7f22867 100644 --- a/src/libs/utils/hostosinfo.cpp +++ b/src/libs/utils/hostosinfo.cpp @@ -35,6 +35,10 @@ #include <qt_windows.h> #endif +#ifdef Q_OS_MACOS +#include <sys/sysctl.h> +#endif + using namespace Utils; Qt::CaseSensitivity HostOsInfo::m_overrideFileNameCaseSensitivity = Qt::CaseSensitive; @@ -70,6 +74,17 @@ HostOsInfo::HostArchitecture HostOsInfo::hostArchitecture() #endif } +bool HostOsInfo::isRunningUnderRosetta() +{ +#ifdef Q_OS_MACOS + int translated = 0; + auto size = sizeof(translated); + if (sysctlbyname("sysctl.proc_translated", &translated, &size, nullptr, 0) == 0) + return translated; +#endif + return false; +} + void HostOsInfo::setOverrideFileNameCaseSensitivity(Qt::CaseSensitivity sensitivity) { m_useOverrideFileNameCaseSensitivity = true; |