1
Fork 0

rustc: Switch the --no-core switch to a #[no_core] attribute

This commit is contained in:
Brian Anderson 2012-01-26 16:23:34 -08:00
parent 2220d0f20f
commit 28fbb19664
8 changed files with 23 additions and 12 deletions

View file

@ -366,7 +366,6 @@ fn build_session_options(match: getopts::match,
} else if opt_present(match, "emit-llvm") { } else if opt_present(match, "emit-llvm") {
link::output_type_bitcode link::output_type_bitcode
} else { link::output_type_exe }; } else { link::output_type_exe };
let libcore = !opt_present(match, "no-core");
let verify = !opt_present(match, "no-verify"); let verify = !opt_present(match, "no-verify");
let save_temps = opt_present(match, "save-temps"); let save_temps = opt_present(match, "save-temps");
let extra_debuginfo = opt_present(match, "xg"); let extra_debuginfo = opt_present(match, "xg");
@ -414,7 +413,6 @@ fn build_session_options(match: getopts::match,
let sopts: @session::options = let sopts: @session::options =
@{crate_type: crate_type, @{crate_type: crate_type,
static: static, static: static,
libcore: libcore,
optimize: opt_level, optimize: opt_level,
debuginfo: debuginfo, debuginfo: debuginfo,
extra_debuginfo: extra_debuginfo, extra_debuginfo: extra_debuginfo,
@ -494,10 +492,11 @@ fn opts() -> [getopts::opt] {
optflag("no-verify"), optflag("no-verify"),
optflag("no-lint-ctypes"), optflag("no-lint-ctypes"),
optmulti("cfg"), optflag("test"), optmulti("cfg"), optflag("test"),
optflag("no-core"),
optflag("lib"), optflag("bin"), optflag("static"), optflag("gc"), optflag("lib"), optflag("bin"), optflag("static"), optflag("gc"),
optflag("no-asm-comments"), optflag("no-asm-comments"),
optflag("warn-unused-imports")]; optflag("warn-unused-imports"),
// FIXME: Transitional. Please remove
optflag("no-core")];
} }
type output_filenames = @{out_filename: str, obj_filename:str}; type output_filenames = @{out_filename: str, obj_filename:str};

View file

@ -33,7 +33,6 @@ options:
--lib compile a library crate --lib compile a library crate
--bin compile an executable crate (default) --bin compile an executable crate (default)
--static use or produce static libraries --static use or produce static libraries
--no-core omit the 'core' library (used and imported by default)
--pretty [type] pretty-print the input instead of compiling --pretty [type] pretty-print the input instead of compiling
--ls list the symbols defined by a crate file --ls list the symbols defined by a crate file
-L <path> add a directory to the library search path -L <path> add a directory to the library search path

View file

@ -29,7 +29,6 @@ type options =
// with additional crate configurations during the compile process // with additional crate configurations during the compile process
{crate_type: crate_type, {crate_type: crate_type,
static: bool, static: bool,
libcore: bool,
optimize: uint, optimize: uint,
debuginfo: bool, debuginfo: bool,
extra_debuginfo: bool, extra_debuginfo: bool,

View file

@ -9,6 +9,7 @@ export attr_meta;
export attr_metas; export attr_metas;
export find_linkage_metas; export find_linkage_metas;
export find_attrs_by_name; export find_attrs_by_name;
export attrs_contains_name;
export find_meta_items_by_name; export find_meta_items_by_name;
export contains; export contains;
export contains_name; export contains_name;
@ -56,6 +57,10 @@ fn find_attrs_by_name(attrs: [ast::attribute], name: ast::ident) ->
ret vec::filter_map(attrs, filter); ret vec::filter_map(attrs, filter);
} }
fn attrs_contains_name(attrs: [ast::attribute], name: ast::ident) -> bool {
vec::is_not_empty(find_attrs_by_name(attrs, name))
}
fn get_attr_name(attr: ast::attribute) -> ast::ident { fn get_attr_name(attr: ast::attribute) -> ast::ident {
get_meta_item_name(@attr.node.value) get_meta_item_name(@attr.node.value)
} }

View file

@ -1,18 +1,23 @@
import driver::session::session; import driver::session::session;
import syntax::ast;
import syntax::codemap; import syntax::codemap;
import syntax::ast;
import front::attr;
export maybe_inject_libcore_ref; export maybe_inject_libcore_ref;
fn maybe_inject_libcore_ref(sess: session, fn maybe_inject_libcore_ref(sess: session,
crate: @ast::crate) -> @ast::crate { crate: @ast::crate) -> @ast::crate {
if sess.opts.libcore { if use_core(crate) {
inject_libcore_ref(sess, crate) inject_libcore_ref(sess, crate)
} else { } else {
crate crate
} }
} }
fn use_core(crate: @ast::crate) -> bool {
!attr::attrs_contains_name(crate.node.attrs, "no_core")
}
fn inject_libcore_ref(sess: session, fn inject_libcore_ref(sess: session,
crate: @ast::crate) -> @ast::crate { crate: @ast::crate) -> @ast::crate {

View file

@ -7,9 +7,13 @@
#[license = "MIT"]; #[license = "MIT"];
#[crate_type = "lib"]; #[crate_type = "lib"];
// Don't link to core. We are core.
#[no_core];
#[doc( #[doc(
brief = "The Rust core library", brief = "The Rust core library",
desc = " desc = "
The core library provides functionality that is closely tied to the Rust The core library provides functionality that is closely tied to the Rust
built-in types and runtime services, or that is used in nearly every built-in types and runtime services, or that is used in nearly every
non-trivial program. non-trivial program.
@ -20,7 +24,8 @@ as though the user had written the following:
use core; use core;
import core::*; import core::*;
This behavior can be disabled with the `--no-core` compiler flag." This behavior can be disabled with the `no_core` crate attribute."
)]; )];
export box, char, float, bessel, f32, f64, int, str, ptr; export box, char, float, bessel, f32, f64, int, str, ptr;

View file

@ -66,7 +66,6 @@ fn build_session() -> session::session {
let sopts: @session::options = @{ let sopts: @session::options = @{
crate_type: session::lib_crate, crate_type: session::lib_crate,
static: false, static: false,
libcore: false,
optimize: 0u, optimize: 0u,
debuginfo: false, debuginfo: false,
extra_debuginfo: false, extra_debuginfo: false,

View file

@ -1,6 +1,6 @@
// error-pattern: whatever // error-pattern:unresolved name: debug
#[no_core]; #[no_core];
fn main() { fn main() {
log(debug, core::int::max_value); log(debug, 0);
} }