22
22
"AllocatorLibrariesImplInfo" ,
23
23
"AllocatorLibrariesInfo" ,
24
24
"BuildInfo" ,
25
+ "CrateInfo" ,
26
+ "CrateGroupInfo" ,
27
+ "DepInfo" ,
25
28
"LintsInfo" ,
26
29
)
27
30
load ("//rust/private:rustc.bzl" , "rustc_compile_action" )
35
38
"determine_lib_name" ,
36
39
"determine_output_hash" ,
37
40
"expand_dict_value_locations" ,
41
+ "filter_deps" ,
38
42
"find_toolchain" ,
39
43
"generate_output_diagnostics" ,
40
44
"get_edition" ,
@@ -53,32 +57,6 @@ def _assert_no_deprecated_attributes(_ctx):
53
57
"""
54
58
pass
55
59
56
- def _assert_correct_dep_mapping (ctx ):
57
- """Forces a failure if proc_macro_deps and deps are mixed inappropriately
58
-
59
- Args:
60
- ctx (ctx): The current rule's context object
61
- """
62
- for dep in ctx .attr .deps :
63
- if rust_common .crate_info in dep :
64
- if dep [rust_common .crate_info ].type == "proc-macro" :
65
- fail (
66
- "{} listed {} in its deps, but it is a proc-macro. It should instead be in the bazel property proc_macro_deps." .format (
67
- ctx .label ,
68
- dep .label ,
69
- ),
70
- )
71
- for dep in ctx .attr .proc_macro_deps :
72
- type = dep [rust_common .crate_info ].type
73
- if type != "proc-macro" :
74
- fail (
75
- "{} listed {} in its proc_macro_deps, but it is not proc-macro, it is a {}. It should probably instead be listed in deps." .format (
76
- ctx .label ,
77
- dep .label ,
78
- type ,
79
- ),
80
- )
81
-
82
60
def _rust_library_impl (ctx ):
83
61
"""The implementation of the `rust_library` rule.
84
62
@@ -148,7 +126,7 @@ def _rust_library_common(ctx, crate_type):
148
126
list: A list of providers. See `rustc_compile_action`
149
127
"""
150
128
_assert_no_deprecated_attributes (ctx )
151
- _assert_correct_dep_mapping (ctx )
129
+ deps , proc_macro_deps = filter_deps (ctx )
152
130
153
131
toolchain = find_toolchain (ctx )
154
132
@@ -195,8 +173,8 @@ def _rust_library_common(ctx, crate_type):
195
173
not ctx .attr .disable_pipelining
196
174
)
197
175
198
- deps = transform_deps (ctx . attr . deps )
199
- proc_macro_deps = transform_deps (ctx . attr . proc_macro_deps + get_import_macro_deps (ctx ))
176
+ deps = transform_deps (deps )
177
+ proc_macro_deps = transform_deps (proc_macro_deps + get_import_macro_deps (ctx ))
200
178
201
179
return rustc_compile_action (
202
180
ctx = ctx ,
@@ -238,16 +216,16 @@ def _rust_binary_impl(ctx):
238
216
"""
239
217
toolchain = find_toolchain (ctx )
240
218
crate_name = compute_crate_name (ctx .workspace_name , ctx .label , toolchain , ctx .attr .crate_name )
241
- _assert_correct_dep_mapping (ctx )
219
+ deps , proc_macro_deps = filter_deps (ctx )
242
220
243
221
if ctx .attr .binary_name :
244
222
output_filename = ctx .attr .binary_name
245
223
else :
246
224
output_filename = ctx .label .name
247
225
output = ctx .actions .declare_file (output_filename + toolchain .binary_ext )
248
226
249
- deps = transform_deps (ctx . attr . deps )
250
- proc_macro_deps = transform_deps (ctx . attr . proc_macro_deps + get_import_macro_deps (ctx ))
227
+ deps = transform_deps (deps )
228
+ proc_macro_deps = transform_deps (proc_macro_deps + get_import_macro_deps (ctx ))
251
229
252
230
crate_root = getattr (ctx .file , "crate_root" , None )
253
231
if not crate_root :
@@ -327,13 +305,13 @@ def _rust_test_impl(ctx):
327
305
list: The list of providers. See `rustc_compile_action`
328
306
"""
329
307
_assert_no_deprecated_attributes (ctx )
330
- _assert_correct_dep_mapping (ctx )
308
+ deps , proc_macro_deps = filter_deps (ctx )
331
309
332
310
toolchain = find_toolchain (ctx )
333
311
334
312
crate_type = "bin"
335
- deps = transform_deps (ctx . attr . deps )
336
- proc_macro_deps = transform_deps (ctx . attr . proc_macro_deps + get_import_macro_deps (ctx ))
313
+ deps = transform_deps (deps )
314
+ proc_macro_deps = transform_deps (proc_macro_deps + get_import_macro_deps (ctx ))
337
315
338
316
if ctx .attr .crate and ctx .attr .srcs :
339
317
fail ("rust_test.crate and rust_test.srcs are mutually exclusive. Update {} to use only one of these attributes" .format (
@@ -526,16 +504,16 @@ def _rust_library_group_impl(ctx):
526
504
runfiles = []
527
505
528
506
for dep in ctx .attr .deps :
529
- if rust_common . crate_info in dep :
507
+ if CrateInfo in dep :
530
508
dep_variant_infos .append (rust_common .dep_variant_info (
531
- crate_info = dep [rust_common . crate_info ] if rust_common . crate_info in dep else None ,
532
- dep_info = dep [rust_common . dep_info ] if rust_common . crate_info in dep else None ,
509
+ crate_info = dep [CrateInfo ] if CrateInfo in dep else None ,
510
+ dep_info = dep [DepInfo ] if DepInfo in dep else None ,
533
511
build_info = dep [BuildInfo ] if BuildInfo in dep else None ,
534
512
cc_info = dep [CcInfo ] if CcInfo in dep else None ,
535
513
crate_group_info = None ,
536
514
))
537
- elif rust_common . crate_group_info in dep :
538
- dep_variant_transitive_infos .append (dep [rust_common . crate_group_info ].dep_variant_infos )
515
+ elif CrateGroupInfo in dep :
516
+ dep_variant_transitive_infos .append (dep [CrateGroupInfo ].dep_variant_infos )
539
517
else :
540
518
fail ("crate_group_info targets can only depend on rust_library or rust_library_group targets." )
541
519
@@ -724,10 +702,12 @@ _common_attrs = {
724
702
# `@local_config_platform//:exec` exposed.
725
703
"proc_macro_deps" : attr .label_list (
726
704
doc = dedent ("""\
727
- List of `rust_proc_macro` targets used to help build this library target.
705
+ Copy of deps in exec configuration. This should really be called `exec_configured_deps`.
706
+
707
+ Rule implementations use this to select exec-configured `rust_proc_macro` targets.
708
+ User code should pass all deps to `deps` for the macros loaded from `defs.bzl`.
728
709
""" ),
729
710
cfg = "exec" ,
730
- providers = [rust_common .crate_info ],
731
711
),
732
712
"rustc_env" : attr .string_dict (
733
713
doc = dedent ("""\
@@ -1330,6 +1310,7 @@ rust_binary_without_process_wrapper = rule(
1330
1310
"_allowlist_function_transition" : attr .label (
1331
1311
default = "@bazel_tools//tools/allowlists/function_transition_allowlist" ,
1332
1312
),
1313
+ "_skip_deps_verification" : attr .bool (default = True ),
1333
1314
}),
1334
1315
executable = True ,
1335
1316
fragments = ["cpp" ],
@@ -1510,7 +1491,7 @@ rust_test = rule(
1510
1491
""" ),
1511
1492
)
1512
1493
1513
- def rust_test_suite (name , srcs , shared_srcs = [], ** kwargs ):
1494
+ def rust_test_suite (name , srcs , shared_srcs = [], deps = [], proc_macro_deps = [], ** kwargs ):
1514
1495
"""A rule for creating a test suite for a set of `rust_test` targets.
1515
1496
1516
1497
This rule can be used for setting up typical rust [integration tests][it]. Given the following
@@ -1593,6 +1574,8 @@ def rust_test_suite(name, srcs, shared_srcs = [], **kwargs):
1593
1574
srcs = [src ] + shared_srcs ,
1594
1575
tags = tags ,
1595
1576
crate_name = crate_name ,
1577
+ deps = deps + proc_macro_deps ,
1578
+ proc_macro_deps = deps + proc_macro_deps ,
1596
1579
** kwargs
1597
1580
)
1598
1581
tests .append (test_name )
0 commit comments