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,80 @@ rust_shared_library = rule(
1072
1048
""" ),
1073
1049
)
1074
1050
1051
+ # See https://github.com/bazelbuild/bazel/blob/952a7580c3fcf913371019238ef06611cead4857/src/main/starlark/builtins_bzl/common/builtin_exec_platforms.bzl#L219-L282
1052
+ _EXEC_TRANSITION_PROPAGATED = [
1053
+ #"//command_line_option:experimental_output_directory_naming_scheme",
1054
+ "//command_line_option:host_compilation_mode" ,
1055
+ #"//command_line_option:experimental_exec_configuration_distinguisher",
1056
+ #"//command_line_option:experimental_output_paths",
1057
+ "//command_line_option:enable_runfiles" ,
1058
+ "//command_line_option:enforce_constraints" ,
1059
+ #"//command_line_option:incompatible_merge_genfiles_directory",
1060
+ #"//command_line_option:experimental_platform_in_output_dir",
1061
+ "//command_line_option:host_cpu" ,
1062
+ #"//command_line_option:incompatible_modify_execution_info_additive",
1063
+ "//command_line_option:include_config_fragments_provider" ,
1064
+ #"//command_line_option:experimental_debug_selects_always_succeed",
1065
+ #"//command_line_option:incompatible_check_testonly_for_output_files",
1066
+ #"//command_line_option:incompatible_auto_exec_groups",
1067
+ #"//command_line_option:incompatible_bazel_test_exec_run_under",
1068
+ #"//command_line_option:experimental_writable_outputs",
1069
+ "//command_line_option:build_runfile_manifests" ,
1070
+ "//command_line_option:build_runfile_links" ,
1071
+ #"//command_line_option:experimental_remotable_source_manifests",
1072
+ #"//command_line_option:incompatible_always_include_files_in_data",
1073
+ #"//command_line_option:experimental_strict_fileset_output",
1074
+ "//command_line_option:strict_filesets" ,
1075
+ "//command_line_option:check_visibility" ,
1076
+ "//command_line_option:check_licenses" ,
1077
+ "//command_line_option:host_features" ,
1078
+ "//command_line_option:host_action_env" ,
1079
+ "//command_line_option:archived_tree_artifact_mnemonics_filter" ,
1080
+ "//command_line_option:allow_unresolved_symlinks" ,
1081
+ #"//command_line_option:experimental_exec_config",
1082
+ #"//command_line_option:experimental_exclude_defines_from_exec_config",
1083
+ #"//command_line_option:experimental_exclude_starlark_flags_from_exec_config",
1084
+ #"//command_line_option:experimental_propagate_custom_flag",
1085
+ "//command_line_option:allow_analysis_failures" ,
1086
+ #"//command_line_option:experimental_collect_code_coverage_for_generated_files",
1087
+ #"//command_line_option:experimental_extended_sanity_checks",
1088
+ #"//command_line_option:experimental_inprocess_symlink_creation",
1089
+ #"//command_line_option:experimental_throttle_action_cache_check",
1090
+ #"//command_line_option:experimental_use_platforms_in_output_dir_legacy_heuristic",
1091
+ #"//command_line_option:incompatible_compact_repo_mapping_manifest",
1092
+ #"//command_line_option:incompatible_filegroup_runfiles_for_data",
1093
+ ]
1094
+
1095
+ def _exec_transition_impl (settings , _attr ):
1096
+ transitioned = {
1097
+ "//command_line_option:compilation_mode" : settings ["//command_line_option:host_compilation_mode" ],
1098
+ "//command_line_option:is exec configuration" : True ,
1099
+ "//command_line_option:cpu" : settings ["//command_line_option:host_cpu" ],
1100
+ "//command_line_option:stamp" : False ,
1101
+ "//command_line_option:action_env" : settings ["//command_line_option:host_action_env" ],
1102
+ "//command_line_option:features" : settings ["//command_line_option:host_features" ],
1103
+ }
1104
+
1105
+ for opt in _EXEC_TRANSITION_PROPAGATED :
1106
+ transitioned [opt ] = settings [opt ]
1107
+
1108
+ return transitioned
1109
+
1110
+ _exec_transition = transition (
1111
+ inputs = [
1112
+ "//command_line_option:features" ,
1113
+ ] + _EXEC_TRANSITION_PROPAGATED ,
1114
+ outputs = [
1115
+ "//command_line_option:compilation_mode" ,
1116
+ "//command_line_option:is exec configuration" ,
1117
+ "//command_line_option:cpu" ,
1118
+ "//command_line_option:stamp" ,
1119
+ "//command_line_option:features" ,
1120
+ "//command_line_option:action_env" ,
1121
+ ] + _EXEC_TRANSITION_PROPAGATED ,
1122
+ implementation = _exec_transition_impl ,
1123
+ )
1124
+
1075
1125
def _proc_macro_dep_transition_impl (settings , _attr ):
1076
1126
if settings ["//rust/private:is_proc_macro_dep_enabled" ]:
1077
1127
return {"//rust/private:is_proc_macro_dep" : True }
@@ -1106,6 +1156,7 @@ rust_proc_macro = rule(
1106
1156
cfg = _proc_macro_dep_transition ,
1107
1157
),
1108
1158
),
1159
+ cfg = _exec_transition ,
1109
1160
fragments = ["cpp" ],
1110
1161
toolchains = [
1111
1162
str (Label ("//rust:toolchain_type" )),
0 commit comments