diff --git a/lib/compiler/src/address_map.rs b/lib/compiler/src/address_map.rs index 538500f83..40d37a073 100644 --- a/lib/compiler/src/address_map.rs +++ b/lib/compiler/src/address_map.rs @@ -1,8 +1,8 @@ //! Data structures to provide transformation of the source // addresses of a WebAssembly module into the native code. +use crate::lib::std::vec::Vec; use crate::sourceloc::SourceLoc; -use crate::std::vec::Vec; #[cfg(feature = "enable-serde")] use serde::{Deserialize, Serialize}; diff --git a/lib/compiler/src/error.rs b/lib/compiler/src/error.rs index c43aac8c4..236c40530 100644 --- a/lib/compiler/src/error.rs +++ b/lib/compiler/src/error.rs @@ -1,4 +1,4 @@ -use crate::std::string::String; +use crate::lib::std::string::String; use thiserror::Error; // Compilation Errors diff --git a/lib/compiler/src/function.rs b/lib/compiler/src/function.rs index 275ba7c4b..45d092537 100644 --- a/lib/compiler/src/function.rs +++ b/lib/compiler/src/function.rs @@ -5,8 +5,8 @@ //! * `jit`: to generate a JIT //! * `obj`: to generate a native object +use crate::lib::std::vec::Vec; use crate::section::{CustomSection, SectionBody, SectionIndex}; -use crate::std::vec::Vec; use crate::trap::TrapInformation; use crate::{CompiledFunctionUnwindInfo, FunctionAddressMap, JumpTableOffsets, Relocation}; #[cfg(feature = "enable-serde")] diff --git a/lib/compiler/src/lib.rs b/lib/compiler/src/lib.rs index 0cbd228ef..2af30d22b 100644 --- a/lib/compiler/src/lib.rs +++ b/lib/compiler/src/lib.rs @@ -8,6 +8,7 @@ #![deny(missing_docs, trivial_numeric_casts, unused_extern_crates)] #![warn(unused_import_braces)] #![cfg_attr(feature = "std", deny(unstable_features))] +#![cfg_attr(not(feature = "std"), no_std)] #![cfg_attr(feature = "clippy", plugin(clippy(conf_file = "../../clippy.toml")))] #![cfg_attr(feature = "cargo-clippy", allow(clippy::new_without_default))] #![cfg_attr( @@ -23,19 +24,22 @@ clippy::use_self ) )] -#![no_std] -#[cfg(not(feature = "std"))] -#[macro_use] -extern crate alloc as std; -#[cfg(feature = "std")] -#[macro_use] -extern crate std; +mod lib { + #[cfg(not(feature = "std"))] + pub mod std { + #[cfg(feature = "core")] + pub use alloc::{boxed, fmt, string, vec}; -#[cfg(not(feature = "std"))] -use hashbrown::HashMap; -#[cfg(feature = "std")] -use std::collections::HashMap; + #[cfg(feature = "core")] + pub use hashbrown as collections; + } + + #[cfg(feature = "std")] + pub mod std { + pub use std::{boxed, collections, fmt, string, vec}; + } +} mod address_map; #[cfg(feature = "translator")] diff --git a/lib/compiler/src/relocation.rs b/lib/compiler/src/relocation.rs index 50e28995a..f781de92d 100644 --- a/lib/compiler/src/relocation.rs +++ b/lib/compiler/src/relocation.rs @@ -9,12 +9,12 @@ //! the generated machine code, so a given frontend (JIT or native) can //! do the corresponding work to run it. +use crate::lib::std::fmt; +use crate::lib::std::vec::Vec; use crate::section::SectionIndex; -use crate::std::vec::Vec; use crate::{Addend, CodeOffset, JumpTable}; #[cfg(feature = "enable-serde")] use serde::{Deserialize, Serialize}; -use std::fmt; use wasm_common::entity::PrimaryMap; use wasm_common::LocalFunctionIndex; use wasmer_runtime::libcalls::LibCall; diff --git a/lib/compiler/src/section.rs b/lib/compiler/src/section.rs index b4e379c23..366cd22dd 100644 --- a/lib/compiler/src/section.rs +++ b/lib/compiler/src/section.rs @@ -5,7 +5,7 @@ //! to emit a custom relocation: `RelocationTarget::CustomSection`, so //! it can be patched later by the engine (native or JIT). -use crate::std::vec::Vec; +use crate::lib::std::vec::Vec; use crate::Relocation; #[cfg(feature = "enable-serde")] use serde::{Deserialize, Serialize}; @@ -56,7 +56,7 @@ pub struct CustomSection { /// The bytes in the section. #[cfg_attr(feature = "enable-serde", derive(Serialize, Deserialize))] #[derive(Debug, Clone, PartialEq, Eq, Default)] -pub struct SectionBody(#[serde(with = "serde_bytes")] Vec); +pub struct SectionBody(#[cfg_attr(feature = "enable-serde", serde(with = "serde_bytes"))] Vec); impl SectionBody { /// Create a new section body with the given contents. diff --git a/lib/compiler/src/sourceloc.rs b/lib/compiler/src/sourceloc.rs index 1888a5e63..3085a87ff 100644 --- a/lib/compiler/src/sourceloc.rs +++ b/lib/compiler/src/sourceloc.rs @@ -4,7 +4,7 @@ //! relative to the WebAssembly module. This is used mainly for debugging //! and tracing errors. -use core::fmt; +use crate::lib::std::fmt; #[cfg(feature = "enable-serde")] use serde::{Deserialize, Serialize}; @@ -19,6 +19,7 @@ use serde::{Deserialize, Serialize}; serde(transparent) )] #[repr(transparent)] +#[derive(Debug, Clone, Copy, PartialEq, Eq)] pub struct SourceLoc(u32); impl SourceLoc { diff --git a/lib/compiler/src/unwind.rs b/lib/compiler/src/unwind.rs index 4ef8ea4b3..292432056 100644 --- a/lib/compiler/src/unwind.rs +++ b/lib/compiler/src/unwind.rs @@ -5,7 +5,7 @@ //! function called that one, and so forth. //! //! More info: https://en.wikipedia.org/wiki/Call_stack -use crate::std::vec::Vec; +use crate::lib::std::vec::Vec; use crate::{Addend, CodeOffset}; #[cfg(feature = "enable-serde")] use serde::{Deserialize, Serialize};