[fuzztest] Enable sharing fuzztest outside of Chromium

For using the fuzztest dependency in V8, we also need its BUILD.gn
file.

To avoid forking the file, we plan to include it as separate
copybara repo. This, however, depends on boringssl and
libFuzzer which both are further intertwined with Chromium
sources, not available in V8. Since they aren't required to build
fuzztest with centipede, this puts them behind the
build_with_chromium flag, as done in several other dependencies.

Within Chromium, this change should be a no-op.

Cq-Include-Trybots: luci.chromium.try:linux-centipede-asan-rel
Cq-Include-Trybots: luci.chromium.try:linux-libfuzzer-asan-rel
Bug: 1500944
Change-Id: I76d6f1f6d9fd78c425e665e57af1435978b34991
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5033300
Reviewed-by: Adrian Taylor <adetaylor@chromium.org>
Commit-Queue: Michael Achenbach <machenbach@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1226801}
NOKEYCHECK=True
GitOrigin-RevId: b51f34374ce78c1afe4964efff658bd5101d9811
diff --git a/BUILD.gn b/BUILD.gn
index 48dca1a..2a8495f 100644
--- a/BUILD.gn
+++ b/BUILD.gn
@@ -12,6 +12,7 @@
 # - fuzztest, a way of building new fuzzing targets using simpler macros.
 
 import("//build/config/sanitizers/sanitizers.gni")
+import("//build_overrides/build.gni")
 
 config("fuzztest_internal_config") {
   cflags = [
@@ -121,10 +122,6 @@
     deps = [
       ":centipede_common",
       ":fuzztest_internal",
-
-      # Depend on fuzzing_engine so that we are automatically built in builds
-      # destined for ClusterFuzz.
-      "//testing/libfuzzer:fuzzing_engine",
       "//third_party/abseil-cpp:absl",
       "//third_party/abseil-cpp/absl/flags:config",
       "//third_party/abseil-cpp/absl/flags:flag",
@@ -134,7 +131,6 @@
       "//third_party/abseil-cpp/absl/log:check",
       "//third_party/abseil-cpp/absl/log:globals",
       "//third_party/abseil-cpp/absl/log:initialize",
-      "//third_party/boringssl",
     ]
     sources = [
       "src/centipede/analyze_corpora.cc",
@@ -175,6 +171,18 @@
       "src/centipede/workdir.cc",
       "src/centipede/workdir.h",
     ]
+
+    if (build_with_chromium) {
+      deps += [
+        # Depend on fuzzing_engine so that we are automatically built in builds
+        # destined for ClusterFuzz.
+        "//testing/libfuzzer:fuzzing_engine",
+        "//third_party/boringssl",
+      ]
+    } else {
+      # Other projects sharing fuzztest might not have boringssl.
+      ldflags = [ "-lcrypto" ]
+    }
   }
 }
 
@@ -257,14 +265,18 @@
 
   deps = [
     "//testing/gtest",
-
-    # Depends transitively on fuzzing_engine so that we are automatically built in builds
-    # destined for ClusterFuzz.
-    "//testing/libfuzzer:fuzzing_engine",
     "//third_party/abseil-cpp/absl/flags:flag",
     "//third_party/abseil-cpp/absl/random:bit_gen_ref",
   ]
 
+  if (build_with_chromium) {
+    deps += [
+      # Depends transitively on fuzzing_engine so that we are automatically
+      # built in builds destined for ClusterFuzz.
+      "//testing/libfuzzer:fuzzing_engine",
+    ]
+  }
+
   public_deps = [
     "//third_party/abseil-cpp:absl",