Skip to content

Commit

Permalink
Inject the compiler_builtins crate whenever the core crate is inj…
Browse files Browse the repository at this point in the history
…ected
  • Loading branch information
oli-obk committed Apr 7, 2018
1 parent ee1014e commit 679657b
Show file tree
Hide file tree
Showing 18 changed files with 57 additions and 16 deletions.
14 changes: 14 additions & 0 deletions src/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions src/liballoc/Cargo.toml
Expand Up @@ -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"
Expand Down
1 change: 1 addition & 0 deletions src/liballoc_jemalloc/Cargo.toml
Expand Up @@ -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" }
Expand Down
1 change: 1 addition & 0 deletions src/liballoc_system/Cargo.toml
Expand Up @@ -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]
Expand Down
1 change: 1 addition & 0 deletions src/libpanic_abort/Cargo.toml
Expand Up @@ -12,3 +12,4 @@ doc = false
[dependencies]
core = { path = "../libcore" }
libc = { path = "../rustc/libc_shim" }
compiler_builtins = { path = "../rustc/compiler_builtins_shim" }
1 change: 1 addition & 0 deletions src/libpanic_unwind/Cargo.toml
Expand Up @@ -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" }
1 change: 1 addition & 0 deletions src/libprofiler_builtins/Cargo.toml
Expand Up @@ -13,6 +13,7 @@ doc = false

[dependencies]
core = { path = "../libcore" }
compiler_builtins = { path = "../rustc/compiler_builtins_shim" }

[build-dependencies]
cc = "1.0.1"
1 change: 1 addition & 0 deletions src/librustc_asan/Cargo.toml
Expand Up @@ -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" }
1 change: 1 addition & 0 deletions src/librustc_lsan/Cargo.toml
Expand Up @@ -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" }
1 change: 1 addition & 0 deletions src/librustc_msan/Cargo.toml
Expand Up @@ -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" }
1 change: 1 addition & 0 deletions src/librustc_tsan/Cargo.toml
Expand Up @@ -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" }
1 change: 1 addition & 0 deletions src/libstd/lib.rs
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions src/libstd_unicode/Cargo.toml
Expand Up @@ -15,3 +15,4 @@ path = "tests/lib.rs"

[dependencies]
core = { path = "../libcore" }
compiler_builtins = { path = "../rustc/compiler_builtins_shim" }
2 changes: 1 addition & 1 deletion src/libsyntax/print/pprust.rs
Expand Up @@ -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
Expand Down
41 changes: 26 additions & 15 deletions src/libsyntax/std_inject.rs
Expand Up @@ -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 {
Expand Down
1 change: 1 addition & 0 deletions src/libunwind/Cargo.toml
Expand Up @@ -14,3 +14,4 @@ doc = false
[dependencies]
core = { path = "../libcore" }
libc = { path = "../rustc/libc_shim" }
compiler_builtins = { path = "../rustc/compiler_builtins_shim" }
1 change: 1 addition & 0 deletions src/rustc/dlmalloc_shim/Cargo.toml
Expand Up @@ -11,4 +11,5 @@ doc = false

[dependencies]
core = { path = "../../libcore" }
compiler_builtins = { path = "../../rustc/compiler_builtins_shim" }
alloc = { path = "../../liballoc" }
2 changes: 2 additions & 0 deletions src/rustc/libc_shim/Cargo.toml
Expand Up @@ -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
Expand Down

0 comments on commit 679657b

Please sign in to comment.