Skip to main content

wasmer_compiler/
lib.rs

1//! The `wasmer-compiler` crate provides the necessary abstractions
2//! to create a compiler.
3//!
4//! It provides an universal way of parsing a module via `wasmparser`,
5//! while giving the responsibility of compiling specific function
6//! WebAssembly bodies to the `Compiler` implementation.
7
8#![deny(missing_docs, trivial_numeric_casts, unused_extern_crates)]
9#![warn(unused_import_braces)]
10#![cfg_attr(not(feature = "std"), no_std)]
11#![allow(clippy::new_without_default, clippy::upper_case_acronyms)]
12#![warn(
13    clippy::float_arithmetic,
14    clippy::mut_mut,
15    clippy::nonminimal_bool,
16    clippy::map_unwrap_or,
17    clippy::print_stdout,
18    clippy::unicode_not_nfc,
19    clippy::use_self
20)]
21#![cfg_attr(docsrs, feature(doc_cfg))]
22
23macro_rules! cfg_std_or_core {
24    ($($item:item)*) => {
25        $(
26            #[cfg(any(
27                feature = "std",
28                feature = "core",
29            ))]
30            $item
31        )*
32    };
33}
34
35#[cfg(all(feature = "std", feature = "core"))]
36compile_error!(
37    "The `std` and `core` features are both enabled, which is an error. Please enable only once."
38);
39
40#[cfg(all(not(feature = "std"), not(feature = "core")))]
41compile_error!("Both the `std` and `core` features are disabled. Please enable one of them.");
42
43#[cfg(feature = "core")]
44extern crate alloc;
45
46#[allow(unused_imports)]
47#[cfg(any(feature = "std", feature = "core"))]
48mod lib {
49    #[cfg(feature = "core")]
50    pub mod std {
51        pub use alloc::{borrow, boxed, str, string, sync, vec};
52        pub use core::fmt;
53        pub use hashbrown as collections;
54    }
55
56    #[cfg(feature = "std")]
57    pub mod std {
58        pub use std::{borrow, boxed, collections, fmt, str, string, sync, vec};
59    }
60}
61
62cfg_std_or_core! {
63    mod engine;
64    mod traits;
65
66    pub mod misc;
67    pub mod object;
68    pub mod progress;
69    pub mod serialize;
70    pub mod types;
71
72    pub use crate::engine::*;
73    pub use crate::traits::*;
74
75    mod artifact_builders;
76
77    pub use self::artifact_builders::*;
78}
79
80#[cfg(feature = "compiler")]
81mod compiler;
82#[cfg(feature = "compiler")]
83pub use crate::compiler::{Compiler, CompilerConfig};
84
85#[cfg(feature = "compiler")]
86mod constants;
87#[cfg(feature = "compiler")]
88pub use crate::constants::*;
89
90#[cfg(feature = "translator")]
91#[macro_use]
92mod translator;
93#[cfg(feature = "translator")]
94pub use crate::translator::{
95    FunctionBinaryReader, FunctionBodyData, FunctionMiddleware, MiddlewareBinaryReader,
96    MiddlewareReaderState, ModuleEnvironment, ModuleMiddleware, ModuleMiddlewareChain,
97    ModuleTranslationState, from_binaryreadererror_wasmerror, translate_module, wpheaptype_to_type,
98    wptype_to_type,
99};
100
101pub use wasmer_types::{Addend, CodeOffset, Features};
102
103#[cfg(feature = "translator")]
104/// wasmparser is exported as a module to slim compiler dependencies
105pub use wasmparser;
106
107/// Version number of this crate.
108pub const VERSION: &str = env!("CARGO_PKG_VERSION");