-
Notifications
You must be signed in to change notification settings - Fork 262
/
rules_impl.bzl
662 lines (623 loc) · 30.7 KB
/
rules_impl.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
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
# Copyright (c) Meta Platforms, Inc. and affiliates.
#
# This source code is licensed under both the MIT license found in the
# LICENSE-MIT file in the root directory of this source tree and the Apache
# License, Version 2.0 found in the LICENSE-APACHE file in the root directory
# of this source tree.
load("@prelude//android:android.bzl", _android_extra_attributes = "extra_attributes", _android_implemented_rules = "implemented_rules")
load("@prelude//android:configuration.bzl", "is_building_android_binary_attr")
load("@prelude//apple:apple_rules_impl.bzl", _apple_extra_attributes = "extra_attributes", _apple_implemented_rules = "implemented_rules")
load("@prelude//configurations:rules.bzl", _config_extra_attributes = "extra_attributes", _config_implemented_rules = "implemented_rules")
load("@prelude//csharp:csharp.bzl", "csharp_library_impl", "prebuilt_dotnet_library_impl")
load("@prelude//cxx:bitcode.bzl", "llvm_link_bitcode_impl")
load("@prelude//cxx:cxx.bzl", "cxx_binary_impl", "cxx_library_impl", "cxx_precompiled_header_impl", "cxx_test_impl", "prebuilt_cxx_library_impl")
load("@prelude//cxx:cxx_toolchain.bzl", "cxx_toolchain_extra_attributes", "cxx_toolchain_impl")
load("@prelude//cxx:cxx_toolchain_types.bzl", "CxxPlatformInfo", "CxxToolchainInfo")
load("@prelude//cxx:headers.bzl", "CPrecompiledHeaderInfo", "HeaderMode")
load("@prelude//cxx:link_groups_types.bzl", "LINK_GROUP_MAP_ATTR")
load("@prelude//cxx:prebuilt_cxx_library_group.bzl", "prebuilt_cxx_library_group_impl")
load("@prelude//cxx:windows_resource.bzl", "windows_resource_impl")
load("@prelude//erlang:erlang.bzl", _erlang_implemented_rules = "implemented_rules")
load("@prelude//git:git_fetch.bzl", "git_fetch_impl")
load("@prelude//go:cgo_library.bzl", "cgo_library_impl")
load("@prelude//go:coverage.bzl", "GoCoverageMode")
load("@prelude//go:go_binary.bzl", "go_binary_impl")
load("@prelude//go:go_exported_library.bzl", "go_exported_library_impl")
load("@prelude//go:go_library.bzl", "go_library_impl")
load("@prelude//go:go_stdlib.bzl", "go_stdlib_impl")
load("@prelude//go:go_test.bzl", "go_test_impl")
load("@prelude//go/transitions:defs.bzl", "asan_attr", "cgo_enabled_attr", "compile_shared_attr", "coverage_mode_attr", "go_binary_transition", "go_exported_library_transition", "go_test_transition", "race_attr", "tags_attr")
load("@prelude//haskell:haskell.bzl", "haskell_binary_impl", "haskell_library_impl", "haskell_prebuilt_library_impl")
load("@prelude//haskell:haskell_ghci.bzl", "haskell_ghci_impl")
load("@prelude//haskell:haskell_haddock.bzl", "haskell_haddock_impl")
load("@prelude//haskell:haskell_ide.bzl", "haskell_ide_impl")
load("@prelude//haskell:library_info.bzl", "HaskellLibraryProvider")
load("@prelude//http_archive:http_archive.bzl", "http_archive_impl")
load("@prelude//java:java.bzl", _java_extra_attributes = "extra_attributes", _java_implemented_rules = "implemented_rules")
load("@prelude//js:js.bzl", _js_extra_attributes = "extra_attributes", _js_implemented_rules = "implemented_rules")
load("@prelude//julia:julia.bzl", _julia_extra_attributes = "extra_attributes", _julia_implemented_rules = "implemented_rules")
load("@prelude//kotlin:kotlin.bzl", _kotlin_extra_attributes = "extra_attributes", _kotlin_implemented_rules = "implemented_rules")
load("@prelude//linking:execution_preference.bzl", "link_execution_preference_attr")
load("@prelude//linking:link_info.bzl", "LinkOrdering")
load("@prelude//linking:types.bzl", "Linkage")
load("@prelude//lua:cxx_lua_extension.bzl", "cxx_lua_extension_impl")
load("@prelude//lua:lua_binary.bzl", "lua_binary_impl")
load("@prelude//lua:lua_library.bzl", "lua_library_impl")
load("@prelude//matlab:matlab.bzl", _matlab_extra_attributes = "extra_attributes", _matlab_implemented_rules = "implemented_rules")
load("@prelude//ocaml:attrs.bzl", _ocaml_extra_attributes = "ocaml_extra_attributes")
load("@prelude//ocaml:ocaml.bzl", "ocaml_binary_impl", "ocaml_library_impl", "ocaml_object_impl", "ocaml_shared_impl", "prebuilt_ocaml_library_impl")
load("@prelude//python:cxx_python_extension.bzl", "cxx_python_extension_impl")
load("@prelude//python:prebuilt_python_library.bzl", "prebuilt_python_library_impl")
load("@prelude//python:python_binary.bzl", "python_binary_impl")
load("@prelude//python:python_library.bzl", "python_library_impl")
load("@prelude//python:python_needed_coverage_test.bzl", "python_needed_coverage_test_impl")
load("@prelude//python:python_test.bzl", "python_test_impl")
load("@prelude//python_bootstrap:python_bootstrap.bzl", "PythonBootstrapSources", "python_bootstrap_binary_impl", "python_bootstrap_library_impl")
load("@prelude//zip_file:zip_file.bzl", _zip_file_extra_attributes = "extra_attributes", _zip_file_implemented_rules = "implemented_rules")
load("@prelude//apple/user/apple_resource_transition.bzl", "apple_resource_transition")
load("@prelude//decls/android_rules.bzl", "android_rules")
load("@prelude//decls/common.bzl", "IncludeType", "LinkableDepType", "buck")
load("@prelude//decls/core_rules.bzl", "core_rules")
load("@prelude//decls/cxx_rules.bzl", "cxx_rules")
load("@prelude//decls/d_rules.bzl", "d_rules")
load("@prelude//decls/dotnet_rules.bzl", "dotnet_rules")
load("@prelude//decls/erlang_rules.bzl", "erlang_rules")
load("@prelude//decls/git_rules.bzl", "git_rules")
load("@prelude//decls/go_rules.bzl", "go_rules")
load("@prelude//decls/groovy_rules.bzl", "groovy_rules")
load("@prelude//decls/halide_rules.bzl", "halide_rules")
load("@prelude//decls/haskell_rules.bzl", "haskell_rules")
load("@prelude//decls/ios_rules.bzl", "ios_rules")
load("@prelude//decls/java_rules.bzl", "java_rules")
load("@prelude//decls/js_rules.bzl", "js_rules")
load("@prelude//decls/kotlin_rules.bzl", "kotlin_rules")
load("@prelude//decls/lua_rules.bzl", "lua_rules")
load("@prelude//decls/ocaml_rules.bzl", "ocaml_rules")
load("@prelude//decls/python_rules.bzl", "python_rules")
load("@prelude//decls/re_test_common.bzl", "re_test_common")
load("@prelude//decls/rust_rules.bzl", "rust_rules")
load("@prelude//decls/scala_rules.bzl", "scala_rules")
load("@prelude//decls/shell_rules.bzl", "shell_rules")
load("@prelude//decls/toolchains_common.bzl", "toolchains_common")
load("@prelude//decls/uncategorized_rules.bzl", "uncategorized_rules")
load("@prelude//transitions/constraint_overrides.bzl", "constraint_overrides_transition")
load(":alias.bzl", "alias_impl", "configured_alias_impl", "toolchain_alias_impl", "versioned_alias_impl")
load(":command_alias.bzl", "command_alias_impl")
load(":export_file.bzl", "export_file_impl")
load(":filegroup.bzl", "filegroup_impl")
load(":genrule.bzl", "genrule_attributes", "genrule_impl")
load(":http_file.bzl", "http_file_impl")
load(":remote_file.bzl", "remote_file_impl")
load(":sh_binary.bzl", "sh_binary_impl")
load(":sh_test.bzl", "sh_test_impl")
load(":test_suite.bzl", "test_suite_impl")
load(":worker_tool.bzl", "worker_tool")
rule_decl_records = [
android_rules,
core_rules,
cxx_rules,
d_rules,
dotnet_rules,
erlang_rules,
git_rules,
go_rules,
groovy_rules,
halide_rules,
haskell_rules,
ios_rules,
java_rules,
kotlin_rules,
lua_rules,
ocaml_rules,
python_rules,
rust_rules,
shell_rules,
js_rules,
scala_rules,
uncategorized_rules,
]
def _merge_dictionaries(dicts):
result = {}
for d in dicts:
for key, value in d.items():
if key in result:
fail("Duplicate key: '{}' while merging dictionaries".format(key))
result[key] = value
return result
extra_implemented_rules = struct(
#common rules
alias = alias_impl,
command_alias = command_alias_impl,
configured_alias = configured_alias_impl,
export_file = export_file_impl,
filegroup = filegroup_impl,
genrule = genrule_impl,
http_archive = http_archive_impl,
http_file = http_file_impl,
remote_file = remote_file_impl,
sh_binary = sh_binary_impl,
sh_test = sh_test_impl,
test_suite = test_suite_impl,
toolchain_alias = toolchain_alias_impl,
versioned_alias = versioned_alias_impl,
worker_tool = worker_tool,
#c#
csharp_library = csharp_library_impl,
prebuilt_dotnet_library = prebuilt_dotnet_library_impl,
#c++
cxx_binary = cxx_binary_impl,
cxx_test = cxx_test_impl,
cxx_toolchain = cxx_toolchain_impl,
cxx_genrule = genrule_impl,
cxx_library = cxx_library_impl,
cxx_precompiled_header = cxx_precompiled_header_impl,
cxx_python_extension = cxx_python_extension_impl,
prebuilt_cxx_library = prebuilt_cxx_library_impl,
prebuilt_cxx_library_group = prebuilt_cxx_library_group_impl,
windows_resource = windows_resource_impl,
# C++ / LLVM
llvm_link_bitcode = llvm_link_bitcode_impl,
#git
git_fetch = git_fetch_impl,
#go
cgo_library = cgo_library_impl,
go_binary = go_binary_impl,
go_exported_library = go_exported_library_impl,
go_library = go_library_impl,
go_test = go_test_impl,
go_stdlib = go_stdlib_impl,
#haskell
haskell_library = haskell_library_impl,
haskell_binary = haskell_binary_impl,
haskell_ghci = haskell_ghci_impl,
haskell_haddock = haskell_haddock_impl,
haskell_ide = haskell_ide_impl,
haskell_prebuilt_library = haskell_prebuilt_library_impl,
#lua
cxx_lua_extension = cxx_lua_extension_impl,
lua_binary = lua_binary_impl,
lua_library = lua_library_impl,
#ocaml
ocaml_binary = ocaml_binary_impl,
ocaml_object = ocaml_object_impl,
ocaml_shared = ocaml_shared_impl,
ocaml_library = ocaml_library_impl,
prebuilt_ocaml_library = prebuilt_ocaml_library_impl,
#python
prebuilt_python_library = prebuilt_python_library_impl,
python_binary = python_binary_impl,
python_library = python_library_impl,
python_test = python_test_impl,
python_needed_coverage_test = python_needed_coverage_test_impl,
#python bootstrap
python_bootstrap_binary = python_bootstrap_binary_impl,
python_bootstrap_library = python_bootstrap_library_impl,
#merged **kwargs
**_merge_dictionaries([
_android_implemented_rules,
_apple_implemented_rules,
_config_implemented_rules,
_erlang_implemented_rules,
_java_implemented_rules,
_js_implemented_rules,
_julia_implemented_rules,
_kotlin_implemented_rules,
_matlab_implemented_rules,
_zip_file_implemented_rules,
])
)
def _cxx_python_extension_attrs():
# cxx_python_extension is a subset of cxx_library, plus a base_module.
# So we can reuse cxx_library, we augment it with the additional attributes it defines.
# This isn't the ideal way to reuse it (we'd rather cxx_library was split it multiple reusable parts),
# but it's the pragmatic way of getting it working for now.
library = cxx_rules.cxx_library.attrs
me = python_rules.cxx_python_extension.attrs
res = {k: attrs.default_only(library[k]) for k in library if k not in me}
res.update({
"allow_embedding": attrs.bool(default = True),
"allow_suffixing": attrs.bool(default = True),
# Copied from cxx_library.
"auto_link_groups": attrs.bool(default = False),
"link_ordering": attrs.option(attrs.enum(LinkOrdering.values()), default = None),
"link_whole": attrs.default_only(attrs.bool(default = True)),
"precompiled_header": attrs.option(attrs.dep(providers = [CPrecompiledHeaderInfo]), default = None),
"preferred_linkage": attrs.default_only(attrs.string(default = "any")),
"suffix_all": attrs.bool(default = True),
"support_shlib_interfaces": attrs.bool(default = True),
"_cxx_hacks": attrs.default_only(attrs.dep(default = "prelude//cxx/tools:cxx_hacks")),
"_cxx_toolchain": toolchains_common.cxx(),
# Copied from python_library.
"_python_toolchain": toolchains_common.python(),
"_target_os_type": buck.target_os_type_arg(),
})
return res
# Attrs common between python binary/test
def _python_executable_attrs():
cxx_binary_attrs = {k: v for k, v in cxx_rules.cxx_binary.attrs.items()}
cxx_binary_attrs.update(_cxx_binary_and_test_attrs())
python_executable_attrs = {}
python_executable_attrs["srcs"] = None
python_executable_attrs.update(python_rules.python_binary.attrs)
updated_attrs = {
key: attrs.default_only(cxx_binary_attrs[key])
for key in cxx_binary_attrs
if key not in python_executable_attrs
}
# allow non-default value for the args below
updated_attrs.update({
"anonymous_link_groups": attrs.bool(default = False),
"binary_linker_flags": attrs.list(attrs.arg(anon_target_compatible = True), default = []),
"bolt_flags": attrs.list(attrs.arg(), default = []),
"bolt_profile": attrs.option(attrs.source(), default = None),
"compiler_flags": attrs.list(attrs.arg(), default = []),
"constraint_overrides": attrs.list(attrs.string(), default = []),
"cxx_main": attrs.source(default = "prelude//python/tools:embedded_main.cpp"),
"distributed_thinlto_partial_split_dwarf": attrs.bool(default = False),
"enable_distributed_thinlto": attrs.bool(default = False),
"executable_deps": attrs.list(attrs.dep(), default = []),
"executable_name": attrs.option(attrs.string(), default = None),
"inplace_build_args": attrs.list(attrs.arg(), default = []),
"link_group": attrs.option(attrs.string(), default = None),
"link_group_map": LINK_GROUP_MAP_ATTR,
"link_group_min_binary_node_count": attrs.option(attrs.int(), default = None),
"link_style": attrs.enum(LinkableDepType, default = "static"),
"main_function": attrs.option(
attrs.string(),
default = None,
doc = """
Name of a Python function that will serve as the main entry point of
the binary. The name is either a fully qualified name like
`foo.bar.baz` or it starts with a `.` like `.bar.baz`, in which case
it is relative to the package containing the target. This should
usually be a function defined within one of the dependencies of this
target. This attribute should be preferred over `main_module` or
`main`, and it is an error to specify more than one of these.
""",
),
"make_py_package": attrs.option(attrs.exec_dep(providers = [RunInfo]), default = None),
"manifest_module_entries": attrs.option(
attrs.dict(
key = attrs.string(),
value = attrs.one_of(
attrs.dict(key = attrs.string(), value = attrs.option(attrs.any())),
attrs.list(attrs.string()),
),
),
default = None,
doc = """If present, it should be a `string` -> `entry` mapping that
gets generated into a `__manifest__` module in the executable. Top
level string keys will be the names of variables in this module (so
they must be valid Python identifiers). An `entry` can be a list of
`string`s, or a further `string`-keyed dictionary.""",
),
"native_link_strategy": attrs.option(attrs.enum(NativeLinkStrategy), default = None),
"package_split_dwarf_dwp": attrs.bool(default = False),
"par_style": attrs.option(attrs.string(), default = None),
"resources": attrs.named_set(attrs.one_of(attrs.dep(), attrs.source(allow_directory = True)), sorted = True, default = []),
"run_with_inplace": attrs.bool(default = False),
"runtime_env": attrs.option(attrs.dict(key = attrs.string(), value = attrs.string()), default = None),
"standalone_build_args": attrs.list(attrs.arg(), default = []),
"static_extension_finder": attrs.source(default = "prelude//python/tools:static_extension_finder.py"),
"static_extension_utils": attrs.source(default = "prelude//python/tools:static_extension_utils.cpp"),
"strip_libpar": attrs.enum(StripLibparStrategy, default = "none"),
"strip_stapsdt": attrs.bool(default = False),
"_create_manifest_for_source_dir": _create_manifest_for_source_dir(),
"_cxx_hacks": attrs.default_only(attrs.dep(default = "prelude//cxx/tools:cxx_hacks")),
"_cxx_toolchain": toolchains_common.cxx(),
"_exec_os_type": buck.exec_os_type_arg(),
"_python_toolchain": toolchains_common.python(),
"_target_os_type": buck.target_os_type_arg(),
})
return updated_attrs
def _python_test_attrs():
test_attrs = _python_executable_attrs()
test_attrs["_test_main"] = attrs.source(default = "prelude//python/tools:__test_main__.py")
test_attrs.update(re_test_common.test_args())
return test_attrs
def _cxx_binary_and_test_attrs():
return {
"anonymous_link_groups": attrs.bool(default = False),
"auto_link_groups": attrs.bool(default = False),
# Linker flags that only apply to the executable link, used for link
# strategies (e.g. link groups) which may link shared libraries from
# top-level binary context.
"binary_linker_flags": attrs.list(attrs.arg(anon_target_compatible = True), default = []),
"bolt_flags": attrs.list(attrs.arg(), default = []),
"bolt_profile": attrs.option(attrs.source(), default = None),
"constraint_overrides": attrs.list(attrs.string(), default = []),
"distributed_thinlto_partial_split_dwarf": attrs.bool(default = False),
"enable_distributed_thinlto": attrs.bool(default = False),
"link_execution_preference": link_execution_preference_attr(),
"link_group_map": LINK_GROUP_MAP_ATTR,
"link_group_min_binary_node_count": attrs.option(attrs.int(), default = None),
"link_ordering": attrs.option(attrs.enum(LinkOrdering.values()), default = None),
"link_whole": attrs.default_only(attrs.bool(default = False)),
"precompiled_header": attrs.option(attrs.dep(providers = [CPrecompiledHeaderInfo]), default = None),
"resources": attrs.named_set(attrs.one_of(attrs.dep(), attrs.source(allow_directory = True)), sorted = True, default = []),
"_cxx_hacks": attrs.dep(default = "prelude//cxx/tools:cxx_hacks"),
"_cxx_toolchain": toolchains_common.cxx(),
}
NativeLinkStrategy = ["separate", "native", "merged"]
StripLibparStrategy = ["full", "extract", "none"]
def _package_python_binary_remotely():
return select({
"DEFAULT": False,
"config//os/constraints:android": True,
})
def _python_binary_attrs():
binary_attrs = _python_executable_attrs()
binary_attrs.update({
"link_style": attrs.enum(LinkableDepType, default = "static"),
"_package_remotely": attrs.bool(default = _package_python_binary_remotely()),
"_python_toolchain": toolchains_common.python(),
})
return binary_attrs
def _create_manifest_for_source_dir():
return attrs.exec_dep(default = "prelude//python/tools:create_manifest_for_source_dir")
inlined_extra_attributes = {
# go
"cgo_library": {
"embedcfg": attrs.option(attrs.source(allow_directory = False), default = None),
"_asan": asan_attr,
"_compile_shared": compile_shared_attr,
"_coverage_mode": coverage_mode_attr,
"_cxx_toolchain": toolchains_common.cxx(),
"_exec_os_type": buck.exec_os_type_arg(),
"_go_stdlib": attrs.default_only(attrs.dep(default = "prelude//go/tools:stdlib")),
"_go_toolchain": toolchains_common.go(),
"_race": race_attr,
"_tags": tags_attr,
},
# csharp
"csharp_library": {
"_csharp_toolchain": toolchains_common.csharp(),
},
"cxx_binary": _cxx_binary_and_test_attrs(),
#c++
"cxx_genrule": genrule_attributes() | {
"_cxx_toolchain": toolchains_common.cxx(),
"_exec_os_type": buck.exec_os_type_arg(),
},
"cxx_library": {
"auto_link_groups": attrs.bool(default = False),
"deps_query": attrs.option(attrs.query(), default = None),
"extra_xcode_sources": attrs.list(attrs.source(allow_directory = True), default = []),
"header_mode": attrs.option(attrs.enum(HeaderMode.values()), default = None),
"link_deps_query_whole": attrs.bool(default = False),
"link_execution_preference": link_execution_preference_attr(),
"link_group_map": LINK_GROUP_MAP_ATTR,
"link_ordering": attrs.option(attrs.enum(LinkOrdering.values()), default = None),
"precompiled_header": attrs.option(attrs.dep(providers = [CPrecompiledHeaderInfo]), default = None),
"prefer_stripped_objects": attrs.bool(default = False),
"preferred_linkage": attrs.enum(Linkage.values(), default = "any"),
"resources": attrs.named_set(attrs.one_of(attrs.dep(), attrs.source(allow_directory = True)), sorted = True, default = []),
"supports_header_symlink_subtarget": attrs.bool(default = False),
"supports_python_dlopen": attrs.option(attrs.bool(), default = None),
"supports_shlib_interfaces": attrs.bool(default = True),
"_cxx_hacks": attrs.default_only(attrs.dep(default = "prelude//cxx/tools:cxx_hacks")),
"_cxx_toolchain": toolchains_common.cxx(),
"_is_building_android_binary": is_building_android_binary_attr(),
},
"cxx_python_extension": _cxx_python_extension_attrs(),
"cxx_test": re_test_common.test_args() | _cxx_binary_and_test_attrs(),
"cxx_toolchain": cxx_toolchain_extra_attributes(is_toolchain_rule = False),
# Generic rule to build from a command
"genrule": genrule_attributes(),
# Go
"go_binary": {
"embedcfg": attrs.option(attrs.source(allow_directory = False), default = None),
"resources": attrs.list(attrs.one_of(attrs.dep(), attrs.source(allow_directory = True)), default = []),
"_asan": asan_attr,
"_exec_os_type": buck.exec_os_type_arg(),
"_go_stdlib": attrs.default_only(attrs.dep(default = "prelude//go/tools:stdlib")),
"_go_toolchain": toolchains_common.go(),
"_race": race_attr,
"_tags": tags_attr,
},
"go_exported_library": {
"embedcfg": attrs.option(attrs.source(allow_directory = False), default = None),
"_asan": asan_attr,
"_exec_os_type": buck.exec_os_type_arg(),
"_go_stdlib": attrs.default_only(attrs.dep(default = "prelude//go/tools:stdlib")),
"_go_toolchain": toolchains_common.go(),
"_race": race_attr,
"_tags": tags_attr,
},
"go_library": {
"embedcfg": attrs.option(attrs.source(allow_directory = False), default = None),
"_asan": asan_attr,
"_cgo_enabled": cgo_enabled_attr,
"_compile_shared": compile_shared_attr,
"_coverage_mode": coverage_mode_attr,
"_go_stdlib": attrs.default_only(attrs.dep(default = "prelude//go/tools:stdlib")),
"_go_toolchain": toolchains_common.go(),
"_race": race_attr,
"_tags": tags_attr,
},
"go_stdlib": {
"_asan": asan_attr,
"_cgo_enabled": cgo_enabled_attr,
"_compile_shared": compile_shared_attr,
"_exec_os_type": buck.exec_os_type_arg(),
"_go_toolchain": toolchains_common.go(),
"_race": race_attr,
"_tags": tags_attr,
},
"go_test": {
"coverage_mode": attrs.option(attrs.enum(GoCoverageMode.values()), default = None),
"embedcfg": attrs.option(attrs.source(allow_directory = False), default = None),
"resources": attrs.list(attrs.source(allow_directory = True), default = []),
"_asan": asan_attr,
"_coverage_mode": coverage_mode_attr,
"_exec_os_type": buck.exec_os_type_arg(),
"_go_stdlib": attrs.default_only(attrs.dep(default = "prelude//go/tools:stdlib")),
"_go_toolchain": toolchains_common.go(),
"_race": race_attr,
"_tags": tags_attr,
"_testmaingen": attrs.default_only(attrs.exec_dep(default = "prelude//go/tools:testmaingen")),
},
# groovy
"groovy_library": {
"resources_root": attrs.option(attrs.string(), default = None),
},
"groovy_test": {
"resources_root": attrs.option(attrs.string(), default = None),
},
"haskell_binary": {
"auto_link_groups": attrs.bool(default = False),
"link_group_map": LINK_GROUP_MAP_ATTR,
"template_deps": attrs.list(attrs.exec_dep(providers = [HaskellLibraryProvider]), default = []),
"_cxx_toolchain": toolchains_common.cxx(),
"_haskell_toolchain": toolchains_common.haskell(),
},
"haskell_ghci": {
"template_deps": attrs.list(attrs.exec_dep(providers = [HaskellLibraryProvider]), default = []),
"_cxx_toolchain": toolchains_common.cxx(),
"_haskell_toolchain": toolchains_common.haskell(),
},
"haskell_haddock": {
"_cxx_toolchain": toolchains_common.cxx(),
"_haskell_toolchain": toolchains_common.haskell(),
},
"haskell_ide": {
"include_projects": attrs.list(attrs.dep(), default = []),
"_haskell_toolchain": toolchains_common.haskell(),
},
"haskell_library": {
"preferred_linkage": attrs.enum(Linkage.values(), default = "any"),
"template_deps": attrs.list(attrs.exec_dep(providers = [HaskellLibraryProvider]), default = []),
"_cxx_toolchain": toolchains_common.cxx(),
"_haskell_toolchain": toolchains_common.haskell(),
},
"llvm_link_bitcode": {
"_cxx_toolchain": toolchains_common.cxx(),
},
"ndk_toolchain": {
"cxx_toolchain": attrs.toolchain_dep(providers = [CxxToolchainInfo, CxxPlatformInfo]),
},
"prebuilt_cxx_library": {
"exported_header_style": attrs.enum(IncludeType, default = "system"),
"header_dirs": attrs.option(attrs.list(attrs.source(allow_directory = True)), default = None),
"linker_flags": attrs.list(attrs.arg(anon_target_compatible = True), default = []),
"platform_header_dirs": attrs.option(attrs.list(attrs.tuple(attrs.regex(), attrs.list(attrs.source(allow_directory = True)))), default = None),
"post_linker_flags": attrs.list(attrs.arg(anon_target_compatible = True), default = []),
"preferred_linkage": attrs.enum(Linkage.values(), default = "any"),
"public_include_directories": attrs.set(attrs.string(), sorted = True, default = []),
"public_system_include_directories": attrs.set(attrs.string(), sorted = True, default = []),
"raw_headers": attrs.set(attrs.source(), sorted = True, default = []),
"supports_python_dlopen": attrs.bool(default = True),
"versioned_header_dirs": attrs.option(attrs.versioned(attrs.list(attrs.source(allow_directory = True))), default = None),
"_cxx_toolchain": toolchains_common.cxx(),
"_target_os_type": buck.target_os_type_arg(),
},
"prebuilt_cxx_library_group": {
"_cxx_toolchain": toolchains_common.cxx(),
},
#python
"prebuilt_python_library": {
"_create_manifest_for_source_dir": _create_manifest_for_source_dir(),
"_extract": attrs.default_only(attrs.exec_dep(default = "prelude//python/tools:extract")),
"_python_toolchain": toolchains_common.python(),
},
"python_binary": _python_binary_attrs(),
#python bootstrap
"python_bootstrap_binary": {
"deps": attrs.list(attrs.dep(providers = [PythonBootstrapSources]), default = []),
"main": attrs.source(),
"_exec_os_type": buck.exec_os_type_arg(),
"_python_bootstrap_toolchain": toolchains_common.python_bootstrap(),
"_win_python_wrapper": attrs.default_only(
attrs.option(
attrs.dep(),
default = select({
"DEFAULT": None,
"config//os:windows": "prelude//python_bootstrap/tools:win_python_wrapper",
}),
),
),
},
"python_bootstrap_library": {
"deps": attrs.list(attrs.dep(providers = [PythonBootstrapSources]), default = []),
"srcs": attrs.list(attrs.source()),
},
"python_library": {
"resources": attrs.named_set(attrs.one_of(attrs.dep(), attrs.source(allow_directory = True)), sorted = True, default = []),
"_create_manifest_for_source_dir": _create_manifest_for_source_dir(),
"_cxx_toolchain": toolchains_common.cxx(),
"_python_toolchain": toolchains_common.python(),
},
"python_needed_coverage_test": dict(
contacts = attrs.list(attrs.string(), default = []),
env = attrs.dict(key = attrs.string(), value = attrs.arg(), sorted = False, default = {}),
labels = attrs.list(attrs.string(), default = []),
needed_coverage = attrs.list(attrs.tuple(attrs.int(), attrs.dep(), attrs.option(attrs.string())), default = []),
test = attrs.dep(providers = [ExternalRunnerTestInfo]),
**re_test_common.test_args()
),
"python_test": _python_test_attrs(),
"remote_file": {
"sha1": attrs.option(attrs.string(), default = None),
"sha256": attrs.option(attrs.string(), default = None),
"_unzip_tool": attrs.default_only(attrs.exec_dep(providers = [RunInfo], default = "prelude//zip_file/tools:unzip")),
},
"rust_test": {},
"sh_test": {},
"windows_resource": {
"_cxx_toolchain": toolchains_common.cxx(),
},
}
all_extra_attributes = _merge_dictionaries([
inlined_extra_attributes,
_android_extra_attributes,
_apple_extra_attributes,
_config_extra_attributes,
_java_extra_attributes,
_js_extra_attributes,
_julia_extra_attributes,
_kotlin_extra_attributes,
_matlab_extra_attributes,
_ocaml_extra_attributes,
_zip_file_extra_attributes,
])
# Inject test toolchain in all tests.
for rule in [
"sh_test",
"rust_test",
"python_test",
"python_needed_coverage_test",
"java_test",
"go_test",
"cxx_test",
"apple_test",
"android_instrumentation_test",
"kotlin_test",
"robolectric_test",
"julia_test",
]:
# NOTE: We make this a `dep` not an `exec_dep` even though we'll execute
# it, because it needs to execute in the same platform as the test itself
# (we run tests in the target platform not the exec platform, since the
# goal is to test the code that is being built!).
all_extra_attributes[rule] = _merge_dictionaries([all_extra_attributes[rule], {
"_inject_test_env": attrs.default_only(attrs.dep(default = "prelude//test/tools:inject_test_env")),
}])
extra_attributes = struct(**all_extra_attributes)
# Configuration transitions to pass `cfg` for builtin rules.
transitions = {
"android_binary": constraint_overrides_transition,
"apple_asset_catalog": apple_resource_transition,
"apple_resource": apple_resource_transition,
"cxx_binary": constraint_overrides_transition,
"cxx_test": constraint_overrides_transition,
"go_binary": go_binary_transition,
"go_exported_library": go_exported_library_transition,
"go_test": go_test_transition,
"python_binary": constraint_overrides_transition,
"python_test": constraint_overrides_transition,
}
toolchain_rule_names = [
"apple_toolchain",
"swift_toolchain",
"toolchain_alias",
]