1
+ use std:: any:: Any ;
1
2
use std:: env:: consts:: { DLL_PREFIX , DLL_SUFFIX } ;
2
3
use std:: path:: { Path , PathBuf } ;
3
4
use std:: sync:: atomic:: { AtomicBool , Ordering } ;
@@ -6,13 +7,20 @@ use std::{env, thread};
6
7
7
8
use rustc_ast as ast;
8
9
use rustc_attr_parsing:: { ShouldEmit , validate_attr} ;
10
+ use rustc_codegen_ssa:: back:: archive:: ArArchiveBuilderBuilder ;
11
+ use rustc_codegen_ssa:: back:: link:: link_binary;
9
12
use rustc_codegen_ssa:: traits:: CodegenBackend ;
13
+ use rustc_codegen_ssa:: { CodegenResults , CrateInfo } ;
14
+ use rustc_data_structures:: fx:: FxIndexMap ;
10
15
use rustc_data_structures:: jobserver:: Proxy ;
11
16
use rustc_data_structures:: sync;
12
17
use rustc_errors:: LintBuffer ;
13
- use rustc_metadata:: { DylibError , load_symbol_from_dylib} ;
14
- use rustc_middle:: ty:: CurrentGcx ;
15
- use rustc_session:: config:: { Cfg , OutFileName , OutputFilenames , OutputTypes , Sysroot , host_tuple} ;
18
+ use rustc_metadata:: { DylibError , EncodedMetadata , load_symbol_from_dylib} ;
19
+ use rustc_middle:: dep_graph:: { WorkProduct , WorkProductId } ;
20
+ use rustc_middle:: ty:: { CurrentGcx , TyCtxt } ;
21
+ use rustc_session:: config:: {
22
+ Cfg , CrateType , OutFileName , OutputFilenames , OutputTypes , Sysroot , host_tuple,
23
+ } ;
16
24
use rustc_session:: output:: { CRATE_TYPES , categorize_crate_type} ;
17
25
use rustc_session:: { EarlyDiagCtxt , Session , filesearch, lint} ;
18
26
use rustc_span:: edit_distance:: find_best_match_for_name;
@@ -316,12 +324,13 @@ pub fn get_codegen_backend(
316
324
let backend = backend_name
317
325
. or ( target. default_codegen_backend . as_deref ( ) )
318
326
. or ( option_env ! ( "CFG_DEFAULT_CODEGEN_BACKEND" ) )
319
- . unwrap_or ( "llvm " ) ;
327
+ . unwrap_or ( "dummy " ) ;
320
328
321
329
match backend {
322
330
filename if filename. contains ( '.' ) => {
323
331
load_backend_from_dylib ( early_dcx, filename. as_ref ( ) )
324
332
}
333
+ "dummy" => || Box :: new ( DummyCodegenBackend ) ,
325
334
#[ cfg( feature = "llvm" ) ]
326
335
"llvm" => rustc_codegen_llvm:: LlvmCodegenBackend :: new,
327
336
backend_name => get_codegen_sysroot ( early_dcx, sysroot, backend_name) ,
@@ -334,6 +343,63 @@ pub fn get_codegen_backend(
334
343
unsafe { load ( ) }
335
344
}
336
345
346
+ struct DummyCodegenBackend ;
347
+
348
+ impl CodegenBackend for DummyCodegenBackend {
349
+ fn locale_resource ( & self ) -> & ' static str {
350
+ ""
351
+ }
352
+
353
+ fn name ( & self ) -> & ' static str {
354
+ "dummy"
355
+ }
356
+
357
+ fn codegen_crate < ' tcx > ( & self , tcx : TyCtxt < ' tcx > ) -> Box < dyn Any > {
358
+ Box :: new ( CodegenResults {
359
+ modules : vec ! [ ] ,
360
+ allocator_module : None ,
361
+ crate_info : CrateInfo :: new ( tcx, String :: new ( ) ) ,
362
+ } )
363
+ }
364
+
365
+ fn join_codegen (
366
+ & self ,
367
+ ongoing_codegen : Box < dyn Any > ,
368
+ _sess : & Session ,
369
+ _outputs : & OutputFilenames ,
370
+ ) -> ( CodegenResults , FxIndexMap < WorkProductId , WorkProduct > ) {
371
+ ( * ongoing_codegen. downcast ( ) . unwrap ( ) , FxIndexMap :: default ( ) )
372
+ }
373
+
374
+ fn link (
375
+ & self ,
376
+ sess : & Session ,
377
+ codegen_results : CodegenResults ,
378
+ metadata : EncodedMetadata ,
379
+ outputs : & OutputFilenames ,
380
+ ) {
381
+ // JUSTIFICATION: TyCtxt no longer available here
382
+ #[ allow( rustc:: bad_opt_access) ]
383
+ if sess. opts . crate_types . iter ( ) . any ( |& crate_type| crate_type != CrateType :: Rlib ) {
384
+ #[ allow( rustc:: untranslatable_diagnostic) ]
385
+ #[ allow( rustc:: diagnostic_outside_of_impl) ]
386
+ sess. dcx ( ) . fatal ( format ! (
387
+ "crate type {} not supported by the dummy codegen backend" ,
388
+ sess. opts. crate_types[ 0 ] ,
389
+ ) ) ;
390
+ }
391
+
392
+ link_binary (
393
+ sess,
394
+ & ArArchiveBuilderBuilder ,
395
+ codegen_results,
396
+ metadata,
397
+ outputs,
398
+ self . name ( ) ,
399
+ ) ;
400
+ }
401
+ }
402
+
337
403
// This is used for rustdoc, but it uses similar machinery to codegen backend
338
404
// loading, so we leave the code here. It is potentially useful for other tools
339
405
// that want to invoke the rustc binary while linking to rustc as well.
0 commit comments