pw_build: Support specifying final link dependencies

- pw_build_LINK_DEPS is a list of build targets that are linked into
  all build artifacts produced by pw_executable, pw_static_library, and
  pw_shared_library.
- Add a ":deps" group to the pw_assert build interface. Require
  $dir_pw_assert:deps to be listed in pw_build_LINK_DEPS if
  pw_assert_BACKEND is set.

Change-Id: Icc01dbe86f95d971e76aa357c7b7174ce85546ba
Reviewed-on: https://pigweed-review.googlesource.com/c/pigweed/pigweed/+/43521
Pigweed-Auto-Submit: Wyatt Hepler <hepler@google.com>
Commit-Queue: Auto-Submit <auto-submit@pigweed.google.com.iam.gserviceaccount.com>
Reviewed-by: Armando Montanez <amontanez@google.com>
diff --git a/pw_build/BUILD.gn b/pw_build/BUILD.gn
index 706b8d6..bb83617 100644
--- a/pw_build/BUILD.gn
+++ b/pw_build/BUILD.gn
@@ -16,6 +16,7 @@
 
 import("$dir_pw_build/python.gni")
 import("$dir_pw_docgen/docs.gni")
+import("target_types.gni")
 
 # IMPORTANT: The compilation flags in this file must be kept in sync with
 #            the CMake flags pw_build/CMakeLists.txt.
@@ -121,6 +122,18 @@
   ]
 }
 
+# This group is linked into all pw_executable, pw_static_library, and
+# pw_shared_library targets. This makes it possible to ensure symbols are
+# defined without a dependency on them.
+#
+# pw_build_LINK_DEPS should only be used when necessary. For example,
+# pw_assert relies on pw_build_LINK_DEPS to avoid circular dependencies
+# in GN. In almost all other cases, build targets should explicitly depend on
+# the other targets they use.
+group("link_deps") {
+  deps = pw_build_LINK_DEPS
+}
+
 # This empty target is used as the default value for module configurations.
 # Projects may set pw_build_DEFAULT_MODULE_CONFIG to a different GN target that
 # overrides modules' configuration options via macro definitions or a header