diff --git a/lib/frontend/Cargo.toml b/lib/frontend/Cargo.toml index 171c158b8e..90f58edc1d 100644 --- a/lib/frontend/Cargo.toml +++ b/lib/frontend/Cargo.toml @@ -13,11 +13,12 @@ readme = "README.md" cranelift-codegen = { path = "../codegen", version = "0.22.0", default-features = false } target-lexicon = { version = "0.0.3", default-features = false } log = { version = "0.4.4", default-features = false, features = ["release_max_level_warn"] } +hashmap_core = { version = "0.1.9", optional = true } [features] default = ["std"] std = ["cranelift-codegen/std"] -core = ["cranelift-codegen/core"] +core = ["hashmap_core", "cranelift-codegen/core"] [badges] maintenance = { status = "experimental" } diff --git a/lib/frontend/src/frontend.rs b/lib/frontend/src/frontend.rs index 98cdc1c753..930466da5b 100644 --- a/lib/frontend/src/frontend.rs +++ b/lib/frontend/src/frontend.rs @@ -653,7 +653,6 @@ impl<'a> FunctionBuilder<'a> { #[cfg(test)] mod tests { - use cranelift_codegen::entity::EntityRef; use cranelift_codegen::ir::types::*; use cranelift_codegen::ir::{AbiParam, ExternalName, Function, InstBuilder, Signature}; @@ -661,6 +660,7 @@ mod tests { use cranelift_codegen::settings::CallConv; use cranelift_codegen::verifier::verify_function; use frontend::{FunctionBuilder, FunctionBuilderContext}; + use std::string::ToString; use Variable; fn sample_function(lazy_seal: bool) { diff --git a/lib/frontend/src/lib.rs b/lib/frontend/src/lib.rs index 1b5eacd939..045705d723 100644 --- a/lib/frontend/src/lib.rs +++ b/lib/frontend/src/lib.rs @@ -176,6 +176,9 @@ #![cfg_attr(not(feature = "std"), no_std)] #![cfg_attr(not(feature = "std"), feature(alloc))] +#[cfg(not(feature = "std"))] +#[macro_use] +extern crate alloc; extern crate cranelift_codegen; #[cfg(test)] extern crate target_lexicon; @@ -191,10 +194,16 @@ mod ssa; mod switch; mod variable; +/// This replaces `std` in builds with `core`. #[cfg(not(feature = "std"))] mod std { - extern crate alloc; - - pub use self::alloc::vec; + pub use alloc::{string, vec}; pub use core::*; + pub mod collections { + #[allow(unused_extern_crates)] + extern crate hashmap_core; + + pub use self::hashmap_core::map as hash_map; + pub use self::hashmap_core::{HashMap, HashSet}; + } } diff --git a/lib/frontend/src/switch.rs b/lib/frontend/src/switch.rs index e86c49bddb..829ae24b7a 100644 --- a/lib/frontend/src/switch.rs +++ b/lib/frontend/src/switch.rs @@ -2,6 +2,7 @@ use cranelift_codegen::ir::condcodes::IntCC; use cranelift_codegen::ir::*; use frontend::FunctionBuilder; use std::collections::HashMap; +use std::vec::Vec; type EntryIndex = u64; @@ -185,6 +186,7 @@ mod tests { use super::*; use cranelift_codegen::ir::Function; use frontend::FunctionBuilderContext; + use std::string::ToString; macro_rules! setup { ($default:expr, [$($index:expr,)*]) => {{