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

[osx] add support for rosetta #23

Merged
merged 6 commits into from
Mar 22, 2021
Merged
Show file tree
Hide file tree
Changes from 5 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
19 changes: 19 additions & 0 deletions src/vcpkg/base/system.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@

#include <ctime>

#if defined(__APPLE__)
#include <sys/sysctl.h>
#endif

using namespace vcpkg::System;

namespace vcpkg
Expand Down Expand Up @@ -55,6 +59,21 @@ namespace vcpkg
return to_cpu_architecture(procarch).value_or_exit(VCPKG_LINE_INFO);
#else // ^^^ defined(_WIN32) / !defined(_WIN32) vvv
#if defined(__x86_64__) || defined(_M_X64)
#if defined(__APPLE__)
// check for rosetta 2 emulation
// see docs:
// https://developer.apple.com/documentation/apple_silicon/about_the_rosetta_translation_environment#3616845
int is_translated = 0;
size_t size = sizeof is_translated;
if (sysctlbyname("sysctl.proc_translated", &is_translated, &size, nullptr, 0) == -1)
{
return CPUArchitecture::X64;
}
if (is_translated == 1)
{
return CPUArchitecture::ARM64;
}
#endif // ^^^ macos
return CPUArchitecture::X64;
#elif defined(__x86__) || defined(_M_X86) || defined(__i386__)
return CPUArchitecture::X86;
Expand Down
30 changes: 16 additions & 14 deletions src/vcpkg/triplet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,8 @@ namespace vcpkg

static Triplet system_triplet()
{
#if defined(_WIN32)
auto host_proc = System::get_host_processor();
#if defined(_WIN32)
switch (host_proc)
{
case System::CPUArchitecture::X86: return Triplet::from_canonical_name("x86-windows");
Expand All @@ -86,24 +86,26 @@ namespace vcpkg
default: return Triplet::from_canonical_name("x86-windows");
}
#elif defined(__APPLE__)
return Triplet::from_canonical_name("x64-osx");
switch (host_proc)
strega-nil marked this conversation as resolved.
Show resolved Hide resolved
{
case System::CPUArchitecture::X64: return Triplet::from_canonical_name("x64-osx");
case System::CPUArchitecture::ARM64: return Triplet::from_canonical_name("arm64-osx");
default: return Triplet::from_canonical_name("x64-osx");
}
#elif defined(__FreeBSD__)
return Triplet::from_canonical_name("x64-freebsd");
#elif defined(__OpenBSD__)
return Triplet::from_canonical_name("x64-openbsd");
#elif defined(__GLIBC__)
#if defined(__aarch64__)
return Triplet::from_canonical_name("arm64-linux");
#elif defined(__arm__)
return Triplet::from_canonical_name("arm-linux");
#elif defined(__s390x__)
return Triplet::from_canonical_name("s390x-linux");
#elif (defined(__ppc64__) || defined(__PPC64__) || defined(__ppc64le__) || defined(__PPC64LE__)) && \
defined(__BYTE_ORDER__) && (__BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__)
return Triplet::from_canonical_name("ppc64le-linux");
#else
return Triplet::from_canonical_name("x64-linux");
#endif
switch (host_proc)
{
case System::CPUArchitecture::X64: return Triplet::from_canonical_name("x64-linux");
case System::CPUArchitecture::ARM: return Triplet::from_canonical_name("arm-linux");
case System::CPUArchitecture::ARM64: return Triplet::from_canonical_name("arm64-linux");
case System::CPUArchitecture::S390X: return Triplet::from_canonical_name("s390x-linux");
case System::CPUArchitecture::PPC64LE: return Triplet::from_canonical_name("ppc64le-linux");
default: return Triplet::from_canonical_name("x64-linux");
}
#else
return Triplet::from_canonical_name("x64-linux-musl");
#endif
Expand Down