Set up all host toolchains

Sets up clang and gcc based toolchains for all host target builds.
Defaults to using Clang for linux/mac and GCC for windows.

Change-Id: I1a15d98581cbf886fbb86321f2d7dabb0dd43cf1
diff --git a/BUILD.gn b/BUILD.gn
index e7116b9..609ec95 100644
--- a/BUILD.gn
+++ b/BUILD.gn
@@ -28,10 +28,19 @@
 
 # Enumerate all of the different targets that Pigweed will build.
 group("default") {
-  _host_target = "$dir_pigweed/targets/host/linux:clang_og"
+  # Auto select a toolchain based on host.
+  if (host_os == "linux") {
+    _host_target_toolchain = "$dir_pigweed/targets/host:gcc_debug"
+  } else if (host_os == "mac") {
+    _host_target_toolchain = "$dir_pigweed/targets/host:clang_debug"
+  } else if (host_os == "win") {
+    _host_target_toolchain = "$dir_pigweed/targets/host:gcc_debug"
+  } else {
+    assert(false, "Please define a host config for your system: $host_os")
+  }
 
   deps = [
-    ":pigweed_default($_host_target)",
+    ":pigweed_default($_host_target_toolchain)",
     ":pigweed_default($dir_pigweed/targets/docs)",
   ]
 }
diff --git a/pw_toolchain/BUILD.gn b/pw_toolchain/BUILD.gn
index 0ae0893..001c986 100644
--- a/pw_toolchain/BUILD.gn
+++ b/pw_toolchain/BUILD.gn
@@ -34,12 +34,12 @@
 
 # Generate Host GCC toolchains
 generate_toolchains("host_gcc_suite") {
-  toolchains = host_gcc_toolchains
+  toolchains = pw_toolchain_host_gcc_list
 }
 
 # Generate Host Clang toolchains
 generate_toolchains("host_clang_suite") {
-  toolchains = host_clang_toolchains
+  toolchains = pw_toolchain_host_clang_list
 }
 
 pw_doc_group("docs") {
diff --git a/pw_toolchain/host_clang/toolchains.gni b/pw_toolchain/host_clang/toolchains.gni
index a4e64cc..3894120 100644
--- a/pw_toolchain/host_clang/toolchains.gni
+++ b/pw_toolchain/host_clang/toolchains.gni
@@ -66,34 +66,38 @@
   }
 }
 
-host_clang_og = {
-  name = "host_clang_og"
-  forward_variables_from(_host_clang_toolchain, "*")
-  defaults = {
-    forward_variables_from(_defaults, "*")
-    default_configs += [ "$dir_pw_build:optimize_debugging" ]
+pw_toolchain_host_clang = {
+  debug = {
+    name = "host_clang_debug"
+    forward_variables_from(_host_clang_toolchain, "*")
+    defaults = {
+      forward_variables_from(_defaults, "*")
+      default_configs += [ "$dir_pw_build:optimize_debugging" ]
+    }
   }
-}
 
-host_clang_o2 = {
-  name = "host_clang_o2"
-  forward_variables_from(_host_clang_toolchain, "*")
-  defaults = {
-    forward_variables_from(_defaults, "*")
-    default_configs += [ "$dir_pw_build:optimize_speed" ]
+  speed_optimized = {
+    name = "host_clang_speed_optimized"
+    forward_variables_from(_host_clang_toolchain, "*")
+    defaults = {
+      forward_variables_from(_defaults, "*")
+      default_configs += [ "$dir_pw_build:optimize_speed" ]
+    }
   }
-}
 
-# Describes host clang toolchains.
-host_clang_toolchains = [
-  host_clang_og,
-  host_clang_o2,
-  {
-    name = "host_clang_os"
+  size_optimized = {
+    name = "host_clang_size_optimized"
     forward_variables_from(_host_clang_toolchain, "*")
     defaults = {
       forward_variables_from(_defaults, "*")
       default_configs += [ "$dir_pw_build:optimize_size" ]
     }
-  },
+  }
+}
+
+# Describes host clang toolchains.
+pw_toolchain_host_clang_list = [
+  pw_toolchain_host_clang.debug,
+  pw_toolchain_host_clang.speed_optimized,
+  pw_toolchain_host_clang.size_optimized,
 ]
diff --git a/pw_toolchain/host_gcc/toolchains.gni b/pw_toolchain/host_gcc/toolchains.gni
index e60ada7..fe24fe8 100644
--- a/pw_toolchain/host_gcc/toolchains.gni
+++ b/pw_toolchain/host_gcc/toolchains.gni
@@ -31,27 +31,35 @@
   "$dir_pw_toolchain/host_gcc:mingw_z_format",
 ]
 
-# Describes host Linux GCC toolchains.
-host_gcc_toolchains = [
-  {
-    name = "host_gcc_og"
+pw_toolchain_host_gcc = {
+  debug = {
+    name = "host_gcc_debug"
     forward_variables_from(_host_gcc_toolchain, "*")
     defaults = {
       default_configs = _configs + [ "$dir_pw_build:optimize_debugging" ]
     }
-  },
-  {
-    name = "host_gcc_o2"
+  }
+
+  speed_optimized = {
+    name = "host_gcc_speed_optimized"
     forward_variables_from(_host_gcc_toolchain, "*")
     defaults = {
       default_configs = _configs + [ "$dir_pw_build:optimize_speed" ]
     }
-  },
-  {
-    name = "host_gcc_os"
+  }
+
+  size_optimized = {
+    name = "host_gcc_size_optimized"
     forward_variables_from(_host_gcc_toolchain, "*")
     defaults = {
       default_configs = _configs + [ "$dir_pw_build:optimize_size" ]
     }
-  },
+  }
+}
+
+# Describes host Linux GCC toolchains.
+pw_toolchain_host_gcc_list = [
+  pw_toolchain_host_gcc.debug,
+  pw_toolchain_host_gcc.speed_optimized,
+  pw_toolchain_host_gcc.size_optimized,
 ]
diff --git a/targets/host/BUILD.gn b/targets/host/BUILD.gn
index 82d2f30..b680c16 100644
--- a/targets/host/BUILD.gn
+++ b/targets/host/BUILD.gn
@@ -17,6 +17,12 @@
 
 import("$dir_pigweed/legacy_target.gni")
 import("$dir_pw_docgen/docs.gni")
+import("$dir_pw_toolchain/generate_toolchain.gni")
+import("target_toolchains.gni")
+generate_toolchains("host_toolchains") {
+  toolchains = pw_target_toolchain_host_list
+}
+
 pw_doc_group("target_docs") {
   sources = [ "target_docs.rst" ]
 }
diff --git a/targets/host/host_common.gni b/targets/host/host_common.gni
deleted file mode 100644
index d4742f2..0000000
--- a/targets/host/host_common.gni
+++ /dev/null
@@ -1,27 +0,0 @@
-# Copyright 2019 The Pigweed Authors
-#
-# Licensed under the Apache License, Version 2.0 (the "License"); you may not
-# use this file except in compliance with the License. You may obtain a copy of
-# the License at
-#
-#     https://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
-# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
-# License for the specific language governing permissions and limitations under
-# the License.
-
-import("//build_overrides/pigweed.gni")
-
-# Use logging-based test output on host.
-pw_unit_test_MAIN = "$dir_pw_unit_test:logging_main"
-
-# Configure backend for assert facade.
-pw_assert_BACKEND = "$dir_pw_assert_basic"
-
-# Configure backend for logging facade.
-pw_log_BACKEND = "$dir_pw_log_basic"
-
-# Configure backend for pw_sys_io facade.
-pw_sys_io_BACKEND = "$dir_pw_sys_io_stdio"
diff --git a/targets/host/linux/linux.bloaty b/targets/host/linux.bloaty
similarity index 100%
rename from targets/host/linux/linux.bloaty
rename to targets/host/linux.bloaty
diff --git a/targets/host/linux/BUILD.gn b/targets/host/linux/BUILD.gn
deleted file mode 100644
index b14c133..0000000
--- a/targets/host/linux/BUILD.gn
+++ /dev/null
@@ -1,38 +0,0 @@
-# Copyright 2020 The Pigweed Authors
-#
-# Licensed under the Apache License, Version 2.0 (the "License"); you may not
-# use this file except in compliance with the License. You may obtain a copy of
-# the License at
-#
-#     https://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
-# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
-# License for the specific language governing permissions and limitations under
-# the License.
-
-# gn-format disable
-import("//build_overrides/pigweed.gni")
-
-import("$dir_pw_toolchain/generate_toolchain.gni")
-import("$dir_pw_toolchain/host_clang/toolchains.gni")
-linux_toolchains = [
-  {
-    name = "clang_og"
-    forward_variables_from(host_clang_og,
-                           "*",
-                           [
-                             "defaults",
-                             "name",
-                           ])
-    defaults = {
-      forward_variables_from(host_clang_og.defaults, "*")
-      import("linux.gni")
-    }
-  },
-]
-
-generate_toolchains("linux") {
-  toolchains = linux_toolchains
-}
diff --git a/targets/host/linux/linux.gni b/targets/host/linux/linux.gni
deleted file mode 100644
index c81bb37..0000000
--- a/targets/host/linux/linux.gni
+++ /dev/null
@@ -1,18 +0,0 @@
-# Copyright 2020 The Pigweed Authors
-#
-# Licensed under the Apache License, Version 2.0 (the "License"); you may not
-# use this file except in compliance with the License. You may obtain a copy of
-# the License at
-#
-#     https://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
-# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
-# License for the specific language governing permissions and limitations under
-# the License.
-
-import("../host_common.gni")
-
-pw_bloat_BLOATY_CONFIG = get_path_info("linux.bloaty", "abspath")
-pw_unit_test_AUTOMATIC_RUNNER = get_path_info("../run_test", "abspath")
diff --git a/targets/host/target_toolchains.gni b/targets/host/target_toolchains.gni
new file mode 100644
index 0000000..6ea32bb
--- /dev/null
+++ b/targets/host/target_toolchains.gni
@@ -0,0 +1,169 @@
+# Copyright 2020 The Pigweed Authors
+#
+# Licensed under the Apache License, Version 2.0 (the "License"); you may not
+# use this file except in compliance with the License. You may obtain a copy of
+# the License at
+#
+#     https://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+# License for the specific language governing permissions and limitations under
+# the License.
+
+# gn-format disable
+import("//build_overrides/pigweed.gni")
+
+import("$dir_pw_toolchain/host_clang/toolchains.gni")
+import("$dir_pw_toolchain/host_gcc/toolchains.gni")
+_host_common = {
+  # Use logging-based test output on host.
+  pw_unit_test_MAIN = "$dir_pw_unit_test:logging_main"
+
+  # Configure backend for assert facade.
+  pw_assert_BACKEND = "$dir_pw_assert_basic"
+
+  # Configure backend for logging facade.
+  pw_log_BACKEND = "$dir_pw_log_basic"
+
+  # Configure backend for pw_sys_io facade.
+  pw_sys_io_BACKEND = "$dir_pw_sys_io_stdio"
+}
+
+# Linux-specific target configuration.
+_linux_config = {
+  pw_bloat_BLOATY_CONFIG = get_path_info("linux.bloaty", "abspath")
+  pw_unit_test_AUTOMATIC_RUNNER = get_path_info("run_test", "abspath")
+}
+
+# macOS-specific target configuration.
+_mac_config = {
+  pw_bloat_BLOATY_CONFIG = get_path_info("macos.bloaty", "abspath")
+  pw_unit_test_AUTOMATIC_RUNNER = get_path_info("run_test", "abspath")
+}
+
+# Windows-specific target configuration.
+_win_config = {
+  # This is here as bloaty_config_file cannot be an empty string or GN fails.
+  # TODO(frolv): Add this file and enable size reports on Windows.
+  pw_bloat_BLOATY_CONFIG = get_path_info("windows.bloaty", "abspath")
+  pw_unit_test_AUTOMATIC_RUNNER = get_path_info("run_test.bat", "abspath")
+}
+
+_os_specific_config = {
+  if (host_os == "linux") {
+    forward_variables_from(_linux_config, "*")
+  } else if (host_os == "mac") {
+    forward_variables_from(_mac_config, "*")
+  } else if (host_os == "win") {
+    forward_variables_from(_win_config, "*")
+  }
+}
+
+pw_target_toolchain_host = {
+  clang_debug = {
+    name = "clang_debug"
+    forward_variables_from(pw_toolchain_host_clang.debug,
+                           "*",
+                           [
+                             "defaults",
+                             "name",
+                           ])
+    defaults = {
+      _toolchain_base = pw_toolchain_host_clang.debug
+      forward_variables_from(_toolchain_base.defaults, "*")
+      forward_variables_from(_host_common, "*")
+      forward_variables_from(_os_specific_config, "*")
+    }
+  }
+
+  clang_speed_optimized = {
+    name = "clang_speed_optimized"
+    forward_variables_from(pw_toolchain_host_clang.speed_optimized,
+                           "*",
+                           [
+                             "defaults",
+                             "name",
+                           ])
+    defaults = {
+      _toolchain_base = pw_toolchain_host_clang.speed_optimized
+      forward_variables_from(_toolchain_base.defaults, "*")
+      forward_variables_from(_host_common, "*")
+      forward_variables_from(_os_specific_config, "*")
+    }
+  }
+
+  clang_size_optimized = {
+    name = "clang_size_optimized"
+    forward_variables_from(pw_toolchain_host_clang.size_optimized,
+                           "*",
+                           [
+                             "defaults",
+                             "name",
+                           ])
+    defaults = {
+      _toolchain_base = pw_toolchain_host_clang.size_optimized
+      forward_variables_from(_toolchain_base.defaults, "*")
+      forward_variables_from(_host_common, "*")
+      forward_variables_from(_os_specific_config, "*")
+    }
+  }
+
+  gcc_debug = {
+    name = "gcc_debug"
+    forward_variables_from(pw_toolchain_host_gcc.debug,
+                           "*",
+                           [
+                             "defaults",
+                             "name",
+                           ])
+    defaults = {
+      _toolchain_base = pw_toolchain_host_gcc.debug
+      forward_variables_from(_toolchain_base.defaults, "*")
+      forward_variables_from(_host_common, "*")
+      forward_variables_from(_os_specific_config, "*")
+    }
+  }
+
+  gcc_speed_optimized = {
+    name = "gcc_speed_optimized"
+    forward_variables_from(pw_toolchain_host_gcc.speed_optimized,
+                           "*",
+                           [
+                             "defaults",
+                             "name",
+                           ])
+    defaults = {
+      _toolchain_base = pw_toolchain_host_gcc.speed_optimized
+      forward_variables_from(_toolchain_base.defaults, "*")
+      forward_variables_from(_host_common, "*")
+      forward_variables_from(_os_specific_config, "*")
+    }
+  }
+
+  gcc_size_optimized = {
+    name = "gcc_size_optimized"
+    forward_variables_from(pw_toolchain_host_gcc.size_optimized,
+                           "*",
+                           [
+                             "defaults",
+                             "name",
+                           ])
+    defaults = {
+      _toolchain_base = pw_toolchain_host_gcc.size_optimized
+      forward_variables_from(_toolchain_base.defaults, "*")
+      forward_variables_from(_host_common, "*")
+      forward_variables_from(_os_specific_config, "*")
+    }
+  }
+}
+
+pw_target_toolchain_host_list = [
+  pw_target_toolchain_host.clang_debug,
+  pw_target_toolchain_host.clang_speed_optimized,
+  pw_target_toolchain_host.clang_size_optimized,
+  pw_target_toolchain_host.gcc_debug,
+  pw_target_toolchain_host.gcc_speed_optimized,
+  pw_target_toolchain_host.gcc_size_optimized,
+]
diff --git a/targets/host/windows.gni b/targets/host/windows.gni
deleted file mode 100644
index b287665..0000000
--- a/targets/host/windows.gni
+++ /dev/null
@@ -1,26 +0,0 @@
-# Copyright 2020 The Pigweed Authors
-#
-# Licensed under the Apache License, Version 2.0 (the "License"); you may not
-# use this file except in compliance with the License. You may obtain a copy of
-# the License at
-#
-#     https://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
-# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
-# License for the specific language governing permissions and limitations under
-# the License.
-
-import("host_common.gni")
-
-pw_automatic_test_runner = get_path_info("run_test.bat", "abspath")
-
-declare_args() {
-  pw_target_toolchain = "$dir_pw_toolchain:host_gcc_og"
-}
-
-# This is here as bloaty_config_file cannot be an empty string or GN fails.
-# TODO(frolv): Add this file and enable size reports on Windows.
-pw_executable_config.bloaty_config_file =
-    get_path_info("windows.bloaty", "abspath")