Skip to content

Commit 9c08db5

Browse files
committed
librustc: Implement #[no_main], which omits the entry point entirely.
Useful for SDL and possibly Android too.
1 parent 34101d2 commit 9c08db5

File tree

4 files changed

+19
-8
lines changed

4 files changed

+19
-8
lines changed

src/librustc/driver/session.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,8 @@ pub struct crate_metadata {
179179
#[deriving(Eq)]
180180
pub enum EntryFnType {
181181
EntryMain,
182-
EntryStart
182+
EntryStart,
183+
EntryNone,
183184
}
184185

185186
pub struct Session_ {

src/librustc/middle/entry.rs

+6
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,12 @@ pub fn find_entry_point(session: Session, crate: &Crate, ast_map: ast_map::map)
5050
return;
5151
}
5252

53+
// If the user wants no main function at all, then stop here.
54+
if attr::contains_name(crate.attrs, "no_main") {
55+
*session.entry_type = Some(session::EntryNone);
56+
return
57+
}
58+
5359
let ctxt = @mut EntryContext {
5460
session: session,
5561
ast_map: ast_map,

src/librustc/middle/trans/base.rs

+9-6
Original file line numberDiff line numberDiff line change
@@ -2295,13 +2295,16 @@ pub fn is_entry_fn(sess: &Session, node_id: ast::NodeId) -> bool {
22952295
// Create a _rust_main(args: ~[str]) function which will be called from the
22962296
// runtime rust_start function
22972297
pub fn create_entry_wrapper(ccx: @mut CrateContext,
2298-
_sp: span, main_llfn: ValueRef) {
2298+
_sp: span,
2299+
main_llfn: ValueRef) {
22992300
let et = ccx.sess.entry_type.unwrap();
2300-
if et == session::EntryMain {
2301-
let llfn = create_main(ccx, main_llfn);
2302-
create_entry_fn(ccx, llfn, true);
2303-
} else {
2304-
create_entry_fn(ccx, main_llfn, false);
2301+
match et {
2302+
session::EntryMain => {
2303+
let llfn = create_main(ccx, main_llfn);
2304+
create_entry_fn(ccx, llfn, true);
2305+
}
2306+
session::EntryStart => create_entry_fn(ccx, main_llfn, false),
2307+
session::EntryNone => {} // Do nothing.
23052308
}
23062309

23072310
fn create_main(ccx: @mut CrateContext, main_llfn: ValueRef) -> ValueRef {

src/librustc/middle/typeck/mod.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -408,9 +408,10 @@ fn check_for_entry_fn(ccx: &CrateCtxt) {
408408
Some((id, sp)) => match *tcx.sess.entry_type {
409409
Some(session::EntryMain) => check_main_fn_ty(ccx, id, sp),
410410
Some(session::EntryStart) => check_start_fn_ty(ccx, id, sp),
411+
Some(session::EntryNone) => {}
411412
None => tcx.sess.bug("entry function without a type")
412413
},
413-
None => tcx.sess.bug("type checking without entry function")
414+
None => {}
414415
}
415416
}
416417
}

0 commit comments

Comments
 (0)