Handle system_dynamic_deps in cc_library macros.

The macro handles defaulting system_dynamic_deps to the appropriate
bionic shared libraries if it is unspecified.

Test: mixed_droid.sh CI
Change-Id: I04b5b1f85a1e68c57737cd3efa69d7d2103b229a
diff --git a/rules/cc_library_static.bzl b/rules/cc_library_static.bzl
index e648249..b9f0d8d 100644
--- a/rules/cc_library_static.bzl
+++ b/rules/cc_library_static.bzl
@@ -1,10 +1,18 @@
 load("@rules_cc//cc:find_cc_toolchain.bzl", "find_cpp_toolchain")
 load("@rules_cc//examples:experimental_cc_shared_library.bzl", "CcSharedLibraryInfo")
+load("//build/bazel/product_variables:constants.bzl", "constants")
+
+_bionic_targets = ["//bionic/libc", "//bionic/libdl", "//bionic/libm"]
+_system_dynamic_deps_defaults = select({
+    constants.ArchVariantToConstraints["linux_bionic"]: _bionic_targets,
+    constants.ArchVariantToConstraints["android"]: _bionic_targets,
+    "//conditions:default": []})
 
 def cc_library_static(
         name,
         implementation_deps = [],
         dynamic_deps = [],
+        system_dynamic_deps = None,
         deps = [],
         hdrs = [],
         includes = [],
@@ -38,6 +46,9 @@
     if not use_libcrt:
         features += ["use_libcrt"]
 
+    if system_dynamic_deps == None:
+        system_dynamic_deps = _system_dynamic_deps_defaults
+
     # Silently drop these attributes for now:
     # - native_bridge_supported
     common_attrs = dict(
@@ -45,7 +56,7 @@
             ("hdrs", hdrs),
             # Add dynamic_deps to implementation_deps, as the include paths from the
             # dynamic_deps are also needed.
-            ("implementation_deps", implementation_deps + dynamic_deps),
+            ("implementation_deps", implementation_deps + dynamic_deps + system_dynamic_deps),
             ("deps", deps + whole_archive_deps),
             ("includes", includes),
             ("features", features),
diff --git a/rules/full_cc_library.bzl b/rules/full_cc_library.bzl
index dcc9755..1d91317 100644
--- a/rules/full_cc_library.bzl
+++ b/rules/full_cc_library.bzl
@@ -3,6 +3,14 @@
 load(":stripped_shared_library.bzl", "stripped_shared_library")
 load(":generate_toc.bzl", "shared_library_toc")
 
+def _add_lists_defaulting_to_none(a, b):
+    """Adds two lists a and b, but is well behaved with a `None` default."""
+    if a == None:
+      return b
+    if b == None:
+      return a
+    return a + b
+
 def cc_library(
         name,
         # attributes for both targets
@@ -18,6 +26,7 @@
         deps = [],
         whole_archive_deps = [],
         dynamic_deps = [],
+        system_dynamic_deps = None,
         includes = [],
         linkopts = [],
         rtti = False,
@@ -53,6 +62,8 @@
         whole_archive_deps = whole_archive_deps + static.get("whole_archive_deps", []),
         implementation_deps = implementation_deps + static.get("static_deps", []),
         dynamic_deps = dynamic_deps + static.get("dynamic_deps", []),
+        system_dynamic_deps = _add_lists_defaulting_to_none(system_dynamic_deps,
+                                                            static.get("system_dynamic_deps", None)),
         deps = deps,
         features = features,
     )
@@ -76,6 +87,8 @@
         whole_archive_deps = whole_archive_deps + shared.get("whole_archive_deps", []),
         implementation_deps = implementation_deps + shared.get("static_deps", []),
         dynamic_deps = dynamic_deps + shared.get("dynamic_deps", []),
+        system_dynamic_deps = _add_lists_defaulting_to_none(system_dynamic_deps,
+                                                            shared.get("system_dynamic_deps", None)),
         deps = deps,
         features = features,
     )