@@ -168,22 +168,11 @@ impl TargetInfo {
168
168
loop {
169
169
let extra_fingerprint = kind. fingerprint_hash ( ) ;
170
170
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
-
183
171
// Query rustc for several kinds of info from each line of output:
184
172
// 0) file-names (to determine output file prefix/suffix for given crate type)
185
173
// 1) sysroot
186
- // 2) cfg
174
+ // 2) split-debuginfo
175
+ // 3) cfg
187
176
//
188
177
// Search `--print` to see what we query so far.
189
178
let mut process = rustc. workspace_process ( ) ;
@@ -213,6 +202,8 @@ impl TargetInfo {
213
202
}
214
203
215
204
process. arg ( "--print=sysroot" ) ;
205
+ process. arg ( "--print=split-debuginfo" ) ;
206
+ process. arg ( "--print=crate-name" ) ; // `___` as a delimiter.
216
207
process. arg ( "--print=cfg" ) ;
217
208
218
209
let ( output, error) = rustc
@@ -228,13 +219,8 @@ impl TargetInfo {
228
219
map. insert ( crate_type. clone ( ) , out) ;
229
220
}
230
221
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) ;
238
224
} ;
239
225
let sysroot = PathBuf :: from ( line) ;
240
226
let sysroot_host_libdir = if cfg ! ( windows) {
@@ -251,6 +237,26 @@ impl TargetInfo {
251
237
} ) ;
252
238
sysroot_target_libdir. push ( "lib" ) ;
253
239
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
+
254
260
let cfg = lines
255
261
. map ( |line| Ok ( Cfg :: from_str ( line) ?) )
256
262
. filter ( TargetInfo :: not_user_specific_cfg)
@@ -590,17 +596,27 @@ fn parse_crate_type(
590
596
} ;
591
597
let mut parts = line. trim ( ) . split ( "___" ) ;
592
598
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) ;
599
601
} ;
600
602
601
603
Ok ( Some ( ( prefix. to_string ( ) , suffix. to_string ( ) ) ) )
602
604
}
603
605
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
+
604
620
/// Helper for creating an error message when parsing rustc output fails.
605
621
fn output_err_info ( cmd : & ProcessBuilder , stdout : & str , stderr : & str ) -> String {
606
622
let mut result = format ! ( "command was: {}\n " , cmd) ;
0 commit comments