|
2 | 2 | with CMake, configure/make, autotools) |
3 | 3 | """ |
4 | 4 |
|
| 5 | +load("@bazel_features//:features.bzl", "bazel_features") |
5 | 6 | load("@bazel_skylib//lib:collections.bzl", "collections") |
6 | 7 | load("@bazel_skylib//lib:paths.bzl", "paths") |
7 | 8 | load("@bazel_tools//tools/cpp:toolchain_utils.bzl", "find_cpp_toolchain") |
@@ -98,6 +99,14 @@ CC_EXTERNAL_RULE_ATTRIBUTES = { |
98 | 99 | default = [], |
99 | 100 | providers = [CcInfo], |
100 | 101 | ), |
| 102 | + "dynamic_deps": attr.label_list( |
| 103 | + doc = ( |
| 104 | + "Same as deps but for cc_shared_library." |
| 105 | + ), |
| 106 | + mandatory = False, |
| 107 | + default = [], |
| 108 | + # providers = [CcSharedLibraryInfo], |
| 109 | + ), |
101 | 110 | "env": attr.string_dict( |
102 | 111 | doc = ( |
103 | 112 | "Environment variables to set during the build. " + |
@@ -866,6 +875,19 @@ def _define_inputs(attrs): |
866 | 875 | bazel_system_includes += headers_info.include_dirs |
867 | 876 | bazel_libs += _collect_libs(dep[CcInfo].linking_context) |
868 | 877 |
|
| 878 | + for dynamic_dep in attrs.dynamic_deps: |
| 879 | + if not bazel_features.globals.CcSharedLibraryInfo: |
| 880 | + fail("CcSharedLibraryInfo is only available in Bazel 7 or greater") |
| 881 | + |
| 882 | + linker_input = dynamic_dep[bazel_features.globals.CcSharedLibraryInfo].linker_input |
| 883 | + bazel_libs += _collect_shared_libs(linker_input) |
| 884 | + linking_context = cc_common.create_linking_context( |
| 885 | + linker_inputs = depset(direct = [linker_input]), |
| 886 | + ) |
| 887 | + |
| 888 | + # create a new CcInfo from the CcSharedLibraryInfo linker_input |
| 889 | + cc_infos.append(CcInfo(linking_context = linking_context)) |
| 890 | + |
869 | 891 | # Keep the order of the transitive foreign dependencies |
870 | 892 | # (the order is important for the correct linking), |
871 | 893 | # but filter out repeating directories |
@@ -989,6 +1011,14 @@ def _collect_libs(cc_linking): |
989 | 1011 | libs.append(library) |
990 | 1012 | return collections.uniq(libs) |
991 | 1013 |
|
| 1014 | +def _collect_shared_libs(cc_linker_input): |
| 1015 | + libs = [] |
| 1016 | + for library_to_link in cc_linker_input.libraries: |
| 1017 | + for library in _extract_libraries(library_to_link): |
| 1018 | + if library: |
| 1019 | + libs.append(library) |
| 1020 | + return collections.uniq(libs) |
| 1021 | + |
992 | 1022 | def expand_locations_and_make_variables(ctx, unexpanded, attr_name, data): |
993 | 1023 | """Expand locations and make variables while ensuring that `execpath` is always set to an absolute path |
994 | 1024 |
|
|
0 commit comments