librustc: Implement #[no_main]
, which omits the entry point entirely.
Useful for SDL and possibly Android too.
This commit is contained in:
parent
34101d2320
commit
9c08db58ab
4 changed files with 19 additions and 8 deletions
|
@ -179,7 +179,8 @@ pub struct crate_metadata {
|
||||||
#[deriving(Eq)]
|
#[deriving(Eq)]
|
||||||
pub enum EntryFnType {
|
pub enum EntryFnType {
|
||||||
EntryMain,
|
EntryMain,
|
||||||
EntryStart
|
EntryStart,
|
||||||
|
EntryNone,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct Session_ {
|
pub struct Session_ {
|
||||||
|
|
|
@ -50,6 +50,12 @@ pub fn find_entry_point(session: Session, crate: &Crate, ast_map: ast_map::map)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// If the user wants no main function at all, then stop here.
|
||||||
|
if attr::contains_name(crate.attrs, "no_main") {
|
||||||
|
*session.entry_type = Some(session::EntryNone);
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
let ctxt = @mut EntryContext {
|
let ctxt = @mut EntryContext {
|
||||||
session: session,
|
session: session,
|
||||||
ast_map: ast_map,
|
ast_map: ast_map,
|
||||||
|
|
|
@ -2295,13 +2295,16 @@ pub fn is_entry_fn(sess: &Session, node_id: ast::NodeId) -> bool {
|
||||||
// Create a _rust_main(args: ~[str]) function which will be called from the
|
// Create a _rust_main(args: ~[str]) function which will be called from the
|
||||||
// runtime rust_start function
|
// runtime rust_start function
|
||||||
pub fn create_entry_wrapper(ccx: @mut CrateContext,
|
pub fn create_entry_wrapper(ccx: @mut CrateContext,
|
||||||
_sp: span, main_llfn: ValueRef) {
|
_sp: span,
|
||||||
|
main_llfn: ValueRef) {
|
||||||
let et = ccx.sess.entry_type.unwrap();
|
let et = ccx.sess.entry_type.unwrap();
|
||||||
if et == session::EntryMain {
|
match et {
|
||||||
let llfn = create_main(ccx, main_llfn);
|
session::EntryMain => {
|
||||||
create_entry_fn(ccx, llfn, true);
|
let llfn = create_main(ccx, main_llfn);
|
||||||
} else {
|
create_entry_fn(ccx, llfn, true);
|
||||||
create_entry_fn(ccx, main_llfn, false);
|
}
|
||||||
|
session::EntryStart => create_entry_fn(ccx, main_llfn, false),
|
||||||
|
session::EntryNone => {} // Do nothing.
|
||||||
}
|
}
|
||||||
|
|
||||||
fn create_main(ccx: @mut CrateContext, main_llfn: ValueRef) -> ValueRef {
|
fn create_main(ccx: @mut CrateContext, main_llfn: ValueRef) -> ValueRef {
|
||||||
|
|
|
@ -408,9 +408,10 @@ fn check_for_entry_fn(ccx: &CrateCtxt) {
|
||||||
Some((id, sp)) => match *tcx.sess.entry_type {
|
Some((id, sp)) => match *tcx.sess.entry_type {
|
||||||
Some(session::EntryMain) => check_main_fn_ty(ccx, id, sp),
|
Some(session::EntryMain) => check_main_fn_ty(ccx, id, sp),
|
||||||
Some(session::EntryStart) => check_start_fn_ty(ccx, id, sp),
|
Some(session::EntryStart) => check_start_fn_ty(ccx, id, sp),
|
||||||
|
Some(session::EntryNone) => {}
|
||||||
None => tcx.sess.bug("entry function without a type")
|
None => tcx.sess.bug("entry function without a type")
|
||||||
},
|
},
|
||||||
None => tcx.sess.bug("type checking without entry function")
|
None => {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue