[unification] Move //zircon/system/core/svchost to the GN build

Generated with: //scripts/unification/move_zn_element.py

scripts/unification/verify_element_move.py --reference local/initial.json:

Warning   aux         size change for test/sys/crashsvc-test: -8% (308.0K)
Error     image       size change for bin/svchost: -11% (284.0K)
Warning   tests       size change for test/sys/crashsvc-test: -8% (308.0K)

Bug: 36139
Change-Id: I11868a6eaff994780bbeadd0f92d7ae397b2d66a
Reviewed-on: https://fuchsia-review.googlesource.com/c/fuchsia/+/377508
Commit-Queue: P.Y. Laligand <pylaligand@google.com>
Reviewed-by: Shai Barack <shayba@google.com>
Reviewed-by: Francois Rousseau <frousseau@google.com>
diff --git a/build/unification/images/BUILD.gn b/build/unification/images/BUILD.gn
index ffc65a0..c6423a4 100644
--- a/build/unification/images/BUILD.gn
+++ b/build/unification/images/BUILD.gn
@@ -90,7 +90,6 @@
     ":bin.sh",
 #------------------
 #------------------
-    ":bin.svchost",
 #------------------
 #------------------
 #------------------
@@ -462,7 +461,6 @@
 #------------------
 #------------------
 #------------------
-    ":test.sys.crashsvc-test",
 #------------------
 #------------------
 #------------------
@@ -1000,7 +998,6 @@
 #------------------
 #------------------
 #------------------
-    ":test.sys.crashsvc-test",
 #------------------
 #------------------
 #------------------
@@ -1270,7 +1267,7 @@
     "//src/devices/spi/bin/spiutil:spiutil-manifest",
     "//zircon/system/uapp/storage-metrics:storage-metrics-manifest",
 #------------------
-    #":bin.svchost",
+    "//zircon/system/core/svchost:svchost-manifest",
 #------------------
 #------------------
     "//zircon/system/uapp/syscall-check:syscall-check-manifest",
@@ -2749,7 +2746,7 @@
     "//zircon/system/core/console:console-test-manifest",
 #------------------
 #------------------
-    #":test.sys.crashsvc-test",
+    "//zircon/system/core/svchost:crashsvc-test-manifest",
 #------------------
     "//src/devices/tests/ddk-fidl-test:ddk-fidl-test-manifest",
     "//src/devices/tests/ddk-lifecycle:ddk-lifecycle-manifest",
@@ -3259,7 +3256,7 @@
     "//zircon/system/core/console:console-test-manifest",
 #------------------
 #------------------
-    #":test.sys.crashsvc-test",
+    "//zircon/system/core/svchost:crashsvc-test-manifest",
 #------------------
     "//src/devices/tests/ddk-fidl-test:ddk-fidl-test-manifest",
     "//src/devices/tests/ddk-lifecycle:ddk-lifecycle-manifest",
diff --git a/build/unification/zbi/BUILD.gn b/build/unification/zbi/BUILD.gn
index 577c057..1a7fc6e 100644
--- a/build/unification/zbi/BUILD.gn
+++ b/build/unification/zbi/BUILD.gn
@@ -78,7 +78,6 @@
 # Artifacts imported from the ZN build which may be added to ZBI tests.
 
 zbiables = [
-  "bin.svchost",
   "driver.fragment",
   "driver.fragment.proxy",
   "test.core.standalone-test",
diff --git a/zircon/system/core/BUILD.gn b/zircon/system/core/BUILD.gn
index 6c9d730..75c042d 100644
--- a/zircon/system/core/BUILD.gn
+++ b/zircon/system/core/BUILD.gn
@@ -7,6 +7,5 @@
     # TODO(bwb): depend on these from GN when build systems are unified. These are
     # data dependencies of devcoordinator
     "$zx/system/core/devmgr/fragment",
-    "$zx/system/core/svchost",
   ]
 }
diff --git a/zircon/system/core/bootsvc/test/BUILD.gn b/zircon/system/core/bootsvc/test/BUILD.gn
index 815887a..03d1625 100644
--- a/zircon/system/core/bootsvc/test/BUILD.gn
+++ b/zircon/system/core/bootsvc/test/BUILD.gn
@@ -101,7 +101,7 @@
     "//zircon/system/core/miscsvc",
     "//zircon/system/core/netsvc",
     "//zircon/system/core/pwrbtn-monitor",
-    "//build/unification/zbi:bin.svchost-zbi",
+    "//zircon/system/core/svchost",
     "//build/unification/zbi:driver.fragment-zbi",
     "//build/unification/zbi:driver.fragment.proxy-zbi",
   ]
diff --git a/zircon/system/core/svchost/BUILD.gn b/zircon/system/core/svchost/BUILD.gn
index c55b238..4062185 100644
--- a/zircon/system/core/svchost/BUILD.gn
+++ b/zircon/system/core/svchost/BUILD.gn
@@ -2,74 +2,125 @@
 # Use of this source code is governed by a BSD-style license that can be
 # found in the LICENSE file.
 
+##########################################
+# Though under //zircon, this build file #
+# is meant to be used in the Fuchsia GN  #
+# build.                                 #
+# See fxb/36139.                         #
+##########################################
+
+assert(!defined(zx) || zx != "/",
+       "This file can only be used in the Fuchsia GN build.")
+
+import("//build/test.gni")
+import("//build/unification/images/migrated_manifest.gni")
+import("//build/unification/zx_library.gni")
+
 zx_library("crashsvc") {
+  sdk = "source"
+
+  sdk_headers = [ "crashsvc/crashsvc.h" ]
+
   sources = [ "crashsvc.cc" ]
 
   deps = [
-    "$zx/system/fidl/fuchsia-exception:llcpp",
-    "$zx/system/ulib/backtrace-request:backtrace-request-utils",
-    "$zx/system/ulib/fbl",
-    "$zx/system/ulib/fdio",
-    "$zx/system/ulib/inspector",
+    "//zircon/public/lib/backtrace-request-utils",
+    "//zircon/public/lib/fbl",
+    "//zircon/public/lib/fdio",
+    "//zircon/public/lib/inspector",
+    "//zircon/system/fidl/fuchsia-exception:llcpp",
   ]
 
-  public_deps = [ "$zx/system/ulib/zx" ]
+  public_deps = [ "//zircon/public/lib/zx" ]
+
+  defines = [ "_ALL_SOURCE" ]
 }
 
-zx_executable("svchost") {
+executable("svchost") {
+  if (is_fuchsia) {
+    configs += [ "//build/unification/config:zircon-migrated" ]
+  }
+  if (is_fuchsia) {
+    fdio_config = [ "//build/config/fuchsia:fdio_config" ]
+    if (configs + fdio_config - fdio_config != configs) {
+      configs -= fdio_config
+    }
+  }
   sources = [
     "svchost.cc",
     "sysmem.cc",
   ]
   deps = [
     ":crashsvc",
-    "$zx/system/fidl/fuchsia-boot:c",
-    "$zx/system/fidl/fuchsia-device:c",
-    "$zx/system/fidl/fuchsia-device:llcpp",
-    "$zx/system/fidl/fuchsia-device-manager:c",
-    "$zx/system/fidl/fuchsia-fshost:c",
-    "$zx/system/fidl/fuchsia-hardware-power-statecontrol:c",
-    "$zx/system/fidl/fuchsia-hardware-pty:c",
-    "$zx/system/fidl/fuchsia-io:c",
-    "$zx/system/fidl/fuchsia-kernel:c",
-    "$zx/system/fidl/fuchsia-logger:c",
-    "$zx/system/fidl/fuchsia-mem:c",
-    "$zx/system/fidl/fuchsia-net:llcpp",
-    "$zx/system/fidl/fuchsia-paver:c",
-    "$zx/system/fidl/fuchsia-posix-socket:llcpp",
-    "$zx/system/fidl/fuchsia-process:c",
-    "$zx/system/fidl/fuchsia-scheduler:c",
-    "$zx/system/fidl/fuchsia-sysinfo:c",
-    "$zx/system/fidl/fuchsia-sysmem:c",
-    "$zx/system/fidl/fuchsia-virtualconsole:c",
-    "$zx/system/ulib/async-loop:async-loop-cpp",
-    "$zx/system/ulib/async-loop:async-loop-default.static",
-    "$zx/system/ulib/fdio",
-    "$zx/system/ulib/fs",
-    "$zx/system/ulib/kcounter",
-    "$zx/system/ulib/kernel-debug",
-    "$zx/system/ulib/kernel-mexec",
-    "$zx/system/ulib/logger",
-    "$zx/system/ulib/profile",
-    "$zx/system/ulib/svc",
-    "$zx/system/ulib/sysmem-connector",
-    "$zx/system/ulib/zircon",
+    "//zircon/public/lib/async-loop-cpp",
+    "//zircon/public/lib/async-loop-default",
+    "//zircon/public/lib/fdio",
+    "//zircon/public/lib/fs",
+    "//zircon/public/lib/kcounter",
+    "//zircon/public/lib/kernel-debug",
+    "//zircon/public/lib/kernel-mexec",
+    "//zircon/public/lib/logger",
+    "//zircon/public/lib/profile",
+    "//zircon/public/lib/svc",
+    "//zircon/public/lib/sysmem-connector",
+    "//zircon/system/fidl/fuchsia-boot:c",
+    "//zircon/system/fidl/fuchsia-device:c",
+    "//zircon/system/fidl/fuchsia-device:llcpp",
+    "//zircon/system/fidl/fuchsia-device-manager:c",
+    "//zircon/system/fidl/fuchsia-fshost:c",
+    "//zircon/system/fidl/fuchsia-hardware-power-statecontrol:c",
+    "//zircon/system/fidl/fuchsia-hardware-pty:c",
+    "//zircon/system/fidl/fuchsia-io:c",
+    "//zircon/system/fidl/fuchsia-kernel:c",
+    "//zircon/system/fidl/fuchsia-logger:c",
+    "//zircon/system/fidl/fuchsia-mem:c",
+    "//zircon/system/fidl/fuchsia-net:llcpp",
+    "//zircon/system/fidl/fuchsia-paver:c",
+    "//zircon/system/fidl/fuchsia-posix-socket:llcpp",
+    "//zircon/system/fidl/fuchsia-process:c",
+    "//zircon/system/fidl/fuchsia-scheduler:c",
+    "//zircon/system/fidl/fuchsia-sysinfo:c",
+    "//zircon/system/fidl/fuchsia-sysmem:c",
+    "//zircon/system/fidl/fuchsia-virtualconsole:c",
   ]
+  output_dir = "$root_out_dir/zircon-migrated"
 }
 
-zx_test("crashsvc-test") {
+test("crashsvc-test") {
+  # Dependent manifests unfortunately cannot be marked as `testonly`.
+  # TODO(44278): Remove when converting this file to proper GN build idioms.
+  if (is_fuchsia) {
+    testonly = false
+  }
+  if (is_fuchsia) {
+    configs += [ "//build/unification/config:zircon-migrated" ]
+  }
+  if (is_fuchsia) {
+    fdio_config = [ "//build/config/fuchsia:fdio_config" ]
+    if (configs + fdio_config - fdio_config != configs) {
+      configs -= fdio_config
+    }
+  }
   output_name = "crashsvc-test"
   sources = [ "crashsvc-test.cc" ]
   deps = [
     ":crashsvc",
-    "$zx/system/fidl/fuchsia-exception:llcpp",
-    "$zx/system/ulib/async:async-cpp",
-    "$zx/system/ulib/async-loop:async-loop-cpp",
-    "$zx/system/ulib/async-loop:async-loop-default.static",
-    "$zx/system/ulib/fdio",
-    "$zx/system/ulib/fidl-async:fidl-async-cpp",
-    "$zx/system/ulib/fs",
-    "$zx/system/ulib/mini-process",
-    "$zx/system/ulib/zxtest",
+    "//zircon/public/lib/async-cpp",
+    "//zircon/public/lib/async-loop-cpp",
+    "//zircon/public/lib/async-loop-default",
+    "//zircon/public/lib/fdio",
+    "//zircon/public/lib/fidl-async-cpp",
+    "//zircon/public/lib/fs",
+    "//zircon/public/lib/mini-process",
+    "//zircon/public/lib/zxtest",
+    "//zircon/system/fidl/fuchsia-exception:llcpp",
   ]
 }
+
+migrated_manifest("svchost-manifest") {
+  deps = [ ":svchost" ]
+}
+
+migrated_manifest("crashsvc-test-manifest") {
+  deps = [ ":crashsvc-test" ]
+}
diff --git a/zircon/system/ulib/BUILD.gn b/zircon/system/ulib/BUILD.gn
index 803df60..94f0df5 100644
--- a/zircon/system/ulib/BUILD.gn
+++ b/zircon/system/ulib/BUILD.gn
@@ -290,6 +290,9 @@
     "kcounter",
 #------------------
 #------------------
+    "kernel-debug",
+#------------------
+#------------------
     "kernel-mexec",
 #------------------
 #------------------
diff --git a/zircon/system/utest/BUILD.gn b/zircon/system/utest/BUILD.gn
index efb013a..13b2c18 100644
--- a/zircon/system/utest/BUILD.gn
+++ b/zircon/system/utest/BUILD.gn
@@ -34,7 +34,6 @@
 #------------------
 #------------------
 #------------------
-      "$zx/system/core/svchost:crashsvc-test",
 #------------------
 #------------------
 #------------------