From 1fdc534e675419a6e50e3c85f4e73fd6be73b697 Mon Sep 17 00:00:00 2001
From: Bouke van der Bijl <i@bou.ke>
Date: Wed, 7 Apr 2021 20:49:01 +0200
Subject: [PATCH] ruby: use x86_64 binary on M1 macs (#25756)

---
 src/ruby/tools/platform_check.rb | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/src/ruby/tools/platform_check.rb b/src/ruby/tools/platform_check.rb
index 52237fee82f..f2cfb68ea94 100644
--- a/src/ruby/tools/platform_check.rb
+++ b/src/ruby/tools/platform_check.rb
@@ -29,7 +29,12 @@ module PLATFORM
   end
 
   def PLATFORM.architecture
-    case RbConfig::CONFIG['host_cpu']
+    host_cpu = RbConfig::CONFIG['host_cpu']
+
+    # When we're on arm in macOS, we can rely on Rosetta and use the x86_64 binary
+    return 'x86_64' if RbConfig::CONFIG['host_os'] =~ /darwin/ && host_cpu =~ /arm/
+
+    case host_cpu
       when /x86_64/
         'x86_64'
       else