[BUILD.gn] Export explicit static targets

Drivers on Fuchsia are expected to statically link all dependencies, so
the default targets (which for Fuchsia targets are shared libraries)
aren't what we want for drivers that need to link boringssl.

So, we define additional libcrypto and libssl targets to cover the build
matrix, and carefully make sure the output name of the default library
type is preserved to avoid changing behavior for existing usage of the
:boringssl target (since otherwise that seems to trip up Rust targets on
host with `non_rust_deps` at link time).

Then, we define an additional `:boringssl-static` target which can be
used to reliably pull in the statically-linked library for use in
drivers.

Change-Id: I4965ed8c6978f41cc2209775275155ef8a897d4e
Reviewed-on: https://fuchsia-review.googlesource.com/c/third_party/boringssl/+/476857
Fuchsia-Auto-Submit: Drew Fisher <zarvox@google.com>
Commit-Queue: Auto-Submit <auto-submit@fuchsia-infra.iam.gserviceaccount.com>
Reviewed-by: Aaron Green <aarongreen@google.com>
diff --git a/BUILD.gn b/BUILD.gn
index 6f079a5..89449ec 100644
--- a/BUILD.gn
+++ b/BUILD.gn
@@ -25,6 +25,20 @@
   ]
 }
 
+group("boringssl-shared") {
+  public_deps = [
+    ":crypto-shared",
+    ":ssl-shared",
+  ]
+}
+
+group("boringssl-static") {
+  public_deps = [
+    ":crypto-static",
+    ":ssl-static",
+  ]
+}
+
 if (current_cpu == "arm64" && (is_fuchsia || is_linux)) {
   crypto_sources += crypto_sources_linux_aarch64
 } else if (current_cpu == "x64" && (is_fuchsia || is_linux)) {
@@ -42,42 +56,62 @@
 # libcrypto.so #
 ################
 
-target(default_library_type, "crypto") {
-  sources = crypto_sources
-  public = crypto_headers
-  public_configs = [ ":boringssl_config" ]
-  configs += [ ":internal_config" ]
+foreach(lib_type, ["static", "shared"]) {
+  target("${lib_type}_library", "crypto-${lib_type}") {
+    if (default_library_type == "${lib_type}_library") {
+      output_name = "crypto"
+    }
+    sources = crypto_sources
+    public = crypto_headers
+    public_configs = [ ":boringssl_config" ]
+    configs += [ ":internal_config" ]
 
-  if (is_fuchsia) {
-    # TODO(46910): UBSan has found an instance of undefined behavior in this target.
-    # Disable UBSan for this target temporarily until it is migrated into CI/CQ.
-    configs += [ "//build/config:temporarily_disable_ubsan_do_not_use" ]
+    if (is_fuchsia) {
+      # TODO(46910): UBSan has found an instance of undefined behavior in this target.
+      # Disable UBSan for this target temporarily until it is migrated into CI/CQ.
+      configs += [ "//build/config:temporarily_disable_ubsan_do_not_use" ]
 
-    # TODO(60545): profile instrumentation significantly affects performance.
-    configs += [ "//build/config:no_profile" ]
+      # TODO(60545): profile instrumentation significantly affects performance.
+      configs += [ "//build/config:no_profile" ]
 
-    # boringssl should always be optimized for speed because otherwise performance is significantly
-    # worse, impacting pave and boot times on debug builds (fxb/55456)
-    configs -= [ "//build/config:default_optimize" ]
-    configs += [ "//build/config:optimize_speed" ]
+      # boringssl should always be optimized for speed because otherwise performance is significantly
+      # worse, impacting pave and boot times on debug builds (fxb/55456)
+      configs -= [ "//build/config:default_optimize" ]
+      configs += [ "//build/config:optimize_speed" ]
 
-    # sysrand() uses Zircon system call.
-    deps = [ "//src/zircon/lib/zircon" ]
+      # sysrand() uses Zircon system call.
+      deps = [ "//src/zircon/lib/zircon" ]
+    }
+  }
+
+  target("${lib_type}_library", "ssl-${lib_type}") {
+    if (default_library_type == "${lib_type}_library") {
+      output_name = "ssl"
+    }
+    sources = ssl_sources
+    public = ssl_headers
+    public_configs = [ ":boringssl_config" ]
+    configs += [ ":internal_config" ]
+    deps = [ ":crypto-${lib_type}" ]
+
+    if (is_fuchsia) {
+      # boringssl should always be optimized for speed because otherwise performance is significantly
+      # worse, impacting pave and boot times on debug builds (fxb/55456)
+      configs -= [ "//build/config:default_optimize" ]
+      configs += [ "//build/config:optimize_speed" ]
+    }
   }
 }
 
-target(default_library_type, "ssl") {
-  sources = ssl_sources
-  public = ssl_headers
-  public_configs = [ ":boringssl_config" ]
-  configs += [ ":internal_config" ]
-  deps = [ ":crypto" ]
-
-  if (is_fuchsia) {
-    # boringssl should always be optimized for speed because otherwise performance is significantly
-    # worse, impacting pave and boot times on debug builds (fxb/55456)
-    configs -= [ "//build/config:default_optimize" ]
-    configs += [ "//build/config:optimize_speed" ]
+foreach(lib_name, ["crypto", "ssl"]) {
+  group("$lib_name") {
+    if (default_library_type == "shared_library") {
+      public_deps = [ ":${lib_name}-shared" ]
+    } else if (default_library_type == "static_library") {
+      public_deps = [ ":${lib_name}-static" ]
+    } else {
+      assert(false, "unsupported default_library_type: $default_library_type")
+    }
   }
 }