1load("//cc/toolchains:args.bzl", "cc_args") 2load("//cc/toolchains:nested_args.bzl", "cc_nested_args") 3load("//cc/toolchains/args/libraries_to_link/private:library_link_args.bzl", "library_link_args") 4 5package(default_visibility = ["//visibility:private"]) 6 7cc_args( 8 name = "libraries_to_link", 9 actions = ["//cc/toolchains/actions:link_actions"], 10 nested = [ 11 ":thinlto_param_file", 12 ":libraries_to_link_args", 13 ], 14 visibility = ["//visibility:public"], 15) 16 17cc_nested_args( 18 name = "thinlto_param_file", 19 args = ["-Wl,@{param_file}"], 20 format = { 21 "param_file": "//cc/toolchains/variables:thinlto_param_file", 22 }, 23 requires_not_none = "//cc/toolchains/variables:thinlto_param_file", 24) 25 26cc_nested_args( 27 name = "libraries_to_link_args", 28 nested = [":iterate_over_libraries_to_link"], 29 requires_not_none = "//cc/toolchains/variables:libraries_to_link", 30) 31 32cc_nested_args( 33 name = "iterate_over_libraries_to_link", 34 iterate_over = "//cc/toolchains/variables:libraries_to_link", 35 nested = [ 36 ":optional_object_file_group_start", 37 ":single_library_args", 38 ":optional_object_file_group_end", 39 ], 40) 41 42cc_nested_args( 43 name = "optional_object_file_group_start", 44 nested = [":start_lib_arg"], 45 requires_equal = "//cc/toolchains/variables:libraries_to_link.type", 46 requires_equal_value = "object_file_group", 47) 48 49cc_nested_args( 50 name = "start_lib_arg", 51 args = ["-Wl,--start-lib"], 52 requires_false = "//cc/toolchains/variables:libraries_to_link.is_whole_archive", 53) 54 55cc_nested_args( 56 name = "optional_object_file_group_end", 57 nested = [":end_lib_arg"], 58 requires_equal = "//cc/toolchains/variables:libraries_to_link.type", 59 requires_equal_value = "object_file_group", 60) 61 62cc_nested_args( 63 name = "end_lib_arg", 64 args = ["-Wl,--end-lib"], 65 requires_false = "//cc/toolchains/variables:libraries_to_link.is_whole_archive", 66) 67 68cc_nested_args( 69 name = "single_library_args", 70 nested = select({ 71 "@platforms//os:macos": [], 72 "//conditions:default": [":optional_whole_archive_start"], 73 }) + [ 74 ":optional_object_file_group", 75 ":optional_object_file", 76 ":optional_interface_library", 77 ":optional_static_library", 78 ":optional_dynamic_library", 79 ] + select({ 80 # maOS has a minor nuance where it uses the path to the library instead of `-l:{library_name}`. 81 "@platforms//os:macos": [":macos_optional_versioned_dynamic_library"], 82 "//conditions:default": [":generic_optional_versioned_dynamic_library"], 83 }) + select({ 84 "@platforms//os:macos": [], 85 "//conditions:default": [":optional_whole_archive_end"], 86 }), 87) 88 89cc_nested_args( 90 name = "optional_whole_archive_start", 91 nested = [":whole_archive_start_arg"], 92 requires_true = "//cc/toolchains/variables:libraries_to_link.is_whole_archive", 93) 94 95cc_nested_args( 96 name = "whole_archive_start_arg", 97 args = ["-Wl,-whole-archive"], 98 requires_equal = "//cc/toolchains/variables:libraries_to_link.type", 99 requires_equal_value = "static_library", 100) 101 102cc_nested_args( 103 name = "optional_whole_archive_end", 104 nested = [":whole_archive_end_arg"], 105 requires_true = "//cc/toolchains/variables:libraries_to_link.is_whole_archive", 106) 107 108cc_nested_args( 109 name = "whole_archive_end_arg", 110 args = ["-Wl,-no-whole-archive"], 111 requires_equal = "//cc/toolchains/variables:libraries_to_link.type", 112 requires_equal_value = "static_library", 113) 114 115library_link_args( 116 name = "optional_object_file_group", 117 from_variable = "//cc/toolchains/variables:libraries_to_link.object_files", 118 iterate_over_variable = True, 119 library_type = "object_file_group", 120) 121 122library_link_args( 123 name = "optional_object_file", 124 from_variable = "//cc/toolchains/variables:libraries_to_link.name", 125 library_type = "object_file", 126) 127 128library_link_args( 129 name = "optional_interface_library", 130 from_variable = "//cc/toolchains/variables:libraries_to_link.name", 131 library_type = "interface_library", 132) 133 134library_link_args( 135 name = "optional_static_library", 136 from_variable = "//cc/toolchains/variables:libraries_to_link.name", 137 library_type = "static_library", 138) 139 140cc_nested_args( 141 name = "optional_dynamic_library", 142 args = ["-l{library}"], 143 format = { 144 "library": "//cc/toolchains/variables:libraries_to_link.name", 145 }, 146 requires_equal = "//cc/toolchains/variables:libraries_to_link.type", 147 requires_equal_value = "dynamic_library", 148) 149 150cc_nested_args( 151 name = "generic_optional_versioned_dynamic_library", 152 args = ["-l:{library_name}"], 153 format = { 154 "library_name": "//cc/toolchains/variables:libraries_to_link.name", 155 }, 156 requires_equal = "//cc/toolchains/variables:libraries_to_link.type", 157 requires_equal_value = "versioned_dynamic_library", 158) 159 160cc_nested_args( 161 name = "macos_optional_versioned_dynamic_library", 162 args = ["{library_path}"], 163 format = { 164 "library_path": "//cc/toolchains/variables:libraries_to_link.path", 165 }, 166 requires_equal = "//cc/toolchains/variables:libraries_to_link.type", 167 requires_equal_value = "versioned_dynamic_library", 168) 169