[build] Assert is_host in golden_test.gni

This CL makes the golden_test template `assert(is_host)`. This would
have saved confusion recently, when a new golden test setup was not
working because the `($host_toolchain)` was missing.

Doing this required reorganizing call sites so that the golden_test
invocation is inside an `if (is_host)` block. Following the
recommendation of build folks, I've structured host-tool BUILD.gn files
to place most things in one big if-statement, with groups at the bottom
that redirect to $host_toolchain.

Change-Id: Id1e747d322ed5bcfa64060463ca8d91db9e1938a
Reviewed-on: https://fuchsia-review.googlesource.com/c/fuchsia/+/513324
Commit-Queue: Mitchell Kember <mkember@google.com>
Reviewed-by: Ian McKellar <ianloic@google.com>
diff --git a/build/testing/golden_test.gni b/build/testing/golden_test.gni
index daf56ab..be61e4c 100644
--- a/build/testing/golden_test.gni
+++ b/build/testing/golden_test.gni
@@ -65,6 +65,8 @@
 #   visibility
 #
 template("golden_test") {
+  assert(is_host, "The golden_test template can only be used on host")
+
   assert(defined(invoker.goldens_dir))
   assert(defined(invoker.entries))
   assert(defined(invoker.deps))
diff --git a/tools/fidl/fidlc/BUILD.gn b/tools/fidl/fidlc/BUILD.gn
index a01cdc8..6187cc6 100644
--- a/tools/fidl/fidlc/BUILD.gn
+++ b/tools/fidl/fidlc/BUILD.gn
@@ -121,22 +121,24 @@
   }
 }
 
-golden_test("fidlc_golden_tests") {
-  goldens_dir = "goldens"
-  deps = []
-  entries = []
-  foreach(info, fidl_testdata_info) {
-    deps += [ "${info.target}($fidl_toolchain)" ]
-    entries += [
-      {
-        golden = "${info.name}.json.golden"
-        generated = "${info.fidl_gen_dir}/${info.target_name}.fidl.json"
-      },
-      {
-        golden = "${info.name}.tables.c.golden"
-        generated = "${info.fidl_gen_dir}/${info.target_name}.fidl.tables.c"
-      },
-    ]
+if (is_host) {
+  golden_test("fidlc_golden_tests") {
+    goldens_dir = "goldens"
+    deps = []
+    entries = []
+    foreach(info, fidl_testdata_info) {
+      deps += [ "${info.target}($fidl_toolchain)" ]
+      entries += [
+        {
+          golden = "${info.name}.json.golden"
+          generated = "${info.fidl_gen_dir}/${info.target_name}.fidl.json"
+        },
+        {
+          golden = "${info.name}.tables.c.golden"
+          generated = "${info.fidl_gen_dir}/${info.target_name}.fidl.tables.c"
+        },
+      ]
+    }
   }
 }
 
diff --git a/tools/fidl/fidldoc/BUILD.gn b/tools/fidl/fidldoc/BUILD.gn
index 1cbc161..093736c 100644
--- a/tools/fidl/fidldoc/BUILD.gn
+++ b/tools/fidl/fidldoc/BUILD.gn
@@ -49,9 +49,7 @@
       ":rust_crates",
       "//src/lib/libdoc",
     ]
-
     sources = common_sources
-
     inputs = common_inputs
   }
 
@@ -67,9 +65,7 @@
       ":rust_crates",
       "//src/lib/libdoc",
     ]
-
     sources = common_sources
-
     inputs = common_inputs + [
                "src/templates/markdown/testdata/README.md",
                "src/templates/markdown/testdata/_toc.yaml",
@@ -93,6 +89,63 @@
       "//third_party/rust_crates:tempfile",
     ]
   }
+
+  fidl_testdata_info_filtered = []
+  foreach(info, fidl_testdata_info) {
+    if (info.denylist + [ "fidldoc" ] - [ "fidldoc" ] == info.denylist) {
+      fidl_testdata_info_filtered += [ info ]
+    }
+  }
+
+  compiled_action("generate_goldens") {
+    testonly = true
+    tool = ":fidldoc_bin"
+    tool_output_name = "fidldoc"
+    deps = [ ":fidldoc_copy_config" ]
+    sources = []
+    inputs = [ "${host_tools_dir}/fidldoc.config.json" ]
+    args = [
+      "--silent",
+      "--config",
+      rebase_path("${host_tools_dir}/fidldoc.config.json", root_build_dir),
+      "--out",
+      rebase_path("${target_gen_dir}/goldens", root_build_dir),
+    ]
+    outputs = [
+      "$target_gen_dir/goldens/_toc.yaml",
+      "$target_gen_dir/goldens/README.md",
+    ]
+    foreach(info, fidl_testdata_info_filtered) {
+      deps += [ "${info.target}($fidl_toolchain)" ]
+      json_ir = "${info.fidl_gen_dir}/${info.target_name}.fidl.json"
+      sources += [ json_ir ]
+      args += [ rebase_path(json_ir, root_build_dir) ]
+      outputs += [ "$target_gen_dir/goldens/${info.library}/README.md" ]
+    }
+  }
+
+  golden_test("fidldoc_golden_tests") {
+    goldens_dir = "goldens"
+    deps = [ ":generate_goldens" ]
+    entries = [
+      {
+        golden = "_toc.yaml.golden"
+        generated = "$target_gen_dir/goldens/_toc.yaml"
+      },
+      {
+        golden = "README.md.golden"
+        generated = "$target_gen_dir/goldens/README.md"
+      },
+    ]
+    foreach(info, fidl_testdata_info_filtered) {
+      entries += [
+        {
+          golden = "${info.name}.md.golden"
+          generated = "$target_gen_dir/goldens/${info.library}/README.md"
+        },
+      ]
+    }
+  }
 }
 
 install_host_tools("fidldoc") {
@@ -100,75 +153,11 @@
     ":fidldoc_bin($host_toolchain)",
     ":fidldoc_copy_config($host_toolchain)",
   ]
-
   outputs = [ "fidldoc" ]
 }
 
-fidl_testdata_info_filtered = []
-foreach(info, fidl_testdata_info) {
-  if (info.denylist + [ "fidldoc" ] - [ "fidldoc" ] == info.denylist) {
-    fidl_testdata_info_filtered += [ info ]
-  }
-}
-
-copy("config_for_tests") {
-  sources = [ "src/fidldoc.config.json" ]
-  outputs = [ "$target_gen_dir/fidldoc.config.json" ]
-}
-
-compiled_action("generate_goldens") {
-  testonly = true
-  tool = ":fidldoc_bin"
-  tool_output_name = "fidldoc"
-  deps = [ ":config_for_tests" ]
-  sources = []
-  args = [
-    "--silent",
-    "--config",
-    rebase_path(target_gen_dir, root_build_dir) + "/fidldoc.config.json",
-    "--out",
-    rebase_path(target_gen_dir, root_build_dir) + "/goldens",
-  ]
-  outputs = [
-    "$target_gen_dir/goldens/_toc.yaml",
-    "$target_gen_dir/goldens/README.md",
-  ]
-  foreach(info, fidl_testdata_info_filtered) {
-    deps += [ "${info.target}($fidl_toolchain)" ]
-    json_ir = "${info.fidl_gen_dir}/${info.target_name}.fidl.json"
-    sources += [ json_ir ]
-    args += [ rebase_path(json_ir, root_build_dir) ]
-    outputs += [ "$target_gen_dir/goldens/${info.library}/README.md" ]
-  }
-  hermetic_deps = false
-}
-
-golden_test("fidldoc_golden_tests") {
-  goldens_dir = "goldens"
-  deps = [ ":generate_goldens" ]
-  entries = [
-    {
-      golden = "_toc.yaml.golden"
-      generated = "$target_gen_dir/goldens/_toc.yaml"
-    },
-    {
-      golden = "README.md.golden"
-      generated = "$target_gen_dir/goldens/README.md"
-    },
-  ]
-  foreach(info, fidl_testdata_info_filtered) {
-    entries += [
-      {
-        golden = "${info.name}.md.golden"
-        generated = "$target_gen_dir/goldens/${info.library}/README.md"
-      },
-    ]
-  }
-}
-
 group("tests") {
   testonly = true
-
   deps = [
     ":fidldoc_bin_test($host_toolchain)",
     ":fidldoc_golden_tests($host_toolchain)",
diff --git a/tools/fidl/fidlgen_cpp/BUILD.gn b/tools/fidl/fidlgen_cpp/BUILD.gn
index 9ec3049..699164e 100644
--- a/tools/fidl/fidlgen_cpp/BUILD.gn
+++ b/tools/fidl/fidlgen_cpp/BUILD.gn
@@ -9,25 +9,55 @@
 import("//build/testing/golden_test.gni")
 import("//tools/fidl/fidlc/testdata/info.gni")
 
-go_library("gopkg") {
-  name = "go.fuchsia.dev/fuchsia/tools/fidl/fidlgen_cpp/..."
-  deps = [
-    "//tools/fidl/lib/fidlgen",
-    "//tools/fidl/lib/fidlgen_cpp",
-  ]
-  sources = [
-    "codegen/codegen.go",
-    "codegen/file_header.tmpl.go",
-    "codegen/file_source.tmpl.go",
-    "codegen/fragment_const.tmpl.go",
-    "codegen/fragment_type_alias.tmpl.go",
-    "main.go",
-  ]
-}
+if (is_host) {
+  go_library("gopkg") {
+    name = "go.fuchsia.dev/fuchsia/tools/fidl/fidlgen_cpp/..."
+    deps = [
+      "//tools/fidl/lib/fidlgen",
+      "//tools/fidl/lib/fidlgen_cpp",
+    ]
+    sources = [
+      "codegen/codegen.go",
+      "codegen/file_header.tmpl.go",
+      "codegen/file_source.tmpl.go",
+      "codegen/fragment_const.tmpl.go",
+      "codegen/fragment_type_alias.tmpl.go",
+      "main.go",
+    ]
+  }
 
-go_binary("fidlgen_cpp") {
-  gopackage = "go.fuchsia.dev/fuchsia/tools/fidl/fidlgen_cpp"
-  deps = [ ":gopkg" ]
+  go_binary("fidlgen_cpp") {
+    gopackage = "go.fuchsia.dev/fuchsia/tools/fidl/fidlgen_cpp"
+    deps = [ ":gopkg" ]
+  }
+
+  clang_format = rebase_path("${clang_prefix}/clang-format", "", root_build_dir)
+  reformat_command = "'${clang_format}' --style=google"
+
+  golden_test("fidlgen_cpp_golden_tests") {
+    goldens_dir = "goldens"
+    reformat_goldens_command = reformat_command
+    deps = []
+    entries = []
+    foreach(info, fidl_testdata_info) {
+      if (info.denylist + [ "fidlgen_cpp" ] - [ "fidlgen_cpp" ] ==
+          info.denylist) {
+        deps += [ "${info.target}_cpp_generate($fidl_toolchain)" ]
+        gen_dir = "${info.fidl_gen_dir}/${info.target_name}/cpp"
+        include_path = string_replace(info.library, ".", "/") + "/cpp"
+        entries += [
+          {
+            golden = "${info.name}.h.golden"
+            generated = "$gen_dir/$include_path/fidl_v2.h"
+          },
+          {
+            golden = "${info.name}.cc.golden"
+            generated = "$gen_dir/$include_path/fidl_v2.cc"
+          },
+        ]
+      }
+    }
+  }
 }
 
 install_host_tools("host") {
@@ -35,34 +65,6 @@
   outputs = [ "fidlgen_cpp" ]
 }
 
-clang_format = rebase_path("${clang_prefix}/clang-format", "", root_build_dir)
-reformat_command = "'${clang_format}' --style=google"
-
-golden_test("fidlgen_cpp_golden_tests") {
-  goldens_dir = "goldens"
-  reformat_goldens_command = reformat_command
-  deps = []
-  entries = []
-  foreach(info, fidl_testdata_info) {
-    if (info.denylist + [ "fidlgen_cpp" ] - [ "fidlgen_cpp" ] ==
-        info.denylist) {
-      deps += [ "${info.target}_cpp_generate($fidl_toolchain)" ]
-      gen_dir = "${info.fidl_gen_dir}/${info.target_name}/cpp"
-      include_path = string_replace(info.library, ".", "/") + "/cpp"
-      entries += [
-        {
-          golden = "${info.name}.h.golden"
-          generated = "$gen_dir/$include_path/fidl_v2.h"
-        },
-        {
-          golden = "${info.name}.cc.golden"
-          generated = "$gen_dir/$include_path/fidl_v2.cc"
-        },
-      ]
-    }
-  }
-}
-
 group("goldens") {
   testonly = true
 
diff --git a/tools/fidl/fidlgen_dart/BUILD.gn b/tools/fidl/fidlgen_dart/BUILD.gn
index d95e7c3..3f3f656 100644
--- a/tools/fidl/fidlgen_dart/BUILD.gn
+++ b/tools/fidl/fidlgen_dart/BUILD.gn
@@ -10,34 +10,65 @@
 import("//build/testing/golden_test.gni")
 import("//tools/fidl/fidlc/testdata/info.gni")
 
-go_library("fidlgen_dart_lib") {
-  name = "go.fuchsia.dev/fuchsia/tools/fidl/fidlgen_dart/..."
+if (is_host) {
+  go_library("fidlgen_dart_lib") {
+    name = "go.fuchsia.dev/fuchsia/tools/fidl/fidlgen_dart/..."
 
-  deps = [ "//tools/fidl/lib/fidlgen" ]
-  sources = [
-    "codegen/bits.tmpl.go",
-    "codegen/const.tmpl.go",
-    "codegen/enum.tmpl.go",
-    "codegen/generator.go",
-    "codegen/interface.tmpl.go",
-    "codegen/ir.go",
-    "codegen/library.tmpl.go",
-    "codegen/struct.tmpl.go",
-    "codegen/table.tmpl.go",
-    "codegen/union.tmpl.go",
-    "main.go",
-  ]
-}
+    deps = [ "//tools/fidl/lib/fidlgen" ]
+    sources = [
+      "codegen/bits.tmpl.go",
+      "codegen/const.tmpl.go",
+      "codegen/enum.tmpl.go",
+      "codegen/generator.go",
+      "codegen/interface.tmpl.go",
+      "codegen/ir.go",
+      "codegen/library.tmpl.go",
+      "codegen/struct.tmpl.go",
+      "codegen/table.tmpl.go",
+      "codegen/union.tmpl.go",
+      "main.go",
+    ]
+  }
 
-go_binary("fidlgen_dart") {
-  gopackage = "go.fuchsia.dev/fuchsia/tools/fidl/fidlgen_dart/"
-  deps = [ ":fidlgen_dart_lib" ]
-}
+  go_binary("fidlgen_dart") {
+    gopackage = "go.fuchsia.dev/fuchsia/tools/fidl/fidlgen_dart/"
+    deps = [ ":fidlgen_dart_lib" ]
+  }
 
-sdk_host_tool("fidlgen_dart_sdk") {
-  category = "partner"
-  output_name = "fidlgen_dart"
-  deps = [ ":fidlgen_dart" ]
+  sdk_host_tool("fidlgen_dart_sdk") {
+    category = "partner"
+    output_name = "fidlgen_dart"
+    deps = [ ":fidlgen_dart" ]
+  }
+
+  dartfmt_command = rebase_path("${dart_sdk}/bin/dartfmt")
+
+  golden_test("fidlgen_dart_golden_tests") {
+    goldens_dir = "goldens"
+    reformat_goldens_command = dartfmt_command
+    deps = []
+    entries = []
+    foreach(info, fidl_testdata_info) {
+      if (info.denylist + [ "fidlgen_dart" ] - [ "fidlgen_dart" ] ==
+          info.denylist) {
+        deps += [ "${info.target}_dart_generate($dart_toolchain)" ]
+        dart_gen_dir =
+            get_label_info("${info.target}($dart_toolchain)", "target_gen_dir")
+        entries += [
+          {
+            golden = "${info.name}_async.dart.golden"
+            generated =
+                "${dart_gen_dir}/${info.library}_package/lib/fidl_async.dart"
+          },
+          {
+            golden = "${info.name}_test.dart.golden"
+            generated =
+                "${dart_gen_dir}/${info.library}_package/lib/fidl_test.dart"
+          },
+        ]
+      }
+    }
+  }
 }
 
 install_host_tools("host") {
@@ -45,35 +76,6 @@
   outputs = [ "fidlgen_dart" ]
 }
 
-dartfmt_command = rebase_path("${dart_sdk}/bin/dartfmt")
-
-golden_test("fidlgen_dart_golden_tests") {
-  goldens_dir = "goldens"
-  reformat_goldens_command = dartfmt_command
-  deps = []
-  entries = []
-  foreach(info, fidl_testdata_info) {
-    if (info.denylist + [ "fidlgen_dart" ] - [ "fidlgen_dart" ] ==
-        info.denylist) {
-      deps += [ "${info.target}_dart_generate($dart_toolchain)" ]
-      dart_gen_dir =
-          get_label_info("${info.target}($dart_toolchain)", "target_gen_dir")
-      entries += [
-        {
-          golden = "${info.name}_async.dart.golden"
-          generated =
-              "${dart_gen_dir}/${info.library}_package/lib/fidl_async.dart"
-        },
-        {
-          golden = "${info.name}_test.dart.golden"
-          generated =
-              "${dart_gen_dir}/${info.library}_package/lib/fidl_test.dart"
-        },
-      ]
-    }
-  }
-}
-
 group("goldens") {
   testonly = true
 
diff --git a/tools/fidl/fidlgen_go/BUILD.gn b/tools/fidl/fidlgen_go/BUILD.gn
index 1e3bcbd..da03abd 100644
--- a/tools/fidl/fidlgen_go/BUILD.gn
+++ b/tools/fidl/fidlgen_go/BUILD.gn
@@ -10,40 +10,35 @@
 import("//build/testing/golden_test.gni")
 import("//tools/fidl/fidlc/testdata/info.gni")
 
-go_library("gopkg") {
-  name = "go.fuchsia.dev/fuchsia/tools/fidl/fidlgen_go/..."
-  deps = [
-    "//tools/fidl/lib/fidlgen",
-    "//tools/fidl/lib/fidlgentest",
-  ]
-  sources = [
-    "codegen/bits.tmpl.go",
-    "codegen/codegen.go",
-    "codegen/enum.tmpl.go",
-    "codegen/ir.go",
-    "codegen/ir_test.go",
-    "codegen/library.tmpl.go",
-    "codegen/protocol.tmpl.go",
-    "codegen/struct.tmpl.go",
-    "codegen/table.tmpl.go",
-    "codegen/union.tmpl.go",
-    "main.go",
-  ]
-}
-
-go_binary("fidlgen_go") {
-  gopackage = "go.fuchsia.dev/fuchsia/tools/fidl/fidlgen_go"
-
-  sdk_category = "partner"
-  deps = [ ":gopkg" ]
-}
-
-install_host_tools("host") {
-  deps = [ ":fidlgen_go" ]
-  outputs = [ "fidlgen_go" ]
-}
-
 if (is_host) {
+  go_library("gopkg") {
+    name = "go.fuchsia.dev/fuchsia/tools/fidl/fidlgen_go/..."
+    deps = [
+      "//tools/fidl/lib/fidlgen",
+      "//tools/fidl/lib/fidlgentest",
+    ]
+    sources = [
+      "codegen/bits.tmpl.go",
+      "codegen/codegen.go",
+      "codegen/enum.tmpl.go",
+      "codegen/ir.go",
+      "codegen/ir_test.go",
+      "codegen/library.tmpl.go",
+      "codegen/protocol.tmpl.go",
+      "codegen/struct.tmpl.go",
+      "codegen/table.tmpl.go",
+      "codegen/union.tmpl.go",
+      "main.go",
+    ]
+  }
+
+  go_binary("fidlgen_go") {
+    gopackage = "go.fuchsia.dev/fuchsia/tools/fidl/fidlgen_go"
+
+    sdk_category = "partner"
+    deps = [ ":gopkg" ]
+  }
+
   fidlc_target = "//tools/fidl/fidlc($host_toolchain)"
 
   go_test("fidlgen_go_lib_tests") {
@@ -63,30 +58,36 @@
     sources = [ get_label_info(fidlc_target, "root_out_dir") + "/fidlc" ]
     deps = [ fidlc_target ]
   }
-}
 
-gofmt_command =
-    rebase_path("//prebuilt/third_party/go/$host_platform/bin/gofmt",
-                root_build_dir)
+  gofmt_command =
+      rebase_path("//prebuilt/third_party/go/$host_platform/bin/gofmt",
+                  root_build_dir)
 
-golden_test("fidlgen_go_golden_tests") {
-  goldens_dir = "goldens"
-  reformat_goldens_command = gofmt_command
-  deps = []
-  entries = []
-  foreach(info, fidl_testdata_info) {
-    if (info.denylist + [ "fidlgen_go" ] - [ "fidlgen_go" ] == info.denylist) {
-      deps += [ "${info.target}_go_generate($go_toolchain)" ]
-      entries += [
-        {
-          golden = "${info.name}.go.golden"
-          generated = "${info.fidl_gen_dir}/${info.target_name}/${info.library}.fidl/impl.go"
-        },
-      ]
+  golden_test("fidlgen_go_golden_tests") {
+    goldens_dir = "goldens"
+    reformat_goldens_command = gofmt_command
+    deps = []
+    entries = []
+    foreach(info, fidl_testdata_info) {
+      if (info.denylist + [ "fidlgen_go" ] - [ "fidlgen_go" ] ==
+          info.denylist) {
+        deps += [ "${info.target}_go_generate($go_toolchain)" ]
+        entries += [
+          {
+            golden = "${info.name}.go.golden"
+            generated = "${info.fidl_gen_dir}/${info.target_name}/${info.library}.fidl/impl.go"
+          },
+        ]
+      }
     }
   }
 }
 
+install_host_tools("host") {
+  deps = [ ":fidlgen_go" ]
+  outputs = [ "fidlgen_go" ]
+}
+
 group("goldens") {
   testonly = true
 
diff --git a/tools/fidl/fidlgen_hlcpp/BUILD.gn b/tools/fidl/fidlgen_hlcpp/BUILD.gn
index d39a9b0..7a69e93 100644
--- a/tools/fidl/fidlgen_hlcpp/BUILD.gn
+++ b/tools/fidl/fidlgen_hlcpp/BUILD.gn
@@ -10,35 +10,103 @@
 import("//build/testing/golden_test.gni")
 import("//tools/fidl/fidlc/testdata/info.gni")
 
-go_library("gopkg") {
-  name = "go.fuchsia.dev/fuchsia/tools/fidl/fidlgen_hlcpp/..."
-  deps = [
-    "//tools/fidl/lib/fidlgen",
-    "//tools/fidl/lib/fidlgen_cpp",
-  ]
-  sources = [
-    "codegen/codegen.go",
-    "codegen/header.tmpl.go",
-    "codegen/implementation.tmpl.go",
-    "codegen/natural_types_bits.tmpl.go",
-    "codegen/natural_types_const.tmpl.go",
-    "codegen/natural_types_enum.tmpl.go",
-    "codegen/natural_types_protocol.tmpl.go",
-    "codegen/natural_types_struct.tmpl.go",
-    "codegen/natural_types_table.tmpl.go",
-    "codegen/natural_types_union.tmpl.go",
-    "codegen/proxies_and_stubs_protocol.tmpl.go",
-    "codegen/proxies_and_stubs_service.tmpl.go",
-    "codegen/test_base.tmpl.go",
-    "main.go",
-  ]
-}
+if (is_host) {
+  go_library("gopkg") {
+    name = "go.fuchsia.dev/fuchsia/tools/fidl/fidlgen_hlcpp/..."
+    deps = [
+      "//tools/fidl/lib/fidlgen",
+      "//tools/fidl/lib/fidlgen_cpp",
+    ]
+    sources = [
+      "codegen/codegen.go",
+      "codegen/header.tmpl.go",
+      "codegen/implementation.tmpl.go",
+      "codegen/natural_types_bits.tmpl.go",
+      "codegen/natural_types_const.tmpl.go",
+      "codegen/natural_types_enum.tmpl.go",
+      "codegen/natural_types_protocol.tmpl.go",
+      "codegen/natural_types_struct.tmpl.go",
+      "codegen/natural_types_table.tmpl.go",
+      "codegen/natural_types_union.tmpl.go",
+      "codegen/proxies_and_stubs_protocol.tmpl.go",
+      "codegen/proxies_and_stubs_service.tmpl.go",
+      "codegen/test_base.tmpl.go",
+      "main.go",
+    ]
+  }
 
-go_binary("fidlgen_hlcpp") {
-  gopackage = "go.fuchsia.dev/fuchsia/tools/fidl/fidlgen_hlcpp"
+  go_binary("fidlgen_hlcpp") {
+    gopackage = "go.fuchsia.dev/fuchsia/tools/fidl/fidlgen_hlcpp"
 
-  sdk_category = "partner"
-  deps = [ ":gopkg" ]
+    sdk_category = "partner"
+    deps = [ ":gopkg" ]
+  }
+
+  # TODO(fxbug.dev/45483): Remove once all SDK customers are using HLCPP backend
+  # directly.
+  go_binary("fidlgen") {
+    gopackage = "go.fuchsia.dev/fuchsia/tools/fidl/fidlgen_hlcpp"
+
+    sdk_category = "partner"
+    deps = [ ":gopkg" ]
+  }
+
+  clang_format = rebase_path("${clang_prefix}/clang-format", "", root_build_dir)
+  reformat_command = "'${clang_format}' --style=google"
+
+  golden_test("fidlgen_hlcpp_golden_tests") {
+    goldens_dir = "goldens/bindings"
+    reformat_goldens_command = reformat_command
+    deps = []
+    entries = []
+    foreach(info, fidl_testdata_info) {
+      if (info.denylist + [ "fidlgen_hlcpp" ] - [ "fidlgen_hlcpp" ] ==
+          info.denylist) {
+        deps += [ "${info.target}_hlcpp_generate($fidl_toolchain)" ]
+        gen_dir = "${info.fidl_gen_dir}/${info.target_name}/hlcpp"
+        include_path = string_replace(info.library, ".", "/") + "/cpp"
+        entries += [
+          {
+            golden = "${info.name}.h.golden"
+            generated = "$gen_dir/$include_path/fidl.h"
+          },
+          {
+            golden = "${info.name}.cc.golden"
+            generated = "$gen_dir/$include_path/fidl.cc"
+          },
+          {
+            golden = "${info.name}_test_base.h.golden"
+            generated = "$gen_dir/$include_path/fidl_test_base.h"
+          },
+        ]
+      }
+    }
+  }
+
+  golden_test("fidlgen_hlcpp_natural_types_golden_tests") {
+    goldens_dir = "goldens/natural_types"
+    reformat_goldens_command = reformat_command
+    deps = []
+    entries = []
+    foreach(info, fidl_testdata_info) {
+      if (info.denylist + [ "fidlgen_hlcpp" ] - [ "fidlgen_hlcpp" ] ==
+          info.denylist) {
+        deps += [ "${info.target}_cpp_natural_types_generate($fidl_toolchain)" ]
+        gen_dir = "${info.fidl_gen_dir}/${info.target_name}/cpp_natural_types"
+        include_path = string_replace(info.library, ".", "/") + "/cpp"
+        entries += [
+          {
+            golden = "${info.name}.h.golden"
+            generated = "$gen_dir/$include_path/natural_types.h"
+          },
+          {
+            golden = "${info.name}.cc.golden"
+            generated = "$gen_dir/$include_path/natural_types.cc"
+          },
+        ]
+      }
+    }
+  }
 }
 
 install_host_tools("host") {
@@ -46,72 +114,6 @@
   outputs = [ "fidlgen_hlcpp" ]
 }
 
-# TODO(fxbug.dev/45483): Remove once all SDK customers are using HLCPP backend
-# directly.
-go_binary("fidlgen") {
-  gopackage = "go.fuchsia.dev/fuchsia/tools/fidl/fidlgen_hlcpp"
-
-  sdk_category = "partner"
-  deps = [ ":gopkg" ]
-}
-
-clang_format = rebase_path("${clang_prefix}/clang-format", "", root_build_dir)
-reformat_command = "'${clang_format}' --style=google"
-
-golden_test("fidlgen_hlcpp_golden_tests") {
-  goldens_dir = "goldens/bindings"
-  reformat_goldens_command = reformat_command
-  deps = []
-  entries = []
-  foreach(info, fidl_testdata_info) {
-    if (info.denylist + [ "fidlgen_hlcpp" ] - [ "fidlgen_hlcpp" ] ==
-        info.denylist) {
-      deps += [ "${info.target}_hlcpp_generate($fidl_toolchain)" ]
-      gen_dir = "${info.fidl_gen_dir}/${info.target_name}/hlcpp"
-      include_path = string_replace(info.library, ".", "/") + "/cpp"
-      entries += [
-        {
-          golden = "${info.name}.h.golden"
-          generated = "$gen_dir/$include_path/fidl.h"
-        },
-        {
-          golden = "${info.name}.cc.golden"
-          generated = "$gen_dir/$include_path/fidl.cc"
-        },
-        {
-          golden = "${info.name}_test_base.h.golden"
-          generated = "$gen_dir/$include_path/fidl_test_base.h"
-        },
-      ]
-    }
-  }
-}
-
-golden_test("fidlgen_hlcpp_natural_types_golden_tests") {
-  goldens_dir = "goldens/natural_types"
-  reformat_goldens_command = reformat_command
-  deps = []
-  entries = []
-  foreach(info, fidl_testdata_info) {
-    if (info.denylist + [ "fidlgen_hlcpp" ] - [ "fidlgen_hlcpp" ] ==
-        info.denylist) {
-      deps += [ "${info.target}_cpp_natural_types_generate($fidl_toolchain)" ]
-      gen_dir = "${info.fidl_gen_dir}/${info.target_name}/cpp_natural_types"
-      include_path = string_replace(info.library, ".", "/") + "/cpp"
-      entries += [
-        {
-          golden = "${info.name}.h.golden"
-          generated = "$gen_dir/$include_path/natural_types.h"
-        },
-        {
-          golden = "${info.name}.cc.golden"
-          generated = "$gen_dir/$include_path/natural_types.cc"
-        },
-      ]
-    }
-  }
-}
-
 group("goldens") {
   testonly = true
 
diff --git a/tools/fidl/fidlgen_libfuzzer/BUILD.gn b/tools/fidl/fidlgen_libfuzzer/BUILD.gn
index 7df7070..990713a 100644
--- a/tools/fidl/fidlgen_libfuzzer/BUILD.gn
+++ b/tools/fidl/fidlgen_libfuzzer/BUILD.gn
@@ -9,34 +9,72 @@
 import("//build/testing/golden_test.gni")
 import("//tools/fidl/fidlc/testdata/info.gni")
 
-go_library("gopkg") {
-  name = "go.fuchsia.dev/fuchsia/tools/fidl/fidlgen_libfuzzer/..."
-  deps = [
-    "//tools/fidl/lib/fidlgen",
-    "//tools/fidl/lib/fidlgen_cpp",
-  ]
-  sources = [
-    "codegen/bits.tmpl.go",
-    "codegen/codegen.go",
-    "codegen/decoder_encoder.tmpl.go",
-    "codegen/decoder_encoder_header.tmpl.go",
-    "codegen/decoder_encoder_source.tmpl.go",
-    "codegen/enum.tmpl.go",
-    "codegen/header.tmpl.go",
-    "codegen/protocol_decoder_encoders.tmpl.go",
-    "codegen/source.tmpl.go",
-    "codegen/struct.tmpl.go",
-    "codegen/table.tmpl.go",
-    "codegen/union.tmpl.go",
-    "main.go",
-  ]
-}
+if (is_host) {
+  go_library("gopkg") {
+    name = "go.fuchsia.dev/fuchsia/tools/fidl/fidlgen_libfuzzer/..."
+    deps = [
+      "//tools/fidl/lib/fidlgen",
+      "//tools/fidl/lib/fidlgen_cpp",
+    ]
+    sources = [
+      "codegen/bits.tmpl.go",
+      "codegen/codegen.go",
+      "codegen/decoder_encoder.tmpl.go",
+      "codegen/decoder_encoder_header.tmpl.go",
+      "codegen/decoder_encoder_source.tmpl.go",
+      "codegen/enum.tmpl.go",
+      "codegen/header.tmpl.go",
+      "codegen/protocol_decoder_encoders.tmpl.go",
+      "codegen/source.tmpl.go",
+      "codegen/struct.tmpl.go",
+      "codegen/table.tmpl.go",
+      "codegen/union.tmpl.go",
+      "main.go",
+    ]
+  }
 
-go_binary("fidlgen_libfuzzer") {
-  gopackage = "go.fuchsia.dev/fuchsia/tools/fidl/fidlgen_libfuzzer"
+  go_binary("fidlgen_libfuzzer") {
+    gopackage = "go.fuchsia.dev/fuchsia/tools/fidl/fidlgen_libfuzzer"
 
-  sdk_category = "partner"
-  deps = [ ":gopkg" ]
+    sdk_category = "partner"
+    deps = [ ":gopkg" ]
+  }
+
+  clang_format = rebase_path("${clang_prefix}/clang-format", "", root_build_dir)
+  reformat_command = "'${clang_format}' --style=google"
+
+  golden_test("fidlgen_libfuzzer_golden_tests") {
+    goldens_dir = "goldens"
+    reformat_goldens_command = reformat_command
+    deps = []
+    entries = []
+    foreach(info, fidl_testdata_info) {
+      if (info.denylist + [ "fidlgen_libfuzzer" ] - [ "fidlgen_libfuzzer" ] ==
+          info.denylist) {
+        deps += [ "${info.target}_libfuzzer_generate($fidl_toolchain)" ]
+        gen_dir = "${info.fidl_gen_dir}/${info.target_name}/libfuzzer"
+        include_path = string_replace(info.library, ".", "/") + "/cpp"
+        entries += [
+          {
+            golden = "${info.name}.h.golden"
+            generated = "$gen_dir/$include_path/libfuzzer.h"
+          },
+          {
+            golden = "${info.name}.cc.golden"
+            generated = "$gen_dir/$include_path/libfuzzer.cc"
+          },
+          {
+            golden = "${info.name}_decode_encode.h.golden"
+            generated = "$gen_dir/$include_path/libfuzzer_decode_encode.h"
+          },
+          {
+            golden = "${info.name}_decode_encode.cc.golden"
+            generated = "$gen_dir/$include_path/libfuzzer_decode_encode.cc"
+          },
+        ]
+      }
+    }
+  }
 }
 
 install_host_tools("host") {
@@ -44,42 +82,6 @@
   outputs = [ "fidlgen_libfuzzer" ]
 }
 
-clang_format = rebase_path("${clang_prefix}/clang-format", "", root_build_dir)
-reformat_command = "'${clang_format}' --style=google"
-
-golden_test("fidlgen_libfuzzer_golden_tests") {
-  goldens_dir = "goldens"
-  reformat_goldens_command = reformat_command
-  deps = []
-  entries = []
-  foreach(info, fidl_testdata_info) {
-    if (info.denylist + [ "fidlgen_libfuzzer" ] - [ "fidlgen_libfuzzer" ] ==
-        info.denylist) {
-      deps += [ "${info.target}_libfuzzer_generate($fidl_toolchain)" ]
-      gen_dir = "${info.fidl_gen_dir}/${info.target_name}/libfuzzer"
-      include_path = string_replace(info.library, ".", "/") + "/cpp"
-      entries += [
-        {
-          golden = "${info.name}.h.golden"
-          generated = "$gen_dir/$include_path/libfuzzer.h"
-        },
-        {
-          golden = "${info.name}.cc.golden"
-          generated = "$gen_dir/$include_path/libfuzzer.cc"
-        },
-        {
-          golden = "${info.name}_decode_encode.h.golden"
-          generated = "$gen_dir/$include_path/libfuzzer_decode_encode.h"
-        },
-        {
-          golden = "${info.name}_decode_encode.cc.golden"
-          generated = "$gen_dir/$include_path/libfuzzer_decode_encode.cc"
-        },
-      ]
-    }
-  }
-}
-
 group("goldens") {
   testonly = true
 
diff --git a/tools/fidl/fidlgen_llcpp/BUILD.gn b/tools/fidl/fidlgen_llcpp/BUILD.gn
index bd62c2f..e4becc3 100644
--- a/tools/fidl/fidlgen_llcpp/BUILD.gn
+++ b/tools/fidl/fidlgen_llcpp/BUILD.gn
@@ -9,49 +9,83 @@
 import("//build/testing/golden_test.gni")
 import("//tools/fidl/fidlc/testdata/info.gni")
 
-go_library("gopkg") {
-  name = "go.fuchsia.dev/fuchsia/tools/fidl/fidlgen_llcpp/..."
-  deps = [
-    "//tools/fidl/lib/fidlgen",
-    "//tools/fidl/lib/fidlgen_cpp",
-  ]
-  sources = [
-    "codegen/codegen.go",
-    "codegen/file_header.tmpl.go",
-    "codegen/file_source.tmpl.go",
-    "codegen/fragment_bits.tmpl.go",
-    "codegen/fragment_client.tmpl.go",
-    "codegen/fragment_client_async_methods.tmpl.go",
-    "codegen/fragment_client_sync_methods.tmpl.go",
-    "codegen/fragment_const.tmpl.go",
-    "codegen/fragment_enum.tmpl.go",
-    "codegen/fragment_event_sender.tmpl.go",
-    "codegen/fragment_method_request.tmpl.go",
-    "codegen/fragment_method_response.tmpl.go",
-    "codegen/fragment_method_response_context.tmpl.go",
-    "codegen/fragment_method_result.tmpl.go",
-    "codegen/fragment_method_unownedresult.tmpl.go",
-    "codegen/fragment_protocol.tmpl.go",
-    "codegen/fragment_protocol_details.tmpl.go",
-    "codegen/fragment_protocol_dispatcher.tmpl.go",
-    "codegen/fragment_protocol_event_handler.tmpl.go",
-    "codegen/fragment_protocol_interface.tmpl.go",
-    "codegen/fragment_reply_caller_allocate.tmpl.go",
-    "codegen/fragment_reply_managed.tmpl.go",
-    "codegen/fragment_service.tmpl.go",
-    "codegen/fragment_struct.tmpl.go",
-    "codegen/fragment_sync_event_handler.tmpl.go",
-    "codegen/fragment_sync_request_caller_allocate.tmpl.go",
-    "codegen/fragment_table.tmpl.go",
-    "codegen/fragment_union.tmpl.go",
-    "codegen/test_base.tmpl.go",
-    "main.go",
-  ]
-}
+if (is_host) {
+  go_library("gopkg") {
+    name = "go.fuchsia.dev/fuchsia/tools/fidl/fidlgen_llcpp/..."
+    deps = [
+      "//tools/fidl/lib/fidlgen",
+      "//tools/fidl/lib/fidlgen_cpp",
+    ]
+    sources = [
+      "codegen/codegen.go",
+      "codegen/file_header.tmpl.go",
+      "codegen/file_source.tmpl.go",
+      "codegen/fragment_bits.tmpl.go",
+      "codegen/fragment_client.tmpl.go",
+      "codegen/fragment_client_async_methods.tmpl.go",
+      "codegen/fragment_client_sync_methods.tmpl.go",
+      "codegen/fragment_const.tmpl.go",
+      "codegen/fragment_enum.tmpl.go",
+      "codegen/fragment_event_sender.tmpl.go",
+      "codegen/fragment_method_request.tmpl.go",
+      "codegen/fragment_method_response.tmpl.go",
+      "codegen/fragment_method_response_context.tmpl.go",
+      "codegen/fragment_method_result.tmpl.go",
+      "codegen/fragment_method_unownedresult.tmpl.go",
+      "codegen/fragment_protocol.tmpl.go",
+      "codegen/fragment_protocol_details.tmpl.go",
+      "codegen/fragment_protocol_dispatcher.tmpl.go",
+      "codegen/fragment_protocol_event_handler.tmpl.go",
+      "codegen/fragment_protocol_interface.tmpl.go",
+      "codegen/fragment_reply_caller_allocate.tmpl.go",
+      "codegen/fragment_reply_managed.tmpl.go",
+      "codegen/fragment_service.tmpl.go",
+      "codegen/fragment_struct.tmpl.go",
+      "codegen/fragment_sync_event_handler.tmpl.go",
+      "codegen/fragment_sync_request_caller_allocate.tmpl.go",
+      "codegen/fragment_table.tmpl.go",
+      "codegen/fragment_union.tmpl.go",
+      "codegen/test_base.tmpl.go",
+      "main.go",
+    ]
+  }
 
-go_binary("fidlgen_llcpp") {
-  gopackage = "go.fuchsia.dev/fuchsia/tools/fidl/fidlgen_llcpp"
-  deps = [ ":gopkg" ]
+  go_binary("fidlgen_llcpp") {
+    gopackage = "go.fuchsia.dev/fuchsia/tools/fidl/fidlgen_llcpp"
+    deps = [ ":gopkg" ]
+  }
+
+  clang_format = rebase_path("${clang_prefix}/clang-format", "", root_build_dir)
+  reformat_command = "'${clang_format}' --style=google"
+
+  golden_test("fidlgen_llcpp_golden_tests") {
+    goldens_dir = "goldens"
+    reformat_goldens_command = reformat_command
+    deps = []
+    entries = []
+    foreach(info, fidl_testdata_info) {
+      if (info.denylist + [ "fidlgen_llcpp" ] - [ "fidlgen_llcpp" ] ==
+          info.denylist) {
+        deps += [ "${info.target}_llcpp_generate($fidl_toolchain)" ]
+        gen_dir = "${info.fidl_gen_dir}/${info.target_name}/llcpp"
+        include_path = string_replace(info.library, ".", "/") + "/llcpp"
+        entries += [
+          {
+            golden = "${info.name}.h.golden"
+            generated = "$gen_dir/$include_path/fidl.h"
+          },
+          {
+            golden = "${info.name}.cc.golden"
+            generated = "$gen_dir/$include_path/fidl.cc"
+          },
+          {
+            golden = "${info.name}_test_base.h.golden"
+            generated = "$gen_dir/$include_path/fidl_test_base.h"
+          },
+        ]
+      }
+    }
+  }
 }
 
 install_host_tools("host") {
@@ -59,38 +93,6 @@
   outputs = [ "fidlgen_llcpp" ]
 }
 
-clang_format = rebase_path("${clang_prefix}/clang-format", "", root_build_dir)
-reformat_command = "'${clang_format}' --style=google"
-
-golden_test("fidlgen_llcpp_golden_tests") {
-  goldens_dir = "goldens"
-  reformat_goldens_command = reformat_command
-  deps = []
-  entries = []
-  foreach(info, fidl_testdata_info) {
-    if (info.denylist + [ "fidlgen_llcpp" ] - [ "fidlgen_llcpp" ] ==
-        info.denylist) {
-      deps += [ "${info.target}_llcpp_generate($fidl_toolchain)" ]
-      gen_dir = "${info.fidl_gen_dir}/${info.target_name}/llcpp"
-      include_path = string_replace(info.library, ".", "/") + "/llcpp"
-      entries += [
-        {
-          golden = "${info.name}.h.golden"
-          generated = "$gen_dir/$include_path/fidl.h"
-        },
-        {
-          golden = "${info.name}.cc.golden"
-          generated = "$gen_dir/$include_path/fidl.cc"
-        },
-        {
-          golden = "${info.name}_test_base.h.golden"
-          generated = "$gen_dir/$include_path/fidl_test_base.h"
-        },
-      ]
-    }
-  }
-}
-
 group("goldens") {
   testonly = true
 
diff --git a/tools/fidl/fidlgen_rust/BUILD.gn b/tools/fidl/fidlgen_rust/BUILD.gn
index 5330ca2..6c7d6cd 100644
--- a/tools/fidl/fidlgen_rust/BUILD.gn
+++ b/tools/fidl/fidlgen_rust/BUILD.gn
@@ -11,43 +11,38 @@
 import("//build/testing/golden_test.gni")
 import("//tools/fidl/fidlc/testdata/info.gni")
 
-go_library("gopkg") {
-  name = "go.fuchsia.dev/fuchsia/tools/fidl/fidlgen_rust/..."
-  deps = [
-    "//tools/fidl/lib/fidlgen",
-    "//tools/fidl/lib/fidlgentest",
-  ]
-  sources = [
-    "codegen/bits.tmpl.go",
-    "codegen/codegen.go",
-    "codegen/const.tmpl.go",
-    "codegen/enum.tmpl.go",
-    "codegen/handle_metadata_wrappers.tmpl.go",
-    "codegen/ir.go",
-    "codegen/ir_test.go",
-    "codegen/protocol.tmpl.go",
-    "codegen/result.tmpl.go",
-    "codegen/service.tmpl.go",
-    "codegen/sourcefile.tmpl.go",
-    "codegen/struct.tmpl.go",
-    "codegen/table.tmpl.go",
-    "codegen/union.tmpl.go",
-    "main.go",
-  ]
-}
-
-go_binary("fidlgen_rust") {
-  gopackage = "go.fuchsia.dev/fuchsia/tools/fidl/fidlgen_rust"
-  sdk_category = "partner"
-  deps = [ ":gopkg" ]
-}
-
-install_host_tools("host") {
-  deps = [ ":fidlgen_rust" ]
-  outputs = [ "fidlgen_rust" ]
-}
-
 if (is_host) {
+  go_library("gopkg") {
+    name = "go.fuchsia.dev/fuchsia/tools/fidl/fidlgen_rust/..."
+    deps = [
+      "//tools/fidl/lib/fidlgen",
+      "//tools/fidl/lib/fidlgentest",
+    ]
+    sources = [
+      "codegen/bits.tmpl.go",
+      "codegen/codegen.go",
+      "codegen/const.tmpl.go",
+      "codegen/enum.tmpl.go",
+      "codegen/handle_metadata_wrappers.tmpl.go",
+      "codegen/ir.go",
+      "codegen/ir_test.go",
+      "codegen/protocol.tmpl.go",
+      "codegen/result.tmpl.go",
+      "codegen/service.tmpl.go",
+      "codegen/sourcefile.tmpl.go",
+      "codegen/struct.tmpl.go",
+      "codegen/table.tmpl.go",
+      "codegen/union.tmpl.go",
+      "main.go",
+    ]
+  }
+
+  go_binary("fidlgen_rust") {
+    gopackage = "go.fuchsia.dev/fuchsia/tools/fidl/fidlgen_rust"
+    sdk_category = "partner"
+    deps = [ ":gopkg" ]
+  }
+
   fidlc_target = "//tools/fidl/fidlc($host_toolchain)"
 
   go_test("fidlgen_rust_lib_tests") {
@@ -70,31 +65,36 @@
     sources = [ get_label_info(fidlc_target, "root_out_dir") + "/fidlc" ]
     deps = [ fidlc_target ]
   }
-}
 
-rustfmt = rebase_path("$fidl_rust_tools_dir/bin/rustfmt", root_build_dir)
-rustfmt_config = rebase_path("//rustfmt.toml", root_build_dir)
+  rustfmt = rebase_path("$fidl_rust_tools_dir/bin/rustfmt", root_build_dir)
+  rustfmt_config = rebase_path("//rustfmt.toml", root_build_dir)
 
-golden_test("fidlgen_rust_golden_tests") {
-  goldens_dir = "goldens"
-  reformat_goldens_command = "'${rustfmt}' --config-path '${rustfmt_config}'"
-  deps = []
-  entries = []
-  foreach(info, fidl_testdata_info) {
-    if (info.denylist + [ "fidlgen_rust" ] - [ "fidlgen_rust" ] ==
-        info.denylist) {
-      deps += [ "${info.target}_rust_generate($rust_toolchain)" ]
-      library_underscore = string_replace(info.library, ".", "_")
-      entries += [
-        {
-          golden = "${info.name}.rs.golden"
-          generated = "${info.fidl_gen_dir}/${info.target_name}/fidl_${library_underscore}.rs"
-        },
-      ]
+  golden_test("fidlgen_rust_golden_tests") {
+    goldens_dir = "goldens"
+    reformat_goldens_command = "'${rustfmt}' --config-path '${rustfmt_config}'"
+    deps = []
+    entries = []
+    foreach(info, fidl_testdata_info) {
+      if (info.denylist + [ "fidlgen_rust" ] - [ "fidlgen_rust" ] ==
+          info.denylist) {
+        deps += [ "${info.target}_rust_generate($rust_toolchain)" ]
+        library_underscore = string_replace(info.library, ".", "_")
+        entries += [
+          {
+            golden = "${info.name}.rs.golden"
+            generated = "${info.fidl_gen_dir}/${info.target_name}/fidl_${library_underscore}.rs"
+          },
+        ]
+      }
     }
   }
 }
 
+install_host_tools("host") {
+  deps = [ ":fidlgen_rust" ]
+  outputs = [ "fidlgen_rust" ]
+}
+
 group("goldens") {
   testonly = true
 
diff --git a/tools/fidl/fidlgen_syzkaller/BUILD.gn b/tools/fidl/fidlgen_syzkaller/BUILD.gn
index 892a6a1..9693042 100644
--- a/tools/fidl/fidlgen_syzkaller/BUILD.gn
+++ b/tools/fidl/fidlgen_syzkaller/BUILD.gn
@@ -10,25 +10,68 @@
 import("//build/testing/golden_test.gni")
 import("//tools/fidl/fidlc/testdata/info.gni")
 
-go_library("gopkg") {
-  name = "go.fuchsia.dev/fuchsia/tools/fidl/fidlgen_syzkaller/..."
-  deps = [ "//tools/fidl/lib/fidlgen" ]
-  sources = [
-    "codegen/codegen.go",
-    "codegen/description.tmpl.go",
-    "codegen/ir.go",
-    "codegen/protocol.tmpl.go",
-    "codegen/struct.tmpl.go",
-    "codegen/union.tmpl.go",
-    "main.go",
-  ]
-}
+if (is_host) {
+  go_library("gopkg") {
+    name = "go.fuchsia.dev/fuchsia/tools/fidl/fidlgen_syzkaller/..."
+    deps = [ "//tools/fidl/lib/fidlgen" ]
+    sources = [
+      "codegen/codegen.go",
+      "codegen/description.tmpl.go",
+      "codegen/ir.go",
+      "codegen/protocol.tmpl.go",
+      "codegen/struct.tmpl.go",
+      "codegen/union.tmpl.go",
+      "main.go",
+    ]
+  }
 
-go_binary("fidlgen_syzkaller") {
-  gopackage = "go.fuchsia.dev/fuchsia/tools/fidl/fidlgen_syzkaller"
+  go_binary("fidlgen_syzkaller") {
+    gopackage = "go.fuchsia.dev/fuchsia/tools/fidl/fidlgen_syzkaller"
 
-  sdk_category = "partner"
-  deps = [ ":gopkg" ]
+    sdk_category = "partner"
+    deps = [ ":gopkg" ]
+  }
+
+  fidl_testdata_info_filtered = []
+  foreach(info, fidl_testdata_info) {
+    if (info.denylist + [ "fidlgen_syzkaller" ] - [ "fidlgen_syzkaller" ] ==
+        info.denylist) {
+      fidl_testdata_info_filtered += [ info ]
+    }
+  }
+
+  compiled_action_foreach("generate_goldens") {
+    testonly = true
+    tool = ":fidlgen_syzkaller"
+    deps = []
+    sources = []
+    foreach(info, fidl_testdata_info_filtered) {
+      deps += [ "${info.target}($fidl_toolchain)" ]
+      sources += [ "${info.fidl_gen_dir}/${info.target_name}.fidl.json" ]
+    }
+    args = [
+      "-json",
+      "{{source}}",
+      "-output-syz",
+      rebase_path(target_gen_dir, root_build_dir) +
+          "/golden_{{source_name_part}}.syz.txt",
+    ]
+    outputs = [ "$target_gen_dir/golden_{{source_name_part}}.syz.txt" ]
+  }
+
+  golden_test("fidlgen_syzkaller_golden_tests") {
+    goldens_dir = "goldens"
+    deps = [ ":generate_goldens" ]
+    entries = []
+    foreach(info, fidl_testdata_info_filtered) {
+      entries += [
+        {
+          golden = "${info.name}.syz.txt.golden"
+          generated = "$target_gen_dir/golden_${info.target_name}.fidl.syz.txt"
+        },
+      ]
+    }
+  }
 }
 
 install_host_tools("host") {
@@ -36,47 +79,6 @@
   outputs = [ "fidlgen_syzkaller" ]
 }
 
-fidl_testdata_info_filtered = []
-foreach(info, fidl_testdata_info) {
-  if (info.denylist + [ "fidlgen_syzkaller" ] - [ "fidlgen_syzkaller" ] ==
-      info.denylist) {
-    fidl_testdata_info_filtered += [ info ]
-  }
-}
-
-compiled_action_foreach("generate_goldens") {
-  testonly = true
-  tool = ":fidlgen_syzkaller"
-  deps = []
-  sources = []
-  foreach(info, fidl_testdata_info_filtered) {
-    deps += [ "${info.target}($fidl_toolchain)" ]
-    sources += [ "${info.fidl_gen_dir}/${info.target_name}.fidl.json" ]
-  }
-  args = [
-    "-json",
-    "{{source}}",
-    "-output-syz",
-    rebase_path(target_gen_dir, root_build_dir) +
-        "/golden_{{source_name_part}}.syz.txt",
-  ]
-  outputs = [ "$target_gen_dir/golden_{{source_name_part}}.syz.txt" ]
-}
-
-golden_test("fidlgen_syzkaller_golden_tests") {
-  goldens_dir = "goldens"
-  deps = [ ":generate_goldens" ]
-  entries = []
-  foreach(info, fidl_testdata_info_filtered) {
-    entries += [
-      {
-        golden = "${info.name}.syz.txt.golden"
-        generated = "$target_gen_dir/golden_${info.target_name}.fidl.syz.txt"
-      },
-    ]
-  }
-}
-
 group("tests") {
   testonly = true
   deps = [ ":fidlgen_syzkaller_golden_tests($host_toolchain)" ]
diff --git a/tools/fidl/gidl/BUILD.gn b/tools/fidl/gidl/BUILD.gn
index 47d0120..d39da20 100644
--- a/tools/fidl/gidl/BUILD.gn
+++ b/tools/fidl/gidl/BUILD.gn
@@ -12,92 +12,68 @@
 import("//src/tests/fidl/conformance_suite/gidl-conformance-suite.gni")
 import("//tools/fidl/gidl/gidl.gni")
 
-go_library("gopkg") {
-  name = "go.fuchsia.dev/fuchsia/tools/fidl/gidl/..."
-  deps = [ "//tools/fidl/lib/fidlgen" ]
-  sources = [
-    "c/conformance.go",
-    "config/defaults.go",
-    "dart/benchmarks.go",
-    "dart/common.go",
-    "dart/conformance.go",
-    "fuzzer_corpus/conformance.go",
-    "golang/benchmarks.go",
-    "golang/common.go",
-    "golang/conformance.go",
-    "golang/golang_test.go",
-    "hlcpp/benchmarks.go",
-    "hlcpp/builder.go",
-    "hlcpp/conformance.go",
-    "hlcpp/equality_builder.go",
-    "ir/error.go",
-    "ir/test_case.go",
-    "ir/util.go",
-    "ir/value.go",
-    "llcpp/benchmarks.go",
-    "llcpp/conformance.go",
-    "llcpp/lib/allocator_builder.go",
-    "llcpp/lib/common.go",
-    "llcpp/lib/equality_builder.go",
-    "llcpp/lib/unowned_builder.go",
-    "main.go",
-    "mixer/mixer.go",
-    "mixer/mixer_test.go",
-    "parser/generators.go",
-    "parser/parser.go",
-    "parser/parser_test.go",
-    "reference/benchmarks.go",
-    "rust/benchmarks.go",
-    "rust/common.go",
-    "rust/conformance.go",
-    "walker/benchmarks.go",
-  ]
-}
-
-go_binary("gidl") {
-  gopackage = "go.fuchsia.dev/fuchsia/tools/fidl/gidl"
-  deps = [ ":gopkg" ]
-}
-
-install_host_tools("host") {
-  deps = [ ":gidl" ]
-  outputs = [ "gidl" ]
-}
-
-fidl("gidl_mixer_test_fidl") {
-  name = "test.mixer"
-  testonly = true
-  sources = [ "//tools/fidl/gidl/mixer/testdata/mixer.test.fidl" ]
-  public_deps = [ "//zircon/vdso/zx" ]
-  experimental_flags = [ "enable_handle_rights" ]
-}
-
-group("tests") {
-  testonly = true
-
-  deps = [
-    ":gidl_golang_test($host_toolchain)",
-    ":gidl_golden_tests($host_toolchain)",
-    ":gidl_mixer_test($host_toolchain)",
-    ":gidl_parser_test($host_toolchain)",
-  ]
-}
-
-go_test("gidl_parser_test") {
-  gopackages = [ "go.fuchsia.dev/fuchsia/tools/fidl/gidl/parser" ]
-  deps = [
-    ":gopkg",
-    "//third_party/golibs:github.com/google/go-cmp",
-  ]
-}
-
-go_test("gidl_golang_test") {
-  gopackages = [ "go.fuchsia.dev/fuchsia/tools/fidl/gidl/golang" ]
-
-  deps = [ ":gopkg" ]
-}
-
 if (is_host) {
+  go_library("gopkg") {
+    name = "go.fuchsia.dev/fuchsia/tools/fidl/gidl/..."
+    deps = [ "//tools/fidl/lib/fidlgen" ]
+    sources = [
+      "c/conformance.go",
+      "config/defaults.go",
+      "dart/benchmarks.go",
+      "dart/common.go",
+      "dart/conformance.go",
+      "fuzzer_corpus/conformance.go",
+      "golang/benchmarks.go",
+      "golang/common.go",
+      "golang/conformance.go",
+      "golang/golang_test.go",
+      "hlcpp/benchmarks.go",
+      "hlcpp/builder.go",
+      "hlcpp/conformance.go",
+      "hlcpp/equality_builder.go",
+      "ir/error.go",
+      "ir/test_case.go",
+      "ir/util.go",
+      "ir/value.go",
+      "llcpp/benchmarks.go",
+      "llcpp/conformance.go",
+      "llcpp/lib/allocator_builder.go",
+      "llcpp/lib/common.go",
+      "llcpp/lib/equality_builder.go",
+      "llcpp/lib/unowned_builder.go",
+      "main.go",
+      "mixer/mixer.go",
+      "mixer/mixer_test.go",
+      "parser/generators.go",
+      "parser/parser.go",
+      "parser/parser_test.go",
+      "reference/benchmarks.go",
+      "rust/benchmarks.go",
+      "rust/common.go",
+      "rust/conformance.go",
+      "walker/benchmarks.go",
+    ]
+  }
+
+  go_binary("gidl") {
+    gopackage = "go.fuchsia.dev/fuchsia/tools/fidl/gidl"
+    deps = [ ":gopkg" ]
+  }
+
+  go_test("gidl_parser_test") {
+    gopackages = [ "go.fuchsia.dev/fuchsia/tools/fidl/gidl/parser" ]
+    deps = [
+      ":gopkg",
+      "//third_party/golibs:github.com/google/go-cmp",
+    ]
+  }
+
+  go_test("gidl_golang_test") {
+    gopackages = [ "go.fuchsia.dev/fuchsia/tools/fidl/gidl/golang" ]
+
+    deps = [ ":gopkg" ]
+  }
+
   host_test_data("gidl_mixer_test_json") {
     deps = [ ":gidl_mixer_test_fidl($fidl_toolchain)" ]
     sources = [ "$root_build_dir/fidling/gen/tools/fidl/gidl/gidl_mixer_test_fidl.fidl.json" ]
@@ -113,63 +89,85 @@
     deps = [ ":gopkg" ]
     non_go_deps = [ ":gidl_mixer_test_json" ]
   }
-}
 
-llcpp_gidl_output_prefix = "conformance_suite__"
-foreach(gidl_file, conformance_suite_golden_gidl_files) {
-  gidl_name = get_path_info(gidl_file, "name")
-  target = "${llcpp_gidl_output_prefix}${gidl_name}"
-  gidl_llcpp_conformance(target) {
-    testonly = true
-    inputs = [ gidl_file ]
+  llcpp_gidl_output_prefix = "conformance_suite__"
+  foreach(gidl_file, conformance_suite_golden_gidl_files) {
+    gidl_name = get_path_info(gidl_file, "name")
+    target = "${llcpp_gidl_output_prefix}${gidl_name}"
+    gidl_llcpp_conformance(target) {
+      inputs = [ gidl_file ]
+      fidl = conformance_suite_fidl_target
+      deps = [ "//third_party/googletest:gtest" ]
+      if (is_fuchsia) {
+        deps += [ "//sdk/cts/tests/pkg/fidl/cpp:handle_util" ]
+      }
+    }
+  }
+
+  gidl_hlcpp_conformance("gidl_hlcpp_goldens") {
+    inputs = conformance_suite_golden_gidl_files
     fidl = conformance_suite_fidl_target
-    deps = [ "//third_party/googletest:gtest" ]
-    if (is_fuchsia) {
-      deps += [ "//sdk/cts/tests/pkg/fidl/cpp:handle_util" ]
+  }
+
+  go_golden_generated_source = "$target_gen_dir/gidl_conformance_goldens.go"
+  gidl("gidl_go_goldens") {
+    type = "conformance"
+    language = "go"
+    inputs = conformance_suite_golden_gidl_files
+    fidl = conformance_suite_fidl_target
+    output = go_golden_generated_source
+  }
+
+  golden_test("gidl_golden_tests") {
+    goldens_dir = "goldens"
+    deps = [
+      ":gidl_go_goldens",
+      ":gidl_hlcpp_goldens_gidl",
+    ]
+    entries = [
+      {
+        golden = "go_golden.go.golden"
+        generated = go_golden_generated_source
+      },
+      {
+        golden = "hlcpp_golden.cc.golden"
+        generated = "${target_gen_dir}/gidl_generated_gidl_hlcpp_goldens.cc"
+      },
+    ]
+    foreach(gidl_file, conformance_suite_golden_gidl_files) {
+      gidl_name = get_path_info(gidl_file, "name")
+      target = "${llcpp_gidl_output_prefix}${gidl_name}"
+      deps += [ ":${target}" ]
+      entries += [
+        {
+          golden = "llcpp_${gidl_name}.cc.golden"
+          generated = "${target_gen_dir}/gidl_generated_${target}.cc"
+        },
+      ]
     }
   }
 }
 
-gidl_hlcpp_conformance("gidl_hlcpp_goldens") {
+fidl("gidl_mixer_test_fidl") {
+  name = "test.mixer"
   testonly = true
-  inputs = conformance_suite_golden_gidl_files
-  fidl = conformance_suite_fidl_target
+  sources = [ "//tools/fidl/gidl/mixer/testdata/mixer.test.fidl" ]
+  public_deps = [ "//zircon/vdso/zx" ]
+  experimental_flags = [ "enable_handle_rights" ]
 }
 
-go_golden_generated_source = "$target_gen_dir/gidl_conformance_goldens.go"
-gidl("gidl_go_goldens") {
-  type = "conformance"
-  language = "go"
-  inputs = conformance_suite_golden_gidl_files
-  fidl = conformance_suite_fidl_target
-  output = go_golden_generated_source
+install_host_tools("host") {
+  deps = [ ":gidl" ]
+  outputs = [ "gidl" ]
 }
 
-golden_test("gidl_golden_tests") {
-  goldens_dir = "goldens"
+group("tests") {
+  testonly = true
+
   deps = [
-    ":gidl_go_goldens",
-    ":gidl_hlcpp_goldens_gidl",
+    ":gidl_golang_test($host_toolchain)",
+    ":gidl_golden_tests($host_toolchain)",
+    ":gidl_mixer_test($host_toolchain)",
+    ":gidl_parser_test($host_toolchain)",
   ]
-  entries = [
-    {
-      golden = "go_golden.go.golden"
-      generated = go_golden_generated_source
-    },
-    {
-      golden = "hlcpp_golden.cc.golden"
-      generated = "${target_gen_dir}/gidl_generated_gidl_hlcpp_goldens.cc"
-    },
-  ]
-  foreach(gidl_file, conformance_suite_golden_gidl_files) {
-    gidl_name = get_path_info(gidl_file, "name")
-    target = "${llcpp_gidl_output_prefix}${gidl_name}"
-    deps += [ ":${target}" ]
-    entries += [
-      {
-        golden = "llcpp_${gidl_name}.cc.golden"
-        generated = "${target_gen_dir}/gidl_generated_${target}.cc"
-      },
-    ]
-  }
 }