[osx] add support for rosetta
* [osx] add support for rosetta
When running an x64 vcpkg binary on arm64, we should still have host processor be arm64
* depend on get_host_processor in system_triplet
* format
* handle default case
* include header
* Robert CRs
MODIFY
src/vcpkg/base/system.cpp
src/vcpkg/base/system.cpp
#include <ctime>
+#if defined(__APPLE__)
+#include <sys/sysctl.h>
+#endif
+
using namespace vcpkg::System;
namespace vcpkg
@@ -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;

MODIFY
src/vcpkg/triplet.cpp
src/vcpkg/triplet.cpp
@@ -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)

[osx] add support for rosetta (#23)

* [osx] add support for rosetta

When running an x64 vcpkg binary on arm64, we should still have host processor be arm64

* depend on get_host_processor in system_triplet

* format

* handle default case

* include header

* Robert CRs