Merge "[freetype] Build freetype2 as a shared library."
diff --git a/BUILD.gn b/BUILD.gn
index 5f7fad0..af6c1e5 100644
--- a/BUILD.gn
+++ b/BUILD.gn
@@ -48,7 +48,16 @@
   ]
 }
 
-source_set("freetype2") {
+# Shared libs are disabled in host toolchain.
+shared_lib = (current_toolchain != host_toolchain)
+
+if (shared_lib) {
+  library_type = "shared_library"
+} else {
+  library_type = "source_set"
+}
+
+target(library_type, "freetype2") {
   sources = [
     "src/autofit/autofit.c",
     "src/base/ftbase.c",
@@ -94,6 +103,14 @@
     "FT_EXPORT(x)=x",
   ]
 
+  if (shared_lib) {
+    defines += [
+      "FT_EXPORT(x)=extern __attribute__(( visibility( \"default\" ) )) x",
+      "FT_EXPORT_DEF(x)=extern __attribute__(( visibility( \"default\" ) )) x",
+      "FT_EXPORT_VAR(x)=extern __attribute__(( visibility( \"default\" ) )) x",
+    ]
+  }
+
   public_configs = [ ":freetype_config" ]
 
   deps = [