From 331f42362f5146bd2a43cac30860db98b3684257 Mon Sep 17 00:00:00 2001 From: Manos Pitsidianakis Date: Fri, 12 Aug 2022 17:32:32 +0300 Subject: [PATCH 1/3] Makefile: remove unnecessary strip of libwasmer-headless.a --- Makefile | 1 - 1 file changed, 1 deletion(-) diff --git a/Makefile b/Makefile index 7bedf81b62c..a6be323b4d9 100644 --- a/Makefile +++ b/Makefile @@ -639,7 +639,6 @@ package-capi-headless: build-capi-headless fi if [ -f $(TARGET_DIR)/libwasmer.a ]; then \ cp $(TARGET_DIR)/libwasmer.a package/lib/libwasmer-headless.a ;\ - strip package/lib/libwasmer-headless.a ;\ fi package-docs: build-docs build-docs-capi From 70f30e4458287fa9abd139ae6fefe22552daa604 Mon Sep 17 00:00:00 2001 From: Manos Pitsidianakis Date: Fri, 12 Aug 2022 17:32:54 +0300 Subject: [PATCH 2/3] create-exe: Prefer libwasmer-headless when cross-compiling --- lib/cli/src/commands/create_exe.rs | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/lib/cli/src/commands/create_exe.rs b/lib/cli/src/commands/create_exe.rs index b6f6ee33bf3..69b9abb4234 100644 --- a/lib/cli/src/commands/create_exe.rs +++ b/lib/cli/src/commands/create_exe.rs @@ -220,9 +220,21 @@ impl CreateExe { } else { "lib/libwasmer.a" }; + let libwasmer_headless_path = if self + .target_triple + .clone() + .unwrap_or(Triple::host()) + .operating_system + == wasmer_types::OperatingSystem::Windows + { + "lib/wasmer.lib" + } else { + "lib/libwasmer-headless.a" + }; let filename = if let Some(local_tarball) = cross_subc.tarball { let files = untar(local_tarball)?; - files.into_iter().find(|f| f.contains(libwasmer_path)).ok_or_else(|| { + files.clone().into_iter().find(|f| f.contains(libwasmer_headless_path)).or_else(|| + files.into_iter().find(|f| f.contains(libwasmer_path))).ok_or_else(|| { anyhow!("Could not find libwasmer for {} target in the provided tarball path.", target)})? } else { #[cfg(feature = "http")] @@ -230,7 +242,8 @@ impl CreateExe { let release = http_fetch::get_latest_release()?; let tarball = http_fetch::download_release(release, target.clone())?; let files = untar(tarball)?; - files.into_iter().find(|f| f.contains(libwasmer_path)).ok_or_else(|| { + files.clone().into_iter().find(|f| f.contains(libwasmer_headless_path)).or_else(|| + files.into_iter().find(|f| f.contains(libwasmer_path))).ok_or_else(|| { anyhow!("Could not find libwasmer for {} target in the fetched release from Github: you can download it manually and specify its path with the --cross-compilation-library-path LIBRARY_PATH flag.", target)})? } #[cfg(not(feature = "http"))] @@ -456,6 +469,10 @@ impl CreateExe { let mut cmd = Command::new(zig_binary_path); let mut cmd_mut: &mut Command = cmd .arg("cc") + .arg("-w") + .arg("-fgnu-inline-asm") + .arg("-fsanitize=undefined") + .arg("-fsanitize-trap=undefined") .arg("-target") .arg(&zig_triple) .arg(&format!("-L{}", libwasmer_path.display())) From 45d60884c2f5f3b539f8f88aadb4fbcb405f6bfb Mon Sep 17 00:00:00 2001 From: Manos Pitsidianakis Date: Fri, 12 Aug 2022 18:27:54 +0300 Subject: [PATCH 3/3] create-exe: add static artifact load feature to libwasmer headless --- lib/c-api/Cargo.toml | 2 ++ lib/compiler/src/engine/artifact.rs | 37 +++++++++++++++-------------- 2 files changed, 21 insertions(+), 18 deletions(-) diff --git a/lib/c-api/Cargo.toml b/lib/c-api/Cargo.toml index c078c1751ec..d275c0fff82 100644 --- a/lib/c-api/Cargo.toml +++ b/lib/c-api/Cargo.toml @@ -63,6 +63,8 @@ compiler = [ "wasmer-compiler/compiler", ] compiler-headless = [ + "wasmer-artifact-load", + "static-artifact-load", "wasmer-api/compiler", "wasmer-compiler/translator", "wasmer-compiler/compiler", diff --git a/lib/compiler/src/engine/artifact.rs b/lib/compiler/src/engine/artifact.rs index a741577b552..a4a3b029721 100644 --- a/lib/compiler/src/engine/artifact.rs +++ b/lib/compiler/src/engine/artifact.rs @@ -14,9 +14,9 @@ use crate::{ use crate::{Compiler, FunctionBodyData, ModuleTranslationState}; use crate::{Engine, EngineInner}; use enumset::EnumSet; -#[cfg(feature = "static-artifact-create")] +#[cfg(any(feature = "static-artifact-create", feature = "static-artifact-load"))] use std::collections::BTreeMap; -#[cfg(feature = "static-artifact-create")] +#[cfg(any(feature = "static-artifact-create", feature = "static-artifact-load"))] use std::mem; use std::sync::Arc; use std::sync::Mutex; @@ -24,17 +24,18 @@ use std::sync::Mutex; use wasmer_object::{emit_compilation, emit_data, get_object_for_target, Object}; use wasmer_types::entity::{BoxedSlice, PrimaryMap}; use wasmer_types::MetadataHeader; -#[cfg(feature = "static-artifact-create")] +#[cfg(any(feature = "static-artifact-create", feature = "static-artifact-load"))] use wasmer_types::{ compilation::symbols::{ModuleMetadata, ModuleMetadataSymbolRegistry}, entity::EntityRef, - CompileModuleInfo, Target, }; use wasmer_types::{ CompileError, CpuFeature, DataInitializer, DeserializeError, FunctionIndex, LocalFunctionIndex, MemoryIndex, ModuleInfo, OwnedDataInitializer, SerializableModule, SerializeError, SignatureIndex, TableIndex, }; +#[cfg(feature = "static-artifact-create")] +use wasmer_types::{CompileModuleInfo, Target}; use wasmer_vm::{FunctionBodyPtr, MemoryStyle, TableStyle, VMSharedSignatureIndex, VMTrampoline}; use wasmer_vm::{InstanceAllocator, InstanceHandle, StoreObjects, TrapHandlerFn, VMExtern}; @@ -44,7 +45,7 @@ pub enum Artifact { Universal(UniversalArtifact), /// Stores functions etc as symbols and data meant to be stored in object files and /// executables. - #[cfg(feature = "static-artifact-create")] + #[cfg(any(feature = "static-artifact-create", feature = "static-artifact-load"))] Static(StaticArtifact), } @@ -64,7 +65,7 @@ pub type PrefixerFn = Box String + Send>; /// Stores functions etc as symbols and data meant to be stored in object files and /// executables. -#[cfg(feature = "static-artifact-create")] +#[cfg(any(feature = "static-artifact-create", feature = "static-artifact-load"))] pub struct StaticArtifact { metadata: ModuleMetadata, _module_bytes: Vec, @@ -245,7 +246,7 @@ impl ArtifactCreate for Artifact { fn create_module_info(&self) -> ModuleInfo { match self { Self::Universal(UniversalArtifact { artifact, .. }) => artifact.create_module_info(), - #[cfg(feature = "static-artifact-create")] + #[cfg(any(feature = "static-artifact-create", feature = "static-artifact-load"))] Self::Static(StaticArtifact { metadata, .. }) => metadata.compile_info.module.clone(), } } @@ -253,7 +254,7 @@ impl ArtifactCreate for Artifact { fn features(&self) -> &Features { match self { Self::Universal(UniversalArtifact { artifact, .. }) => artifact.features(), - #[cfg(feature = "static-artifact-create")] + #[cfg(any(feature = "static-artifact-create", feature = "static-artifact-load"))] Self::Static(StaticArtifact { metadata, .. }) => &metadata.compile_info.features, } } @@ -261,7 +262,7 @@ impl ArtifactCreate for Artifact { fn cpu_features(&self) -> EnumSet { match self { Self::Universal(_self) => _self.artifact.cpu_features(), - #[cfg(feature = "static-artifact-create")] + #[cfg(any(feature = "static-artifact-create", feature = "static-artifact-load"))] Self::Static(_self) => EnumSet::from_u64(_self.metadata.cpu_features), } } @@ -269,7 +270,7 @@ impl ArtifactCreate for Artifact { fn data_initializers(&self) -> &[OwnedDataInitializer] { match self { Self::Universal(_self) => _self.artifact.data_initializers(), - #[cfg(feature = "static-artifact-create")] + #[cfg(any(feature = "static-artifact-create", feature = "static-artifact-load"))] Self::Static(_self) => &_self.metadata.data_initializers, } } @@ -277,7 +278,7 @@ impl ArtifactCreate for Artifact { fn memory_styles(&self) -> &PrimaryMap { match self { Self::Universal(_self) => _self.artifact.memory_styles(), - #[cfg(feature = "static-artifact-create")] + #[cfg(any(feature = "static-artifact-create", feature = "static-artifact-load"))] Self::Static(_self) => &_self.metadata.compile_info.memory_styles, } } @@ -285,7 +286,7 @@ impl ArtifactCreate for Artifact { fn table_styles(&self) -> &PrimaryMap { match self { Self::Universal(UniversalArtifact { artifact, .. }) => artifact.table_styles(), - #[cfg(feature = "static-artifact-create")] + #[cfg(any(feature = "static-artifact-create", feature = "static-artifact-load"))] Self::Static(StaticArtifact { metadata, .. }) => &metadata.compile_info.table_styles, } } @@ -293,7 +294,7 @@ impl ArtifactCreate for Artifact { fn serialize(&self) -> Result, SerializeError> { match self { Self::Universal(UniversalArtifact { artifact, .. }) => artifact.serialize(), - #[cfg(feature = "static-artifact-create")] + #[cfg(any(feature = "static-artifact-create", feature = "static-artifact-load"))] Self::Static(StaticArtifact { .. }) => todo!(), } } @@ -328,7 +329,7 @@ impl Artifact { frame_infos.clone(), ); } - #[cfg(feature = "static-artifact-create")] + #[cfg(any(feature = "static-artifact-create", feature = "static-artifact-load"))] Self::Static(_self) => { // Do nothing for static artifact } @@ -340,7 +341,7 @@ impl Artifact { pub fn finished_functions(&self) -> &BoxedSlice { match self { Self::Universal(_self) => &_self.finished_functions, - #[cfg(feature = "static-artifact-create")] + #[cfg(any(feature = "static-artifact-create", feature = "static-artifact-load"))] Self::Static(_self) => &_self.finished_functions, } } @@ -350,7 +351,7 @@ impl Artifact { pub fn finished_function_call_trampolines(&self) -> &BoxedSlice { match self { Self::Universal(_self) => &_self.finished_function_call_trampolines, - #[cfg(feature = "static-artifact-create")] + #[cfg(any(feature = "static-artifact-create", feature = "static-artifact-load"))] Self::Static(_self) => &_self.finished_function_call_trampolines, } } @@ -362,7 +363,7 @@ impl Artifact { ) -> &BoxedSlice { match self { Self::Universal(_self) => &_self.finished_dynamic_function_trampolines, - #[cfg(feature = "static-artifact-create")] + #[cfg(any(feature = "static-artifact-create", feature = "static-artifact-load"))] Self::Static(_self) => &_self.finished_dynamic_function_trampolines, } } @@ -371,7 +372,7 @@ impl Artifact { pub fn signatures(&self) -> &BoxedSlice { match self { Self::Universal(_self) => &_self.signatures, - #[cfg(feature = "static-artifact-create")] + #[cfg(any(feature = "static-artifact-create", feature = "static-artifact-load"))] Self::Static(_self) => &_self.signatures, } }