-
Notifications
You must be signed in to change notification settings - Fork 3.9k
/
cc_library.bzl
executable file
·630 lines (538 loc) · 24.5 KB
/
cc_library.bzl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
# Copyright 2020 The Bazel Authors. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""cc_library Starlark implementation replacing native"""
load(":common/cc/cc_helper.bzl", "cc_helper")
load(":common/cc/semantics.bzl", "semantics")
CcInfo = _builtins.toplevel.CcInfo
cc_common = _builtins.toplevel.cc_common
cc_internal = _builtins.internal.cc_internal
def _cc_library_impl(ctx):
cc_helper.check_srcs_extensions(ctx, ALLOWED_SRC_FILES, "cc_library", True)
common = cc_internal.create_common(ctx = ctx)
common.report_invalid_options(ctx = ctx)
cc_toolchain = common.toolchain
feature_configuration = cc_common.configure_features(
ctx = ctx,
cc_toolchain = cc_toolchain,
requested_features = ctx.features,
unsupported_features = ctx.disabled_features,
)
precompiled_files = cc_helper.build_precompiled_files(ctx = ctx)
semantics.validate_attributes(ctx = ctx)
_check_no_repeated_srcs(ctx)
semantics.check_can_use_implementation_deps(ctx)
interface_deps = cc_helper.get_compilation_contexts_from_deps(ctx.attr.deps)
implementation_deps = cc_helper.get_compilation_contexts_from_deps(ctx.attr.implementation_deps)
if not _is_stl(ctx.attr.tags) and ctx.attr._stl != None:
interface_deps.append(ctx.attr._stl[CcInfo].compilation_context)
additional_make_variable_substitutions = cc_helper.get_toolchain_global_make_variables(cc_toolchain)
additional_make_variable_substitutions.update(cc_helper.get_cc_flags_make_variable(ctx, common, cc_toolchain))
(compilation_context, srcs_compilation_outputs) = cc_common.compile(
actions = ctx.actions,
name = ctx.label.name,
cc_toolchain = cc_toolchain,
feature_configuration = feature_configuration,
user_compile_flags = cc_helper.get_copts(ctx, common, feature_configuration, additional_make_variable_substitutions),
defines = common.defines,
local_defines = common.local_defines + cc_helper.get_local_defines_for_runfiles_libraries(ctx),
loose_includes = common.loose_include_dirs,
system_includes = common.system_include_dirs,
copts_filter = common.copts_filter,
purpose = "cc_library-compile",
srcs = common.srcs,
private_hdrs = common.private_hdrs,
public_hdrs = common.public_hdrs,
code_coverage_enabled = cc_helper.is_code_coverage_enabled(ctx),
compilation_contexts = interface_deps,
implementation_compilation_contexts = implementation_deps,
hdrs_checking_mode = semantics.determine_headers_checking_mode(ctx),
grep_includes = ctx.executable._grep_includes,
textual_hdrs = ctx.files.textual_hdrs,
include_prefix = ctx.attr.include_prefix,
strip_include_prefix = ctx.attr.strip_include_prefix,
)
precompiled_objects = cc_common.create_compilation_outputs(
# TODO(bazel-team): Perhaps this should be objects, leaving as it is in the original
# Java code for now. Changing it might cause breakages.
objects = depset(precompiled_files[1]),
pic_objects = depset(precompiled_files[1]),
)
compilation_outputs = cc_common.merge_compilation_outputs(
compilation_outputs = [precompiled_objects, srcs_compilation_outputs],
)
supports_dynamic_linker = cc_common.is_enabled(
feature_configuration = feature_configuration,
feature_name = "supports_dynamic_linker",
)
create_dynamic_library = (not ctx.attr.linkstatic and
supports_dynamic_linker and
(not cc_helper.is_compilation_outputs_empty(compilation_outputs) or
cc_common.is_enabled(
feature_configuration = feature_configuration,
feature_name = "header_module_codegen",
)))
output_group_builder = {}
has_compilation_outputs = not cc_helper.is_compilation_outputs_empty(compilation_outputs)
linking_context = CcInfo().linking_context
empty_archive_linking_context = CcInfo().linking_context
is_google = True
linking_contexts = cc_helper.get_linking_contexts_from_deps(ctx.attr.deps)
linking_contexts.extend(cc_helper.get_linking_contexts_from_deps(ctx.attr.implementation_deps))
if ctx.file.linkstamp != None:
linkstamps = []
linkstamps.append(cc_internal.create_linkstamp(
actions = ctx.actions,
linkstamp = ctx.file.linkstamp,
compilation_context = compilation_context,
))
linkstamps_linker_input = cc_common.create_linker_input(
owner = ctx.label,
linkstamps = depset(linkstamps),
)
linkstamps_linking_context = cc_common.create_linking_context(
linker_inputs = depset([linkstamps_linker_input]),
)
linking_contexts.append(linkstamps_linking_context)
if has_compilation_outputs:
dll_name_suffix = ""
win_def_file = None
def_file = None
if cc_common.is_enabled(
feature_configuration = feature_configuration,
feature_name = "targets_windows",
):
dll_name_suffix = cc_helper.dll_hash_suffix(ctx, feature_configuration, ctx.fragments.cpp)
generated_def_file = None
def_parser = ctx.file._def_parser
if def_parser != None:
generated_def_file = cc_helper.generate_def_file(ctx, def_parser, compilation_outputs.objects, ctx.label.name + dll_name_suffix)
output_group_builder["def_file"] = depset([generated_def_file])
win_def_file = cc_helper.get_windows_def_file_for_linking(ctx, ctx.file.win_def_file, generated_def_file, feature_configuration)
(
linking_context,
linking_outputs,
) = cc_common.create_linking_context_from_compilation_outputs(
actions = ctx.actions,
name = ctx.label.name,
compilation_outputs = compilation_outputs,
cc_toolchain = cc_toolchain,
feature_configuration = feature_configuration,
additional_inputs = _filter_linker_scripts(ctx.files.deps),
linking_contexts = linking_contexts,
grep_includes = ctx.executable._grep_includes,
user_link_flags = common.linkopts,
alwayslink = ctx.attr.alwayslink,
disallow_dynamic_library = not create_dynamic_library,
linked_dll_name_suffix = dll_name_suffix,
win_def_file = win_def_file,
)
elif semantics.should_create_empty_archive():
precompiled_files_count = 0
for precompiled_files_entry in precompiled_files:
precompiled_files_count += len(precompiled_files_entry)
(
linking_context,
linking_outputs,
) = cc_common.create_linking_context_from_compilation_outputs(
actions = ctx.actions,
name = ctx.label.name,
cc_toolchain = cc_toolchain,
compilation_outputs = cc_common.create_compilation_outputs(),
feature_configuration = feature_configuration,
grep_includes = ctx.executable._grep_includes,
disallow_dynamic_library = True,
alwayslink = ctx.attr.alwayslink,
)
if precompiled_files_count == 0:
empty_archive_linking_context = linking_context
else:
linking_outputs = struct(library_to_link = None)
_add_linker_artifacts_output_groups(ctx, output_group_builder, linking_outputs)
precompiled_libraries = _convert_precompiled_libraries_to_library_to_link(
ctx,
cc_toolchain,
feature_configuration,
ctx.fragments.cpp.force_pic(),
precompiled_files,
)
if not cc_helper.is_compilation_outputs_empty(compilation_outputs):
_check_if_link_outputs_colliding_with_precompiled_files(
ctx,
linking_outputs,
precompiled_libraries,
)
precompiled_linking_context = cc_helper.build_linking_context_from_libraries(ctx, precompiled_libraries)
contexts_to_merge = [precompiled_linking_context, empty_archive_linking_context]
if has_compilation_outputs:
contexts_to_merge.append(linking_context)
else:
user_link_flags = common.linkopts
linker_scripts = _filter_linker_scripts(ctx.files.deps)
if len(common.linkopts) > 0 or len(linker_scripts) > 0:
linker_input = cc_common.create_linker_input(
owner = ctx.label,
user_link_flags = common.linkopts,
additional_inputs = depset(linker_scripts),
)
contexts_to_merge.append(cc_common.create_linking_context(linker_inputs = depset([linker_input])))
contexts_to_merge.extend(linking_contexts)
linking_context = cc_common.merge_linking_contexts(
linking_contexts = contexts_to_merge,
)
libraries_to_link = _create_libraries_to_link_list(
linking_outputs.library_to_link,
precompiled_libraries,
)
linking_context_for_runfiles = cc_helper.build_linking_context_from_libraries(ctx, libraries_to_link)
cc_native_library_info = cc_helper.collect_native_cc_libraries(
deps = ctx.attr.deps,
libraries = libraries_to_link,
)
files_builder = []
if linking_outputs.library_to_link != None:
artifacts_to_build = linking_outputs.library_to_link
if artifacts_to_build.static_library != None:
files_builder.append(artifacts_to_build.static_library)
if artifacts_to_build.pic_static_library != None:
files_builder.append(artifacts_to_build.pic_static_library)
if not cc_common.is_enabled(
feature_configuration = feature_configuration,
feature_name = "targets_windows",
):
if artifacts_to_build.resolved_symlink_dynamic_library != None:
files_builder.append(artifacts_to_build.resolved_symlink_dynamic_library)
elif artifacts_to_build.dynamic_library != None:
files_builder.append(artifacts_to_build.dynamic_library)
if artifacts_to_build.resolved_symlink_interface_library != None:
files_builder.append(artifacts_to_build.resolved_symlink_interface_library)
elif artifacts_to_build.interface_library != None:
files_builder.append(artifacts_to_build.interface_library)
instrumented_object_files = []
instrumented_object_files.extend(compilation_outputs.objects)
instrumented_object_files.extend(compilation_outputs.pic_objects)
instrumented_files_info = common.instrumented_files_info(
files = instrumented_object_files,
with_base_line_coverage = True,
)
runfiles_list = []
for data_dep in ctx.attr.data:
if data_dep[DefaultInfo].data_runfiles.files:
runfiles_list.append(data_dep[DefaultInfo].data_runfiles)
else:
runfiles_list.append(ctx.runfiles(transitive_files = data_dep[DefaultInfo].files))
for src in ctx.attr.srcs:
runfiles_list.append(src[DefaultInfo].default_runfiles)
for dep in ctx.attr.deps:
runfiles_list.append(dep[DefaultInfo].default_runfiles)
runfiles = ctx.runfiles().merge_all(runfiles_list)
default_runfiles = ctx.runfiles(files = cc_helper.get_dynamic_libraries_for_runtime(linking_context_for_runfiles, True))
default_runfiles = runfiles.merge(default_runfiles)
data_runfiles = ctx.runfiles(files = cc_helper.get_dynamic_libraries_for_runtime(linking_context_for_runfiles, False))
data_runfiles = runfiles.merge(data_runfiles)
current_output_groups = cc_helper.build_output_groups_for_emitting_compile_providers(
compilation_outputs,
compilation_context,
ctx.fragments.cpp,
cc_toolchain,
feature_configuration,
ctx,
generate_hidden_top_level_group = True,
)
providers = []
providers.append(DefaultInfo(
files = depset(files_builder),
default_runfiles = default_runfiles,
data_runfiles = data_runfiles,
))
debug_context = cc_helper.merge_cc_debug_contexts(compilation_outputs, cc_helper.get_providers(ctx.attr.deps, CcInfo))
cc_info = CcInfo(
compilation_context = compilation_context,
linking_context = linking_context,
debug_context = debug_context,
cc_native_library_info = cc_native_library_info,
)
merged_output_groups = cc_helper.merge_output_groups(
[current_output_groups, output_group_builder],
)
providers.append(cc_info)
providers.append(OutputGroupInfo(**merged_output_groups))
providers.append(instrumented_files_info)
if ctx.fragments.cpp.enable_legacy_cc_provider():
return struct(
cc = cc_internal.create_cc_provider(cc_info = cc_info),
providers = providers,
)
else:
return providers
def _add_linker_artifacts_output_groups(ctx, output_group_builder, linking_outputs):
archive_file = []
dynamic_library = []
lib = linking_outputs.library_to_link
if lib == None:
return
if lib.static_library != None:
archive_file.append(lib.static_library)
elif lib.pic_static_library != None:
archive_file.append(lib.pic_static_library)
if lib.resolved_symlink_dynamic_library != None:
dynamic_library.append(lib.resolved_symlink_dynamic_library)
elif lib.dynamic_library != None:
dynamic_library.append(lib.dynamic_library)
if lib.resolved_symlink_interface_library != None:
dynamic_library.append(lib.resolved_symlink_interface_library)
elif lib.interface_library != None:
dynamic_library.append(lib.interface_library)
output_group_builder["archive"] = depset(archive_file)
output_group_builder["dynamic_library"] = depset(dynamic_library)
def _convert_precompiled_libraries_to_library_to_link(
ctx,
cc_toolchain,
feature_configuration,
force_pic,
precompiled_files):
static_libraries = _build_map_identifier_to_artifact(precompiled_files[2])
pic_static_libraries = _build_map_identifier_to_artifact(precompiled_files[3])
alwayslink_static_libraries = _build_map_identifier_to_artifact(precompiled_files[4])
alwayslink_pic_static_libraries = _build_map_identifier_to_artifact(precompiled_files[5])
dynamic_libraries = _build_map_identifier_to_artifact(precompiled_files[6])
libraries = []
identifiers_used = {}
static_libraries_it = []
static_libraries_it.extend(static_libraries.items())
static_libraries_it.extend(alwayslink_static_libraries.items())
for identifier, v in static_libraries_it:
static_library = None
pic_static_library = None
dynamic_library = None
interface_library = None
has_pic = identifier in pic_static_libraries
has_always_pic = identifier in alwayslink_pic_static_libraries
if has_pic or has_always_pic:
if has_pic:
pic_static_library = pic_static_libraries[identifier]
else:
pic_static_library = alwayslink_pic_static_libraries[identifier]
if not force_pic or not (has_pic or has_always_pic):
static_library = v
if identifier in dynamic_libraries:
dynamic_library = dynamic_libraries[identifier]
identifiers_used[identifier] = True
library = cc_common.create_library_to_link(
actions = ctx.actions,
feature_configuration = feature_configuration,
cc_toolchain = cc_toolchain,
static_library = static_library,
pic_static_library = pic_static_library,
dynamic_library = dynamic_library,
alwayslink = identifier in alwayslink_static_libraries,
)
libraries.append(library)
pic_static_libraries_it = []
pic_static_libraries_it.extend(pic_static_libraries.items())
pic_static_libraries_it.extend(alwayslink_pic_static_libraries.items())
for identifier, v in pic_static_libraries_it:
if identifier in identifiers_used:
continue
pic_static_library = v
if identifier in dynamic_libraries:
dynamic_library = dynamic_libraries[identifier]
identifiers_used[identifier] = True
library = cc_common.create_library_to_link(
actions = ctx.actions,
feature_configuration = feature_configuration,
cc_toolchain = cc_toolchain,
pic_static_library = pic_static_library,
alwayslink = identifier in alwayslink_static_libraries,
)
libraries.append(library)
for identifier, v in dynamic_libraries.items():
if identifier in identifiers_used:
continue
dynamic_library = dynamic_libraries[identifier]
library = cc_common.create_library_to_link(
actions = ctx.actions,
feature_configuration = feature_configuration,
cc_toolchain = cc_toolchain,
dynamic_library = dynamic_library,
)
libraries.append(library)
return libraries
def _build_map_identifier_to_artifact(artifacts):
libraries = {}
for artifact in artifacts:
identifier = _identifier_of_artifact(artifact)
if identifier in libraries:
fail(
"Trying to link twice a library with the same identifier '{}',".format(identifier) +
"files: {} and {}".format(
artifact.short_path,
libraries[identifier].short_path,
),
attr = "srcs",
)
libraries[identifier] = artifact
return libraries
def _identifier_of_artifact(artifact):
name = artifact.short_path
for pic_suffix in [".pic.a", ".nopic.a", ".pic.lo"]:
if name.endswith(pic_suffix):
return name[:len(name) - len(pic_suffix)]
return name[:len(name) - len(artifact.extension) - 1]
def _identifier_of_library(library):
if library.static_library != None:
return _identifier_of_artifact(library.static_library)
if library.pic_static_library != None:
return _identifier_of_artifact(library.pic_static_library)
if library.dynamic_library != None:
return _identifier_of_artifact(library.dynamic_library)
if library.interface_library != None:
return _identifier_of_artifact(library.interface_libary)
return None
def _create_libraries_to_link_list(current_library, precompiled_libraries):
libraries = []
libraries.extend(precompiled_libraries)
if current_library != None:
libraries.append(current_library)
return libraries
def _filter_linker_scripts(files):
linker_scripts = []
for file in files:
extension = "." + file.extension
if extension in LINKER_SCRIPT:
linker_scripts.append(file)
return linker_scripts
def _check_if_link_outputs_colliding_with_precompiled_files(ctx, linking_outputs, precompiled_libraries):
identifier = _identifier_of_library(linking_outputs.library_to_link)
for precompiled_library in precompiled_libraries:
precompiled_library_identifier = _identifier_of_library(precompiled_library)
if precompiled_library_identifier == identifier:
fail("Can't put library with identifier '{}' into the srcs of a cc_library with".format(identifier) +
" the same name ({}) which also contains other code or objects to link".format(
ctx.label.name,
))
def _check_no_repeated_srcs(ctx):
seen = {}
for target in ctx.attr.srcs:
if DefaultInfo in target:
for file in target.files.to_list():
extension = "." + file.extension
if extension not in cc_helper.extensions.CC_HEADER:
if extension in cc_helper.extensions.CC_AND_OBJC:
if file.path in seen:
if seen[file.path] != target.label:
fail("Artifact '{}' is duplicated (through ".format(file.path) +
"'{}' and '{}')".format(str(seen[file.path]), str(target.label)))
seen[file.path] = target.label
ALLOWED_SRC_FILES = []
ALLOWED_SRC_FILES.extend(cc_helper.extensions.CC_SOURCE)
ALLOWED_SRC_FILES.extend(cc_helper.extensions.C_SOURCE)
ALLOWED_SRC_FILES.extend(cc_helper.extensions.CC_HEADER)
ALLOWED_SRC_FILES.extend(cc_helper.extensions.ASSESMBLER_WITH_C_PREPROCESSOR)
ALLOWED_SRC_FILES.extend(cc_helper.extensions.ASSEMBLER)
ALLOWED_SRC_FILES.extend(cc_helper.extensions.ARCHIVE)
ALLOWED_SRC_FILES.extend(cc_helper.extensions.PIC_ARCHIVE)
ALLOWED_SRC_FILES.extend(cc_helper.extensions.ALWAYSLINK_LIBRARY)
ALLOWED_SRC_FILES.extend(cc_helper.extensions.ALWAYSLINK_PIC_LIBRARY)
ALLOWED_SRC_FILES.extend(cc_helper.extensions.SHARED_LIBRARY)
SRCS_FOR_COMPILATION = []
SRCS_FOR_COMPILATION.extend(cc_helper.extensions.CC_SOURCE)
SRCS_FOR_COMPILATION.extend(cc_helper.extensions.C_SOURCE)
SRCS_FOR_COMPILATION.extend(cc_helper.extensions.ASSESMBLER_WITH_C_PREPROCESSOR)
SRCS_FOR_COMPILATION.extend(cc_helper.extensions.ASSEMBLER)
ALLOWED_SRC_FILES.extend(cc_helper.extensions.OBJECT_FILE)
ALLOWED_SRC_FILES.extend(cc_helper.extensions.PIC_OBJECT_FILE)
LINKER_SCRIPT = [".ld", ".lds", ".ldscript"]
PREPROCESSED_C = [".i"]
DEPS_ALLOWED_RULES = [
"genrule",
"cc_library",
"cc_inc_library",
"cc_embed_data",
"go_library",
"objc_library",
"cc_import",
"cc_proto_library",
"gentpl",
"gentplvars",
"genantlr",
"sh_library",
"cc_binary",
"cc_test",
]
def _is_stl(tags):
return "__CC_STL__" in tags
attrs = {
"srcs": attr.label_list(
allow_files = True,
flags = ["DIRECT_COMPILE_TIME_INPUT"],
),
"alwayslink": attr.bool(default = False),
"linkstatic": attr.bool(default = False),
"implementation_deps": attr.label_list(providers = [CcInfo], allow_files = False),
"hdrs": attr.label_list(
allow_files = True,
flags = ["ORDER_INDEPENDENT", "DIRECT_COMPILE_TIME_INPUT"],
),
"strip_include_prefix": attr.string(),
"include_prefix": attr.string(),
"textual_hdrs": attr.label_list(
allow_files = True,
flags = ["ORDER_INDEPENDENT", "DIRECT_COMPILE_TIME_INPUT"],
),
"linkstamp": attr.label(allow_single_file = True),
"linkopts": attr.string_list(),
"nocopts": attr.string(),
"includes": attr.string_list(),
"defines": attr.string_list(),
"copts": attr.string_list(),
"_default_copts": attr.string_list(default = cc_internal.default_copts_computed_default()),
"hdrs_check": attr.string(default = cc_internal.default_hdrs_check_computed_default()),
"local_defines": attr.string_list(),
"deps": attr.label_list(
providers = [CcInfo],
flags = ["SKIP_ANALYSIS_TIME_FILETYPE_CHECK"],
allow_files = LINKER_SCRIPT + PREPROCESSED_C,
allow_rules = DEPS_ALLOWED_RULES,
),
"data": attr.label_list(
allow_files = True,
flags = ["SKIP_CONSTRAINTS_OVERRIDE"],
),
"win_def_file": attr.label(allow_single_file = [".def"]),
"licenses": attr.license() if hasattr(attr, "license") else attr.string_list(),
"_stl": semantics.get_stl(),
"_grep_includes": attr.label(
allow_files = True,
executable = True,
cfg = "exec",
default = Label("@" + semantics.get_repo() + "//tools/cpp:grep-includes"),
),
"_def_parser": semantics.get_def_parser(),
"_cc_toolchain": attr.label(default = "@" + semantics.get_repo() + "//tools/cpp:current_cc_toolchain"),
}
attrs.update(semantics.get_distribs_attr())
attrs.update(semantics.get_loose_mode_in_hdrs_check_allowed_attr())
attrs.update(semantics.get_implementation_deps_allowed_attr())
cc_library = rule(
implementation = _cc_library_impl,
attrs = attrs,
toolchains = cc_helper.use_cpp_toolchain(),
fragments = ["cpp"] + semantics.additional_fragments(),
incompatible_use_toolchain_transition = True,
provides = [CcInfo],
exec_groups = {
"cpp_link": exec_group(copy_from_rule = True),
},
compile_one_filetype = [".cc", ".h", ".c"],
)