Inject the compiler_builtins crate whenever the core crate is injected

This commit is contained in:
Oliver Schneider 2018-03-30 13:06:34 +02:00
parent ee1014e505
commit 679657b863
No known key found for this signature in database
GPG Key ID: 1D5CB4FC597C3004
18 changed files with 57 additions and 16 deletions

14
src/Cargo.lock generated
View File

@ -10,6 +10,7 @@ dependencies = [
name = "alloc"
version = "0.0.0"
dependencies = [
"compiler_builtins 0.0.0",
"core 0.0.0",
"rand 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)",
"std_unicode 0.0.0",
@ -23,6 +24,7 @@ dependencies = [
"alloc_system 0.0.0",
"build_helper 0.1.0",
"cc 1.0.9 (registry+https://github.com/rust-lang/crates.io-index)",
"compiler_builtins 0.0.0",
"core 0.0.0",
"libc 0.0.0",
]
@ -32,6 +34,7 @@ name = "alloc_system"
version = "0.0.0"
dependencies = [
"alloc 0.0.0",
"compiler_builtins 0.0.0",
"core 0.0.0",
"dlmalloc 0.0.0",
"libc 0.0.0",
@ -541,6 +544,7 @@ name = "dlmalloc"
version = "0.0.0"
dependencies = [
"alloc 0.0.0",
"compiler_builtins 0.0.0",
"core 0.0.0",
]
@ -976,6 +980,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
name = "libc"
version = "0.0.0"
dependencies = [
"compiler_builtins 0.0.0",
"core 0.0.0",
]
@ -1254,6 +1259,7 @@ dependencies = [
name = "panic_abort"
version = "0.0.0"
dependencies = [
"compiler_builtins 0.0.0",
"core 0.0.0",
"libc 0.0.0",
]
@ -1263,6 +1269,7 @@ name = "panic_unwind"
version = "0.0.0"
dependencies = [
"alloc 0.0.0",
"compiler_builtins 0.0.0",
"core 0.0.0",
"libc 0.0.0",
"unwind 0.0.0",
@ -1401,6 +1408,7 @@ name = "profiler_builtins"
version = "0.0.0"
dependencies = [
"cc 1.0.9 (registry+https://github.com/rust-lang/crates.io-index)",
"compiler_builtins 0.0.0",
"core 0.0.0",
]
@ -1797,6 +1805,7 @@ dependencies = [
"alloc_system 0.0.0",
"build_helper 0.1.0",
"cmake 0.1.29 (registry+https://github.com/rust-lang/crates.io-index)",
"compiler_builtins 0.0.0",
"core 0.0.0",
]
@ -1942,6 +1951,7 @@ dependencies = [
"alloc_system 0.0.0",
"build_helper 0.1.0",
"cmake 0.1.29 (registry+https://github.com/rust-lang/crates.io-index)",
"compiler_builtins 0.0.0",
"core 0.0.0",
]
@ -1991,6 +2001,7 @@ dependencies = [
"alloc_system 0.0.0",
"build_helper 0.1.0",
"cmake 0.1.29 (registry+https://github.com/rust-lang/crates.io-index)",
"compiler_builtins 0.0.0",
"core 0.0.0",
]
@ -2130,6 +2141,7 @@ dependencies = [
"alloc_system 0.0.0",
"build_helper 0.1.0",
"cmake 0.1.29 (registry+https://github.com/rust-lang/crates.io-index)",
"compiler_builtins 0.0.0",
"core 0.0.0",
]
@ -2343,6 +2355,7 @@ dependencies = [
name = "std_unicode"
version = "0.0.0"
dependencies = [
"compiler_builtins 0.0.0",
"core 0.0.0",
]
@ -2725,6 +2738,7 @@ dependencies = [
name = "unwind"
version = "0.0.0"
dependencies = [
"compiler_builtins 0.0.0",
"core 0.0.0",
"libc 0.0.0",
]

View File

@ -10,6 +10,7 @@ path = "lib.rs"
[dependencies]
core = { path = "../libcore" }
std_unicode = { path = "../libstd_unicode" }
compiler_builtins = { path = "../rustc/compiler_builtins_shim" }
[dev-dependencies]
rand = "0.4"

View File

@ -16,6 +16,7 @@ alloc = { path = "../liballoc" }
alloc_system = { path = "../liballoc_system" }
core = { path = "../libcore" }
libc = { path = "../rustc/libc_shim" }
compiler_builtins = { path = "../rustc/compiler_builtins_shim" }
[build-dependencies]
build_helper = { path = "../build_helper" }

View File

@ -13,6 +13,7 @@ doc = false
alloc = { path = "../liballoc" }
core = { path = "../libcore" }
libc = { path = "../rustc/libc_shim" }
compiler_builtins = { path = "../rustc/compiler_builtins_shim" }
# See comments in the source for what this dependency is
[target.'cfg(all(target_arch = "wasm32", not(target_os = "emscripten")))'.dependencies]

View File

@ -12,3 +12,4 @@ doc = false
[dependencies]
core = { path = "../libcore" }
libc = { path = "../rustc/libc_shim" }
compiler_builtins = { path = "../rustc/compiler_builtins_shim" }

View File

@ -14,3 +14,4 @@ alloc = { path = "../liballoc" }
core = { path = "../libcore" }
libc = { path = "../rustc/libc_shim" }
unwind = { path = "../libunwind" }
compiler_builtins = { path = "../rustc/compiler_builtins_shim" }

View File

@ -13,6 +13,7 @@ doc = false
[dependencies]
core = { path = "../libcore" }
compiler_builtins = { path = "../rustc/compiler_builtins_shim" }
[build-dependencies]
cc = "1.0.1"

View File

@ -17,3 +17,4 @@ cmake = "0.1.18"
alloc = { path = "../liballoc" }
alloc_system = { path = "../liballoc_system" }
core = { path = "../libcore" }
compiler_builtins = { path = "../rustc/compiler_builtins_shim" }

View File

@ -17,3 +17,4 @@ cmake = "0.1.18"
alloc = { path = "../liballoc" }
alloc_system = { path = "../liballoc_system" }
core = { path = "../libcore" }
compiler_builtins = { path = "../rustc/compiler_builtins_shim" }

View File

@ -17,3 +17,4 @@ cmake = "0.1.18"
alloc = { path = "../liballoc" }
alloc_system = { path = "../liballoc_system" }
core = { path = "../libcore" }
compiler_builtins = { path = "../rustc/compiler_builtins_shim" }

View File

@ -17,3 +17,4 @@ cmake = "0.1.18"
alloc = { path = "../liballoc" }
alloc_system = { path = "../liballoc_system" }
core = { path = "../libcore" }
compiler_builtins = { path = "../rustc/compiler_builtins_shim" }

View File

@ -373,6 +373,7 @@ extern crate unwind;
// compiler-rt intrinsics
#[doc(masked)]
#[cfg(stage0)]
extern crate compiler_builtins;
// During testing, this crate is not actually the "real" std library, but rather

View File

@ -15,3 +15,4 @@ path = "tests/lib.rs"
[dependencies]
core = { path = "../libcore" }
compiler_builtins = { path = "../rustc/compiler_builtins_shim" }

View File

@ -94,7 +94,7 @@ pub fn print_crate<'a>(cm: &'a CodeMap,
is_expanded: bool) -> io::Result<()> {
let mut s = State::new_from_input(cm, sess, filename, input, out, ann, is_expanded);
if is_expanded && !std_inject::injected_crate_name().is_none() {
if is_expanded && std_inject::injected_crate_name().is_some() {
// We need to print `#![no_std]` (and its feature gate) so that
// compiling pretty-printed source won't inject libstd again.
// However we don't want these attributes in the AST because

View File

@ -44,27 +44,38 @@ thread_local! {
}
pub fn maybe_inject_crates_ref(mut krate: ast::Crate, alt_std_name: Option<&str>) -> ast::Crate {
let name = if attr::contains_name(&krate.attrs, "no_core") {
// the first name in this list is the crate name of the crate with the prelude
let names: &[&str] = if attr::contains_name(&krate.attrs, "no_core") {
return krate;
} else if attr::contains_name(&krate.attrs, "no_std") {
"core"
if attr::contains_name(&krate.attrs, "compiler_builtins") {
&["core"]
} else {
&["core", "compiler_builtins"]
}
} else {
"std"
&["std"]
};
INJECTED_CRATE_NAME.with(|opt_name| opt_name.set(Some(name)));
for name in names {
krate.module.items.insert(0, P(ast::Item {
attrs: vec![attr::mk_attr_outer(DUMMY_SP,
attr::mk_attr_id(),
attr::mk_word_item(ast::Ident::from_str("macro_use")))],
vis: dummy_spanned(ast::VisibilityKind::Inherited),
node: ast::ItemKind::ExternCrate(alt_std_name.map(Symbol::intern)),
ident: ast::Ident::from_str(name),
id: ast::DUMMY_NODE_ID,
span: DUMMY_SP,
tokens: None,
}));
}
krate.module.items.insert(0, P(ast::Item {
attrs: vec![attr::mk_attr_outer(DUMMY_SP,
attr::mk_attr_id(),
attr::mk_word_item(ast::Ident::from_str("macro_use")))],
vis: dummy_spanned(ast::VisibilityKind::Inherited),
node: ast::ItemKind::ExternCrate(alt_std_name.map(Symbol::intern)),
ident: ast::Ident::from_str(name),
id: ast::DUMMY_NODE_ID,
span: DUMMY_SP,
tokens: None,
}));
// the crates have been injected, the assumption is that the first one is the one with
// the prelude.
let name = names[0];
INJECTED_CRATE_NAME.with(|opt_name| opt_name.set(Some(name)));
let span = ignored_span(DUMMY_SP);
krate.module.items.insert(0, P(ast::Item {

View File

@ -14,3 +14,4 @@ doc = false
[dependencies]
core = { path = "../libcore" }
libc = { path = "../rustc/libc_shim" }
compiler_builtins = { path = "../rustc/compiler_builtins_shim" }

View File

@ -11,4 +11,5 @@ doc = false
[dependencies]
core = { path = "../../libcore" }
compiler_builtins = { path = "../../rustc/compiler_builtins_shim" }
alloc = { path = "../../liballoc" }

View File

@ -29,6 +29,8 @@ doc = false
#
# See https://github.com/rust-lang/rfcs/pull/1133.
core = { path = "../../libcore" }
compiler_builtins = { path = "../compiler_builtins_shim" }
[features]
# Certain parts of libc are conditionally compiled differently than when used