Target macOS 10.12 when building LLVM

When enabling C++17, LLVM uses std::shared_mutex instead of its own
implementation. On macOS it requires version 10.12 (Sierra), while
Chrome must still support 10.11. However, we don't need LLVM as Reactor
backend, except for ARM64, but Mac devices with such CPU have a more
recent OS version.

llvm-10.0/llvm/include/llvm/Support/RWMutex.h:100:8: error: 'shared_mutex' is unavailable: introduced in macOS 10.12

Bug: b/174843857
Change-Id: Ie24095aa17d22072cfb9d655b87252cbea5209d0
Reviewed-on: https://swiftshader-review.googlesource.com/c/SwiftShader/+/52030
Reviewed-by: Antonio Maiorano <amaiorano@google.com>
Tested-by: Nicolas Capens <nicolascapens@google.com>
diff --git a/BUILD.gn b/BUILD.gn
index 2e02016..5bb08b0 100644
--- a/BUILD.gn
+++ b/BUILD.gn
@@ -15,6 +15,7 @@
 import("//build/config/c++/c++.gni")
 import("//build/config/compiler/compiler.gni")
 import("//build/config/mips.gni")
+import("//build/config/sysroot.gni")
 import("src/Reactor/reactor.gni")
 
 config("swiftshader_config") {
@@ -68,6 +69,14 @@
       "-fno-operator-names",
     ]
     cflags_cc = [ "-std=c++17" ]
+    # On macOS, some C++17 features used by LLVM require version 10.12.
+    if (is_mac && supports_llvm) {
+      cflags += [
+        "-isysroot",
+        rebase_path(sysroot, root_build_dir),
+        "-mmacosx-version-min=10.12.0",
+      ]
+    }
 
     defines += [
       "__STDC_CONSTANT_MACROS",
diff --git a/src/Reactor/reactor.gni b/src/Reactor/reactor.gni
index 3744d07..f8de370 100644
--- a/src/Reactor/reactor.gni
+++ b/src/Reactor/reactor.gni
@@ -9,9 +9,16 @@
 import("//build_overrides/build.gni")
 
 declare_args() {
-  # Subzero doesn't support ARM64, MIPS64, and PPC64.
+  # Subzero doesn't support ARM64, MIPS64, and PPC64 (only x86 and ARMv7a).
   supports_subzero = current_cpu != "arm64" && current_cpu != "mips64el" && current_cpu != "ppc64"
-  supports_llvm = is_linux || is_chromeos || is_fuchsia || is_win || is_android || is_mac
+}
+
+declare_args() {
+  supports_llvm = is_linux || is_chromeos || is_fuchsia || is_win || is_android
+    # LLVM uses C++17 features which require macOS 10.12, while Chrome's minimum platform for x86 is 10.11.
+    # Don't build LLVM on Mac, unless we have to. This only happens on ARM64 devices, which launched with 11.0.
+    # TODO(b/174843857): Remove check for !supports_subzero once Chrome supports macOS 10.12
+    || (is_mac && !supports_subzero)
 }
 
 declare_args() {