fix(compiler) Make it compile with or without std.

This commit is contained in:
Ivan Enderlin
2020-05-19 09:24:16 +02:00
parent e70ed0303d
commit 63f5cd5302
8 changed files with 25 additions and 20 deletions

View File

@@ -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};

View File

@@ -1,4 +1,4 @@
use crate::std::string::String;
use crate::lib::std::string::String;
use thiserror::Error;
// Compilation Errors

View File

@@ -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")]

View File

@@ -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")]

View File

@@ -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;

View File

@@ -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<u8>);
pub struct SectionBody(#[cfg_attr(feature = "enable-serde", serde(with = "serde_bytes"))] Vec<u8>);
impl SectionBody {
/// Create a new section body with the given contents.

View File

@@ -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 {

View File

@@ -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};