Skip to content

librustc: Implement #[no_main], which omits the entry point entirely. #8279

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/librustc/driver/session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,8 @@ pub struct crate_metadata {
#[deriving(Eq)]
pub enum EntryFnType {
EntryMain,
EntryStart
EntryStart,
EntryNone,
}

pub struct Session_ {
Expand Down
6 changes: 6 additions & 0 deletions src/librustc/middle/entry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,12 @@ pub fn find_entry_point(session: Session, crate: &Crate, ast_map: ast_map::map)
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 {
session: session,
ast_map: ast_map,
Expand Down
15 changes: 9 additions & 6 deletions src/librustc/middle/trans/base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
// runtime rust_start function
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();
if et == session::EntryMain {
let llfn = create_main(ccx, main_llfn);
create_entry_fn(ccx, llfn, true);
} else {
create_entry_fn(ccx, main_llfn, false);
match et {
session::EntryMain => {
let llfn = create_main(ccx, main_llfn);
create_entry_fn(ccx, llfn, true);
}
session::EntryStart => create_entry_fn(ccx, main_llfn, false),
session::EntryNone => {} // Do nothing.
}

fn create_main(ccx: @mut CrateContext, main_llfn: ValueRef) -> ValueRef {
Expand Down
3 changes: 2 additions & 1 deletion src/librustc/middle/typeck/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -408,9 +408,10 @@ fn check_for_entry_fn(ccx: &CrateCtxt) {
Some((id, sp)) => match *tcx.sess.entry_type {
Some(session::EntryMain) => check_main_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("type checking without entry function")
None => {}
}
}
}
Expand Down