Enable in-tree libc++ builds on iOS

Binary size regression of about 109kB is expected -- please add
thomasanderson@ and thakis@ to the bug.

BUG=945054
R=thakis

Change-Id: Iaca4178e3b23b55a36af55d119d2eda2b76ef71d
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1534897
Commit-Queue: Thomas Anderson <[email protected]>
Auto-Submit: Thomas Anderson <[email protected]>
Reviewed-by: Justin Cohen <[email protected]>
Reviewed-by: Rohit Rao <[email protected]>
Reviewed-by: Nico Weber <[email protected]>
Cr-Commit-Position: refs/heads/master@{#645001}
diff --git a/build/config/c++/BUILD.gn b/build/config/c++/BUILD.gn
index 84b1af4..abe3be0d 100644
--- a/build/config/c++/BUILD.gn
+++ b/build/config/c++/BUILD.gn
@@ -14,7 +14,7 @@
   # symbols are not exported.
   # TODO(thomasanderson): Set this to true by default once rL352899 is available
   # in MacOS's lldb.
-  libcxx_abi_unstable = !(is_mac && is_debug && is_component_build)
+  libcxx_abi_unstable = !((is_mac || is_ios) && is_debug && is_component_build)
 }
 
 # TODO(xiaohuic): https://crbug/917533 Crashes on internal ChromeOS build.
diff --git a/build/config/c++/c++.gni b/build/config/c++/c++.gni
index b444656..e12ebbe 100644
--- a/build/config/c++/c++.gni
+++ b/build/config/c++/c++.gni
@@ -11,7 +11,7 @@
   # Don't check in changes that set this to false for more platforms; doing so
   # is not supported.
   use_custom_libcxx =
-      is_fuchsia || is_android || is_mac || (is_win && is_clang) ||
+      is_fuchsia || is_android || is_mac || is_ios || (is_win && is_clang) ||
       (is_linux &&
        (!is_chromeos || default_toolchain != "//build/toolchain/cros:target"))
 
diff --git a/buildtools/third_party/libc++/BUILD.gn b/buildtools/third_party/libc++/BUILD.gn
index 02a501a..a021562 100644
--- a/buildtools/third_party/libc++/BUILD.gn
+++ b/buildtools/third_party/libc++/BUILD.gn
@@ -122,7 +122,9 @@
     defines += [ "_LIBCPP_EXTERN_TEMPLATE_TYPE_VIS=__attribute__((__visibility__(\"default\")))" ]
   }
   if (!libcxx_is_shared) {
-    if (is_mac && is_clang) {
+    # TODO(https://crbug.com/946629): Remove use_xcode_clang condition once
+    # XCode clang is updated to support -fvisibility-global-new-delete-hidden.
+    if ((is_mac || (is_ios && !use_xcode_clang)) && is_clang) {
       # We want operator new/delete to be private on Mac, but these functions
       # are implicitly created by the compiler for each translation unit, as
       # specified in the C++ spec 3.7.4p2, which makes them always have default
@@ -149,7 +151,7 @@
       ]
     }
   }
-  if (!is_mac && (is_asan || is_tsan || is_msan)) {
+  if (!is_mac && !is_ios && (is_asan || is_tsan || is_msan)) {
     # In {a,t,m}san configurations, operator new and operator delete will be
     # provided by the sanitizer runtime library.  Since libc++ defines these
     # symbols with weak linkage, and the *san runtime uses strong linkage, it
diff --git a/buildtools/third_party/libc++abi/BUILD.gn b/buildtools/third_party/libc++abi/BUILD.gn
index 8949236..e571b86 100644
--- a/buildtools/third_party/libc++abi/BUILD.gn
+++ b/buildtools/third_party/libc++abi/BUILD.gn
@@ -56,7 +56,7 @@
 
   # This file should really be included on linux as well, but that
   # would introduce an unwanted glibc 2.18 dependency.
-  if (is_fuchsia || (is_posix && !is_mac && !is_linux)) {
+  if (is_fuchsia || (is_posix && !is_mac && !is_ios && !is_linux)) {
     sources += [ "trunk/src/cxa_thread_atexit.cpp" ]
   }