@@ -15,7 +15,7 @@ use rustc_data_structures::fx::FxHashMap;
15
15
use rustc_data_structures:: profiling:: { get_resident_set_size, print_time_passes_entry} ;
16
16
use rustc_data_structures:: sync:: { par_iter, ParallelIterator } ;
17
17
use rustc_hir as hir;
18
- use rustc_hir:: def_id:: { LocalDefId , LOCAL_CRATE } ;
18
+ use rustc_hir:: def_id:: { DefId , LOCAL_CRATE } ;
19
19
use rustc_hir:: lang_items:: LangItem ;
20
20
use rustc_index:: vec:: Idx ;
21
21
use rustc_middle:: middle:: codegen_fn_attrs:: CodegenFnAttrs ;
@@ -348,12 +348,29 @@ pub fn maybe_create_entry_wrapper<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>(
348
348
cx : & ' a Bx :: CodegenCx ,
349
349
) -> Option < Bx :: Function > {
350
350
let main_def_id = cx. tcx ( ) . entry_fn ( LOCAL_CRATE ) . map ( |( def_id, _) | def_id) ?;
351
- let instance = Instance :: mono ( cx. tcx ( ) , main_def_id. to_def_id ( ) ) ;
351
+ let main_is_local = main_def_id. is_local ( ) ;
352
+ let instance = Instance :: mono ( cx. tcx ( ) , main_def_id) ;
352
353
353
- if !cx . codegen_unit ( ) . contains_item ( & MonoItem :: Fn ( instance ) ) {
354
+ if main_is_local {
354
355
// We want to create the wrapper in the same codegen unit as Rust's main
355
356
// function.
356
- return None ;
357
+ if !cx. codegen_unit ( ) . contains_item ( & MonoItem :: Fn ( instance) ) {
358
+ return None ;
359
+ }
360
+ } else {
361
+ // FIXME: Add support for non-local main fn codegen
362
+ let span = cx. tcx ( ) . main_def . unwrap ( ) . span ;
363
+ let n = 28937 ;
364
+ cx. sess ( )
365
+ . struct_span_err ( span, "entry symbol `main` from foreign crate is not yet supported." )
366
+ . note ( & format ! (
367
+ "see issue #{} <https://github.com/rust-lang/rust/issues/{}> \
368
+ for more information",
369
+ n, n,
370
+ ) )
371
+ . emit ( ) ;
372
+ cx. sess ( ) . abort_if_errors ( ) ;
373
+ bug ! ( ) ;
357
374
}
358
375
359
376
let main_llfn = cx. get_fn_addr ( instance) ;
@@ -366,7 +383,7 @@ pub fn maybe_create_entry_wrapper<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>(
366
383
fn create_entry_fn < ' a , ' tcx , Bx : BuilderMethods < ' a , ' tcx > > (
367
384
cx : & ' a Bx :: CodegenCx ,
368
385
rust_main : Bx :: Value ,
369
- rust_main_def_id : LocalDefId ,
386
+ rust_main_def_id : DefId ,
370
387
use_start_lang_item : bool ,
371
388
) -> Bx :: Function {
372
389
// The entry function is either `int main(void)` or `int main(int argc, char **argv)`,
0 commit comments