41
41
"is_exec_configuration" ,
42
42
"is_std_dylib" ,
43
43
"make_static_lib_symlink" ,
44
+ "parse_env_strings" ,
44
45
"relativize" ,
45
46
)
46
47
@@ -67,6 +68,16 @@ ErrorFormatInfo = provider(
67
68
fields = {"error_format" : "(string) [" + ", " .join (_error_format_values ) + "]" },
68
69
)
69
70
71
+ ExtraRustcEnvInfo = provider (
72
+ doc = "Pass each value as an environment variable to non-exec rustc invocations" ,
73
+ fields = {"extra_rustc_env" : "List[string] Extra env to pass to rustc in non-exec configuration" },
74
+ )
75
+
76
+ ExtraExecRustcEnvInfo = provider (
77
+ doc = "Pass each value as an environment variable to exec rustc invocations" ,
78
+ fields = {"extra_exec_rustc_env" : "List[string] Extra env to pass to rustc in exec configuration" },
79
+ )
80
+
70
81
ExtraRustcFlagsInfo = provider (
71
82
doc = "Pass each value as an additional flag to non-exec rustc invocations" ,
72
83
fields = {"extra_rustc_flags" : "List[string] Extra flags to pass to rustc in non-exec configuration" },
@@ -1104,6 +1115,10 @@ def construct_arguments(
1104
1115
else :
1105
1116
rustc_flags .add_all (toolchain .extra_rustc_flags , map_each = map_flag )
1106
1117
1118
+ # extra_rustc_env applies to the target configuration, not the exec configuration.
1119
+ if hasattr (ctx .attr , "_extra_rustc_env" ) and not is_exec_configuration (ctx ):
1120
+ env .update (ctx .attr ._extra_rustc_env [ExtraRustcEnvInfo ].extra_rustc_env )
1121
+
1107
1122
# extra_rustc_flags apply to the target configuration, not the exec configuration.
1108
1123
if hasattr (ctx .attr , "_extra_rustc_flags" ) and not is_exec_configuration (ctx ):
1109
1124
rustc_flags .add_all (ctx .attr ._extra_rustc_flags [ExtraRustcFlagsInfo ].extra_rustc_flags , map_each = map_flag )
@@ -1115,6 +1130,9 @@ def construct_arguments(
1115
1130
per_crate_rustc_flags = ctx .attr ._per_crate_rustc_flag [PerCrateRustcFlagsInfo ].per_crate_rustc_flags
1116
1131
_add_per_crate_rustc_flags (ctx , rustc_flags , map_flag , crate_info , per_crate_rustc_flags )
1117
1132
1133
+ if hasattr (ctx .attr , "_extra_exec_rustc_env" ) and is_exec_configuration (ctx ):
1134
+ env .update (ctx .attr ._extra_exec_rustc_env [ExtraExecRustcEnvInfo ].extra_exec_rustc_env )
1135
+
1118
1136
if hasattr (ctx .attr , "_extra_exec_rustc_flags" ) and is_exec_configuration (ctx ):
1119
1137
rustc_flags .add_all (ctx .attr ._extra_exec_rustc_flags [ExtraExecRustcFlagsInfo ].extra_exec_rustc_flags , map_each = map_flag )
1120
1138
@@ -2336,6 +2354,19 @@ rustc_output_diagnostics = rule(
2336
2354
build_setting = config .bool (flag = True ),
2337
2355
)
2338
2356
2357
+ def _extra_rustc_env_impl (ctx ):
2358
+ env_vars = parse_env_strings (ctx .build_setting_value )
2359
+ return ExtraRustcEnvInfo (extra_rustc_env = env_vars )
2360
+
2361
+ extra_rustc_env = rule (
2362
+ doc = (
2363
+ "Add additional environment variables to rustc in non-exec configuration using " +
2364
+ "`--@rules_rust//rust/settings:extra_rustc_env=FOO=bar`. Multiple values may be specified."
2365
+ ),
2366
+ implementation = _extra_rustc_env_impl ,
2367
+ build_setting = config .string_list (flag = True ),
2368
+ )
2369
+
2339
2370
def _extra_rustc_flags_impl (ctx ):
2340
2371
return ExtraRustcFlagsInfo (extra_rustc_flags = ctx .build_setting_value )
2341
2372
@@ -2376,6 +2407,19 @@ extra_exec_rustc_flags = rule(
2376
2407
build_setting = config .string_list (flag = True ),
2377
2408
)
2378
2409
2410
+ def _extra_exec_rustc_env_impl (ctx ):
2411
+ env_vars = parse_env_strings (ctx .build_setting_value )
2412
+ return ExtraExecRustcEnvInfo (extra_exec_rustc_env = env_vars )
2413
+
2414
+ extra_exec_rustc_env = rule (
2415
+ doc = (
2416
+ "Add additional environment variables to rustc in non-exec configuration using " +
2417
+ "`--@rules_rust//rust/settings:extra_exec_rustc_env=FOO=bar`. Multiple values may be specified."
2418
+ ),
2419
+ implementation = _extra_exec_rustc_env_impl ,
2420
+ build_setting = config .string_list (flag = True ),
2421
+ )
2422
+
2379
2423
def _extra_exec_rustc_flag_impl (ctx ):
2380
2424
return ExtraExecRustcFlagsInfo (extra_exec_rustc_flags = [f for f in ctx .build_setting_value if f != "" ])
2381
2425
0 commit comments