Skip to content

Commit dbaca98

Browse files
committed
auto merge of #8279 : pcwalton/rust/no-main, r=brson
Useful for SDL and possibly Android too. r? @brson
2 parents 4db0611 + 9c08db5 commit dbaca98

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
@@ -2268,13 +2268,16 @@ pub fn is_entry_fn(sess: &Session, node_id: ast::NodeId) -> bool {
22682268
// Create a _rust_main(args: ~[str]) function which will be called from the
22692269
// runtime rust_start function
22702270
pub fn create_entry_wrapper(ccx: @mut CrateContext,
2271-
_sp: span, main_llfn: ValueRef) {
2271+
_sp: span,
2272+
main_llfn: ValueRef) {
22722273
let et = ccx.sess.entry_type.unwrap();
2273-
if et == session::EntryMain {
2274-
let llfn = create_main(ccx, main_llfn);
2275-
create_entry_fn(ccx, llfn, true);
2276-
} else {
2277-
create_entry_fn(ccx, main_llfn, false);
2274+
match et {
2275+
session::EntryMain => {
2276+
let llfn = create_main(ccx, main_llfn);
2277+
create_entry_fn(ccx, llfn, true);
2278+
}
2279+
session::EntryStart => create_entry_fn(ccx, main_llfn, false),
2280+
session::EntryNone => {} // Do nothing.
22782281
}
22792282

22802283
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)