Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

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

Closed
wants to merge 1 commit into from

3 participants

@pcwalton
Owner

Useful for SDL and possibly Android too.

r? @brson

@brson
Owner

r+

Collaborator

saw approval from brson
at pcwalton@9c08db5

Collaborator

merging pcwalton/rust/no-main = 9c08db5 into auto

Collaborator

pcwalton/rust/no-main = 9c08db5 merged ok, testing candidate = dbaca98

Collaborator

fast-forwarding master to auto = dbaca98

@bors bors referenced this pull request from a commit
@bors bors auto merge of #8279 : pcwalton/rust/no-main, r=brson
Useful for SDL and possibly Android too.

r? @brson
dbaca98
@bors bors closed this
@jayanderson jayanderson referenced this pull request from a commit
Commit has since been removed from the repository and is no longer available.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Aug 4, 2013
  1. @pcwalton

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

    pcwalton authored
    Useful for SDL and possibly Android too.
This page is out of date. Refresh to see the latest.
View
3  src/librustc/driver/session.rs
@@ -179,7 +179,8 @@ pub struct crate_metadata {
#[deriving(Eq)]
pub enum EntryFnType {
EntryMain,
- EntryStart
+ EntryStart,
+ EntryNone,
}
pub struct Session_ {
View
6 src/librustc/middle/entry.rs
@@ -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,
View
15 src/librustc/middle/trans/base.rs
@@ -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 {
View
3  src/librustc/middle/typeck/mod.rs
@@ -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 => {}
}
}
}
Something went wrong with that request. Please try again.