39
39
"generate_output_diagnostics" ,
40
40
"get_edition" ,
41
41
"get_import_macro_deps" ,
42
+ "partition_deps" ,
42
43
"transform_deps" ,
43
44
"transform_sources" ,
44
45
)
@@ -53,31 +54,6 @@ def _assert_no_deprecated_attributes(_ctx):
53
54
"""
54
55
pass
55
56
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
57
82
58
def _rust_library_impl (ctx ):
83
59
"""The implementation of the `rust_library` rule.
@@ -148,7 +124,7 @@ def _rust_library_common(ctx, crate_type):
148
124
list: A list of providers. See `rustc_compile_action`
149
125
"""
150
126
_assert_no_deprecated_attributes (ctx )
151
- _assert_correct_dep_mapping (ctx )
127
+ deps , proc_macro_deps = partition_deps (ctx )
152
128
153
129
toolchain = find_toolchain (ctx )
154
130
@@ -195,8 +171,8 @@ def _rust_library_common(ctx, crate_type):
195
171
not ctx .attr .disable_pipelining
196
172
)
197
173
198
- deps = transform_deps (ctx . attr . deps )
199
- proc_macro_deps = transform_deps (ctx . attr . proc_macro_deps + get_import_macro_deps (ctx ))
174
+ deps = transform_deps (deps )
175
+ proc_macro_deps = transform_deps (proc_macro_deps + get_import_macro_deps (ctx ))
200
176
201
177
return rustc_compile_action (
202
178
ctx = ctx ,
@@ -238,16 +214,16 @@ def _rust_binary_impl(ctx):
238
214
"""
239
215
toolchain = find_toolchain (ctx )
240
216
crate_name = compute_crate_name (ctx .workspace_name , ctx .label , toolchain , ctx .attr .crate_name )
241
- _assert_correct_dep_mapping (ctx )
217
+ deps , proc_macro_deps = partition_deps (ctx )
242
218
243
219
if ctx .attr .binary_name :
244
220
output_filename = ctx .attr .binary_name
245
221
else :
246
222
output_filename = ctx .label .name
247
223
output = ctx .actions .declare_file (output_filename + toolchain .binary_ext )
248
224
249
- deps = transform_deps (ctx . attr . deps )
250
- proc_macro_deps = transform_deps (ctx . attr . proc_macro_deps + get_import_macro_deps (ctx ))
225
+ deps = transform_deps (deps )
226
+ proc_macro_deps = transform_deps (proc_macro_deps + get_import_macro_deps (ctx ))
251
227
252
228
crate_root = getattr (ctx .file , "crate_root" , None )
253
229
if not crate_root :
@@ -327,13 +303,13 @@ def _rust_test_impl(ctx):
327
303
list: The list of providers. See `rustc_compile_action`
328
304
"""
329
305
_assert_no_deprecated_attributes (ctx )
330
- _assert_correct_dep_mapping (ctx )
306
+ deps , proc_macro_deps = partition_deps (ctx )
331
307
332
308
toolchain = find_toolchain (ctx )
333
309
334
310
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 ))
311
+ deps = transform_deps (deps )
312
+ proc_macro_deps = transform_deps (proc_macro_deps + get_import_macro_deps (ctx ))
337
313
338
314
if ctx .attr .crate and ctx .attr .srcs :
339
315
fail ("rust_test.crate and rust_test.srcs are mutually exclusive. Update {} to use only one of these attributes" .format (
@@ -1072,6 +1048,21 @@ rust_shared_library = rule(
1072
1048
""" ),
1073
1049
)
1074
1050
1051
+ def _exec_transition_impl (_settings , attr ):
1052
+ return {
1053
+ "//command_line_option:is exec configuration" : not attr .internal_doctest_transition_override ,
1054
+ "//command_line_option:stamp" : False ,
1055
+ }
1056
+
1057
+ _exec_transition = transition (
1058
+ inputs = [],
1059
+ outputs = [
1060
+ "//command_line_option:is exec configuration" ,
1061
+ "//command_line_option:stamp" ,
1062
+ ],
1063
+ implementation = _exec_transition_impl ,
1064
+ )
1065
+
1075
1066
def _proc_macro_dep_transition_impl (settings , _attr ):
1076
1067
if settings ["//rust/private:is_proc_macro_dep_enabled" ]:
1077
1068
return {"//rust/private:is_proc_macro_dep" : True }
@@ -1105,7 +1096,11 @@ rust_proc_macro = rule(
1105
1096
""" ),
1106
1097
cfg = _proc_macro_dep_transition ,
1107
1098
),
1099
+ internal_doctest_transition_override = attr .bool (
1100
+ doc = "Used for internal testing; do not set" ,
1101
+ ),
1108
1102
),
1103
+ cfg = _exec_transition ,
1109
1104
fragments = ["cpp" ],
1110
1105
toolchains = [
1111
1106
str (Label ("//rust:toolchain_type" )),
0 commit comments