aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChris Parsons <cparsons@google.com>2021-07-13 11:37:01 -0400
committerChris Parsons <cparsons@google.com>2021-07-13 14:11:47 -0400
commit5828e0b656cb07914154b0ba72675d803a3f88c4 (patch)
treeeb0bf32df1f4fdc9028692a64c14ce95fd97902d
parent45eb532818ed1084f20dbd1424df5b21fd843583 (diff)
downloadbazel-android-s-beta-3.tar.gz
Rules changes to support libm mixed buildsandroid-s-beta-4android-s-beta-3android-s-beta-4
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
-rw-r--r--rules/cc_library_static.bzl17
-rw-r--r--rules/cc_object.bzl3
-rw-r--r--rules_cc/examples/experimental_cc_shared_library.bzl6
3 files changed, 14 insertions, 12 deletions
diff --git a/rules/cc_library_static.bzl b/rules/cc_library_static.bzl
index 9e61d935..e6482493 100644
--- a/rules/cc_library_static.bzl
+++ b/rules/cc_library_static.bzl
@@ -12,7 +12,7 @@ def cc_library_static(
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 @@ def cc_library_static(
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 @@ def cc_library_static(
native.cc_library(
name = asm_name,
srcs = srcs_as,
- copts = copts + asflags,
+ copts = asflags,
**common_attrs
)
@@ -75,7 +77,6 @@ def cc_library_static(
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 @@ def _combine_and_own(ctx, old_owner_labels, cc_infos):
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 @@ def _link_archive(ctx, objects):
args.add_all(command_line)
args.add_all(objects)
+
ctx.actions.run(
executable = archiver_path,
arguments = [args],
@@ -200,7 +196,6 @@ _cc_library_combiner = rule(
# 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 bb3f24ab..d5b1801b 100644
--- a/rules/cc_object.bzl
+++ b/rules/cc_object.bzl
@@ -115,6 +115,7 @@ def cc_object(
hdrs = [],
asflags = [],
srcs = [],
+ srcs_as = [],
deps = [],
native_bridge_supported = False, # TODO: not supported yet.
**kwargs):
@@ -125,7 +126,7 @@ def cc_object(
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 561e4f6d..45659b90 100644
--- a/rules_cc/examples/experimental_cc_shared_library.bzl
+++ b/rules_cc/examples/experimental_cc_shared_library.bzl
@@ -287,6 +287,12 @@ def _filter_inputs(
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):