[zircon] [gn] Build fdio, FIDL support

This brings in FIDL support, as well as several other libraries fdio
depends on.  For simplicity, BUILD.gn files for all FIDL libraries are
added now, not just those needed to build fdio.

Bug: BLD-325
Test: gn gen && ninja
Change-Id: I7721db32c1ae1f97be59ec6cd9b7af923f64daf2
diff --git a/zircon/BUILD.gn b/zircon/BUILD.gn
index d4c2d78..246f49d 100644
--- a/zircon/BUILD.gn
+++ b/zircon/BUILD.gn
@@ -95,6 +95,7 @@
       # TODO: This indirectly reaches everything that builds so far.
       "$zx/system/core/userboot",
       "$zx/system/ulib/c",
+      "$zx/system/ulib/fdio",
     ]
   }
 }
diff --git a/zircon/public/gn/fidl.gni b/zircon/public/gn/fidl.gni
new file mode 100644
index 0000000..c01fa61
--- /dev/null
+++ b/zircon/public/gn/fidl.gni
@@ -0,0 +1,294 @@
+# Copyright 2019 The Fuchsia Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+import("$zx/public/gn/fidl/fidlc.gni")
+
+# List of FIDL support modules.  Each of these defines its own version of
+# $fidl_support_fidlc and $fidl_support_templates.
+#
+# $fidl_support_templates:
+# Type: list of scopes
+#
+#   import
+#     Required: Source-absolute path to the .gni file that defines $target.
+#     Type: file
+#
+#   target
+#     Required: Name of a template to invoke, defined in the $import file.
+#     Type: string
+#
+#   fidlc
+#     Optional: Name of an entry in $fidl_support_fidlc describing fidlc
+#     outputs that this template requires.
+#
+# The $target template is invoked with the $target_name from fidl_library()
+# and these parameters:
+#
+#   fidl_deps
+#     Required: $public_deps list from fidl_library() after canonicalization.
+#     Type: list(label_no_toolchain)
+#
+#   fidl_name
+#     Required: The FIDL library name (with dots).
+#     Type: string
+#
+#   fidl_path
+#     Required: $fidl_name with each `.` replaced by a `/`.
+#     Type: string
+#
+#   fidl_gen_dir
+#     Optional: If $fidlc was set, this is the directory in which those
+#     fidlc outputs went.  e.g. "$fidl_gen_dir/include" might be useful.
+#     Type: file
+#
+#   fidlc_outputs
+#     Optional: If $fidlc was set, this is the list of output files generated
+#     by fidlc for that entry in $fidl_support_fidlc.
+#
+#   fidlc_deps
+#     Optional: If $fidlc was set, this is the label to include in $deps
+#     of something using $fidlc_outputs.
+#
+#   visibility, testonly
+#     Optional: Forwarded from fidl_library().
+#
+# $fidl_support_fidlc:
+# Type: list of scopes
+#
+#   name
+#     Required: Name for this collection of fidlc output
+#     Type: string
+#
+#   files
+#     Required: A list of scopes describing outputs from fidlc.
+#     Type: list of scopes
+#       switch
+#         Required: fidlc command-line switch preceding output file name.
+#         Type: string
+#       path
+#         Optional: Required unless $path_prefix and $path_suffix are given.
+#         The fidlc output file is "$fidl_gen_dir/$path".
+#         Type: string
+#       path_prefix, path_suffix
+#         Optional: If one is specified, both must be and $path must not be.
+#         The output file is "$fidl_gen_dir/$path_prefix$fidl_path$path_suffix".
+#         Type: string
+#
+# All these kinds of output will be generated in one run of fidlc.  Modules
+# should use the $fidl_support_fidlc list only for generation work that is
+# more or less free once you're running fidlc anyway.  These output files
+# will be generated if *any* $fidl_support_fidlc output file from *any*
+# support module is needed in the build.  For more costly generation steps
+# (or ones requiring more than a simple fidlc command-line switch), support
+# modules should use $fidl_support_templates.
+#
+# TODO(mcgrathr): Add more language generators.  For language support from
+# a different petal, add a build argument to contribute to this list via
+# default_overrides.
+fidl_support = [ "$zx/public/gn/fidl/c.gni" ]
+
+# Each support module defines $fidl_support_fidlc and
+# $fidl_support_templates lists in its .gni file.
+_fidl_generators = []
+foreach(module, fidl_support) {
+  _fidl_generators += [
+    {
+      import(module)
+    },
+  ]
+}
+
+# Collect all fidlc outputs from the support modules, and deduplicate.
+# Collect all the generation templates to invoke, and deduplicate.  All
+# these templates will be invoked by fidl_library() to define their targets.
+_fidl_gen_fidlc = []
+_fidl_gen_templates = []
+foreach(gen, _fidl_generators) {
+  _fidl_gen_fidlc += gen.fidl_support_fidlc
+  _fidl_gen_fidlc -= gen.fidl_support_fidlc
+  _fidl_gen_fidlc += gen.fidl_support_fidlc
+  _fidl_gen_templates += gen.fidl_support_templates
+  _fidl_gen_templates -= gen.fidl_support_templates
+  _fidl_gen_templates += gen.fidl_support_templates
+}
+
+# Define a FIDL library and implicitly generate bindings targets.
+#
+# The $fidl_support global determines what targets this actually produces.
+#
+# Parameters
+#
+#   sources
+#     Required: List of `.fidl` source files.
+#
+#   deps
+#     Optional: This is *not* the way to express dependencies on other FIDL
+#     libraries.  Use $public_deps for that.  The only use for $deps is if
+#     some of $sources are generated, to depend on the targets generating them.
+#     Type: list(label)
+#
+#   public_deps
+#     Optional: Other fidl_library() targets this library depends on.
+#     If `using foo;` appears in a $sources file, then the label of the
+#     fidl_library() target should be listed here.  This must list only
+#     other fidl_library() targets and may not use a "(toolchain)" suffix.
+#     Type: list(label_no_toolchain)
+#
+template("fidl_library") {
+  assert(defined(invoker.sources),
+         "fidl_library(\"$target_name\") must set `sources`")
+
+  fidl_target = target_name
+
+  # TODO(mcgrathr): temporary until everything is renamed with . names
+  fidl_name = string_replace(fidl_target, "-", ".")
+  fidl_path = string_replace(fidl_name, ".", "/")
+
+  # Collect the dependencies on other FIDL libraries, and canonicalize them.
+  fidl_library_deps = []
+  if (defined(invoker.public_deps)) {
+    foreach(label, invoker.public_deps) {
+      assert(get_label_info(label, "toolchain") == current_toolchain,
+             "fidl_library() `deps` must be fidl_library() target labels")
+      fidl_library_deps += [ get_label_info(label, "label_no_toolchain") ]
+    }
+  }
+
+  files_rspfile_target = "_fidl_library.files.$fidl_target.rsp"
+  fidl_gen_dir =
+      get_label_info(":$fidl_target($default_toolchain)", "target_gen_dir")
+  files_rspfile = "$fidl_gen_dir/$fidl_target.rsp"
+
+  gen_target = "_fidl_library.generate.$fidl_target"
+
+  # This is the label to use in deps.
+  files_rspfile_label = ":$files_rspfile_target($default_toolchain)"
+  gen_target_label = ":$gen_target($default_toolchain)"
+
+  gens = []
+  foreach(gen, _fidl_gen_fidlc) {
+    gen_dir = "$fidl_gen_dir/$fidl_target.${gen.name}"
+    gen_outputs = []
+    gen_args = []
+    foreach(file, gen.files) {
+      gen_args += [ file.switch ]
+      if (defined(file.path)) {
+        file = file.path
+      } else {
+        file = "${file.path_prefix}${fidl_path}${file.path_suffix}"
+      }
+      gen_outputs += [ "$gen_dir/$file" ]
+      gen_args += [ rebase_path("$gen_dir/$file", root_build_dir) ]
+    }
+    gens += [
+      {
+        name = gen.name
+        outputs = gen_outputs
+        args = gen_args
+      },
+    ]
+  }
+
+  if (current_toolchain == default_toolchain) {
+    # This just groups the dependencies together with the metadata listing
+    # the input files.
+    group(fidl_target) {
+      forward_variables_from(invoker,
+                             [
+                               "deps",
+                               "public_deps",
+                               "visibility",
+                               "testonly",
+                             ])
+      if (defined(visibility)) {
+        visibility += [ ":$files_rspfile_target" ]
+      }
+
+      metadata = {
+        # These inputs are needed both here and in every dependent library.
+        # Each --files switch introduces a group of source files that make
+        # up a single FIDL library (all have identical `library ...;` lines).
+        fidl_rspfile =
+            [ "--files" ] + rebase_path(invoker.sources, root_build_dir)
+      }
+    }
+
+    # Produce a metadata response file from all the fidl_rspfile lists.
+    # fidlc() uses this file.
+    generated_file(files_rspfile_target) {
+      forward_variables_from(invoker, [ "testonly" ])
+      deps = [
+        ":$fidl_target",
+      ]
+      outputs = [
+        files_rspfile,
+      ]
+      output_conversion = "list lines"
+      data_keys = [ "fidl_rspfile" ]
+    }
+
+    fidlc(gen_target) {
+      visibility = [ ":*" ]
+      forward_variables_from(invoker, [ "testonly" ])
+      deps = [
+        ":$fidl_target",
+      ]
+      outputs = []
+      args = []
+      foreach(gen, gens) {
+        outputs += gen.outputs
+        args += gen.args
+      }
+    }
+  } else {
+    not_needed(invoker, "*")
+  }
+
+  # Subroutine used in the _fidl_gen_templates loop in fidl_library().
+  # The inner template provides a local scope for the import so it
+  # won't clobber the outer template scope.
+  template("_fidl_gen_subtarget") {
+    import(invoker.import)
+    target(invoker.target, target_name) {
+      forward_variables_from(invoker.args, "*")
+    }
+  }
+
+  # Invoke each template.
+  foreach(gen, _fidl_gen_templates) {
+    # The target_name for the template is the main FIDL target name.
+    # The template will define its targets using appropriate suffixes.
+    _fidl_gen_subtarget(fidl_target) {
+      import = gen.import
+      target = gen.target
+      args = {
+        forward_variables_from(invoker,
+                               [
+                                 "visibility",
+                                 "testonly",
+                               ])
+
+        # The bindings-library template can map these to corresponding
+        # bindings-library targets.
+        fidl_deps = fidl_library_deps
+
+        # Provide these for convenience.  They're derived from target_name
+        # but every generator will be doing it the same way.
+        fidl_name = fidl_name
+        fidl_path = fidl_path
+
+        # If the template uses our main fidlc run, give it details about that.
+        if (defined(gen.fidlc)) {
+          fidlc_gen_dir = "$fidl_gen_dir/$fidl_target.${gen.fidlc}"
+          fidlc_deps = [ gen_target_label ]
+          foreach(gen_fidlc, gens) {
+            if (gen.fidlc == gen_fidlc.name) {
+              fidlc_outputs = gen_fidlc.outputs
+            }
+          }
+        }
+      }
+    }
+  }
+}
diff --git a/zircon/public/gn/fidl/c.gni b/zircon/public/gn/fidl/c.gni
new file mode 100644
index 0000000..7d7850b
--- /dev/null
+++ b/zircon/public/gn/fidl/c.gni
@@ -0,0 +1,112 @@
+# Copyright 2019 The Fuchsia Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+import("$zx/public/gn/subtarget_aliases.gni")
+
+# This is the $fidl_support module for C bindings.  See fidl_library() for
+# details.  This file should not normally be imported by other code.
+
+# This tells fidl_library() to invoke fidl_c_library().
+fidl_support_templates = [
+  {
+    import = "$zx/public/gn/fidl/c.gni"
+    target = "fidl_c_library"
+    fidlc = "c"
+  },
+]
+
+# This tells fidl_library() what fidlc outputs fidl_c_library() requires.
+fidl_support_fidlc = [
+  {
+    name = "c"
+    files = [
+      {
+        switch = "--c-header"
+        path_prefix = "include/"
+        path_suffix = "/c/fidl.h"
+      },
+      {
+        switch = "--c-client"
+        path = "client.c"
+      },
+      {
+        switch = "--c-server"
+        path = "server.c"
+      },
+      {
+        switch = "--tables"
+        path = "tables.cpp"
+      },
+    ]
+  },
+]
+
+# Provide C bindings for fidl_library().  **Do not use directly!**
+#
+# This is never used directly, but only indirectly by fidl_library().
+# See there for details.
+template("fidl_c_library") {
+  not_needed([ "target_name" ])
+  not_needed(invoker, "*")
+  if (current_toolchain != default_toolchain) {
+    fidl_target = target_name
+    library_target = "$fidl_target.c"
+
+    config("_fidl_c_library.config.$library_target") {
+      visibility = [
+        ":$library_target.headers",
+        ":$library_target.static",
+      ]
+      include_dirs = [ "${invoker.fidlc_gen_dir}/include" ]
+    }
+
+    library(library_target) {
+      forward_variables_from(invoker,
+                             [
+                               "visibility",
+                               "testonly",
+                             ])
+
+      configs += [ "$zx/public/gn/config:visibility_hidden" ]
+
+      # Depend on the fidlc generation step and compile what it produces.
+      deps = invoker.fidlc_deps
+      sources = invoker.fidlc_outputs
+
+      # Users of the bindings library need the generated headers.
+      public_configs = [ ":_fidl_c_library.config.$library_target" ]
+
+      # The generated headers of a dependent fidl_library() will #include the
+      # generated headers for its dependencies' bindings libraries, so those
+      # headers are needed in public_deps.  The generated bindings code may
+      # call into its dependencies' bindings code, so the libraries
+      # themselves are needed in deps too.
+      public_deps = []
+      foreach(dep, invoker.fidl_deps) {
+        deps += [ "$dep.c" ]
+        public_deps += [ "$dep.c.headers" ]
+      }
+
+      # The generated code uses these.
+      deps += [
+        "$zx/system/ulib/fidl",
+        "$zx/system/ulib/zircon",
+      ]
+    }
+
+    # Things normally depend on "fidl/foo:c" rather than "fidl/foo:foo.c".
+    subtarget_aliases(target_name) {
+      forward_variables_from(invoker,
+                             [
+                               "visibility",
+                               "testonly",
+                             ])
+      outputs = [
+        "c",
+        "c.headers",
+        "c.static",
+      ]
+    }
+  }
+}
diff --git a/zircon/public/gn/fidl/fidlc.gni b/zircon/public/gn/fidl/fidlc.gni
new file mode 100644
index 0000000..f10f4ef
--- /dev/null
+++ b/zircon/public/gn/fidl/fidlc.gni
@@ -0,0 +1,114 @@
+# Copyright 2019 The Fuchsia Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+import("$zx/public/gn/host_tool_action.gni")
+
+# Run the FIDL compiler for a fidl_library().
+#
+# This is not really meant for general use.  It's used by FIDL support
+# modules (see $zx/public/gn/fidl.gni for details).
+#
+# Parameters
+#
+#   deps
+#     Required: List of exactly one fidl_library() target label.
+#     Type: list(label_no_toolchain)
+#
+#   args
+#     Required: Arguments for `fidlc` to generate the desired outputs.
+#     Type: list(string)
+#
+#   outputs
+#     Required: Files that `fidlc` will generate when given $args.
+#     Type: list(file)
+#
+#   tool
+#     Optional: Label of the host_tool() to run.
+#     Type: label_no_toolchain
+#     Default: "$zx/system/host/fidl:fidlc"
+#
+template("fidlc") {
+  if (current_toolchain == default_toolchain) {
+    fidlc_target = target_name
+
+    fidl_deps = invoker.deps
+    fidlc_outputs = invoker.outputs
+
+    fidl_library = fidl_deps[0]
+    assert(fidl_deps == [ fidl_library ],
+           "fidlc() must list exactly one fidl_library() target in `deps`")
+    fidl_label_dir = get_label_info(fidl_library, "dir")
+    fidl_label_name = get_label_info(fidl_library, "name")
+
+    # TODO(mcgrathr): temporary until everything is renamed with . names
+    fidl_name = string_replace(fidl_label_name, "-", ".")
+
+    # fidl_library() generates a response file of all the input arguments.
+    fidl_gen_dir = get_label_info(fidl_library, "target_gen_dir")
+    fidl_target_name = get_label_info(fidl_library, "name")
+    files_rspfile = "$fidl_gen_dir/$fidl_target_name.rsp"
+    files_rspfile_target =
+        "$fidl_label_dir:_fidl_library.files.$fidl_label_name.rsp"
+
+    # Next, combine that into a response file for the whole command.
+    # At the same time, produce a depfile listing all the input files.
+    fidlc_rspfile = "$target_out_dir/$fidlc_target.rsp"
+    fidlc_depfile = "$target_out_dir/$fidlc_target.d"
+    action("_fidlc.rsp.$target_name") {
+      forward_variables_from(invoker, [ "testonly" ])
+      visibility = [ ":$fidlc_target" ]
+      deps = [
+        files_rspfile_target,
+      ]
+      sources = [
+        files_rspfile,
+      ]
+      outputs = [
+        fidlc_rspfile,
+        fidlc_depfile,
+      ]
+      script = "$zx/public/gn/fidl/gen-fidlc-rsp.sh"
+      args = rebase_path(outputs + [ fidlc_outputs[0] ] + sources,
+                         root_build_dir) +
+             [
+               "--name",
+               fidl_name,
+             ] + invoker.args
+    }
+
+    host_tool_action(fidlc_target) {
+      forward_variables_from(invoker,
+                             [
+                               "visibility",
+                               "testonly",
+                             ])
+      if (defined(invoker.tool)) {
+        tool = invoker.tool
+      } else {
+        tool = "$zx/system/host/fidl:fidlc"
+      }
+      outputs = fidlc_outputs
+      deps = [
+        ":_fidlc.rsp.$target_name",
+      ]
+      sources = [
+        fidlc_rspfile,
+      ]
+      depfile = fidlc_depfile
+      args = [ "@" + rebase_path(fidlc_rspfile, root_build_dir) ]
+    }
+  } else {
+    group(target_name) {
+      forward_variables_from(invoker,
+                             [
+                               "visibility",
+                               "testonly",
+                             ])
+      public_deps = [
+        ":$target_name($default_toolchain)",
+      ]
+      not_needed(invoker, "*")
+    }
+  }
+}
diff --git a/zircon/public/gn/fidl/gen-fidlc-rsp.sh b/zircon/public/gn/fidl/gen-fidlc-rsp.sh
new file mode 100755
index 0000000..4766a3e
--- /dev/null
+++ b/zircon/public/gn/fidl/gen-fidlc-rsp.sh
@@ -0,0 +1,47 @@
+#!/bin/bash
+#
+# Copyright 2019 The Fuchsia Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+set -e
+
+OUTFILE="$1"
+DEPFILE="$2"
+DEPOUTFILE="$3"
+RSPFILE="$4"
+shift 4
+
+ARGS=()
+FILES=()
+
+handle_args() {
+  ARGS+=("$@")
+  local arg in_files=false
+  for arg in "$@"; do
+    if [ "$arg" = --files ]; then
+      in_files=true
+    elif $in_files; then
+      FILES+=("$arg")
+    fi
+  done
+}
+
+read_rspfile() {
+  local arg
+  while read arg; do
+    handle_args "$arg"
+  done
+}
+
+write_output() {
+  local arg
+  for arg in "${ARGS[@]}"; do
+    echo "$arg"
+  done
+}
+
+handle_args "$@"
+read_rspfile < "$RSPFILE"
+echo "$DEPOUTFILE: ${FILES[*]}" > "$DEPFILE"
+write_output > "$OUTFILE"
diff --git a/zircon/public/gn/subtarget_aliases.gni b/zircon/public/gn/subtarget_aliases.gni
new file mode 100644
index 0000000..68cf9f9
--- /dev/null
+++ b/zircon/public/gn/subtarget_aliases.gni
@@ -0,0 +1,37 @@
+# Copyright 2019 The Fuchsia Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+# Define aliases for subtargets of a directory's main target.
+#
+# This is a subroutine for a template that defines targets called
+# "$target_name", "$target_name.a", and "$target_name.b".  If $target_name
+# matches the name of the directory, then this defines redirecting alias
+# targets called just "a" and "b".  Otherwise, this does nothing.
+#
+# Parameters
+#
+#   outputs
+#     Required: List of subtarget names (e.g. [ "a", "b" ]).
+#     Type: list(string)
+#
+template("subtarget_aliases") {
+  if (get_label_info(":$target_name", "name") ==
+      get_path_info(get_label_info(":$target_name", "dir"), "file")) {
+    invoker_name = target_name
+    foreach(subtarget, invoker.outputs) {
+      group(subtarget) {
+        forward_variables_from(invoker,
+                               [
+                                 "testonly",
+                                 "visibility",
+                               ])
+        public_deps = [
+          ":$invoker_name.$subtarget"
+        ]
+      }
+    }
+  } else {
+    not_needed(invoker, "*")
+  }
+}
diff --git a/zircon/system/fidl/fuchsia-blobfs/BUILD.gn b/zircon/system/fidl/fuchsia-blobfs/BUILD.gn
new file mode 100644
index 0000000..ee69f47
--- /dev/null
+++ b/zircon/system/fidl/fuchsia-blobfs/BUILD.gn
@@ -0,0 +1,11 @@
+# Copyright 2019 The Fuchsia Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+import("$zx/public/gn/fidl.gni")
+
+fidl_library("fuchsia-blobfs") {
+  sources = [
+    "blobfs.fidl",
+  ]
+}
diff --git a/zircon/system/fidl/fuchsia-cobalt/BUILD.gn b/zircon/system/fidl/fuchsia-cobalt/BUILD.gn
new file mode 100644
index 0000000..9a7c23b
--- /dev/null
+++ b/zircon/system/fidl/fuchsia-cobalt/BUILD.gn
@@ -0,0 +1,15 @@
+# Copyright 2019 The Fuchsia Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+import("$zx/public/gn/fidl.gni")
+
+fidl_library("fuchsia-cobalt") {
+  sources = [
+    "cobalt.fidl",
+    "cobalt_controller.fidl",
+  ]
+  public_deps = [
+    "$zx/system/fidl/fuchsia-mem",
+  ]
+}
diff --git a/zircon/system/fidl/fuchsia-crash/BUILD.gn b/zircon/system/fidl/fuchsia-crash/BUILD.gn
new file mode 100644
index 0000000..66d3164
--- /dev/null
+++ b/zircon/system/fidl/fuchsia-crash/BUILD.gn
@@ -0,0 +1,14 @@
+# Copyright 2019 The Fuchsia Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+import("$zx/public/gn/fidl.gni")
+
+fidl_library("fuchsia-crash") {
+  sources = [
+    "crash.fidl",
+  ]
+  public_deps = [
+    "$zx/system/fidl/fuchsia-mem",
+  ]
+}
diff --git a/zircon/system/fidl/fuchsia-device-manager/BUILD.gn b/zircon/system/fidl/fuchsia-device-manager/BUILD.gn
new file mode 100644
index 0000000..bcc25d4
--- /dev/null
+++ b/zircon/system/fidl/fuchsia-device-manager/BUILD.gn
@@ -0,0 +1,12 @@
+# Copyright 2019 The Fuchsia Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+import("$zx/public/gn/fidl.gni")
+
+fidl_library("fuchsia-device-manager") {
+  sources = [
+    "coordinator.fidl",
+    "dmctl.fidl",
+  ]
+}
diff --git a/zircon/system/fidl/fuchsia-device-test/BUILD.gn b/zircon/system/fidl/fuchsia-device-test/BUILD.gn
new file mode 100644
index 0000000..ea5fd16
--- /dev/null
+++ b/zircon/system/fidl/fuchsia-device-test/BUILD.gn
@@ -0,0 +1,11 @@
+# Copyright 2019 The Fuchsia Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+import("$zx/public/gn/fidl.gni")
+
+fidl_library("fuchsia-device-test") {
+  sources = [
+    "test.fidl",
+  ]
+}
diff --git a/zircon/system/fidl/fuchsia-device-vsock/BUILD.gn b/zircon/system/fidl/fuchsia-device-vsock/BUILD.gn
new file mode 100644
index 0000000..5d6c6fc
--- /dev/null
+++ b/zircon/system/fidl/fuchsia-device-vsock/BUILD.gn
@@ -0,0 +1,11 @@
+# Copyright 2019 The Fuchsia Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+import("$zx/public/gn/fidl.gni")
+
+fidl_library("fuchsia-device-vsock") {
+  sources = [
+    "vsock.fidl",
+  ]
+}
diff --git a/zircon/system/fidl/fuchsia-device/BUILD.gn b/zircon/system/fidl/fuchsia-device/BUILD.gn
new file mode 100644
index 0000000..926fb19
--- /dev/null
+++ b/zircon/system/fidl/fuchsia-device/BUILD.gn
@@ -0,0 +1,11 @@
+# Copyright 2019 The Fuchsia Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+import("$zx/public/gn/fidl.gni")
+
+fidl_library("fuchsia-device") {
+  sources = [
+    "controller.fidl",
+  ]
+}
diff --git a/zircon/system/fidl/fuchsia-hardware-backlight/BUILD.gn b/zircon/system/fidl/fuchsia-hardware-backlight/BUILD.gn
new file mode 100644
index 0000000..a807774
--- /dev/null
+++ b/zircon/system/fidl/fuchsia-hardware-backlight/BUILD.gn
@@ -0,0 +1,11 @@
+# Copyright 2019 The Fuchsia Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+import("$zx/public/gn/fidl.gni")
+
+fidl_library("fuchsia-hardware-backlight") {
+  sources = [
+    "backlight.fidl",
+  ]
+}
diff --git a/zircon/system/fidl/fuchsia-hardware-block-partition/BUILD.gn b/zircon/system/fidl/fuchsia-hardware-block-partition/BUILD.gn
new file mode 100644
index 0000000..51cce7b
--- /dev/null
+++ b/zircon/system/fidl/fuchsia-hardware-block-partition/BUILD.gn
@@ -0,0 +1,14 @@
+# Copyright 2019 The Fuchsia Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+import("$zx/public/gn/fidl.gni")
+
+fidl_library("fuchsia-hardware-block-partition") {
+  sources = [
+    "partition.fidl",
+  ]
+  deps = [
+    "$zx/system/fidl/fuchsia-hardware-block",
+  ]
+}
diff --git a/zircon/system/fidl/fuchsia-hardware-block-volume/BUILD.gn b/zircon/system/fidl/fuchsia-hardware-block-volume/BUILD.gn
new file mode 100644
index 0000000..2835152
--- /dev/null
+++ b/zircon/system/fidl/fuchsia-hardware-block-volume/BUILD.gn
@@ -0,0 +1,15 @@
+# Copyright 2019 The Fuchsia Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+import("$zx/public/gn/fidl.gni")
+
+fidl_library("fuchsia-hardware-block-volume") {
+  sources = [
+    "volume.fidl",
+  ]
+  deps = [
+    "$zx/system/fidl/fuchsia-hardware-block",
+    "$zx/system/fidl/fuchsia-hardware-block-partition",
+  ]
+}
diff --git a/zircon/system/fidl/fuchsia-hardware-block/BUILD.gn b/zircon/system/fidl/fuchsia-hardware-block/BUILD.gn
new file mode 100644
index 0000000..ae406b7
--- /dev/null
+++ b/zircon/system/fidl/fuchsia-hardware-block/BUILD.gn
@@ -0,0 +1,12 @@
+# Copyright 2019 The Fuchsia Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+import("$zx/public/gn/fidl.gni")
+
+fidl_library("fuchsia-hardware-block") {
+  sources = [
+    "block.fidl",
+    "ftl.fidl",
+  ]
+}
diff --git a/zircon/system/fidl/fuchsia-hardware-display/BUILD.gn b/zircon/system/fidl/fuchsia-hardware-display/BUILD.gn
new file mode 100644
index 0000000..a5e7e0d
--- /dev/null
+++ b/zircon/system/fidl/fuchsia-hardware-display/BUILD.gn
@@ -0,0 +1,11 @@
+# Copyright 2019 The Fuchsia Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+import("$zx/public/gn/fidl.gni")
+
+fidl_library("fuchsia-hardware-display") {
+  sources = [
+    "display-controller.fidl",
+  ]
+}
diff --git a/zircon/system/fidl/fuchsia-hardware-ethernet/BUILD.gn b/zircon/system/fidl/fuchsia-hardware-ethernet/BUILD.gn
new file mode 100644
index 0000000..6fa4d4a
--- /dev/null
+++ b/zircon/system/fidl/fuchsia-hardware-ethernet/BUILD.gn
@@ -0,0 +1,11 @@
+# Copyright 2019 The Fuchsia Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+import("$zx/public/gn/fidl.gni")
+
+fidl_library("fuchsia-hardware-ethernet") {
+  sources = [
+    "ethernet.fidl",
+  ]
+}
diff --git a/zircon/system/fidl/fuchsia-hardware-gpu-clock/BUILD.gn b/zircon/system/fidl/fuchsia-hardware-gpu-clock/BUILD.gn
new file mode 100644
index 0000000..3d4ca07
--- /dev/null
+++ b/zircon/system/fidl/fuchsia-hardware-gpu-clock/BUILD.gn
@@ -0,0 +1,11 @@
+# Copyright 2019 The Fuchsia Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+import("$zx/public/gn/fidl.gni")
+
+fidl_library("fuchsia-hardware-gpu-clock") {
+  sources = [
+    "clock.fidl",
+  ]
+}
diff --git a/zircon/system/fidl/fuchsia-hardware-hidctl/BUILD.gn b/zircon/system/fidl/fuchsia-hardware-hidctl/BUILD.gn
new file mode 100644
index 0000000..9bb9498
--- /dev/null
+++ b/zircon/system/fidl/fuchsia-hardware-hidctl/BUILD.gn
@@ -0,0 +1,11 @@
+# Copyright 2019 The Fuchsia Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+import("$zx/public/gn/fidl.gni")
+
+fidl_library("fuchsia-hardware-hidctl") {
+  sources = [
+    "hidctl.fidl",
+  ]
+}
diff --git a/zircon/system/fidl/fuchsia-hardware-i2c/BUILD.gn b/zircon/system/fidl/fuchsia-hardware-i2c/BUILD.gn
new file mode 100644
index 0000000..68bf8e7
--- /dev/null
+++ b/zircon/system/fidl/fuchsia-hardware-i2c/BUILD.gn
@@ -0,0 +1,11 @@
+# Copyright 2019 The Fuchsia Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+import("$zx/public/gn/fidl.gni")
+
+fidl_library("fuchsia-hardware-i2c") {
+  sources = [
+    "i2c.fidl",
+  ]
+}
diff --git a/zircon/system/fidl/fuchsia-hardware-input/BUILD.gn b/zircon/system/fidl/fuchsia-hardware-input/BUILD.gn
new file mode 100644
index 0000000..3327302
--- /dev/null
+++ b/zircon/system/fidl/fuchsia-hardware-input/BUILD.gn
@@ -0,0 +1,11 @@
+# Copyright 2019 The Fuchsia Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+import("$zx/public/gn/fidl.gni")
+
+fidl_library("fuchsia-hardware-input") {
+  sources = [
+    "input.fidl",
+  ]
+}
diff --git a/zircon/system/fidl/fuchsia-hardware-light/BUILD.gn b/zircon/system/fidl/fuchsia-hardware-light/BUILD.gn
new file mode 100644
index 0000000..3f65751
--- /dev/null
+++ b/zircon/system/fidl/fuchsia-hardware-light/BUILD.gn
@@ -0,0 +1,11 @@
+# Copyright 2019 The Fuchsia Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+import("$zx/public/gn/fidl.gni")
+
+fidl_library("fuchsia-hardware-light") {
+  sources = [
+    "light.fidl",
+  ]
+}
diff --git a/zircon/system/fidl/fuchsia-hardware-nand/BUILD.gn b/zircon/system/fidl/fuchsia-hardware-nand/BUILD.gn
new file mode 100644
index 0000000..8785709
--- /dev/null
+++ b/zircon/system/fidl/fuchsia-hardware-nand/BUILD.gn
@@ -0,0 +1,12 @@
+# Copyright 2019 The Fuchsia Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+import("$zx/public/gn/fidl.gni")
+
+fidl_library("fuchsia-hardware-nand") {
+  sources = [
+    "nand.fidl",
+    "ram-nand.fidl",
+  ]
+}
diff --git a/zircon/system/fidl/fuchsia-hardware-power/BUILD.gn b/zircon/system/fidl/fuchsia-hardware-power/BUILD.gn
new file mode 100644
index 0000000..ccf1084
--- /dev/null
+++ b/zircon/system/fidl/fuchsia-hardware-power/BUILD.gn
@@ -0,0 +1,11 @@
+# Copyright 2019 The Fuchsia Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+import("$zx/public/gn/fidl.gni")
+
+fidl_library("fuchsia-hardware-power") {
+  sources = [
+    "power.fidl",
+  ]
+}
diff --git a/zircon/system/fidl/fuchsia-hardware-ramdisk/BUILD.gn b/zircon/system/fidl/fuchsia-hardware-ramdisk/BUILD.gn
new file mode 100644
index 0000000..d949c41
--- /dev/null
+++ b/zircon/system/fidl/fuchsia-hardware-ramdisk/BUILD.gn
@@ -0,0 +1,11 @@
+# Copyright 2019 The Fuchsia Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+import("$zx/public/gn/fidl.gni")
+
+fidl_library("fuchsia-hardware-ramdisk") {
+  sources = [
+    "ramdisk.fidl",
+  ]
+}
diff --git a/zircon/system/fidl/fuchsia-hardware-rtc/BUILD.gn b/zircon/system/fidl/fuchsia-hardware-rtc/BUILD.gn
new file mode 100644
index 0000000..8325aac
--- /dev/null
+++ b/zircon/system/fidl/fuchsia-hardware-rtc/BUILD.gn
@@ -0,0 +1,11 @@
+# Copyright 2019 The Fuchsia Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+import("$zx/public/gn/fidl.gni")
+
+fidl_library("fuchsia-hardware-rtc") {
+  sources = [
+    "rtc.fidl",
+  ]
+}
diff --git a/zircon/system/fidl/fuchsia-hardware-skipblock/BUILD.gn b/zircon/system/fidl/fuchsia-hardware-skipblock/BUILD.gn
new file mode 100644
index 0000000..b2ab15d
--- /dev/null
+++ b/zircon/system/fidl/fuchsia-hardware-skipblock/BUILD.gn
@@ -0,0 +1,11 @@
+# Copyright 2019 The Fuchsia Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+import("$zx/public/gn/fidl.gni")
+
+fidl_library("fuchsia-hardware-skipblock") {
+  sources = [
+    "skip-block.fidl",
+  ]
+}
diff --git a/zircon/system/fidl/fuchsia-hardware-tee/BUILD.gn b/zircon/system/fidl/fuchsia-hardware-tee/BUILD.gn
new file mode 100644
index 0000000..ef55a90
--- /dev/null
+++ b/zircon/system/fidl/fuchsia-hardware-tee/BUILD.gn
@@ -0,0 +1,11 @@
+# Copyright 2019 The Fuchsia Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+import("$zx/public/gn/fidl.gni")
+
+fidl_library("fuchsia-hardware-tee") {
+  sources = [
+    "tee.fidl",
+  ]
+}
diff --git a/zircon/system/fidl/fuchsia-hardware-usb-device/BUILD.gn b/zircon/system/fidl/fuchsia-hardware-usb-device/BUILD.gn
new file mode 100644
index 0000000..e2c9b14
--- /dev/null
+++ b/zircon/system/fidl/fuchsia-hardware-usb-device/BUILD.gn
@@ -0,0 +1,11 @@
+# Copyright 2019 The Fuchsia Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+import("$zx/public/gn/fidl.gni")
+
+fidl_library("fuchsia-hardware-usb-device") {
+  sources = [
+    "usb-device.fidl",
+  ]
+}
diff --git a/zircon/system/fidl/fuchsia-hardware-usb-fwloader/BUILD.gn b/zircon/system/fidl/fuchsia-hardware-usb-fwloader/BUILD.gn
new file mode 100644
index 0000000..3ae3909
--- /dev/null
+++ b/zircon/system/fidl/fuchsia-hardware-usb-fwloader/BUILD.gn
@@ -0,0 +1,14 @@
+# Copyright 2019 The Fuchsia Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+import("$zx/public/gn/fidl.gni")
+
+fidl_library("fuchsia-hardware-usb-fwloader") {
+  sources = [
+    "usb-test-fwloader.fidl",
+  ]
+  public_deps = [
+    "$zx/system/fidl/fuchsia-mem",
+  ]
+}
diff --git a/zircon/system/fidl/fuchsia-hardware-usb-peripheral/BUILD.gn b/zircon/system/fidl/fuchsia-hardware-usb-peripheral/BUILD.gn
new file mode 100644
index 0000000..9f68fe3
--- /dev/null
+++ b/zircon/system/fidl/fuchsia-hardware-usb-peripheral/BUILD.gn
@@ -0,0 +1,11 @@
+# Copyright 2019 The Fuchsia Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+import("$zx/public/gn/fidl.gni")
+
+fidl_library("fuchsia-hardware-usb-peripheral") {
+  sources = [
+    "usb-peripheral.fidl",
+  ]
+}
diff --git a/zircon/system/fidl/fuchsia-hardware-usb-tester/BUILD.gn b/zircon/system/fidl/fuchsia-hardware-usb-tester/BUILD.gn
new file mode 100644
index 0000000..bd5c700
--- /dev/null
+++ b/zircon/system/fidl/fuchsia-hardware-usb-tester/BUILD.gn
@@ -0,0 +1,11 @@
+# Copyright 2019 The Fuchsia Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+import("$zx/public/gn/fidl.gni")
+
+fidl_library("fuchsia-hardware-usb-tester") {
+  sources = [
+    "usb-tester.fidl",
+  ]
+}
diff --git a/zircon/system/fidl/fuchsia-hardware-usb-virtual-bus/BUILD.gn b/zircon/system/fidl/fuchsia-hardware-usb-virtual-bus/BUILD.gn
new file mode 100644
index 0000000..c908da6
--- /dev/null
+++ b/zircon/system/fidl/fuchsia-hardware-usb-virtual-bus/BUILD.gn
@@ -0,0 +1,20 @@
+# Copyright 2019 The Fuchsia Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+import("$zx/public/gn/fidl.gni")
+
+# TODO(ZX-3365): rename the dir
+if (current_toolchain != default_toolchain) {
+  group("c") {
+    public_deps = [
+      ":fuchsia.usb.virtualbus.c",
+    ]
+  }
+}
+
+fidl_library("fuchsia.usb.virtualbus") {
+  sources = [
+    "usb-virtual-bus.fidl",
+  ]
+}
diff --git a/zircon/system/fidl/fuchsia-hardware-vsock/BUILD.gn b/zircon/system/fidl/fuchsia-hardware-vsock/BUILD.gn
new file mode 100644
index 0000000..04ff89c1
--- /dev/null
+++ b/zircon/system/fidl/fuchsia-hardware-vsock/BUILD.gn
@@ -0,0 +1,11 @@
+# Copyright 2019 The Fuchsia Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+import("$zx/public/gn/fidl.gni")
+
+fidl_library("fuchsia-hardware-vsock") {
+  sources = [
+    "vsock.fidl",
+  ]
+}
diff --git a/zircon/system/fidl/fuchsia-i2c/BUILD.gn b/zircon/system/fidl/fuchsia-i2c/BUILD.gn
new file mode 100644
index 0000000..99d4f3f
--- /dev/null
+++ b/zircon/system/fidl/fuchsia-i2c/BUILD.gn
@@ -0,0 +1,11 @@
+# Copyright 2019 The Fuchsia Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+import("$zx/public/gn/fidl.gni")
+
+fidl_library("fuchsia-i2c") {
+  sources = [
+    "i2c.fidl",
+  ]
+}
diff --git a/zircon/system/fidl/fuchsia-inspect/BUILD.gn b/zircon/system/fidl/fuchsia-inspect/BUILD.gn
new file mode 100644
index 0000000..7cd06fd
--- /dev/null
+++ b/zircon/system/fidl/fuchsia-inspect/BUILD.gn
@@ -0,0 +1,11 @@
+# Copyright 2019 The Fuchsia Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+import("$zx/public/gn/fidl.gni")
+
+fidl_library("fuchsia-inspect") {
+  sources = [
+    "inspect.fidl",
+  ]
+}
diff --git a/zircon/system/fidl/fuchsia-io/BUILD.gn b/zircon/system/fidl/fuchsia-io/BUILD.gn
new file mode 100644
index 0000000..088adae
--- /dev/null
+++ b/zircon/system/fidl/fuchsia-io/BUILD.gn
@@ -0,0 +1,14 @@
+# Copyright 2019 The Fuchsia Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+import("$zx/public/gn/fidl.gni")
+
+fidl_library("fuchsia-io") {
+  sources = [
+    "io.fidl",
+  ]
+  public_deps = [
+    "$zx/system/fidl/fuchsia-mem",
+  ]
+}
diff --git a/zircon/system/fidl/fuchsia-ldsvc/BUILD.gn b/zircon/system/fidl/fuchsia-ldsvc/BUILD.gn
new file mode 100644
index 0000000..0542554
--- /dev/null
+++ b/zircon/system/fidl/fuchsia-ldsvc/BUILD.gn
@@ -0,0 +1,11 @@
+# Copyright 2019 The Fuchsia Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+import("$zx/public/gn/fidl.gni")
+
+fidl_library("fuchsia-ldsvc") {
+  sources = [
+    "ldsvc.fidl",
+  ]
+}
diff --git a/zircon/system/fidl/fuchsia-logger/BUILD.gn b/zircon/system/fidl/fuchsia-logger/BUILD.gn
new file mode 100644
index 0000000..d5a45fe
--- /dev/null
+++ b/zircon/system/fidl/fuchsia-logger/BUILD.gn
@@ -0,0 +1,11 @@
+# Copyright 2019 The Fuchsia Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+import("$zx/public/gn/fidl.gni")
+
+fidl_library("fuchsia-logger") {
+  sources = [
+    "logger.fidl",
+  ]
+}
diff --git a/zircon/system/fidl/fuchsia-mem/BUILD.gn b/zircon/system/fidl/fuchsia-mem/BUILD.gn
new file mode 100644
index 0000000..f0b210f3
--- /dev/null
+++ b/zircon/system/fidl/fuchsia-mem/BUILD.gn
@@ -0,0 +1,11 @@
+# Copyright 2019 The Fuchsia Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+import("$zx/public/gn/fidl.gni")
+
+fidl_library("fuchsia-mem") {
+  sources = [
+    "buffer.fidl",
+  ]
+}
diff --git a/zircon/system/fidl/fuchsia-minfs/BUILD.gn b/zircon/system/fidl/fuchsia-minfs/BUILD.gn
new file mode 100644
index 0000000..309ed60
--- /dev/null
+++ b/zircon/system/fidl/fuchsia-minfs/BUILD.gn
@@ -0,0 +1,11 @@
+# Copyright 2019 The Fuchsia Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+import("$zx/public/gn/fidl.gni")
+
+fidl_library("fuchsia-minfs") {
+  sources = [
+    "minfs.fidl",
+  ]
+}
diff --git a/zircon/system/fidl/fuchsia-nand/BUILD.gn b/zircon/system/fidl/fuchsia-nand/BUILD.gn
new file mode 100644
index 0000000..dfbc35d
--- /dev/null
+++ b/zircon/system/fidl/fuchsia-nand/BUILD.gn
@@ -0,0 +1,14 @@
+# Copyright 2019 The Fuchsia Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+import("$zx/public/gn/fidl.gni")
+
+fidl_library("fuchsia-nand") {
+  sources = [
+    "broker.fidl",
+  ]
+  public_deps = [
+    "$zx/system/fidl/fuchsia-hardware-nand",
+  ]
+}
diff --git a/zircon/system/fidl/fuchsia-net-stack/BUILD.gn b/zircon/system/fidl/fuchsia-net-stack/BUILD.gn
new file mode 100644
index 0000000..98f59f9
--- /dev/null
+++ b/zircon/system/fidl/fuchsia-net-stack/BUILD.gn
@@ -0,0 +1,15 @@
+# Copyright 2019 The Fuchsia Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+import("$zx/public/gn/fidl.gni")
+
+fidl_library("fuchsia-net-stack") {
+  sources = [
+    "stack.fidl",
+  ]
+  public_deps = [
+    "$zx/system/fidl/fuchsia-hardware-ethernet",
+    "$zx/system/fidl/fuchsia-net",
+  ]
+}
diff --git a/zircon/system/fidl/fuchsia-net/BUILD.gn b/zircon/system/fidl/fuchsia-net/BUILD.gn
new file mode 100644
index 0000000..03f1d2c
--- /dev/null
+++ b/zircon/system/fidl/fuchsia-net/BUILD.gn
@@ -0,0 +1,13 @@
+# Copyright 2019 The Fuchsia Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+import("$zx/public/gn/fidl.gni")
+
+fidl_library("fuchsia-net") {
+  sources = [
+    "connectivity.fidl",
+    "net.fidl",
+    "socket.fidl",
+  ]
+}
diff --git a/zircon/system/fidl/fuchsia-power/BUILD.gn b/zircon/system/fidl/fuchsia-power/BUILD.gn
new file mode 100644
index 0000000..5087d0d
--- /dev/null
+++ b/zircon/system/fidl/fuchsia-power/BUILD.gn
@@ -0,0 +1,11 @@
+# Copyright 2019 The Fuchsia Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+import("$zx/public/gn/fidl.gni")
+
+fidl_library("fuchsia-power") {
+  sources = [
+    "power.fidl",
+  ]
+}
diff --git a/zircon/system/fidl/fuchsia-process/BUILD.gn b/zircon/system/fidl/fuchsia-process/BUILD.gn
new file mode 100644
index 0000000..8085f25
--- /dev/null
+++ b/zircon/system/fidl/fuchsia-process/BUILD.gn
@@ -0,0 +1,16 @@
+# Copyright 2019 The Fuchsia Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+import("$zx/public/gn/fidl.gni")
+
+fidl_library("fuchsia-process") {
+  sources = [
+    "launcher.fidl",
+    "resolver.fidl",
+  ]
+  public_deps = [
+    "$zx/system/fidl/fuchsia-io",
+    "$zx/system/fidl/fuchsia-ldsvc",
+  ]
+}
diff --git a/zircon/system/fidl/fuchsia-profile/BUILD.gn b/zircon/system/fidl/fuchsia-profile/BUILD.gn
new file mode 100644
index 0000000..073b396
--- /dev/null
+++ b/zircon/system/fidl/fuchsia-profile/BUILD.gn
@@ -0,0 +1,20 @@
+# Copyright 2019 The Fuchsia Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+import("$zx/public/gn/fidl.gni")
+
+fidl_library("fuchsia.scheduler") {
+  sources = [
+    "profile.fidl",
+  ]
+}
+
+if (current_toolchain != default_toolchain) {
+  group("c") {
+    # TODO(ZX-3365): rename this dir
+    public_deps = [
+      ":fuchsia.scheduler.c",
+    ]
+  }
+}
diff --git a/zircon/system/fidl/fuchsia-sysinfo/BUILD.gn b/zircon/system/fidl/fuchsia-sysinfo/BUILD.gn
new file mode 100644
index 0000000..aa35ffca
--- /dev/null
+++ b/zircon/system/fidl/fuchsia-sysinfo/BUILD.gn
@@ -0,0 +1,11 @@
+# Copyright 2019 The Fuchsia Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+import("$zx/public/gn/fidl.gni")
+
+fidl_library("fuchsia-sysinfo") {
+  sources = [
+    "sysinfo.fidl",
+  ]
+}
diff --git a/zircon/system/fidl/fuchsia-sysmem/BUILD.gn b/zircon/system/fidl/fuchsia-sysmem/BUILD.gn
new file mode 100644
index 0000000..10dad2a
--- /dev/null
+++ b/zircon/system/fidl/fuchsia-sysmem/BUILD.gn
@@ -0,0 +1,20 @@
+# Copyright 2019 The Fuchsia Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+import("$zx/public/gn/fidl.gni")
+
+fidl_library("fuchsia-sysmem") {
+  sources = [
+    "allocator.fidl",
+    "allocator_2.fidl",
+    "collection.fidl",
+    "collections.fidl",
+    "constraints.fidl",
+    "driver_connector.fidl",
+    "format_modifier.fidl",
+    "formats.fidl",
+    "image_formats.fidl",
+    "usages.fidl",
+  ]
+}
diff --git a/zircon/system/fidl/fuchsia-tracelink/BUILD.gn b/zircon/system/fidl/fuchsia-tracelink/BUILD.gn
new file mode 100644
index 0000000..5f2cbb7
--- /dev/null
+++ b/zircon/system/fidl/fuchsia-tracelink/BUILD.gn
@@ -0,0 +1,11 @@
+# Copyright 2019 The Fuchsia Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+import("$zx/public/gn/fidl.gni")
+
+fidl_library("fuchsia-tracelink") {
+  sources = [
+    "tracelink.fidl",
+  ]
+}
diff --git a/zircon/system/fidl/fuchsia-usb-debug/BUILD.gn b/zircon/system/fidl/fuchsia-usb-debug/BUILD.gn
new file mode 100644
index 0000000..2910a37
--- /dev/null
+++ b/zircon/system/fidl/fuchsia-usb-debug/BUILD.gn
@@ -0,0 +1,11 @@
+# Copyright 2019 The Fuchsia Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+import("$zx/public/gn/fidl.gni")
+
+fidl_library("fuchsia-usb-debug") {
+  sources = [
+    "usb-debug.fidl",
+  ]
+}
diff --git a/zircon/system/ulib/async/BUILD.gn b/zircon/system/ulib/async/BUILD.gn
new file mode 100644
index 0000000..c023b00
--- /dev/null
+++ b/zircon/system/ulib/async/BUILD.gn
@@ -0,0 +1,66 @@
+# Copyright 2019 The Fuchsia Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+library("async") {
+  sdk = "source"
+  sdk_headers = [
+    "lib/async/dispatcher.h",
+    "lib/async/exception.h",
+    "lib/async/receiver.h",
+    "lib/async/task.h",
+    "lib/async/time.h",
+    "lib/async/trap.h",
+    "lib/async/wait.h",
+  ]
+  sources = [
+    "ops.c",
+  ]
+  configs += [ "$zx/public/gn/config:visibility_hidden" ]
+  deps = [
+    "$zx/system/ulib/zircon",
+  ]
+}
+
+library("async-cpp") {
+  sdk = "source"
+  sdk_headers = [
+    "lib/async/cpp/exception.h",
+    "lib/async/cpp/receiver.h",
+    "lib/async/cpp/task.h",
+    "lib/async/cpp/time.h",
+    "lib/async/cpp/trap.h",
+    "lib/async/cpp/wait.h",
+  ]
+  public_deps = [
+    # <lib/async/cpp/task.h> has #include <lib/zx/time.h>.
+    "$zx/system/ulib/zx:headers",
+
+    # <lib/async/cpp/task.h> has #include <fbl/function.h>.
+    "$zx/system/ulib/fbl:headers",
+  ]
+  sources = [
+    "exception.cpp",
+    "receiver.cpp",
+    "task.cpp",
+    "trap.cpp",
+    "wait.cpp",
+  ]
+  configs += [ "$zx/public/gn/config:visibility_hidden" ]
+  deps = [
+    ":async",
+    "$zx/system/ulib/fbl",
+    "$zx/system/ulib/zircon",
+    "$zx/system/ulib/zx",
+  ]
+}
+
+library("async-default") {
+  sdk = "shared"
+  sdk_headers = [ "lib/async/default.h" ]
+  shared = true
+  sources = [
+    "default.c",
+  ]
+  configs += [ "$zx/public/gn/config:visibility_hidden" ]
+}
diff --git a/zircon/system/ulib/fdio/BUILD.gn b/zircon/system/ulib/fdio/BUILD.gn
new file mode 100644
index 0000000..07d94f5
--- /dev/null
+++ b/zircon/system/ulib/fdio/BUILD.gn
@@ -0,0 +1,57 @@
+# Copyright 2019 The Fuchsia Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+library("fdio") {
+  sdk = "shared"
+  sdk_headers = [
+    "lib/fdio/debug.h",
+    "lib/fdio/directory.h",
+    "lib/fdio/fd.h",
+    "lib/fdio/fdio.h",
+    "lib/fdio/io.h",
+    "lib/fdio/limits.h",
+    "lib/fdio/namespace.h",
+    "lib/fdio/private.h",
+    "lib/fdio/spawn.h",
+    "lib/fdio/unsafe.h",
+    "lib/fdio/util.h",
+    "lib/fdio/vfs.h",
+    "lib/fdio/watcher.h",
+  ]
+  shared = true
+  sources = [
+    "bsdsocket.c",
+    "fd.cpp",
+    "fdio.c",
+    "get-vmo.c",
+    "namespace/local-connection.cpp",
+    "namespace/local-filesystem.cpp",
+    "namespace/local-vnode.cpp",
+    "namespace/namespace.cpp",
+    "null.c",
+    "remoteio.c",
+    "socket.c",
+    "spawn.c",
+    "stubs.c",
+    "uname.c",
+    "unistd.c",
+    "waitable.cpp",
+    "watcher.c",
+    "zxio.c",
+  ]
+  configs += [ "$zx/public/gn/config:visibility_hidden" ]
+  deps = [
+    "$zx/system/fidl/fuchsia-io:c",
+    "$zx/system/fidl/fuchsia-ldsvc:c",
+    "$zx/system/fidl/fuchsia-net:c",
+    "$zx/system/fidl/fuchsia-process:c",
+    "$zx/system/ulib/fbl",
+    "$zx/system/ulib/fidl",
+    "$zx/system/ulib/zircon",
+    "$zx/system/ulib/zx",
+    "$zx/system/ulib/zxcpp",
+    "$zx/system/ulib/zxio",
+    "$zx/system/ulib/zxs",
+  ]
+}
diff --git a/zircon/system/ulib/fidl/BUILD.gn b/zircon/system/ulib/fidl/BUILD.gn
new file mode 100644
index 0000000..4b51392
--- /dev/null
+++ b/zircon/system/ulib/fidl/BUILD.gn
@@ -0,0 +1,48 @@
+# Copyright 2019 The Fuchsia Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+library("fidl") {
+  sdk = "source"
+  sdk_headers = [
+    "lib/fidl/cpp/message.h",
+    "lib/fidl/cpp/string_view.h",
+    "lib/fidl/cpp/message_part.h",
+    "lib/fidl/cpp/message_builder.h",
+    "lib/fidl/cpp/builder.h",
+    "lib/fidl/cpp/message_buffer.h",
+    "lib/fidl/cpp/vector_view.h",
+    "lib/fidl/coding.h",
+    "lib/fidl/llcpp/array_wrapper.h",
+    "lib/fidl/llcpp/encoded_message.h",
+    "lib/fidl/llcpp/coding.h",
+    "lib/fidl/llcpp/decoded_message.h",
+    "lib/fidl/llcpp/traits.h",
+    "lib/fidl/epitaph.h",
+    "lib/fidl/transport.h",
+    "lib/fidl/internal_callable_traits.h",
+    "lib/fidl/internal.h",
+  ]
+  sources = [
+    "builder.cpp",
+    "decoding.cpp",
+    "encoding.cpp",
+    "envelope_frames.h",
+    "epitaph.c",
+    "formatting.cpp",
+    "handle_closing.cpp",
+    "linearizing.cpp",
+    "message.cpp",
+    "message_buffer.cpp",
+    "message_builder.cpp",
+    "transport.cpp",
+    "validating.cpp",
+    "visitor.h",
+    "walker.cpp",
+    "walker.h",
+  ]
+  configs += [ "$zx/public/gn/config:visibility_hidden" ]
+  deps = [
+    "$zx/system/ulib/zircon",
+  ]
+}
diff --git a/zircon/system/ulib/zx/BUILD.gn b/zircon/system/ulib/zx/BUILD.gn
new file mode 100644
index 0000000..3176eda
--- /dev/null
+++ b/zircon/system/ulib/zx/BUILD.gn
@@ -0,0 +1,69 @@
+# Copyright 2019 The Fuchsia Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+assert(is_fuchsia)
+
+library("zx") {
+  sdk = "source"
+  sdk_headers = [
+    "lib/zx/bti.h",
+    "lib/zx/channel.h",
+    "lib/zx/debuglog.h",
+    "lib/zx/event.h",
+    "lib/zx/eventpair.h",
+    "lib/zx/fifo.h",
+    "lib/zx/guest.h",
+    "lib/zx/handle.h",
+    "lib/zx/interrupt.h",
+    "lib/zx/iommu.h",
+    "lib/zx/job.h",
+    "lib/zx/object.h",
+    "lib/zx/object_traits.h",
+    "lib/zx/pager.h",
+    "lib/zx/pmt.h",
+    "lib/zx/port.h",
+    "lib/zx/process.h",
+    "lib/zx/profile.h",
+    "lib/zx/resource.h",
+    "lib/zx/socket.h",
+    "lib/zx/suspend_token.h",
+    "lib/zx/task.h",
+    "lib/zx/thread.h",
+    "lib/zx/time.h",
+    "lib/zx/timer.h",
+    "lib/zx/vcpu.h",
+    "lib/zx/vmar.h",
+    "lib/zx/vmo.h",
+  ]
+  sources = [
+    "bti.cpp",
+    "channel.cpp",
+    "debuglog.cpp",
+    "event.cpp",
+    "eventpair.cpp",
+    "fifo.cpp",
+    "guest.cpp",
+    "interrupt.cpp",
+    "iommu.cpp",
+    "job.cpp",
+    "pager.cpp",
+    "port.cpp",
+    "process.cpp",
+    "profile.cpp",
+    "resource.cpp",
+    "socket.cpp",
+    "thread.cpp",
+    "timer.cpp",
+    "vcpu.cpp",
+    "vmar.cpp",
+    "vmo.cpp",
+  ]
+  configs += [ "$zx/public/gn/config:visibility_hidden" ]
+  deps = [
+    "$zx/system/ulib/zircon",
+  ]
+  public_deps = [
+    "$zx/system/ulib/zircon:headers",
+  ]
+}
diff --git a/zircon/system/ulib/zxcpp/BUILD.gn b/zircon/system/ulib/zxcpp/BUILD.gn
new file mode 100644
index 0000000..add9a07
--- /dev/null
+++ b/zircon/system/ulib/zxcpp/BUILD.gn
@@ -0,0 +1,19 @@
+# Copyright 2019 The Fuchsia Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+library("zxcpp") {
+  kernel = true
+  static = true
+  sdk = "source"
+  sdk_headers = []
+  sources = [
+    "new.cpp",
+    "pure_virtual.cpp",
+    "thread_atexit.cpp",
+  ]
+  if (toolchain.environment == "kernel") {
+    # Avoid circularity.
+    configs -= [ "$zx/kernel/vm:headers.config" ]
+  }
+}
diff --git a/zircon/system/ulib/zxio/BUILD.gn b/zircon/system/ulib/zxio/BUILD.gn
new file mode 100644
index 0000000..626d3bb2
--- /dev/null
+++ b/zircon/system/ulib/zxio/BUILD.gn
@@ -0,0 +1,36 @@
+# Copyright 2019 The Fuchsia Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+library("zxio") {
+  sdk = "static"
+  sdk_headers = [
+    "lib/zxio/inception.h",
+    "lib/zxio/null.h",
+    "lib/zxio/ops.h",
+    "lib/zxio/types.h",
+    "lib/zxio/zxio.h",
+  ]
+  sources = [
+    "debuglog.cpp",
+    "null.cpp",
+    "pipe.cpp",
+    "remote.cpp",
+    "socket.cpp",
+    "vmo.cpp",
+    "vmofile.cpp",
+    "zxio.cpp",
+  ]
+  public_deps = [
+    # <lib/zxio/zxio.h> has #include <fuchsia/io/c/fidl.h>.
+    "$zx/system/fidl/fuchsia-io:c.headers",
+  ]
+  configs += [ "$zx/public/gn/config:visibility_hidden" ]
+  deps = [
+    "$zx/system/fidl/fuchsia-io:c",
+    "$zx/system/fidl/fuchsia-net:c",
+    "$zx/system/ulib/zircon",
+    "$zx/system/ulib/zx",
+    "$zx/system/ulib/zxs",
+  ]
+}
diff --git a/zircon/system/ulib/zxs/BUILD.gn b/zircon/system/ulib/zxs/BUILD.gn
new file mode 100644
index 0000000..943fce7
--- /dev/null
+++ b/zircon/system/ulib/zxs/BUILD.gn
@@ -0,0 +1,24 @@
+# Copyright 2019 The Fuchsia Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+library("zxs") {
+  sdk = "static"
+  sdk_headers = [
+    "lib/zxs/protocol.h",
+    "lib/zxs/zxs.h",
+  ]
+  sources = [
+    "zxs.cpp",
+  ]
+  public_deps = [
+    # <lib/zxs/zxs.h> has #include <fuchsia/net/c/fidl.h>.
+    "$zx/system/fidl/fuchsia-net:c.headers",
+  ]
+  configs += [ "$zx/public/gn/config:visibility_hidden" ]
+  deps = [
+    "$zx/system/fidl/fuchsia-net:c",
+    "$zx/system/ulib/zircon",
+    "$zx/system/ulib/zx",
+  ]
+}