Skip to content

Commit a1b215a

Browse files
committed
Add --no-core option and inject a use core/import core::* pair into crate unless it's given.
1 parent 03d4ec5 commit a1b215a

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed

src/comp/driver/rustc.rs

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,30 @@ fn time<T>(do_it: bool, what: str, thunk: fn@() -> T) -> T {
108108
ret rv;
109109
}
110110

111+
fn inject_libcore_reference(sess: session::session,
112+
crate: @ast::crate) -> @ast::crate {
113+
114+
fn spanned<copy T>(x: T) -> @ast::spanned<T> {
115+
ret @{node: x,
116+
span: {lo: 0u, hi: 0u,
117+
expanded_from: codemap::os_none}};
118+
}
119+
120+
let n1 = sess.next_node_id();
121+
let n2 = sess.next_node_id();
122+
123+
let vi1 = spanned(ast::view_item_use("core", [], n1));
124+
let vi2 = spanned(ast::view_item_import_glob(@["core"], n2));
125+
126+
let cd1 = spanned(ast::cdir_view_item(vi1));
127+
let cd2 = spanned(ast::cdir_view_item(vi2));
128+
129+
let cdirs = [cd1, cd2] + crate.node.directives;
130+
131+
ret @{node: {directives: cdirs with crate.node} with *crate }
132+
}
133+
134+
111135
fn compile_input(sess: session::session, cfg: ast::crate_cfg, input: str,
112136
output: str) {
113137
let time_passes = sess.get_opts().time_passes;
@@ -126,6 +150,10 @@ fn compile_input(sess: session::session, cfg: ast::crate_cfg, input: str,
126150
time(time_passes, "expansion",
127151
bind syntax::ext::expand::expand_crate(sess, crate));
128152

153+
if sess.get_opts().libcore {
154+
crate = inject_libcore_reference(sess, crate);
155+
}
156+
129157
let ast_map =
130158
time(time_passes, "ast indexing",
131159
bind middle::ast_map::map_crate(*crate));
@@ -257,6 +285,7 @@ options:
257285
-o <filename> write output to <filename>
258286
--lib compile a library crate
259287
--static use or produce static libraries
288+
--no-core omit the 'core' library (used and imported by default)
260289
--pretty [type] pretty-print the input instead of compiling
261290
--ls list the symbols defined by a crate file
262291
-L <path> add a directory to the library search path
@@ -362,6 +391,7 @@ fn build_session_options(match: getopts::match)
362391
} else if opt_present(match, "emit-llvm") {
363392
link::output_type_bitcode
364393
} else { link::output_type_exe };
394+
let libcore = !opt_present(match, "no-core");
365395
let verify = !opt_present(match, "no-verify");
366396
let save_temps = opt_present(match, "save-temps");
367397
let debuginfo = opt_present(match, "g");
@@ -409,6 +439,7 @@ fn build_session_options(match: getopts::match)
409439
let sopts: @session::options =
410440
@{library: library,
411441
static: static,
442+
libcore: libcore,
412443
optimize: opt_level,
413444
debuginfo: debuginfo,
414445
verify: verify,
@@ -465,6 +496,7 @@ fn opts() -> [getopts::opt] {
465496
optflag("time-passes"), optflag("time-llvm-passes"),
466497
optflag("no-verify"),
467498
optmulti("cfg"), optflag("test"),
499+
optflag("no-core"),
468500
optflag("lib"), optflag("static"), optflag("gc"),
469501
optflag("stack-growth"),
470502
optflag("no-asm-comments"),

src/comp/driver/session.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ type options =
2626
// with additional crate configurations during the compile process
2727
{library: bool,
2828
static: bool,
29+
libcore: bool,
2930
optimize: uint,
3031
debuginfo: bool,
3132
verify: bool,

0 commit comments

Comments
 (0)