Import Fontations build rules

Import the Fontations build rules from Chromium's //skia/BUILD.gn into
PDFium's. The build rules are gated behind the `pdf_enable_fontations`
GN arg, similar to how Fontations was first introduced into Chromium.

Bug: 42271123
Change-Id: Ifd632dd928ace32883c27f17d2826e1007dfd3ec
Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/121353
Reviewed-by: Dominik Röttsches <drott@chromium.org>
Commit-Queue: Lei Zhang <thestig@chromium.org>
diff --git a/BUILD.gn b/BUILD.gn
index 7206404..25978d9 100644
--- a/BUILD.gn
+++ b/BUILD.gn
@@ -592,9 +592,6 @@
   if (pdf_is_standalone) {
     deps += [ "testing/tools:test_runner_py" ]
   }
-  if (pdf_use_skia && pdf_enable_fontations) {
-    deps += [ "//skia:bridge_rust_side_deps" ]
-  }
 }
 
 # Makes additional targets reachable only for "gn check". These are not always
diff --git a/pdfium.gni b/pdfium.gni
index 693fae7..7cdb44b 100644
--- a/pdfium.gni
+++ b/pdfium.gni
@@ -88,5 +88,5 @@
        "pdf_is_complete_lib=true requires is_component_build=false")
 
 assert(
-    !pdf_enable_fontations || (enable_rust && pdf_use_skia),
-    "pdf_enable_fontations=true requires enable_rust=true and pdf_use_skia=true")
+    !pdf_enable_fontations || (enable_rust && enable_rust_cxx && pdf_use_skia),
+    "pdf_enable_fontations=true requires enable_rust=true, enable_rust_cxx=true, and pdf_use_skia=true")
diff --git a/skia/BUILD.gn b/skia/BUILD.gn
index caefe86..c122348 100644
--- a/skia/BUILD.gn
+++ b/skia/BUILD.gn
@@ -19,17 +19,34 @@
   import("//build/config/mips.gni")
 }
 
+if (pdf_enable_fontations) {
+  import("//build/rust/rust_static_library.gni")
+}
+
 skia_use_ganesh_backend = !is_ios
 skia_support_pdf = false
 
-# TODO(crbug.com/42271123): Add real build rules to support Fontations.
 if (pdf_enable_fontations) {
-  group("bridge_rust_side_deps") {
+  source_set("path_bridge") {
+    sources = [ "//third_party/skia/src/ports/fontations/src/skpath_bridge.h" ]
+  }
+
+  rust_static_library("bridge_rust_side") {
+    allow_unsafe = true
+    crate_root = "//third_party/skia/src/ports/fontations/src/ffi.rs"
+    sources = [ "//third_party/skia/src/ports/fontations/src/ffi.rs" ]
+    cxx_bindings = [ "//third_party/skia/src/ports/fontations/src/ffi.rs" ]
     deps = [
+      ":path_bridge",
       "//third_party/rust/font_types/v0_5:lib",
       "//third_party/rust/read_fonts/v0_19:lib",
       "//third_party/rust/skrifa/v0_19:lib",
     ]
+    configs -= [ "//build/config/compiler:chromium_code" ]
+    configs += [
+      ":skia_config",
+      "//build/config/compiler:no_chromium_code",
+    ]
   }
 }
 
@@ -93,6 +110,10 @@
   if (is_win) {
     defines += [ "GR_GL_FUNCTION_TYPE=__stdcall" ]
   }
+
+  if (pdf_enable_fontations) {
+    include_dirs += [ "$root_gen_dir/third_party/skia" ]
+  }
 }
 
 # Internal-facing config for Skia library code.
@@ -321,6 +342,19 @@
     ]
   }
 
+  if (pdf_enable_fontations) {
+    sources += [
+      "//third_party/skia/src/ports/SkTypeface_fontations.cpp",
+      "//third_party/skia/src/ports/SkTypeface_fontations_priv.h",
+    ]
+
+    # Fontations Rust/C++ bridge interfaces.
+    deps += [
+      ":bridge_rust_side",
+      ":path_bridge",
+    ]
+  }
+
   if (is_clang && !is_nacl) {
     # Skia won't compile with some of the more strict clang warnings.
     # e.g. it does: