Fix various build issues

- clang sysroot issues for pw_display_driver_imgui on Linux
- pw_spi_arduino library path
- pw_digital_io_stm32cube typo
- mimxrt595_executable.gni change to allow .ninja file parsing by:
https://cs.opensource.google/pigweed/pigweed/+/main:pw_build/py/pw_build/gn_resolver.py

Bug: b/256272529
Change-Id: I7eca9570b715fd910522d69442c7512c377b1dd9
Reviewed-on: https://pigweed-review.googlesource.com/c/pigweed/experimental/+/148797
Reviewed-by: Chris Mumford <cmumford@google.com>
Commit-Queue: Anthony DiGirolamo <tonymd@google.com>
Reviewed-by: Rob Mohr <mohrr@google.com>
diff --git a/BUILD.gn b/BUILD.gn
index f48de4b..537480a 100644
--- a/BUILD.gn
+++ b/BUILD.gn
@@ -59,8 +59,11 @@
 
     if (pw_arduino_build_CORE_NAME == "teensy") {
       deps += [
+        # TODO(tonymd): pw_framebuffer_pool depends on
+        # "pw_sync/counting_semaphore.h". Teensy does not have a implementation
+        # for that yet.
         # See //pw_lcd_display_teensy_ili9341/README.md for instructions.
-        "//applications/terminal_display:all(//targets/arduino:arduino_debug)",
+        # "//applications/terminal_display:all(//targets/arduino:arduino_debug)",
       ]
     }
   }
diff --git a/applications/app_common_impl/BUILD.gn b/applications/app_common_impl/BUILD.gn
index 8d8a464..f47e05d 100644
--- a/applications/app_common_impl/BUILD.gn
+++ b/applications/app_common_impl/BUILD.gn
@@ -177,6 +177,10 @@
     "$dir_pw_framebuffer_pool",
   ]
   sources = [ "common_host_imgui.cc" ]
+  remove_configs = []
+  if (host_os == "linux") {
+    remove_configs += [ "$dir_pw_toolchain/host_clang:linux_sysroot" ]
+  }
 }
 
 pw_source_set("host_null") {
diff --git a/applications/rpc/BUILD.gn b/applications/rpc/BUILD.gn
index 87560d1..78343b7 100644
--- a/applications/rpc/BUILD.gn
+++ b/applications/rpc/BUILD.gn
@@ -26,12 +26,9 @@
 group("all") {
   deps = [ ":rpc" ]
 
-  # Build tokenizer_database for elf binaries only
-  # TODO(b/256272529): Figure out why this needs to be disabled on
-  #                    mimxrt595_evk.
+  # Build tokenizer_database for elf and Linux binaries only
   if (host_os == "linux" ||
-      (get_label_info(current_toolchain, "name") != "host_debug" &&
-       pw_build_EXECUTABLE_TARGET_TYPE != "mimxrt595_executable")) {
+      get_label_info(current_toolchain, "name") != "host_debug") {
     deps += [ ":tokenizer_database" ]
   }
 }
diff --git a/applications/strings/BUILD.gn b/applications/strings/BUILD.gn
index 61f4797..76bb4aa 100644
--- a/applications/strings/BUILD.gn
+++ b/applications/strings/BUILD.gn
@@ -21,12 +21,9 @@
 group("all") {
   deps = [ ":string_demo" ]
 
-  # Build tokenizer_database for elf binaries only
-  # TODO(b/256272529): Figure out why this needs to be disabled on
-  #                    mimxrt595_evk.
+  # Build tokenizer_database for elf and Linux binaries only
   if (host_os == "linux" ||
-      (get_label_info(current_toolchain, "name") != "host_debug" &&
-       pw_build_EXECUTABLE_TARGET_TYPE != "mimxrt595_executable")) {
+      get_label_info(current_toolchain, "name") != "host_debug") {
     deps += [ ":tokenizer_database" ]
   }
 }
diff --git a/applications/terminal_display/BUILD.gn b/applications/terminal_display/BUILD.gn
index 9480ef7..7cf36a5 100644
--- a/applications/terminal_display/BUILD.gn
+++ b/applications/terminal_display/BUILD.gn
@@ -22,12 +22,9 @@
 group("all") {
   deps = [ ":terminal_demo" ]
 
-  # Build tokenizer_database for elf binaries only
-  # TODO(b/256272529): Figure out why this needs to be disabled on
-  #                    mimxrt595_evk.
+  # Build tokenizer_database for elf and Linux binaries only.
   if (host_os == "linux" ||
-      (get_label_info(current_toolchain, "name") != "host_debug" &&
-       pw_build_EXECUTABLE_TARGET_TYPE != "mimxrt595_executable")) {
+      get_label_info(current_toolchain, "name") != "host_debug") {
     deps += [ ":tokenizer_database" ]
   }
 }
@@ -64,10 +61,11 @@
     "$dir_pw_sys_io",
     "$dir_pw_touchscreen",
   ]
-  remove_configs = [
-    "$dir_pw_build:strict_warnings",
-    "//third_party/pigweed/pw_toolchain/host_clang:linux_sysroot",
-  ]
+  remove_configs = [ "$dir_pw_build:strict_warnings" ]
+
+  if (host_os == "linux") {
+    remove_configs += [ "$dir_pw_toolchain/host_clang:linux_sysroot" ]
+  }
 
   # Hack for targets with no pre-init target implementation.
   defines = []
diff --git a/pw_digital_io_stm32cube/BUILD.gn b/pw_digital_io_stm32cube/BUILD.gn
index 0a18a10..1bd0f55 100644
--- a/pw_digital_io_stm32cube/BUILD.gn
+++ b/pw_digital_io_stm32cube/BUILD.gn
@@ -22,7 +22,7 @@
 
 pw_source_set("pw_digital_io_stm32cube") {
   public_configs = [ ":public_includes" ]
-  public = [ "public/ps_digital_io_stm32cube/digital_io.h" ]
+  public = [ "public/pw_digital_io_stm32cube/digital_io.h" ]
   deps = [ "$dir_pw_assert" ]
   public_deps = [
     "$dir_pw_digital_io",
diff --git a/pw_display_driver_imgui/BUILD.gn b/pw_display_driver_imgui/BUILD.gn
index a8ed653..e191e07 100644
--- a/pw_display_driver_imgui/BUILD.gn
+++ b/pw_display_driver_imgui/BUILD.gn
@@ -35,4 +35,8 @@
   ]
   sources = [ "display_driver.cc" ]
   remove_configs = [ "$dir_pw_build:strict_warnings" ]
+
+  if (host_os == "linux") {
+    remove_configs += [ "$dir_pw_toolchain/host_clang:linux_sysroot" ]
+  }
 }
diff --git a/pw_graphics/pw_display_imgui/BUILD.gn b/pw_graphics/pw_display_imgui/BUILD.gn
index 04038c8..b05a0a0 100644
--- a/pw_graphics/pw_display_imgui/BUILD.gn
+++ b/pw_graphics/pw_display_imgui/BUILD.gn
@@ -30,4 +30,9 @@
     "$dir_pw_status",
   ]
   sources = [ "display.cc" ]
+
+  remove_configs = []
+  if (host_os == "linux") {
+    remove_configs += [ "$dir_pw_toolchain/host_clang:linux_sysroot" ]
+  }
 }
diff --git a/pw_spi_arduino/BUILD.gn b/pw_spi_arduino/BUILD.gn
index 739236d..577d293 100644
--- a/pw_spi_arduino/BUILD.gn
+++ b/pw_spi_arduino/BUILD.gn
@@ -25,7 +25,7 @@
   _library_args = [
     "--library-path",
     rebase_path(
-        "$pw_arduino_build_CORE_PATH/teensy/hardware/teensy/avr/libraries"),
+        "$pw_arduino_build_CORE_PATH/teensy/hardware/${pw_arduino_build_PACKAGE_NAME}/libraries"),
     "--library-names",
 
     # Arduino Core Libaries. The c/c++ files for these should only be included
diff --git a/targets/mimxrt595_evk/mimxrt595_executable.gni b/targets/mimxrt595_evk/mimxrt595_executable.gni
index e29ca91..0719260 100644
--- a/targets/mimxrt595_evk/mimxrt595_executable.gni
+++ b/targets/mimxrt595_evk/mimxrt595_executable.gni
@@ -19,22 +19,16 @@
 
 # Executable wrapper that includes some baremetal startup code.
 template("mimxrt595_executable") {
-  group(target_name) {
-    deps = [
-      ":${target_name}__binary",
-      ":${target_name}__elf",
-    ]
-  }
-
   # .elf binary created by the standard toolchain.
-  _base_target_name = target_name
-  executable("${target_name}__elf") {
-    output_name = "${_base_target_name}"
+  _bin_name = "${target_name}.bin"
+  _elf_name = "${target_name}.elf"
+
+  executable(_elf_name) {
     forward_variables_from(invoker, "*")
     if (!defined(deps)) {
       deps = []
     }
-    deps += [ "$dir_pigweed_experimental/targets/mimxrt595_evk:boot" ]
+    deps += [ "//targets/mimxrt595_evk:boot" ]
     if (pw_malloc_BACKEND != "") {
       if (!defined(configs)) {
         configs = []
@@ -44,21 +38,25 @@
   }
 
   # .bin binary created by extracting from the toolchain output.
-  pw_exec("${target_name}__binary") {
+  pw_exec(_bin_name) {
     if (defined(invoker.output_dir)) {
       _output_dir = invoker.output_dir
     } else {
       _output_dir = target_out_dir
     }
 
-    outputs = [ "${_output_dir}/${_base_target_name}.bin" ]
-    deps = [ ":${_base_target_name}__elf" ]
+    outputs = [ "${_output_dir}/${_bin_name}" ]
+    deps = [ ":${_elf_name}" ]
 
     program = "arm-none-eabi-objcopy"
     args = [
       "-Obinary",
-      "<TARGET_FILE(:${_base_target_name}__elf)>",
+      "<TARGET_FILE(:${_elf_name})>",
       rebase_path(outputs[0], root_build_dir),
     ]
   }
+
+  group(target_name) {
+    deps = [ ":${_bin_name}" ]
+  }
 }
diff --git a/third_party/glfw/BUILD.gn b/third_party/glfw/BUILD.gn
index 2ff8372..73008ea 100644
--- a/third_party/glfw/BUILD.gn
+++ b/third_party/glfw/BUILD.gn
@@ -36,6 +36,7 @@
     ]
     include_dirs = [
       "$dir_pw_third_party_glfw/include",
+      "/usr/include/x86_64-linux-gnu",
       "/usr/include",
     ]
     lib_dirs = [
diff --git a/third_party/imgui/BUILD.gn b/third_party/imgui/BUILD.gn
index d1baa77..3b9461b 100644
--- a/third_party/imgui/BUILD.gn
+++ b/third_party/imgui/BUILD.gn
@@ -37,8 +37,10 @@
     "$dir_pw_third_party_imgui/imgui_tables.cpp",
     "$dir_pw_third_party_imgui/imgui_widgets.cpp",
   ]
-  remove_configs = [
-    "$dir_pw_build:strict_warnings",
-    "//third_party/pigweed/pw_toolchain/host_clang:linux_sysroot",
-  ]
+
+  remove_configs = [ "$dir_pw_build:strict_warnings" ]
+
+  if (host_os == "linux") {
+    remove_configs += [ "$dir_pw_toolchain/host_clang:linux_sysroot" ]
+  }
 }
diff --git a/tools/pigweed_experimental_tools/presubmit_checks.py b/tools/pigweed_experimental_tools/presubmit_checks.py
index 804bd39..1e8f343 100755
--- a/tools/pigweed_experimental_tools/presubmit_checks.py
+++ b/tools/pigweed_experimental_tools/presubmit_checks.py
@@ -20,6 +20,7 @@
 from pathlib import Path
 import re
 import sys
+from typing import Callable
 
 try:
     import pw_cli.log
@@ -75,26 +76,66 @@
     build.ninja(ctx)
 
 
-def pico_build(ctx: PresubmitContext):
-    build.install_package(ctx, 'pico_sdk')
-    build.gn_gen(
-        ctx,
-        PICO_SRC_DIR='"{}"'.format(str(ctx.package_root / 'pico_sdk')),
-    )
-    build.ninja(ctx)
+def _package_root_arg(name: str) -> Callable[[PresubmitContext], str]:
+    def _format(ctx: PresubmitContext) -> str:
+        return '"{}"'.format(ctx.package_root / name)
+
+    return _format
 
 
-def stm32cube_f4_build(ctx: PresubmitContext):
-    build.install_package(ctx, 'freertos')
-    build.install_package(ctx, 'stm32cube_f4')
-    build.gn_gen(
-        ctx,
-        dir_pw_third_party_freertos='"{}"'.format(ctx.package_root /
-                                                  'freertos'),
-        dir_pw_third_party_stm32cube_f4='"{}"'.format(ctx.package_root /
-                                                      'stm32cube_f4'),
-    )
-    build.ninja(ctx)
+teensy_build = build.GnGenNinja(
+    name='teensy_build',
+    packages=('teensy', ),
+    gn_args=dict(
+        pw_arduino_build_CORE_PATH=lambda ctx: '"{}"'.format(
+            str(ctx.package_root)),
+        pw_arduino_build_CORE_NAME='"teensy"',
+        pw_arduino_build_PACKAGE_NAME='"avr/1.58.1"',
+        pw_arduino_build_BOARD='"teensy41"',
+        pw_arduino_build_MENU_OPTIONS=(
+            '["menu.usb.serial", "menu.keys.en-us", "menu.opt.o2std"]'),
+    ),
+)
+
+pico_build = build.GnGenNinja(
+    name='pico_build',
+    packages=('pico_sdk', ),
+    gn_args=dict(
+        PICO_SRC_DIR=_package_root_arg('pico_sdk'),
+        dir_pw_third_party_freertos='"//third_party/freertos/Source"',
+    ),
+)
+
+stm32cube_f4_build = build.GnGenNinja(
+    name='stm32cube_f4_build',
+    packages=('stm32cube_f4', ),
+    gn_args=dict(
+        dir_pw_third_party_stm32cube_f4=_package_root_arg('stm32cube_f4'),
+        dir_pw_third_party_freertos='"//third_party/freertos/Source"',
+    ),
+)
+
+# pylint: disable=line-too-long
+mimxrt595_evk_build = build.GnGenNinja(
+    name='mimxrt595_evk_build',
+    gn_args=dict(
+        dir_pw_third_party_freertos='"//third_party/freertos/Source"',
+        pw_MIMXRT595_EVK_SDK=_package_root_arg("SDK_2_12_1_EVK-MIMXRT595"),
+        pw_target_mimxrt595_evk_MANIFEST=_package_root_arg(
+            "SDK_2_12_1_EVK-MIMXRT595/EVK-MIMXRT595_manifest_v3_10.xml"),
+        pw_third_party_mcuxpresso_SDK="//targets/mimxrt595_evk:mimxrt595_sdk",
+    ),
+)
+# pylint: enable=line-too-long
+
+pw_graphics_host = build.GnGenNinja(
+    name='pw_graphics_host',
+    packages=('imgui', 'glfw'),
+    gn_args=dict(
+        dir_pw_third_party_glfw=_package_root_arg('glfw'),
+        dir_pw_third_party_imgui=_package_root_arg('imgui'),
+    ),
+)
 
 
 def check_for_git_changes(_: PresubmitContext):
@@ -122,6 +163,9 @@
 OTHER_CHECKS = (
     build.gn_gen_check,
     inclusive_language.presubmit_check.with_filter(exclude=PATH_EXCLUSIONS),
+    pw_graphics_host,
+    mimxrt595_evk_build,
+    teensy_build,
 )
 
 QUICK = (
@@ -149,7 +193,7 @@
     stm32cube_f4_build,
 )
 
-CI_CQ = (default_build, pico_build)
+CI_CQ = (default_build, pico_build, stm32cube_f4_build)
 
 PROGRAMS = pw_presubmit.Programs(
     # keep-sorted: start