Rules changes to support libm mixed builds

There are a couple of meaningful changes:
1. For static libraries, branch copts from asflags; copts should apply
only to C and C++.
2. Add dynamic_deps as implementation_deps for static libraries so that
include paths propagate from the dynamic deps.
3. For shared libraries, always add the dynamic deps as linker inputs,
even if they don't seem to contain dependencies reachable from the
shared library roots.

Test: Droid CI script
Change-Id: I27e809f90ef2c9a092b33b094e388c212a194b27
diff --git a/rules/cc_library_static.bzl b/rules/cc_library_static.bzl
index 9e61d93..e648249 100644
--- a/rules/cc_library_static.bzl
+++ b/rules/cc_library_static.bzl
@@ -12,7 +12,7 @@
         whole_archive_deps = [],
         use_libcrt = True,
         rtti = False,
-        # Flags for all languages
+        # Flags for C and C++
         copts = [],
         # C++ attributes
         srcs = [],
@@ -43,7 +43,9 @@
     common_attrs = dict(
         [
             ("hdrs", hdrs),
-            ("implementation_deps", implementation_deps),
+            # Add dynamic_deps to implementation_deps, as the include paths from the
+            # dynamic_deps are also needed.
+            ("implementation_deps", implementation_deps + dynamic_deps),
             ("deps", deps + whole_archive_deps),
             ("includes", includes),
             ("features", features),
@@ -66,7 +68,7 @@
     native.cc_library(
         name = asm_name,
         srcs = srcs_as,
-        copts = copts + asflags,
+        copts = asflags,
         **common_attrs
     )
 
@@ -75,7 +77,6 @@
         name = name,
         deps = [cpp_name, c_name, asm_name],
         whole_archive_deps = whole_archive_deps,
-        dynamic_deps = dynamic_deps, # Propagate shared object deps as linker inputs.
     )
 
 # Returns a CcInfo object which combines one or more CcInfo objects, except that all linker inputs
@@ -102,12 +103,6 @@
             for lib in li.libraries:
                 objects_to_link.extend(lib.objects)
 
-    # Also add cc_shared_library deps to linker inputs.
-    for dynamic_dep in ctx.attr.dynamic_deps:
-        li = dynamic_dep[CcSharedLibraryInfo].linker_input
-        for lib in li.libraries:
-            objects_to_link.extend([lib.dynamic_library])
-
     return _link_archive(ctx, objects_to_link)
 
 def _cc_library_combiner_impl(ctx):
@@ -164,6 +159,7 @@
     args.add_all(command_line)
     args.add_all(objects)
 
+
     ctx.actions.run(
         executable = archiver_path,
         arguments = [args],
@@ -200,7 +196,6 @@
         # depend on each other through the "deps" attribute.
         "deps": attr.label_list(providers = [CcInfo]),
         "whole_archive_deps": attr.label_list(providers = [CcInfo]),
-        "dynamic_deps": attr.label_list(providers = [CcSharedLibraryInfo]),
         "_cc_toolchain": attr.label(
             default = Label("@local_config_cc//:toolchain"),
             providers = [cc_common.CcToolchainInfo],
diff --git a/rules/cc_object.bzl b/rules/cc_object.bzl
index bb3f24a..d5b1801 100644
--- a/rules/cc_object.bzl
+++ b/rules/cc_object.bzl
@@ -115,6 +115,7 @@
         hdrs = [],
         asflags = [],
         srcs = [],
+        srcs_as = [],
         deps = [],
         native_bridge_supported = False, # TODO: not supported yet.
         **kwargs):
@@ -125,7 +126,7 @@
         hdrs = hdrs,
         asflags = asflags,
         copts = _CC_OBJECT_COPTS + copts,
-        srcs = srcs,
+        srcs = srcs + srcs_as,
         deps = deps,
         **kwargs
     )
diff --git a/rules_cc/examples/experimental_cc_shared_library.bzl b/rules_cc/examples/experimental_cc_shared_library.bzl
index 561e4f6..45659b9 100644
--- a/rules_cc/examples/experimental_cc_shared_library.bzl
+++ b/rules_cc/examples/experimental_cc_shared_library.bzl
@@ -287,6 +287,12 @@
                     fail("We can't link " +
                          str(owner) + " either statically or dynamically")
 
+    # Divergence from rules_cc: Add all dynamic dependencies as linker inputs
+    # even if they do not contain transitive dependencies of the roots.
+    # TODO(cparsons): Push this as an option upstream..
+    for dynamic_dep_input in transitive_exports.values():
+        linker_inputs.append(dynamic_dep_input)
+
     return (exports, linker_inputs, link_once_static_libs)
 
 def _same_package_or_above(label_a, label_b):