mirror of
https://github.com/mii443/wasmer.git
synced 2025-12-13 05:48:45 +00:00
Improved code based on comments
This commit is contained in:
@@ -26,6 +26,7 @@ pub use crate::types::{
|
||||
MemoryType, Mutability, TableType, Val, ValType,
|
||||
};
|
||||
|
||||
pub use target_lexicon::{Architecture, OperatingSystem, Triple, HOST};
|
||||
pub use wasm_common::{Bytes, Pages, ValueType, WasmExternType, WasmTypeList};
|
||||
#[cfg(feature = "compiler")]
|
||||
pub use wasmer_compiler::CompilerConfig;
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
# Wasmer Native
|
||||
|
||||
The Wasmer Native is usable with any compiler implementation
|
||||
based on `wasmer-compiler`.
|
||||
based on `wasmer-compiler` that is able to emit Position Independent
|
||||
Code (PIC).
|
||||
|
||||
After the compiler process the result, the Native Engine generates
|
||||
a shared object file and links it via `dlsym` so it can be usable by the
|
||||
`wasmer` api.
|
||||
|
||||
@@ -231,7 +231,10 @@ impl NativeEngineInner {
|
||||
if self.compiler.is_none() {
|
||||
return Err(CompileError::Codegen("The NativeEngine is operating in headless mode, so it can only execute already compiled Modules.".to_string()));
|
||||
}
|
||||
Ok(&**self.compiler.as_ref().expect("Can't get compiler reference"))
|
||||
Ok(&**self
|
||||
.compiler
|
||||
.as_ref()
|
||||
.expect("Can't get compiler reference"))
|
||||
}
|
||||
|
||||
/// Validate the module
|
||||
|
||||
@@ -4,6 +4,8 @@
|
||||
//! it generates a shared object file (`.so` or `.dylib` depending on
|
||||
//! the target), saves it temporarily to disk and uses it natively
|
||||
//! via `dlopen` and `dlsym` (using the `libloading` library).
|
||||
//!
|
||||
//! Note: `.dll` generation for Windows is not yet supported
|
||||
|
||||
#![deny(missing_docs, trivial_numeric_casts, unused_extern_crates)]
|
||||
#![warn(unused_import_braces)]
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
|
||||
use crate::engine::{NativeEngine, NativeEngineInner};
|
||||
use crate::serialize::ModuleMetadata;
|
||||
use faerie::{ArtifactBuilder, Decl, Link, Reloc, SectionKind};
|
||||
use faerie::{ArtifactBuilder, ArtifactError, Decl, Link, Reloc, SectionKind};
|
||||
use libloading::{Library, Symbol};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::any::Any;
|
||||
@@ -344,7 +344,6 @@ impl NativeModule {
|
||||
use std::slice::from_raw_parts;
|
||||
|
||||
let mut size = &mut **symbol.deref();
|
||||
// println!("Size {:?}", size.to_vec());
|
||||
let mut readable = &size[..];
|
||||
let metadata_len = leb128::read::unsigned(&mut readable).map_err(|e| {
|
||||
DeserializeError::CorruptedBinary("Can't read metadata size".to_string())
|
||||
|
||||
@@ -35,7 +35,17 @@ impl Compile {
|
||||
.map(|osstr| osstr.to_string_lossy().to_string())
|
||||
.unwrap_or_default();
|
||||
let recommended_extension = match engine_name.as_ref() {
|
||||
"native" => "so",
|
||||
"native" => {
|
||||
// TODO: Match it depending on the `BinaryFormat` instead of the
|
||||
// `OperatingSystem`.
|
||||
let target = self.compiler.get_target()?;
|
||||
match target.triple().operating_system {
|
||||
OperatingSystem::Darwin
|
||||
| OperatingSystem::Ios
|
||||
| OperatingSystem::MacOSX { .. } => "dylib",
|
||||
_ => "so",
|
||||
}
|
||||
}
|
||||
"jit" => "wjit",
|
||||
_ => "?",
|
||||
};
|
||||
|
||||
18
src/store.rs
18
src/store.rs
@@ -101,23 +101,35 @@ impl StoreOptions {
|
||||
}
|
||||
}
|
||||
|
||||
/// Get the Target architecture
|
||||
pub fn get_features(&self) -> Result<Features> {
|
||||
Ok(Features::default())
|
||||
}
|
||||
|
||||
/// Get the Target architecture
|
||||
pub fn get_target(&self) -> Result<Target> {
|
||||
Ok(Target::default())
|
||||
}
|
||||
|
||||
/// Get the Compiler Config for the current options
|
||||
#[allow(unused_variables)]
|
||||
fn get_config(&self, compiler: Compiler) -> Result<Box<dyn CompilerConfig>> {
|
||||
let features = self.get_features()?;
|
||||
let target = self.get_target()?;
|
||||
let config: Box<dyn CompilerConfig> = match compiler {
|
||||
#[cfg(feature = "singlepass")]
|
||||
Compiler::Singlepass => {
|
||||
let config = wasmer_compiler_singlepass::SinglepassConfig::default();
|
||||
let config = wasmer_compiler_singlepass::SinglepassConfig::new(features, target);
|
||||
Box::new(config)
|
||||
}
|
||||
#[cfg(feature = "cranelift")]
|
||||
Compiler::Cranelift => {
|
||||
let config = wasmer_compiler_cranelift::CraneliftConfig::default();
|
||||
let config = wasmer_compiler_cranelift::CraneliftConfig::new(features, target);
|
||||
Box::new(config)
|
||||
}
|
||||
#[cfg(feature = "llvm")]
|
||||
Compiler::LLVM => {
|
||||
let config = wasmer_compiler_llvm::LLVMConfig::default();
|
||||
let config = wasmer_compiler_llvm::LLVMConfig::new(features, target);
|
||||
Box::new(config)
|
||||
}
|
||||
#[cfg(not(all(feature = "singlepass", feature = "cranelift", feature = "llvm",)))]
|
||||
|
||||
Reference in New Issue
Block a user