1+ use std:: any:: Any ;
12use std:: env:: consts:: { DLL_PREFIX , DLL_SUFFIX } ;
23use std:: path:: { Path , PathBuf } ;
34use std:: sync:: atomic:: { AtomicBool , Ordering } ;
@@ -6,13 +7,20 @@ use std::{env, thread};
67
78use rustc_ast as ast;
89use rustc_attr_parsing:: { ShouldEmit , validate_attr} ;
10+ use rustc_codegen_ssa:: back:: archive:: ArArchiveBuilderBuilder ;
11+ use rustc_codegen_ssa:: back:: link:: link_binary;
912use rustc_codegen_ssa:: traits:: CodegenBackend ;
13+ use rustc_codegen_ssa:: { CodegenResults , CrateInfo } ;
14+ use rustc_data_structures:: fx:: FxIndexMap ;
1015use rustc_data_structures:: jobserver:: Proxy ;
1116use rustc_data_structures:: sync;
1217use 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+ } ;
1624use rustc_session:: output:: { CRATE_TYPES , categorize_crate_type} ;
1725use rustc_session:: { EarlyDiagCtxt , Session , filesearch, lint} ;
1826use rustc_span:: edit_distance:: find_best_match_for_name;
@@ -316,12 +324,13 @@ pub fn get_codegen_backend(
316324 let backend = backend_name
317325 . or ( target. default_codegen_backend . as_deref ( ) )
318326 . or ( option_env ! ( "CFG_DEFAULT_CODEGEN_BACKEND" ) )
319- . unwrap_or ( "llvm " ) ;
327+ . unwrap_or ( "dummy " ) ;
320328
321329 match backend {
322330 filename if filename. contains ( '.' ) => {
323331 load_backend_from_dylib ( early_dcx, filename. as_ref ( ) )
324332 }
333+ "dummy" => || Box :: new ( DummyCodegenBackend ) ,
325334 #[ cfg( feature = "llvm" ) ]
326335 "llvm" => rustc_codegen_llvm:: LlvmCodegenBackend :: new,
327336 backend_name => get_codegen_sysroot ( early_dcx, sysroot, backend_name) ,
@@ -334,6 +343,63 @@ pub fn get_codegen_backend(
334343 unsafe { load ( ) }
335344}
336345
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+
337403// This is used for rustdoc, but it uses similar machinery to codegen backend
338404// loading, so we leave the code here. It is potentially useful for other tools
339405// that want to invoke the rustc binary while linking to rustc as well.
0 commit comments