Fix missing no_std support in cretonne-module.

And, tidy up the extern crate declarations in the std replacement modules.
This commit is contained in:
Dan Gohman
2018-06-07 11:26:09 -07:00
parent 750483b9ac
commit b2b20a95a1
6 changed files with 43 additions and 21 deletions

View File

@@ -42,10 +42,6 @@
#![cfg_attr(not(feature = "std"), no_std)] #![cfg_attr(not(feature = "std"), no_std)]
#![cfg_attr(not(feature = "std"), feature(alloc))] #![cfg_attr(not(feature = "std"), feature(alloc))]
// Include the `hashmap_core` crate if std is not available.
#[allow(unused_extern_crates)]
#[cfg(not(feature = "std"))]
extern crate hashmap_core;
#[cfg(not(feature = "std"))] #[cfg(not(feature = "std"))]
#[macro_use] #[macro_use]
extern crate alloc; extern crate alloc;
@@ -119,8 +115,11 @@ mod std {
pub use alloc::{boxed, string, vec}; pub use alloc::{boxed, string, vec};
pub use core::*; pub use core::*;
pub mod collections { 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};
pub use alloc::BTreeSet; pub use alloc::BTreeSet;
pub use hashmap_core::map as hash_map;
pub use hashmap_core::{HashMap, HashSet};
} }
} }

View File

@@ -143,9 +143,6 @@
extern crate cretonne_codegen; extern crate cretonne_codegen;
#[cfg(not(feature = "std"))]
extern crate alloc;
pub use frontend::{FunctionBuilder, FunctionBuilderContext}; pub use frontend::{FunctionBuilder, FunctionBuilderContext};
pub use variable::Variable; pub use variable::Variable;
@@ -155,6 +152,8 @@ mod variable;
#[cfg(not(feature = "std"))] #[cfg(not(feature = "std"))]
mod std { mod std {
pub use alloc::vec; extern crate alloc;
pub use self::alloc::vec;
pub use core::*; pub use core::*;
} }

View File

@@ -3,6 +3,8 @@
use cretonne_codegen::binemit::{Addend, CodeOffset}; use cretonne_codegen::binemit::{Addend, CodeOffset};
use cretonne_codegen::entity::PrimaryMap; use cretonne_codegen::entity::PrimaryMap;
use cretonne_codegen::ir; use cretonne_codegen::ir;
use std::boxed::Box;
use std::vec::Vec;
/// This specifies how data is to be initialized. /// This specifies how data is to be initialized.
#[derive(PartialEq, Eq, Debug)] #[derive(PartialEq, Eq, Debug)]

View File

@@ -1,7 +1,8 @@
//! Top-level lib.rs for `cretonne_module`. //! Top-level lib.rs for `cretonne_module`.
#![deny(missing_docs, trivial_numeric_casts, unused_extern_crates)] #![deny(missing_docs, trivial_numeric_casts, unused_extern_crates)]
#![warn(unused_import_braces, unstable_features)] #![warn(unused_import_braces)]
#![cfg_attr(feature = "std", warn(unstable_features))]
#![cfg_attr(feature = "clippy", plugin(clippy(conf_file = "../../clippy.toml")))] #![cfg_attr(feature = "clippy", plugin(clippy(conf_file = "../../clippy.toml")))]
#![cfg_attr(feature = "cargo-clippy", allow(new_without_default, new_without_default_derive))] #![cfg_attr(feature = "cargo-clippy", allow(new_without_default, new_without_default_derive))]
#![cfg_attr( #![cfg_attr(
@@ -11,6 +12,13 @@
print_stdout, unicode_not_nfc, use_self print_stdout, unicode_not_nfc, use_self
) )
)] )]
// Turns on no_std and alloc features if std is not available.
#![cfg_attr(not(feature = "std"), no_std)]
#![cfg_attr(not(feature = "std"), feature(alloc))]
#[cfg(not(feature = "std"))]
#[cfg_attr(test, macro_use)]
extern crate alloc;
#[macro_use] #[macro_use]
extern crate cretonne_codegen; extern crate cretonne_codegen;
@@ -26,3 +34,17 @@ mod module;
pub use backend::Backend; pub use backend::Backend;
pub use data_context::{DataContext, DataDescription, Init, Writability}; pub use data_context::{DataContext, DataDescription, Init, Writability};
pub use module::{DataId, FuncId, FuncOrDataId, Linkage, Module, ModuleError, ModuleNamespace}; pub use module::{DataId, FuncId, FuncOrDataId, Linkage, Module, ModuleError, ModuleNamespace};
/// This replaces `std` in builds with `core`.
#[cfg(not(feature = "std"))]
mod std {
pub use alloc::{borrow, boxed, 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};
}
}

View File

@@ -9,7 +9,9 @@ use cretonne_codegen::entity::{EntityRef, PrimaryMap};
use cretonne_codegen::result::CtonError; use cretonne_codegen::result::CtonError;
use cretonne_codegen::{binemit, ir, Context}; use cretonne_codegen::{binemit, ir, Context};
use data_context::DataContext; use data_context::DataContext;
use std::borrow::ToOwned;
use std::collections::HashMap; use std::collections::HashMap;
use std::string::String;
use Backend; use Backend;
/// A function identifier for use in the `Module` interface. /// A function identifier for use in the `Module` interface.

View File

@@ -24,13 +24,6 @@
#![cfg_attr(not(feature = "std"), no_std)] #![cfg_attr(not(feature = "std"), no_std)]
#![cfg_attr(not(feature = "std"), feature(alloc))] #![cfg_attr(not(feature = "std"), feature(alloc))]
#[cfg(not(feature = "std"))]
extern crate alloc;
#[allow(unused_extern_crates)]
#[cfg(not(feature = "std"))]
extern crate hashmap_core;
#[macro_use(dbg)] #[macro_use(dbg)]
extern crate cretonne_codegen; extern crate cretonne_codegen;
extern crate cretonne_frontend; extern crate cretonne_frontend;
@@ -58,12 +51,17 @@ pub use translation_utils::{FunctionIndex, Global, GlobalIndex, GlobalInit, Memo
#[cfg(not(feature = "std"))] #[cfg(not(feature = "std"))]
mod std { mod std {
pub use alloc::string; extern crate alloc;
pub use alloc::vec;
pub use self::alloc::string;
pub use self::alloc::vec;
pub use core::fmt; pub use core::fmt;
pub use core::option; pub use core::option;
pub use core::{cmp, i32, str, u32}; pub use core::{cmp, i32, str, u32};
pub mod collections { pub mod collections {
pub use hashmap_core::{map as hash_map, HashMap}; #[allow(unused_extern_crates)]
extern crate hashmap_core;
pub use self::hashmap_core::{map as hash_map, HashMap};
} }
} }