diff --git a/lib/api/src/lib.rs b/lib/api/src/lib.rs index 39146b8ff..390c97485 100644 --- a/lib/api/src/lib.rs +++ b/lib/api/src/lib.rs @@ -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; diff --git a/lib/engine-native/README.md b/lib/engine-native/README.md index 999c2be03..96cb136ad 100644 --- a/lib/engine-native/README.md +++ b/lib/engine-native/README.md @@ -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. diff --git a/lib/engine-native/src/engine.rs b/lib/engine-native/src/engine.rs index 5104f4119..0b92c0c44 100644 --- a/lib/engine-native/src/engine.rs +++ b/lib/engine-native/src/engine.rs @@ -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 diff --git a/lib/engine-native/src/lib.rs b/lib/engine-native/src/lib.rs index b5a4bba48..de94e0f25 100644 --- a/lib/engine-native/src/lib.rs +++ b/lib/engine-native/src/lib.rs @@ -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)] diff --git a/lib/engine-native/src/module.rs b/lib/engine-native/src/module.rs index 78a4654cf..7e47efdb7 100644 --- a/lib/engine-native/src/module.rs +++ b/lib/engine-native/src/module.rs @@ -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()) diff --git a/src/commands/compile.rs b/src/commands/compile.rs index 5dd9f47b4..1753ddfa4 100644 --- a/src/commands/compile.rs +++ b/src/commands/compile.rs @@ -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", _ => "?", }; diff --git a/src/store.rs b/src/store.rs index 84c36a47d..d260b5be9 100644 --- a/src/store.rs +++ b/src/store.rs @@ -101,23 +101,35 @@ impl StoreOptions { } } + /// Get the Target architecture + pub fn get_features(&self) -> Result { + Ok(Features::default()) + } + + /// Get the Target architecture + pub fn get_target(&self) -> Result { + Ok(Target::default()) + } + /// Get the Compiler Config for the current options #[allow(unused_variables)] fn get_config(&self, compiler: Compiler) -> Result> { + let features = self.get_features()?; + let target = self.get_target()?; let config: Box = 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",)))]