Skip to content
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
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
34 changes: 9 additions & 25 deletions src/vcpkg/triplet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,37 +76,21 @@ namespace vcpkg
static Triplet system_triplet()
{
#if defined(_WIN32)
auto host_proc = System::get_host_processor();
switch (host_proc)
{
case System::CPUArchitecture::X86: return Triplet::from_canonical_name("x86-windows");
case System::CPUArchitecture::X64: return Triplet::from_canonical_name("x64-windows");
case System::CPUArchitecture::ARM: return Triplet::from_canonical_name("arm-windows");
case System::CPUArchitecture::ARM64: return Triplet::from_canonical_name("arm64-windows");
default: return Triplet::from_canonical_name("x86-windows");
}
StringLiteral operating_system = "windows";
#elif defined(__APPLE__)
return Triplet::from_canonical_name("x64-osx");
StringLiteral operating_system = "osx";
#elif defined(__FreeBSD__)
return Triplet::from_canonical_name("x64-freebsd");
StringLiteral operating_system = "freebsd";
#elif defined(__OpenBSD__)
return Triplet::from_canonical_name("x64-openbsd");
StringLiteral operating_system = "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");
StringLiteral operating_system = "linux";
#else
return Triplet::from_canonical_name("x64-linux");
#endif
#else
return Triplet::from_canonical_name("x64-linux-musl");
StringLiteral operating_system = "linux-musl";
#endif
auto host_proc = System::get_host_processor();
auto canonical_name = Strings::format("%s-%s", to_zstring_view(host_proc), operating_system);
return Triplet::from_canonical_name(std::move(canonical_name));
}

Triplet default_triplet(const VcpkgCmdArguments& args)
Expand Down