@@ -52,6 +52,11 @@ ErrorFormatInfo = provider(
52
52
fields = {"error_format" : "(string) [" + ", " .join (_error_format_values ) + "]" },
53
53
)
54
54
55
+ OutputDiagnosticsInfo = provider (
56
+ doc = "Save json diagnostics form rustc" ,
57
+ fields = {"output_diagnostics" : "(bool)" },
58
+ )
59
+
55
60
ExtraRustcFlagsInfo = provider (
56
61
doc = "Pass each value as an additional flag to non-exec rustc invocations" ,
57
62
fields = {"extra_rustc_flags" : "List[string] Extra flags to pass to rustc in non-exec configuration" },
@@ -857,10 +862,8 @@ def construct_arguments(
857
862
process_wrapper_flags .add ("--rustc-quit-on-rmeta" , "true" )
858
863
if crate_info .rust_metadata_rustc_output :
859
864
process_wrapper_flags .add ("--output-file" , crate_info .rust_metadata_rustc_output .path )
860
- else :
861
- if crate_info .rust_lib_rustc_output :
862
- process_wrapper_flags .add ("--output-file" , crate_info .rust_lib_rustc_output .path )
863
-
865
+ elif crate_info .rust_lib_rustc_output :
866
+ process_wrapper_flags .add ("--output-file" , crate_info .rust_lib_rustc_output .path )
864
867
865
868
rustc_flags .add ("--error-format=" + error_format )
866
869
@@ -1104,7 +1107,7 @@ def rustc_compile_action(
1104
1107
build_flags_files = build_flags_files ,
1105
1108
force_all_deps_direct = force_all_deps_direct ,
1106
1109
stamp = stamp ,
1107
- use_json_output = bool (build_metadata ),
1110
+ use_json_output = bool (build_metadata ) or bool ( rust_lib_rustc_output ) or bool ( rust_metadata_rustc_output ) ,
1108
1111
)
1109
1112
1110
1113
args_metadata = None
@@ -1844,6 +1847,30 @@ error_format = rule(
1844
1847
build_setting = config .string (flag = True ),
1845
1848
)
1846
1849
1850
+ def _output_diagnostics_impl (ctx ):
1851
+ """Implementation of the `output_diagnostics` rule
1852
+
1853
+ Args:
1854
+ ctx (ctx): The rule's context object
1855
+
1856
+ Returns:
1857
+ list: A list containing the OutputDiagnosticsInfo provider
1858
+ """
1859
+ return [OutputDiagnosticsInfo (output_diagnostics = ctx .build_setting_value )]
1860
+
1861
+ output_diagnostics = rule (
1862
+ doc = (
1863
+ "Setting this flag from the command line with `--@rules_rust//:output_diagnostics` " +
1864
+ "makes rules_rust save rustc json output(suitable for consumption by rust-analyzer) in a file. " +
1865
+ "These are accessible via the " +
1866
+ "`rust_metadata_rustc_output`(for pipelined compilation) and `rust_lib_rustc_output` output groups. " +
1867
+ "You can find these either by using something like `find <dir> -name '*.rustc-output'` or by using " +
1868
+ "`bazel cquery --output=files`."
1869
+ ),
1870
+ implementation = _output_diagnostics_impl ,
1871
+ build_setting = config .bool (flag = True ),
1872
+ )
1873
+
1847
1874
def _extra_rustc_flags_impl (ctx ):
1848
1875
return ExtraRustcFlagsInfo (extra_rustc_flags = ctx .build_setting_value )
1849
1876
0 commit comments