Allows Skia users to disable use of API_AVAILABLE in the Metal backend.

On certain older versions of the Clang toolchain, the use of the API_AVAILABLE
macro on symbols in C++ translation units causes the visibility of those
symbols to me treated as default instead of the hidden. This causes internal
symbols to be exposed from release dylibs.

This mechanism allows users of the toolchains that have not been updated to the
latest versions to disable the use of the macro in release configurations.

Change-Id: I656361770c2011cff4c1b252761b5d0f3d89edc5
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/277775
Auto-Submit: Chinmay Garde <chinmaygarde@google.com>
Commit-Queue: Brian Salomon <bsalomon@google.com>
Reviewed-by: Jim Van Verth <jvanverth@google.com>
Reviewed-by: Brian Salomon <bsalomon@google.com>
diff --git a/BUILD.gn b/BUILD.gn
index 28edea5..db110ee 100644
--- a/BUILD.gn
+++ b/BUILD.gn
@@ -28,6 +28,7 @@
   include_dirs = [ "." ]
 
   defines = []
+  cflags_objcc = []
   if (is_component_build) {
     defines += [ "SKIA_DLL" ]
   }
@@ -53,6 +54,17 @@
   } else if (skia_gl_standard == "webgl") {
     defines += [ "SK_ASSUME_WEBGL=1" ]
   }
+
+  # Some older versions of the Clang toolchain change the visibility of
+  # symbols decorated with API_AVAILABLE macro to be visible. Users of such
+  # toolchains suppress the use of this macro till toolchain updates are made.
+  if (is_mac || is_ios) {
+    if (skia_enable_api_available_macro) {
+      defines += [ "SK_ENABLE_API_AVAILABLE" ]
+    } else {
+      cflags_objcc += [ "-Wno-unguarded-availability" ]
+    }
+  }
 }
 
 # Skia internal APIs, used by Skia itself and a few test tools.