@@ -168,22 +168,11 @@ impl TargetInfo {
168168 loop {
169169 let extra_fingerprint = kind. fingerprint_hash ( ) ;
170170
171- // Query rustc for supported -Csplit-debuginfo values
172- let support_split_debuginfo = rustc
173- . cached_output (
174- rustc. workspace_process ( ) . arg ( "--print=split-debuginfo" ) ,
175- extra_fingerprint,
176- )
177- . unwrap_or_default ( )
178- . 0
179- . lines ( )
180- . map ( String :: from)
181- . collect ( ) ;
182-
183171 // Query rustc for several kinds of info from each line of output:
184172 // 0) file-names (to determine output file prefix/suffix for given crate type)
185173 // 1) sysroot
186- // 2) cfg
174+ // 2) split-debuginfo
175+ // 3) cfg
187176 //
188177 // Search `--print` to see what we query so far.
189178 let mut process = rustc. workspace_process ( ) ;
@@ -213,6 +202,8 @@ impl TargetInfo {
213202 }
214203
215204 process. arg ( "--print=sysroot" ) ;
205+ process. arg ( "--print=split-debuginfo" ) ;
206+ process. arg ( "--print=crate-name" ) ; // `___` as a delimiter.
216207 process. arg ( "--print=cfg" ) ;
217208
218209 let ( output, error) = rustc
@@ -228,13 +219,8 @@ impl TargetInfo {
228219 map. insert ( crate_type. clone ( ) , out) ;
229220 }
230221
231- let line = match lines. next ( ) {
232- Some ( line) => line,
233- None => anyhow:: bail!(
234- "output of --print=sysroot missing when learning about \
235- target-specific information from rustc\n {}",
236- output_err_info( & process, & output, & error)
237- ) ,
222+ let Some ( line) = lines. next ( ) else {
223+ return error_missing_print_output ( "sysroot" , & process, & output, & error) ;
238224 } ;
239225 let sysroot = PathBuf :: from ( line) ;
240226 let sysroot_host_libdir = if cfg ! ( windows) {
@@ -251,6 +237,26 @@ impl TargetInfo {
251237 } ) ;
252238 sysroot_target_libdir. push ( "lib" ) ;
253239
240+ let support_split_debuginfo = {
241+ // HACK: abuse `--print=crate-name` to use `___` as a delimiter.
242+ let mut res = Vec :: new ( ) ;
243+ loop {
244+ match lines. next ( ) {
245+ Some ( line) if line == "___" => break ,
246+ Some ( line) => res. push ( line. into ( ) ) ,
247+ None => {
248+ return error_missing_print_output (
249+ "split-debuginfo" ,
250+ & process,
251+ & output,
252+ & error,
253+ )
254+ }
255+ }
256+ }
257+ res
258+ } ;
259+
254260 let cfg = lines
255261 . map ( |line| Ok ( Cfg :: from_str ( line) ?) )
256262 . filter ( TargetInfo :: not_user_specific_cfg)
@@ -590,17 +596,27 @@ fn parse_crate_type(
590596 } ;
591597 let mut parts = line. trim ( ) . split ( "___" ) ;
592598 let prefix = parts. next ( ) . unwrap ( ) ;
593- let suffix = match parts. next ( ) {
594- Some ( part) => part,
595- None => anyhow:: bail!(
596- "output of --print=file-names has changed in the compiler, cannot parse\n {}" ,
597- output_err_info( cmd, output, error)
598- ) ,
599+ let Some ( suffix) = parts. next ( ) else {
600+ return error_missing_print_output ( "file-names" , cmd, output, error) ;
599601 } ;
600602
601603 Ok ( Some ( ( prefix. to_string ( ) , suffix. to_string ( ) ) ) )
602604}
603605
606+ /// Helper for creating an error message for missing output from a certain `--print` request.
607+ fn error_missing_print_output < T > (
608+ request : & str ,
609+ cmd : & ProcessBuilder ,
610+ stdout : & str ,
611+ stderr : & str ,
612+ ) -> CargoResult < T > {
613+ let err_info = output_err_info ( cmd, stdout, stderr) ;
614+ anyhow:: bail!(
615+ "output of --print={request} missing when learning about \
616+ target-specific information from rustc\n {err_info}",
617+ )
618+ }
619+
604620/// Helper for creating an error message when parsing rustc output fails.
605621fn output_err_info ( cmd : & ProcessBuilder , stdout : & str , stderr : & str ) -> String {
606622 let mut result = format ! ( "command was: {}\n " , cmd) ;
0 commit comments