From cf2d30940b059e5f7529d0e2e5e9b59d8bf19879 Mon Sep 17 00:00:00 2001 From: Edoardo Marangoni Date: Wed, 6 Nov 2024 16:42:06 +0100 Subject: [PATCH 01/16] feat: Move "compilation" types from `wasmer_types` to `wasmer_compiler` --- Cargo.lock | 32 +--- Cargo.toml | 12 +- lib/api/src/lib.rs | 11 +- lib/api/src/sys/engine.rs | 4 +- .../wasmer-capi-examples-runner/src/lib.rs | 26 +-- .../tests/wasmer-c-api-test-runner/src/lib.rs | 34 ++-- lib/cli-compiler/Cargo.toml | 45 +++-- lib/cli-compiler/src/commands/compile.rs | 10 +- lib/cli-compiler/src/commands/validate.rs | 6 +- lib/cli-compiler/src/store.rs | 8 +- lib/cli/Cargo.toml | 5 +- lib/cli/src/c_gen/staticlib_header.rs | 3 +- lib/cli/src/commands/create_exe.rs | 34 ++-- lib/cli/src/commands/gen_c_header.rs | 16 +- lib/compiler-cranelift/src/address_map.rs | 6 +- lib/compiler-cranelift/src/compiler.rs | 43 +++-- lib/compiler-cranelift/src/config.rs | 14 +- lib/compiler-cranelift/src/dwarf.rs | 10 +- .../src/trampoline/dynamic_function.rs | 16 +- .../src/trampoline/function_call.rs | 12 +- .../src/translator/translation_utils.rs | 12 +- .../src/translator/unwind.rs | 5 +- lib/compiler-llvm/src/compiler.rs | 20 +- lib/compiler-llvm/src/config.rs | 42 ++--- lib/compiler-llvm/src/object_file.rs | 17 +- lib/compiler-llvm/src/trampoline/wasm.rs | 25 ++- lib/compiler-llvm/src/translator/code.rs | 13 +- lib/compiler-singlepass/src/address_map.rs | 3 +- lib/compiler-singlepass/src/arm64_decl.rs | 10 +- lib/compiler-singlepass/src/codegen.rs | 48 +++-- lib/compiler-singlepass/src/compiler.rs | 12 +- lib/compiler-singlepass/src/config.rs | 7 +- lib/compiler-singlepass/src/dwarf.rs | 15 +- lib/compiler-singlepass/src/emitter_arm64.rs | 20 +- lib/compiler-singlepass/src/emitter_x64.rs | 19 +- lib/compiler-singlepass/src/machine.rs | 32 ++-- lib/compiler-singlepass/src/machine_arm64.rs | 33 ++-- lib/compiler-singlepass/src/machine_x64.rs | 35 ++-- lib/compiler-singlepass/src/unwind.rs | 2 +- lib/compiler-singlepass/src/x64_decl.rs | 3 +- lib/compiler/Cargo.toml | 7 +- .../src/artifact_builders/artifact_builder.rs | 45 ++--- .../src/artifact_builders/trampoline.rs | 10 +- lib/compiler/src/compiler.rs | 20 +- lib/compiler/src/engine/artifact.rs | 84 ++++----- lib/compiler/src/engine/builder.rs | 4 +- lib/compiler/src/engine/code_memory.rs | 11 +- lib/compiler/src/engine/inner.rs | 31 ++-- lib/compiler/src/engine/link.rs | 25 ++- lib/compiler/src/engine/trap/frame_info.rs | 22 +-- lib/compiler/src/engine/tunables.rs | 3 +- lib/compiler/src/engine/unwind/systemv.rs | 2 +- lib/compiler/src/lib.rs | 4 + .../src => compiler/src/object}/error.rs | 0 .../src/lib.rs => compiler/src/object/mod.rs} | 4 +- .../src => compiler/src/object}/module.rs | 25 +-- lib/compiler/src/serialize.rs | 175 ++++++++++++++++++ lib/compiler/src/traits.rs | 3 +- .../src/types}/address_map.rs | 2 +- .../src/types}/function.rs | 24 ++- .../compilation => compiler/src/types}/mod.rs | 0 .../src/types}/module.rs | 5 +- .../src/types}/relocation.rs | 5 +- .../src/types}/section.rs | 2 +- .../src/types}/symbols.rs | 12 +- .../src/types}/target.rs | 2 +- .../src/types}/unwind.rs | 0 lib/object/Cargo.toml | 21 --- lib/object/README.md | 10 - lib/package/src/package/mod.rs | 2 +- lib/package/src/package/volume/fs.rs | 6 +- lib/types/Cargo.toml | 2 +- lib/types/src/lib.rs | 38 +--- lib/types/src/serialize.rs | 171 +---------------- lib/virtual-fs/src/mem_fs/stdio.rs | 18 +- tests/integration/cli/tests/run.rs | 2 +- tests/integration/cli/tests/snapshot.rs | 2 +- 77 files changed, 763 insertions(+), 756 deletions(-) rename lib/{object/src => compiler/src/object}/error.rs (100%) rename lib/{object/src/lib.rs => compiler/src/object/mod.rs} (83%) rename lib/{object/src => compiler/src/object}/module.rs (96%) create mode 100644 lib/compiler/src/serialize.rs rename lib/{types/src/compilation => compiler/src/types}/address_map.rs (98%) rename lib/{types/src/compilation => compiler/src/types}/function.rs (92%) rename lib/{types/src/compilation => compiler/src/types}/mod.rs (100%) rename lib/{types/src/compilation => compiler/src/types}/module.rs (91%) rename lib/{types/src/compilation => compiler/src/types}/relocation.rs (98%) rename lib/{types/src/compilation => compiler/src/types}/section.rs (99%) rename lib/{types/src/compilation => compiler/src/types}/symbols.rs (97%) rename lib/{types/src/compilation => compiler/src/types}/target.rs (99%) rename lib/{types/src/compilation => compiler/src/types}/unwind.rs (100%) delete mode 100644 lib/object/Cargo.toml delete mode 100644 lib/object/README.md diff --git a/Cargo.lock b/Cargo.lock index 7c6adcb591b..c500b9c0e1f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2152,9 +2152,6 @@ name = "hashbrown" version = "0.12.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8a9ee70c43aaf417c914396645a0fa852624801b24ebb7ae78fe8272889ac888" -dependencies = [ - "ahash 0.7.8", -] [[package]] name = "hashbrown" @@ -3252,18 +3249,6 @@ version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "830b246a0e5f20af87141b25c173cd1b609bd7779a4617d6ec582abaf90870f3" -[[package]] -name = "object" -version = "0.29.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "21158b2c33aa6d4561f1c0a6ea283ca92bc54802a93b263e910746d679a7eb53" -dependencies = [ - "crc32fast", - "hashbrown 0.12.3", - "indexmap 1.9.3", - "memchr", -] - [[package]] name = "object" version = "0.30.4" @@ -3280,7 +3265,10 @@ version = "0.32.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a6a622008b6e321afc04970976f62ee297fdbaa6f95318ca343e3eebb9648441" dependencies = [ + "crc32fast", "flate2", + "hashbrown 0.14.5", + "indexmap 2.6.0", "memchr", "ruzstd", ] @@ -6544,7 +6532,6 @@ dependencies = [ "wasmer-compiler-llvm", "wasmer-compiler-singlepass", "wasmer-config", - "wasmer-object", "wasmer-package", "wasmer-types", "wasmer-vm", @@ -6570,6 +6557,7 @@ dependencies = [ "loupe", "memmap2 0.6.2", "more-asserts", + "object 0.32.2", "region", "rkyv", "self_cell", @@ -6577,8 +6565,8 @@ dependencies = [ "serde_bytes", "shared-buffer", "smallvec", + "target-lexicon 0.12.16", "thiserror", - "wasmer-object", "wasmer-types", "wasmer-vm", "wasmparser 0.216.0", @@ -6603,6 +6591,7 @@ dependencies = [ "unix_mode", "wasmer-compiler", "wasmer-compiler-cranelift", + "wasmer-compiler-llvm", "wasmer-compiler-singlepass", "wasmer-types", ] @@ -6798,15 +6787,6 @@ dependencies = [ "wasmer-vm", ] -[[package]] -name = "wasmer-object" -version = "5.0.0" -dependencies = [ - "object 0.29.0", - "thiserror", - "wasmer-types", -] - [[package]] name = "wasmer-package" version = "0.2.0" diff --git a/Cargo.toml b/Cargo.toml index 4edcd59265b..ef1c9aa2740 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -54,7 +54,6 @@ members = [ "lib/compiler", "lib/config", "lib/derive", - "lib/object", "lib/sys-utils", "lib/types", "lib/virtual-io", @@ -121,6 +120,8 @@ socket2 = "0.5.7" pretty_assertions = "1.4.0" base64 = "0.22.0" time = "0.3.36" +target-lexicon = { version = "0.12.2", default-features = false } +object = "0.32.0" [build-dependencies] test-generator = { path = "tests/lib/test-generator" } @@ -158,14 +159,7 @@ reqwest.workspace = true [features] # Don't add the compiler features in default, please add them on the Makefile # since we might want to autoconfigure them depending on the availability on the host. -default = [ - "wat", - "wast", - "cache", - "wasi", - "engine", - "middlewares", -] +default = ["wat", "wast", "cache", "wasi", "engine", "middlewares"] # backend means that the `wasmer` crate will be compiled with the `wasmer-compiler` or the `jsc`. # That means: that is able to execute modules backend = [] diff --git a/lib/api/src/lib.rs b/lib/api/src/lib.rs index ec69685a6d4..ffb83fc1c37 100644 --- a/lib/api/src/lib.rs +++ b/lib/api/src/lib.rs @@ -520,12 +520,13 @@ pub use value::Value; pub use wasmer_derive::ValueType; // TODO: OnCalledAction is needed for asyncify. It will be refactored with https://github.com/wasmerio/wasmer/issues/3451 +pub use wasmer_compiler::types::target::{CpuFeature, Target}; pub use wasmer_types::{ - is_wasm, Bytes, CompileError, CpuFeature, DeserializeError, ExportIndex, ExportType, - ExternType, FrameInfo, FunctionType, GlobalInit, GlobalType, ImportType, LocalFunctionIndex, - MemoryError, MemoryType, MiddlewareError, Mutability, OnCalledAction, Pages, - ParseCpuFeatureError, SerializeError, TableType, Target, Type, ValueType, WasmError, - WasmResult, WASM_MAX_PAGES, WASM_MIN_PAGES, WASM_PAGE_SIZE, + is_wasm, Bytes, CompileError, DeserializeError, ExportIndex, ExportType, ExternType, FrameInfo, + FunctionType, GlobalInit, GlobalType, ImportType, LocalFunctionIndex, MemoryError, MemoryType, + MiddlewareError, Mutability, OnCalledAction, Pages, ParseCpuFeatureError, SerializeError, + TableType, Type, ValueType, WasmError, WasmResult, WASM_MAX_PAGES, WASM_MIN_PAGES, + WASM_PAGE_SIZE, }; #[cfg(feature = "wat")] pub use wat::parse_bytes as wat2wasm; diff --git a/lib/api/src/sys/engine.rs b/lib/api/src/sys/engine.rs index 076bd40153e..de4c5e11eff 100644 --- a/lib/api/src/sys/engine.rs +++ b/lib/api/src/sys/engine.rs @@ -2,11 +2,11 @@ use std::{path::Path, sync::Arc}; use shared_buffer::OwnedBuffer; pub use wasmer_compiler::{ - Artifact, BaseTunables, CompilerConfig, Engine, EngineBuilder, Tunables, + types::target::Target, Artifact, BaseTunables, CompilerConfig, Engine, EngineBuilder, Tunables, }; #[cfg(feature = "compiler")] use wasmer_types::Features; -use wasmer_types::{DeserializeError, HashAlgorithm, Target}; +use wasmer_types::{DeserializeError, HashAlgorithm}; /// Get the default config for the sys Engine #[allow(unreachable_code)] diff --git a/lib/c-api/examples/wasmer-capi-examples-runner/src/lib.rs b/lib/c-api/examples/wasmer-capi-examples-runner/src/lib.rs index ace57150b11..9cf16353964 100644 --- a/lib/c-api/examples/wasmer-capi-examples-runner/src/lib.rs +++ b/lib/c-api/examples/wasmer-capi-examples-runner/src/lib.rs @@ -190,7 +190,7 @@ fn test_run() { for test in TESTS.iter() { let manifest_dir_parent = std::path::Path::new(&manifest_dir); let manifest_dir_parent = manifest_dir_parent.parent().unwrap(); - let c_file_path = manifest_dir_parent.join(&format!("{test}.c")); + let c_file_path = manifest_dir_parent.join(format!("{test}.c")); if target.contains("msvc") { let mut build = cc::Build::new(); @@ -208,10 +208,10 @@ fn test_run() { let compiler = build.try_get_compiler().unwrap(); let mut command = compiler.to_command(); - command.arg(&format!("{}", c_file_path.display())); + command.arg(format!("{}", c_file_path.display())); if !config.wasmer_dir.is_empty() { command.arg("/I"); - command.arg(&format!("{}/include/", config.wasmer_dir)); + command.arg(format!("{}/include/", config.wasmer_dir)); let mut log = String::new(); fixup_symlinks( &[ @@ -225,17 +225,17 @@ fn test_run() { println!("{log}"); } - let exe_outpath = manifest_dir_parent.join(&format!("{test}.exe")); + let exe_outpath = manifest_dir_parent.join(format!("{test}.exe")); let exe_outpath = format!("{}", exe_outpath.display()); println!("compiling exe to {exe_outpath}"); - command.arg(&format!("/Fo:{}/", manifest_dir_parent.display())); + command.arg(format!("/Fo:{}/", manifest_dir_parent.display())); command.arg("/link"); if !config.wasmer_dir.is_empty() { - command.arg(&format!("/LIBPATH:{}/lib", config.wasmer_dir)); - command.arg(&format!("{}/lib/wasmer.dll.lib", config.wasmer_dir)); + command.arg(format!("/LIBPATH:{}/lib", config.wasmer_dir)); + command.arg(format!("{}/lib/wasmer.dll.lib", config.wasmer_dir)); } - command.arg(&format!("/OUT:{exe_outpath}")); + command.arg(format!("/OUT:{exe_outpath}")); // read vcvars into file, append command, then execute the bat @@ -309,7 +309,7 @@ fn test_run() { if !config.wasmer_dir.is_empty() { command.arg("-I"); - command.arg(&format!("{}/include", config.wasmer_dir)); + command.arg(format!("{}/include", config.wasmer_dir)); let mut log = String::new(); fixup_symlinks( &[ @@ -324,12 +324,12 @@ fn test_run() { command.arg(&c_file_path); if !config.wasmer_dir.is_empty() { command.arg("-L"); - command.arg(&format!("{}/lib/", config.wasmer_dir)); + command.arg(format!("{}/lib/", config.wasmer_dir)); command.arg("-lwasmer"); - command.arg(&format!("-Wl,-rpath,{}/lib/", config.wasmer_dir)); + command.arg(format!("-Wl,-rpath,{}/lib/", config.wasmer_dir)); } command.arg("-o"); - command.arg(&format!("{manifest_dir}/../{test}")); + command.arg(format!("{manifest_dir}/../{test}")); // cc -g -IC:/Users/felix/Development/wasmer/lib/c-api/examples/../tests // -IC:/Users/felix/Development/wasmer/package/include @@ -358,7 +358,7 @@ fn test_run() { } // execute - let mut command = std::process::Command::new(&format!("{manifest_dir}/../{test}")); + let mut command = std::process::Command::new(format!("{manifest_dir}/../{test}")); command.env("LD_PRELOAD", &libwasmer_so_path); command.current_dir(&exe_dir); println!("execute: {command:#?}"); diff --git a/lib/c-api/tests/wasmer-c-api-test-runner/src/lib.rs b/lib/c-api/tests/wasmer-c-api-test-runner/src/lib.rs index 5abe14c39ef..f500de27ddc 100644 --- a/lib/c-api/tests/wasmer-c-api-test-runner/src/lib.rs +++ b/lib/c-api/tests/wasmer-c-api-test-runner/src/lib.rs @@ -167,12 +167,12 @@ fn test_ok() { let mut command = compiler.to_command(); - command.arg(&format!("{manifest_dir}/../{test}.c")); + command.arg(format!("{manifest_dir}/../{test}.c")); if !config.wasmer_dir.is_empty() { command.arg("/I"); - command.arg(&format!("{}/wasm-c-api/include/", config.root_dir)); + command.arg(format!("{}/wasm-c-api/include/", config.root_dir)); command.arg("/I"); - command.arg(&format!("{}/include/", config.wasmer_dir)); + command.arg(format!("{}/include/", config.wasmer_dir)); let mut log = String::new(); fixup_symlinks( &[ @@ -188,10 +188,10 @@ fn test_ok() { } command.arg("/link"); if !config.wasmer_dir.is_empty() { - command.arg(&format!("/LIBPATH:{}/lib", config.wasmer_dir)); - command.arg(&format!("{}/lib/wasmer.dll.lib", config.wasmer_dir)); + command.arg(format!("/LIBPATH:{}/lib", config.wasmer_dir)); + command.arg(format!("{}/lib/wasmer.dll.lib", config.wasmer_dir)); } - command.arg(&format!("/OUT:{manifest_dir}/../{test}.exe")); + command.arg(format!("/OUT:{manifest_dir}/../{test}.exe")); println!("compiling {test}: {command:?}"); @@ -212,7 +212,7 @@ fn test_ok() { } // execute - let mut command = std::process::Command::new(&format!("{manifest_dir}/../{test}.exe")); + let mut command = std::process::Command::new(format!("{manifest_dir}/../{test}.exe")); println!("newpath: {}", newpath.clone()); command.env("PATH", newpath.clone()); command.current_dir(exe_dir.clone()); @@ -250,9 +250,9 @@ fn test_ok() { if !config.wasmer_dir.is_empty() { command.arg("-I"); - command.arg(&format!("{}/wasm-c-api/include/", config.root_dir)); + command.arg(format!("{}/wasm-c-api/include/", config.root_dir)); command.arg("-I"); - command.arg(&format!("{}/include/", config.wasmer_dir)); + command.arg(format!("{}/include/", config.wasmer_dir)); let mut log = String::new(); fixup_symlinks( &[ @@ -265,15 +265,15 @@ fn test_ok() { ) .unwrap_or_else(|_| panic!("failed to fix symlinks: {log}")); } - command.arg(&format!("{manifest_dir}/../{test}.c")); + command.arg(format!("{manifest_dir}/../{test}.c")); if !config.wasmer_dir.is_empty() { command.arg("-L"); - command.arg(&format!("{}/lib/", config.wasmer_dir)); + command.arg(format!("{}/lib/", config.wasmer_dir)); command.arg("-lwasmer"); - command.arg(&format!("-Wl,-rpath,{}/lib/", config.wasmer_dir)); + command.arg(format!("-Wl,-rpath,{}/lib/", config.wasmer_dir)); } command.arg("-o"); - command.arg(&format!("{manifest_dir}/../{test}")); + command.arg(format!("{manifest_dir}/../{test}")); // print_wasmer_root_to_stdout(&config); @@ -293,7 +293,7 @@ fn test_ok() { } // execute - let mut command = std::process::Command::new(&format!("{manifest_dir}/../{test}")); + let mut command = std::process::Command::new(format!("{manifest_dir}/../{test}")); command.env("LD_PRELOAD", libwasmer_so_path.clone()); command.current_dir(exe_dir.clone()); println!("execute: {command:#?}"); @@ -310,9 +310,9 @@ fn test_ok() { } for test in CAPI_BASE_TESTS.iter() { - let _ = std::fs::remove_file(&format!("{manifest_dir}/{test}.obj")); - let _ = std::fs::remove_file(&format!("{manifest_dir}/../{test}.exe")); - let _ = std::fs::remove_file(&format!("{manifest_dir}/../{test}")); + let _ = std::fs::remove_file(format!("{manifest_dir}/{test}.obj")); + let _ = std::fs::remove_file(format!("{manifest_dir}/../{test}.exe")); + let _ = std::fs::remove_file(format!("{manifest_dir}/../{test}")); } } diff --git a/lib/cli-compiler/Cargo.toml b/lib/cli-compiler/Cargo.toml index 152dbb21b39..2703f6388db 100644 --- a/lib/cli-compiler/Cargo.toml +++ b/lib/cli-compiler/Cargo.toml @@ -20,7 +20,9 @@ path = "src/bin/wasmer_compiler.rs" doc = false [dependencies] -wasmer-compiler = { version = "=5.0.0", path = "../compiler", features = ["compiler"] } +wasmer-compiler = { version = "=5.0.0", path = "../compiler", features = [ + "compiler", +] } wasmer-types = { version = "=5.0.0", path = "../types" } is-terminal = "0.4.7" colored = "2.0" @@ -37,23 +39,28 @@ target-lexicon = { version = "0.12", features = ["std"] } [target.'cfg(not(target_arch = "wasm32"))'.dependencies] wasmer-compiler-singlepass = { version = "=5.0.0", path = "../compiler-singlepass", optional = true } +wasmer-compiler-llvm = { version = "=5.0.0", path = "../compiler-llvm", optional = true } wasmer-compiler-cranelift = { version = "=5.0.0", path = "../compiler-cranelift", optional = true } clap = { version = "4.4.0", features = ["derive", "env"] } [target.'cfg(target_arch = "wasm32")'.dependencies] -wasmer-compiler-singlepass = { version = "=5.0.0", path = "../compiler-singlepass", optional = true, default-features = false, features = ["wasm"] } -wasmer-compiler-cranelift = { version = "=5.0.0", path = "../compiler-cranelift", optional = true, default-features = false, features = ["wasm"] } +wasmer-compiler-singlepass = { version = "=5.0.0", path = "../compiler-singlepass", optional = true, default-features = false, features = [ + "wasm", +] } +wasmer-compiler-cranelift = { version = "=5.0.0", path = "../compiler-cranelift", optional = true, default-features = false, features = [ + "wasm", +] } # NOTE: Must use different features for clap because the "color" feature does not # work on wasi, due to the anstream dependency not compiling. clap = { version = "4.4.0", default-features = false, features = [ - "std", - "help", - "usage", - "error-context", - "suggestions", - "derive", - "env", -]} + "std", + "help", + "usage", + "error-context", + "suggestions", + "derive", + "env", +] } [target.'cfg(target_os = "linux")'.dependencies] unix_mode = "0.1.3" @@ -63,18 +70,10 @@ unix_mode = "0.1.3" # since we might want to autoconfigure them depending on the availability on the host. default = [] engine = [] -compiler = [ - "wasmer-compiler/translator", - "wasmer-compiler/compiler", -] -singlepass = [ - "wasmer-compiler-singlepass", - "compiler", -] -cranelift = [ - "wasmer-compiler-cranelift", - "compiler", -] +compiler = ["wasmer-compiler/translator", "wasmer-compiler/compiler"] +singlepass = ["wasmer-compiler-singlepass", "compiler"] +cranelift = ["wasmer-compiler-cranelift", "compiler"] +llvm = ["wasmer-compiler-llvm", "compiler"] debug = ["fern", "log"] disable-all-logging = [] jit = [] diff --git a/lib/cli-compiler/src/commands/compile.rs b/lib/cli-compiler/src/commands/compile.rs index 9d7dd9ffbf1..1b4ef927ff3 100644 --- a/lib/cli-compiler/src/commands/compile.rs +++ b/lib/cli-compiler/src/commands/compile.rs @@ -4,12 +4,12 @@ use anyhow::{Context, Result}; use clap::Parser; use std::fs; use std::path::{Path, PathBuf}; -use wasmer_compiler::{ArtifactBuild, ArtifactCreate, ModuleEnvironment}; -use wasmer_types::entity::PrimaryMap; -use wasmer_types::{ - Architecture, CompileError, CpuFeature, MemoryIndex, MemoryStyle, TableIndex, TableStyle, - Target, Triple, +use wasmer_compiler::{ + types::target::{Architecture, CpuFeature, Target, Triple}, + ArtifactBuild, ArtifactCreate, ModuleEnvironment, }; +use wasmer_types::entity::PrimaryMap; +use wasmer_types::{CompileError, MemoryIndex, MemoryStyle, TableIndex, TableStyle}; #[derive(Debug, Parser)] /// The options for the `wasmer compile` subcommand diff --git a/lib/cli-compiler/src/commands/validate.rs b/lib/cli-compiler/src/commands/validate.rs index c3c421f466d..9641fd82d70 100644 --- a/lib/cli-compiler/src/commands/validate.rs +++ b/lib/cli-compiler/src/commands/validate.rs @@ -1,9 +1,9 @@ use crate::store::StoreOptions; use anyhow::{bail, Context, Result}; use clap::Parser; -use std::path::PathBuf; -use std::str::FromStr; -use wasmer_types::{is_wasm, CpuFeature, Target, Triple}; +use std::{path::PathBuf, str::FromStr}; +use wasmer_compiler::types::target::{CpuFeature, Target, Triple}; +use wasmer_types::is_wasm; #[derive(Debug, Parser)] /// The options for the `wasmer validate` subcommand diff --git a/lib/cli-compiler/src/store.rs b/lib/cli-compiler/src/store.rs index 59d2f60fbc5..fcf5201567b 100644 --- a/lib/cli-compiler/src/store.rs +++ b/lib/cli-compiler/src/store.rs @@ -7,9 +7,11 @@ use clap::Parser; use std::string::ToString; #[allow(unused_imports)] use std::sync::Arc; -use wasmer_compiler::EngineBuilder; -use wasmer_compiler::{CompilerConfig, Features}; -use wasmer_types::{MemoryStyle, MemoryType, Pages, PointerWidth, TableStyle, TableType, Target}; +use wasmer_compiler::{ + types::target::{PointerWidth, Target}, + CompilerConfig, EngineBuilder, Features, +}; +use wasmer_types::{MemoryStyle, MemoryType, Pages, TableStyle, TableType}; /// Minimul Subset of Tunable parameters for WebAssembly compilation. #[derive(Clone)] diff --git a/lib/cli/Cargo.toml b/lib/cli/Cargo.toml index 4183b059b0c..be871872675 100644 --- a/lib/cli/Cargo.toml +++ b/lib/cli/Cargo.toml @@ -70,7 +70,6 @@ wasmer-artifact-create = [ "wasmer/wasmer-artifact-create", "wasmer-compiler/wasmer-artifact-load", "wasmer-compiler/wasmer-artifact-create", - "wasmer-object", ] static-artifact-create = [ "compiler", @@ -78,7 +77,6 @@ static-artifact-create = [ "wasmer/static-artifact-create", "wasmer-compiler/static-artifact-load", "wasmer-compiler/static-artifact-create", - "wasmer-object", ] wasmer-artifact-load = [ "compiler", @@ -134,7 +132,6 @@ wasmer-wast = { version = "=5.0.0", path = "../../tests/lib/wast", optional = tr wasmer-types = { version = "=5.0.0", path = "../types", features = [ "enable-serde", ] } -wasmer-object = { version = "=5.0.0", path = "../object", optional = true } virtual-fs = { version = "0.19.0", path = "../virtual-fs", default-features = false, features = [ "host-fs", ] } @@ -188,7 +185,7 @@ log = "0.4.17" semver = "1.0.14" pathdiff = "0.2.1" sha2 = "0.10.6" -object = "0.32.0" +object = { workspace = true } wasm-coredump-builder = { version = "0.1.11", optional = true } tracing = { version = "0.1" } tracing-subscriber = { version = "0.3", features = [ diff --git a/lib/cli/src/c_gen/staticlib_header.rs b/lib/cli/src/c_gen/staticlib_header.rs index 27c10c6a1b3..f2999b6a00e 100644 --- a/lib/cli/src/c_gen/staticlib_header.rs +++ b/lib/cli/src/c_gen/staticlib_header.rs @@ -1,6 +1,7 @@ //! Generate a header file for the static object file produced. -use wasmer_types::{ModuleInfo, Symbol, SymbolRegistry}; +use wasmer_compiler::types::symbols::{Symbol, SymbolRegistry}; +use wasmer_types::ModuleInfo; use super::{generate_c, CStatement, CType}; diff --git a/lib/cli/src/commands/create_exe.rs b/lib/cli/src/commands/create_exe.rs index aef93caba46..4fbd187b0bd 100644 --- a/lib/cli/src/commands/create_exe.rs +++ b/lib/cli/src/commands/create_exe.rs @@ -17,14 +17,14 @@ use std::{ process::{Command, Stdio}, }; use tar::Archive; -use wasmer::sys::Artifact; -use wasmer::*; -use wasmer_object::{emit_serialized, get_object_for_target}; +use wasmer::{sys::Artifact, *}; +use wasmer_compiler::{ + object::{emit_serialized, get_object_for_target}, + types::symbols::ModuleMetadataSymbolRegistry, +}; use wasmer_package::utils::from_disk; -use wasmer_types::{compilation::symbols::ModuleMetadataSymbolRegistry, ModuleInfo}; -use webc::Container; -use webc::PathSegments; -use webc::{Metadata, Volume as WebcVolume}; +use wasmer_types::ModuleInfo; +use webc::{Container, Metadata, PathSegments, Volume as WebcVolume}; const LINK_SYSTEM_LIBRARIES_WINDOWS: &[&str] = &["userenv", "Ws2_32", "advapi32", "bcrypt"]; @@ -1593,7 +1593,7 @@ pub(super) mod utils { use anyhow::{anyhow, Context}; use target_lexicon::{Architecture, Environment, OperatingSystem, Triple}; - use wasmer_types::{CpuFeature, Target}; + use wasmer_compiler::types::target::{self as wasmer_types, CpuFeature, Target}; use crate::config::WasmerEnv; @@ -1835,22 +1835,20 @@ pub(super) mod utils { pub(super) fn triple_to_zig_triple(target_triple: &Triple) -> String { let arch = match target_triple.architecture { - wasmer_types::Architecture::X86_64 => "x86_64".into(), - wasmer_types::Architecture::Aarch64(wasmer_types::Aarch64Architecture::Aarch64) => { - "aarch64".into() - } + Architecture::X86_64 => "x86_64".into(), + Architecture::Aarch64(wasmer_types::Aarch64Architecture::Aarch64) => "aarch64".into(), v => v.to_string(), }; let os = match target_triple.operating_system { - wasmer_types::OperatingSystem::Linux => "linux".into(), - wasmer_types::OperatingSystem::Darwin => "macos".into(), - wasmer_types::OperatingSystem::Windows => "windows".into(), + OperatingSystem::Linux => "linux".into(), + OperatingSystem::Darwin => "macos".into(), + OperatingSystem::Windows => "windows".into(), v => v.to_string(), }; let env = match target_triple.environment { - wasmer_types::Environment::Musl => "musl", - wasmer_types::Environment::Gnu => "gnu", - wasmer_types::Environment::Msvc => "msvc", + Environment::Musl => "musl", + Environment::Gnu => "gnu", + Environment::Msvc => "msvc", _ => "none", }; format!("{}-{}-{}", arch, os, env) diff --git a/lib/cli/src/commands/gen_c_header.rs b/lib/cli/src/commands/gen_c_header.rs index 144ffd84f53..aa523f28517 100644 --- a/lib/cli/src/commands/gen_c_header.rs +++ b/lib/cli/src/commands/gen_c_header.rs @@ -3,14 +3,16 @@ use std::path::PathBuf; use anyhow::{Context, Error}; use bytes::Bytes; use clap::Parser; -use wasmer_compiler::Artifact; -use wasmer_package::package::WasmerPackageError; -use wasmer_package::utils::from_bytes; -use wasmer_types::{ - compilation::symbols::ModuleMetadataSymbolRegistry, CpuFeature, MetadataHeader, Triple, +use wasmer_compiler::{ + types::{ + symbols::ModuleMetadataSymbolRegistry, + target::{CpuFeature, Triple}, + }, + Artifact, }; -use webc::{compat::SharedBytes, DetectError}; -use webc::{Container, ContainerError}; +use wasmer_package::{package::WasmerPackageError, utils::from_bytes}; +use wasmer_types::MetadataHeader; +use webc::{compat::SharedBytes, Container, ContainerError, DetectError}; use crate::store::CompilerOptions; diff --git a/lib/compiler-cranelift/src/address_map.rs b/lib/compiler-cranelift/src/address_map.rs index 41c7d80f879..cdef0523a1d 100644 --- a/lib/compiler-cranelift/src/address_map.rs +++ b/lib/compiler-cranelift/src/address_map.rs @@ -1,10 +1,10 @@ // This file contains code from external sources. // Attributions: https://github.com/wasmerio/wasmer/blob/main/docs/ATTRIBUTIONS.md -use cranelift_codegen::Context; -use cranelift_codegen::MachSrcLoc; +use cranelift_codegen::{Context, MachSrcLoc}; use std::ops::Range; -use wasmer_types::{FunctionAddressMap, InstructionAddressMap, SourceLoc}; +use wasmer_compiler::types::address_map::{FunctionAddressMap, InstructionAddressMap}; +use wasmer_types::SourceLoc; pub fn get_function_address_map( context: &Context, diff --git a/lib/compiler-cranelift/src/compiler.rs b/lib/compiler-cranelift/src/compiler.rs index d32bf998121..f783e80620e 100644 --- a/lib/compiler-cranelift/src/compiler.rs +++ b/lib/compiler-cranelift/src/compiler.rs @@ -1,35 +1,48 @@ //! Support for compiling with Cranelift. -use crate::address_map::get_function_address_map; -use crate::config::Cranelift; #[cfg(feature = "unwind")] use crate::dwarf::WriterRelocate; -use crate::func_environ::{get_function_name, FuncEnvironment}; -use crate::trampoline::{ - make_trampoline_dynamic_function, make_trampoline_function_call, FunctionBuilderContext, + +use crate::{ + address_map::get_function_address_map, + config::Cranelift, + func_environ::{get_function_name, FuncEnvironment}, + trampoline::{ + make_trampoline_dynamic_function, make_trampoline_function_call, FunctionBuilderContext, + }, + translator::{ + compiled_function_unwind_info, irlibcall_to_libcall, irreloc_to_relocationkind, + signature_to_cranelift_ir, CraneliftUnwindInfo, FuncTranslator, + }, }; -use crate::translator::{ - compiled_function_unwind_info, irlibcall_to_libcall, irreloc_to_relocationkind, - signature_to_cranelift_ir, CraneliftUnwindInfo, FuncTranslator, +use cranelift_codegen::{ + ir::{self, ExternalName, UserFuncName}, + Context, FinalizedMachReloc, FinalizedRelocTarget, MachTrap, }; -use cranelift_codegen::ir::{ExternalName, UserFuncName}; -use cranelift_codegen::{ir, FinalizedMachReloc, FinalizedRelocTarget}; -use cranelift_codegen::{Context, MachTrap}; + #[cfg(feature = "unwind")] use gimli::write::{Address, EhFrame, FrameTable}; + #[cfg(feature = "rayon")] use rayon::prelude::{IntoParallelRefIterator, ParallelIterator}; use std::sync::Arc; + use wasmer_compiler::{ + types::{ + function::{Compilation, CompiledFunction, CompiledFunctionFrameInfo, Dwarf, FunctionBody}, + module::CompileModuleInfo, + relocation::{Relocation, RelocationTarget}, + section::SectionIndex, + target::{CallingConvention, Target}, + unwind::CompiledFunctionUnwindInfo, + }, Compiler, FunctionBinaryReader, FunctionBodyData, MiddlewareBinaryReader, ModuleMiddleware, ModuleMiddlewareChain, ModuleTranslationState, }; use wasmer_types::entity::{EntityRef, PrimaryMap}; use wasmer_types::{ - CallingConvention, Compilation, CompileError, CompileModuleInfo, CompiledFunction, - CompiledFunctionFrameInfo, CompiledFunctionUnwindInfo, Dwarf, FunctionBody, FunctionIndex, - LocalFunctionIndex, ModuleInfo, Relocation, RelocationTarget, SectionIndex, SignatureIndex, - Target, TrapCode, TrapInformation, + CompileError, FunctionIndex, LocalFunctionIndex, ModuleInfo, SignatureIndex, TrapCode, + TrapInformation, }; /// A compiler that compiles a WebAssembly module with Cranelift, translating the Wasm to Cranelift IR, diff --git a/lib/compiler-cranelift/src/config.rs b/lib/compiler-cranelift/src/config.rs index 475bf1ad571..b3f5144c248 100644 --- a/lib/compiler-cranelift/src/config.rs +++ b/lib/compiler-cranelift/src/config.rs @@ -1,10 +1,14 @@ use crate::compiler::CraneliftCompiler; -use cranelift_codegen::isa::{lookup, TargetIsa}; -use cranelift_codegen::settings::{self, Configurable}; -use cranelift_codegen::CodegenResult; +use cranelift_codegen::{ + isa::{lookup, TargetIsa}, + settings::{self, Configurable}, + CodegenResult, +}; use std::sync::Arc; -use wasmer_compiler::{Compiler, CompilerConfig, Engine, EngineBuilder, ModuleMiddleware}; -use wasmer_types::{Architecture, CpuFeature, Target}; +use wasmer_compiler::{ + types::target::{Architecture, CpuFeature, Target}, + Compiler, CompilerConfig, Engine, EngineBuilder, ModuleMiddleware, +}; // Runtime Environment diff --git a/lib/compiler-cranelift/src/dwarf.rs b/lib/compiler-cranelift/src/dwarf.rs index 8ab9b0b4b21..50fd10ef8e7 100644 --- a/lib/compiler-cranelift/src/dwarf.rs +++ b/lib/compiler-cranelift/src/dwarf.rs @@ -1,11 +1,11 @@ use gimli::write::{Address, EndianVec, Result, Writer}; use gimli::{RunTimeEndian, SectionId}; -use wasmer_types::entity::EntityRef; -use wasmer_types::LocalFunctionIndex; -use wasmer_types::{ - CustomSection, CustomSectionProtection, Endianness, Relocation, RelocationKind, - RelocationTarget, SectionBody, +use wasmer_compiler::types::{ + relocation::{Relocation, RelocationKind, RelocationTarget}, + section::{CustomSection, CustomSectionProtection, SectionBody}, + target::Endianness, }; +use wasmer_types::{entity::EntityRef, LocalFunctionIndex}; #[derive(Clone, Debug)] pub struct WriterRelocate { diff --git a/lib/compiler-cranelift/src/trampoline/dynamic_function.rs b/lib/compiler-cranelift/src/trampoline/dynamic_function.rs index b8bc84210f1..ead1caa3f96 100644 --- a/lib/compiler-cranelift/src/trampoline/dynamic_function.rs +++ b/lib/compiler-cranelift/src/trampoline/dynamic_function.rs @@ -4,17 +4,15 @@ //! A trampoline generator for calling dynamic host functions from Wasm. use crate::translator::{compiled_function_unwind_info, signature_to_cranelift_ir}; -use cranelift_codegen::ir; -use cranelift_codegen::ir::{ - Function, InstBuilder, MemFlags, StackSlotData, StackSlotKind, UserFuncName, +use cranelift_codegen::{ + ir::{self, Function, InstBuilder, MemFlags, StackSlotData, StackSlotKind, UserFuncName}, + isa::TargetIsa, + Context, }; -use cranelift_codegen::isa::TargetIsa; -use cranelift_codegen::Context; -use std::cmp; -use std::mem; - use cranelift_frontend::{FunctionBuilder, FunctionBuilderContext}; -use wasmer_types::{CompileError, FunctionBody, FunctionType, VMOffsets}; +use std::{cmp, mem}; +use wasmer_compiler::types::function::FunctionBody; +use wasmer_types::{CompileError, FunctionType, VMOffsets}; /// Create a trampoline for invoking a WebAssembly function. pub fn make_trampoline_dynamic_function( diff --git a/lib/compiler-cranelift/src/trampoline/function_call.rs b/lib/compiler-cranelift/src/trampoline/function_call.rs index 7cc2c916e28..ebe874f0b34 100644 --- a/lib/compiler-cranelift/src/trampoline/function_call.rs +++ b/lib/compiler-cranelift/src/trampoline/function_call.rs @@ -9,13 +9,15 @@ //! my_func.call([1, 2]) //! ``` use crate::translator::{compiled_function_unwind_info, signature_to_cranelift_ir}; -use cranelift_codegen::ir; -use cranelift_codegen::ir::InstBuilder; -use cranelift_codegen::isa::TargetIsa; -use cranelift_codegen::Context; +use cranelift_codegen::{ + ir::{self, InstBuilder}, + isa::TargetIsa, + Context, +}; use cranelift_frontend::{FunctionBuilder, FunctionBuilderContext}; use std::mem; -use wasmer_types::{CompileError, FunctionBody, FunctionType}; +use wasmer_compiler::types::function::FunctionBody; +use wasmer_types::{CompileError, FunctionType}; /// Create a trampoline for invoking a WebAssembly function. pub fn make_trampoline_function_call( diff --git a/lib/compiler-cranelift/src/translator/translation_utils.rs b/lib/compiler-cranelift/src/translator/translation_utils.rs index 952b5db800e..19a83f8eb84 100644 --- a/lib/compiler-cranelift/src/translator/translation_utils.rs +++ b/lib/compiler-cranelift/src/translator/translation_utils.rs @@ -2,12 +2,14 @@ use super::func_environ::TargetEnvironment; use crate::std::string::ToString; -use cranelift_codegen::binemit::Reloc; -use cranelift_codegen::ir::{self, AbiParam}; -use cranelift_codegen::isa::TargetFrontendConfig; +use cranelift_codegen::{ + binemit::Reloc, + ir::{self, AbiParam}, + isa::TargetFrontendConfig, +}; use cranelift_frontend::FunctionBuilder; -use wasmer_compiler::wasmparser; -use wasmer_types::{FunctionType, LibCall, RelocationKind, Type, WasmError, WasmResult}; +use wasmer_compiler::{types::relocation::RelocationKind, wasmparser}; +use wasmer_types::{FunctionType, LibCall, Type, WasmError, WasmResult}; /// Helper function translate a Function signature into Cranelift Ir pub fn signature_to_cranelift_ir( diff --git a/lib/compiler-cranelift/src/translator/unwind.rs b/lib/compiler-cranelift/src/translator/unwind.rs index 4de700b2d86..ceddcbd5058 100644 --- a/lib/compiler-cranelift/src/translator/unwind.rs +++ b/lib/compiler-cranelift/src/translator/unwind.rs @@ -3,10 +3,9 @@ #[cfg(feature = "unwind")] use cranelift_codegen::isa::unwind::{systemv::UnwindInfo as DwarfFDE, UnwindInfo}; -use cranelift_codegen::print_errors::pretty_error; -use cranelift_codegen::{isa, Context}; +use cranelift_codegen::{isa, print_errors::pretty_error, Context}; +use wasmer_compiler::types::unwind::CompiledFunctionUnwindInfo; use wasmer_types::CompileError; -use wasmer_types::CompiledFunctionUnwindInfo; /// Cranelift specific unwind info pub(crate) enum CraneliftUnwindInfo { diff --git a/lib/compiler-llvm/src/compiler.rs b/lib/compiler-llvm/src/compiler.rs index 176402c47be..12fd819bdac 100644 --- a/lib/compiler-llvm/src/compiler.rs +++ b/lib/compiler-llvm/src/compiler.rs @@ -10,13 +10,19 @@ use inkwell::DLLStorageClass; use rayon::iter::ParallelBridge; use rayon::prelude::{IntoParallelIterator, IntoParallelRefIterator, ParallelIterator}; use std::sync::Arc; -use wasmer_compiler::{Compiler, FunctionBodyData, ModuleMiddleware, ModuleTranslationState}; -use wasmer_types::entity::{EntityRef, PrimaryMap}; -use wasmer_types::{ - Compilation, CompileError, CompileModuleInfo, CustomSection, CustomSectionProtection, Dwarf, - FunctionIndex, LocalFunctionIndex, RelocationTarget, SectionBody, SectionIndex, SignatureIndex, - Symbol, SymbolRegistry, Target, +use wasmer_compiler::types::function::{Compilation, Dwarf}; +use wasmer_compiler::types::module::CompileModuleInfo; +use wasmer_compiler::{ + types::{ + relocation::RelocationTarget, + section::{CustomSection, CustomSectionProtection, SectionBody, SectionIndex}, + symbols::{Symbol, SymbolRegistry}, + target::Target, + }, + Compiler, FunctionBodyData, ModuleMiddleware, ModuleTranslationState, }; +use wasmer_types::entity::{EntityRef, PrimaryMap}; +use wasmer_types::{CompileError, FunctionIndex, LocalFunctionIndex, SignatureIndex}; //use std::sync::Mutex; @@ -172,7 +178,7 @@ impl LLVMCompiler { let metadata_gv = merged_module.add_global( metadata_init.get_type(), None, - &symbol_registry.symbol_to_name(wasmer_types::Symbol::Metadata), + &symbol_registry.symbol_to_name(wasmer_compiler::types::symbols::Symbol::Metadata), ); metadata_gv.set_initializer(&metadata_init); metadata_gv.set_linkage(Linkage::DLLExport); diff --git a/lib/compiler-llvm/src/config.rs b/lib/compiler-llvm/src/config.rs index 5d76872ec46..a41b09c4a50 100644 --- a/lib/compiler-llvm/src/config.rs +++ b/lib/compiler-llvm/src/config.rs @@ -7,9 +7,11 @@ pub use inkwell::OptimizationLevel as LLVMOptLevel; use itertools::Itertools; use std::fmt::Debug; use std::sync::Arc; -use target_lexicon::Architecture; -use wasmer_compiler::{Compiler, CompilerConfig, Engine, EngineBuilder, ModuleMiddleware}; -use wasmer_types::{FunctionType, LocalFunctionIndex, Target, Triple}; +use wasmer_compiler::{ + types::target::{Architecture, OperatingSystem, Target, Triple}, + Compiler, CompilerConfig, Engine, EngineBuilder, ModuleMiddleware, +}; +use wasmer_types::{FunctionType, LocalFunctionIndex}; /// The InkWell ModuleInfo type pub type InkwellModule<'ctx> = inkwell::module::Module<'ctx>; @@ -106,24 +108,22 @@ impl LLVM { }; // Hack: we're using is_pic to determine whether this is a native // build or not. - let operating_system = if target.triple().operating_system - == wasmer_types::OperatingSystem::Darwin - && !self.is_pic - { - // LLVM detects static relocation + darwin + 64-bit and - // force-enables PIC because MachO doesn't support that - // combination. They don't check whether they're targeting - // MachO, they check whether the OS is set to Darwin. - // - // Since both linux and darwin use SysV ABI, this should work. - // but not in the case of Aarch64, there the ABI is slightly different - #[allow(clippy::match_single_binding)] - match target.triple().architecture { - _ => wasmer_types::OperatingSystem::Linux, - } - } else { - target.triple().operating_system - }; + let operating_system = + if target.triple().operating_system == OperatingSystem::Darwin && !self.is_pic { + // LLVM detects static relocation + darwin + 64-bit and + // force-enables PIC because MachO doesn't support that + // combination. They don't check whether they're targeting + // MachO, they check whether the OS is set to Darwin. + // + // Since both linux and darwin use SysV ABI, this should work. + // but not in the case of Aarch64, there the ABI is slightly different + #[allow(clippy::match_single_binding)] + match target.triple().architecture { + _ => OperatingSystem::Linux, + } + } else { + target.triple().operating_system + }; let binary_format = if self.is_pic { target.triple().binary_format } else { diff --git a/lib/compiler-llvm/src/object_file.rs b/lib/compiler-llvm/src/object_file.rs index 06b196326ed..4dae1f3b4f0 100644 --- a/lib/compiler-llvm/src/object_file.rs +++ b/lib/compiler-llvm/src/object_file.rs @@ -4,12 +4,15 @@ use std::collections::{HashMap, HashSet}; use std::convert::TryInto; use std::num::TryFromIntError; -use wasmer_types::entity::PrimaryMap; -use wasmer_types::{ - CompileError, CompiledFunctionFrameInfo, CustomSection, CustomSectionProtection, - CustomSections, FunctionAddressMap, FunctionBody, InstructionAddressMap, Relocation, - RelocationKind, RelocationTarget, SectionBody, SectionIndex, SourceLoc, +use wasmer_types::{entity::PrimaryMap, CompileError, SourceLoc}; + +use wasmer_compiler::types::{ + address_map::{FunctionAddressMap, InstructionAddressMap}, + function::{CompiledFunctionFrameInfo, CustomSections, FunctionBody}, + relocation::{Relocation, RelocationKind, RelocationTarget}, + section::{CustomSection, CustomSectionProtection, SectionBody, SectionIndex}, }; + use wasmer_vm::libcalls::LibCall; fn map_tryfromint_err(error: TryFromIntError) -> CompileError { @@ -21,7 +24,7 @@ fn map_object_err(error: object::read::Error) -> CompileError { } pub struct CompiledFunction { - pub compiled_function: wasmer_types::CompiledFunction, + pub compiled_function: wasmer_compiler::types::function::CompiledFunction, pub custom_sections: CustomSections, pub eh_frame_section_indices: Vec, } @@ -421,7 +424,7 @@ where }; Ok(CompiledFunction { - compiled_function: wasmer_types::CompiledFunction { + compiled_function: wasmer_compiler::types::function::CompiledFunction { body: function_body, relocations: relocations .remove_entry(&root_section_index) diff --git a/lib/compiler-llvm/src/trampoline/wasm.rs b/lib/compiler-llvm/src/trampoline/wasm.rs index ee614cc8b9d..17c46cebf5f 100644 --- a/lib/compiler-llvm/src/trampoline/wasm.rs +++ b/lib/compiler-llvm/src/trampoline/wasm.rs @@ -1,24 +1,23 @@ -use crate::abi::{get_abi, Abi}; -use crate::config::{CompiledKind, LLVM}; -use crate::error::{err, err_nt}; -use crate::object_file::{load_object_file, CompiledFunction}; -use crate::translator::intrinsics::{type_to_llvm, type_to_llvm_ptr, Intrinsics}; -use inkwell::passes::PassBuilderOptions; -use inkwell::values::BasicMetadataValueEnum; +use crate::{ + abi::{get_abi, Abi}, + config::{CompiledKind, LLVM}, + error::{err, err_nt}, + object_file::{load_object_file, CompiledFunction}, + translator::intrinsics::{type_to_llvm, type_to_llvm_ptr, Intrinsics}, +}; use inkwell::{ attributes::{Attribute, AttributeLoc}, context::Context, module::{Linkage, Module}, + passes::PassBuilderOptions, targets::{FileType, TargetMachine}, types::FunctionType, - values::FunctionValue, + values::{BasicMetadataValueEnum, FunctionValue}, AddressSpace, DLLStorageClass, }; -use std::cmp; -use std::convert::TryInto; -use wasmer_types::{ - CompileError, FunctionBody, FunctionType as FuncType, LocalFunctionIndex, RelocationTarget, -}; +use std::{cmp, convert::TryInto}; +use wasmer_compiler::types::{function::FunctionBody, relocation::RelocationTarget}; +use wasmer_types::{CompileError, FunctionType as FuncType, LocalFunctionIndex}; pub struct FuncTrampoline { ctx: Context, diff --git a/lib/compiler-llvm/src/translator/code.rs b/lib/compiler-llvm/src/translator/code.rs index 2efaab6bded..47fb09a7be8 100644 --- a/lib/compiler-llvm/src/translator/code.rs +++ b/lib/compiler-llvm/src/translator/code.rs @@ -30,15 +30,20 @@ use crate::{ config::{CompiledKind, LLVM}, error::err_nt, }; -use wasmer_compiler::wasmparser::{MemArg, Operator}; use wasmer_compiler::{ - from_binaryreadererror_wasmerror, wpheaptype_to_type, wptype_to_type, FunctionBinaryReader, - FunctionBodyData, MiddlewareBinaryReader, ModuleMiddlewareChain, ModuleTranslationState, + from_binaryreadererror_wasmerror, + types::{ + relocation::RelocationTarget, + symbols::{Symbol, SymbolRegistry}, + }, + wasmparser::{MemArg, Operator}, + wpheaptype_to_type, wptype_to_type, FunctionBinaryReader, FunctionBodyData, + MiddlewareBinaryReader, ModuleMiddlewareChain, ModuleTranslationState, }; use wasmer_types::entity::PrimaryMap; use wasmer_types::{ CompileError, FunctionIndex, FunctionType, GlobalIndex, LocalFunctionIndex, MemoryIndex, - ModuleInfo, RelocationTarget, SignatureIndex, Symbol, SymbolRegistry, TableIndex, Type, + ModuleInfo, SignatureIndex, TableIndex, Type, }; use wasmer_vm::{MemoryStyle, TableStyle, VMOffsets}; diff --git a/lib/compiler-singlepass/src/address_map.rs b/lib/compiler-singlepass/src/address_map.rs index cc4eb6cde54..666000f07b5 100644 --- a/lib/compiler-singlepass/src/address_map.rs +++ b/lib/compiler-singlepass/src/address_map.rs @@ -1,5 +1,6 @@ +use wasmer_compiler::types::address_map::{FunctionAddressMap, InstructionAddressMap}; use wasmer_compiler::FunctionBodyData; -use wasmer_types::{FunctionAddressMap, InstructionAddressMap, SourceLoc}; +use wasmer_types::SourceLoc; pub fn get_function_address_map( instructions: Vec, diff --git a/lib/compiler-singlepass/src/arm64_decl.rs b/lib/compiler-singlepass/src/arm64_decl.rs index 2292d29b935..cd4d94172d8 100644 --- a/lib/compiler-singlepass/src/arm64_decl.rs +++ b/lib/compiler-singlepass/src/arm64_decl.rs @@ -1,11 +1,13 @@ //! ARM64 structures. -use crate::common_decl::{MachineState, MachineValue, RegisterIndex}; -use crate::location::CombinedRegister; -use crate::location::Reg as AbstractReg; +use crate::{ + common_decl::{MachineState, MachineValue, RegisterIndex}, + location::{CombinedRegister, Reg as AbstractReg}, +}; use std::collections::BTreeMap; use std::slice::Iter; -use wasmer_types::{CallingConvention, Type}; +use wasmer_compiler::types::target::CallingConvention; +use wasmer_types::Type; /// General-purpose registers. #[repr(u8)] diff --git a/lib/compiler-singlepass/src/codegen.rs b/lib/compiler-singlepass/src/codegen.rs index 91f3f487404..5141e9c17d9 100644 --- a/lib/compiler-singlepass/src/codegen.rs +++ b/lib/compiler-singlepass/src/codegen.rs @@ -1,31 +1,43 @@ -use crate::address_map::get_function_address_map; -use crate::codegen_error; #[cfg(feature = "unwind")] use crate::dwarf::WriterRelocate; -use crate::location::{Location, Reg}; -use crate::machine::{Label, Machine, MachineStackOffset, NATIVE_PAGE_SIZE}; -use crate::unwind::UnwindFrame; -use crate::{common_decl::*, config::Singlepass}; + +use crate::{ + address_map::get_function_address_map, + codegen_error, + common_decl::*, + config::Singlepass, + location::{Location, Reg}, + machine::{Label, Machine, MachineStackOffset, NATIVE_PAGE_SIZE}, + unwind::UnwindFrame, +}; #[cfg(feature = "unwind")] use gimli::write::Address; use smallvec::{smallvec, SmallVec}; -use std::cmp; -use std::iter; -use wasmer_compiler::wasmparser::{ - BlockType as WpTypeOrFuncType, HeapType as WpHeapType, Operator, RefType as WpRefType, - ValType as WpType, +use std::{cmp, iter}; + +use wasmer_compiler::{ + types::{ + function::{CompiledFunction, CompiledFunctionFrameInfo, FunctionBody}, + relocation::{Relocation, RelocationTarget}, + section::SectionIndex, + target::CallingConvention, + }, + wasmparser::{ + BlockType as WpTypeOrFuncType, HeapType as WpHeapType, Operator, RefType as WpRefType, + ValType as WpType, + }, + FunctionBodyData, }; -use wasmer_compiler::FunctionBodyData; + #[cfg(feature = "unwind")] -use wasmer_types::CompiledFunctionUnwindInfo; +use wasmer_compiler::types::unwind::CompiledFunctionUnwindInfo; + use wasmer_types::{ entity::{EntityRef, PrimaryMap}, - CallingConvention, CompileError, FunctionIndex, FunctionType, GlobalIndex, LocalFunctionIndex, - LocalMemoryIndex, MemoryIndex, MemoryStyle, ModuleInfo, Relocation, RelocationTarget, - SectionIndex, SignatureIndex, TableIndex, TableStyle, TrapCode, Type, VMBuiltinFunctionIndex, - VMOffsets, + CompileError, FunctionIndex, FunctionType, GlobalIndex, LocalFunctionIndex, LocalMemoryIndex, + MemoryIndex, MemoryStyle, ModuleInfo, SignatureIndex, TableIndex, TableStyle, TrapCode, Type, + VMBuiltinFunctionIndex, VMOffsets, }; -use wasmer_types::{CompiledFunction, CompiledFunctionFrameInfo, FunctionBody}; /// The singlepass per-function code generator. pub struct FuncGen<'a, M: Machine> { diff --git a/lib/compiler-singlepass/src/compiler.rs b/lib/compiler-singlepass/src/compiler.rs index 06f9cecf70c..a76a05030a1 100644 --- a/lib/compiler-singlepass/src/compiler.rs +++ b/lib/compiler-singlepass/src/compiler.rs @@ -21,15 +21,19 @@ use gimli::write::{EhFrame, FrameTable}; use rayon::prelude::{IntoParallelIterator, ParallelIterator}; use std::sync::Arc; use wasmer_compiler::{ + types::{ + function::{Compilation, CompiledFunction, Dwarf, FunctionBody}, + module::CompileModuleInfo, + section::SectionIndex, + target::{Architecture, CallingConvention, CpuFeature, OperatingSystem, Target}, + }, Compiler, CompilerConfig, FunctionBinaryReader, FunctionBodyData, MiddlewareBinaryReader, ModuleMiddleware, ModuleMiddlewareChain, ModuleTranslationState, }; use wasmer_types::entity::{EntityRef, PrimaryMap}; use wasmer_types::{ - Architecture, CallingConvention, Compilation, CompileError, CompileModuleInfo, - CompiledFunction, CpuFeature, Dwarf, FunctionBody, FunctionIndex, FunctionType, - LocalFunctionIndex, MemoryIndex, ModuleInfo, OperatingSystem, SectionIndex, TableIndex, Target, - TrapCode, TrapInformation, VMOffsets, + CompileError, FunctionIndex, FunctionType, LocalFunctionIndex, MemoryIndex, ModuleInfo, + TableIndex, TrapCode, TrapInformation, VMOffsets, }; /// A compiler that compiles a WebAssembly module with Singlepass. diff --git a/lib/compiler-singlepass/src/config.rs b/lib/compiler-singlepass/src/config.rs index ea01ebb6dec..18b14ceb2a9 100644 --- a/lib/compiler-singlepass/src/config.rs +++ b/lib/compiler-singlepass/src/config.rs @@ -3,8 +3,11 @@ use crate::compiler::SinglepassCompiler; use std::sync::Arc; -use wasmer_compiler::{Compiler, CompilerConfig, Engine, EngineBuilder, ModuleMiddleware}; -use wasmer_types::{CpuFeature, Features, Target}; +use wasmer_compiler::{ + types::target::{CpuFeature, Target}, + Compiler, CompilerConfig, Engine, EngineBuilder, ModuleMiddleware, +}; +use wasmer_types::Features; #[derive(Debug, Clone)] pub struct Singlepass { diff --git a/lib/compiler-singlepass/src/dwarf.rs b/lib/compiler-singlepass/src/dwarf.rs index 815787b4681..8254b1cea9a 100644 --- a/lib/compiler-singlepass/src/dwarf.rs +++ b/lib/compiler-singlepass/src/dwarf.rs @@ -1,10 +1,13 @@ -use gimli::write::{Address, EndianVec, Result, Writer}; -use gimli::{RunTimeEndian, SectionId}; -use wasmer_types::entity::EntityRef; -use wasmer_types::{ - CustomSection, CustomSectionProtection, Endianness, LocalFunctionIndex, Relocation, - RelocationKind, RelocationTarget, SectionBody, +use gimli::{ + write::{Address, EndianVec, Result, Writer}, + RunTimeEndian, SectionId, }; +use wasmer_compiler::types::{ + relocation::{Relocation, RelocationKind, RelocationTarget}, + section::{CustomSection, CustomSectionProtection, SectionBody}, + target::Endianness, +}; +use wasmer_types::{entity::EntityRef, LocalFunctionIndex}; #[derive(Clone, Debug)] pub struct WriterRelocate { diff --git a/lib/compiler-singlepass/src/emitter_arm64.rs b/lib/compiler-singlepass/src/emitter_arm64.rs index 1716b7ba912..7596a90bf92 100644 --- a/lib/compiler-singlepass/src/emitter_arm64.rs +++ b/lib/compiler-singlepass/src/emitter_arm64.rs @@ -1,19 +1,21 @@ -pub use crate::arm64_decl::{ARM64Register, ArgumentRegisterAllocator, GPR, NEON}; -use crate::codegen_error; -use crate::common_decl::Size; -use crate::location::Location as AbstractLocation; -pub use crate::location::{Multiplier, Reg}; -pub use crate::machine::{Label, Offset}; +pub use crate::{ + arm64_decl::{ARM64Register, ArgumentRegisterAllocator, GPR, NEON}, + location::{Multiplier, Reg}, + machine::{Label, Offset}, +}; +use crate::{codegen_error, common_decl::Size, location::Location as AbstractLocation}; use dynasm::dynasm; pub use dynasmrt::aarch64::{encode_logical_immediate_32bit, encode_logical_immediate_64bit}; use dynasmrt::{ aarch64::Aarch64Relocation, AssemblyOffset, DynamicLabel, DynasmApi, DynasmLabelApi, VecAssembler, }; -use wasmer_types::{ - CallingConvention, CompileError, CustomSection, CustomSectionProtection, FunctionBody, - FunctionIndex, FunctionType, SectionBody, Type, VMOffsets, +use wasmer_compiler::types::{ + function::FunctionBody, + section::{CustomSection, CustomSectionProtection, SectionBody}, + target::CallingConvention, }; +use wasmer_types::{CompileError, FunctionIndex, FunctionType, Type, VMOffsets}; type Assembler = VecAssembler; diff --git a/lib/compiler-singlepass/src/emitter_x64.rs b/lib/compiler-singlepass/src/emitter_x64.rs index a145d8a5547..2393725a478 100644 --- a/lib/compiler-singlepass/src/emitter_x64.rs +++ b/lib/compiler-singlepass/src/emitter_x64.rs @@ -1,13 +1,16 @@ -use crate::codegen_error; -use crate::common_decl::Size; -use crate::location::Location as AbstractLocation; -pub use crate::location::Multiplier; -pub use crate::machine::{Label, Offset}; -use crate::machine_x64::AssemblerX64; -pub use crate::x64_decl::{GPR, XMM}; +use crate::{ + codegen_error, common_decl::Size, location::Location as AbstractLocation, + machine_x64::AssemblerX64, +}; +pub use crate::{ + location::Multiplier, + machine::{Label, Offset}, + x64_decl::{GPR, XMM}, +}; use dynasm::dynasm; use dynasmrt::{AssemblyOffset, DynamicLabel, DynasmApi, DynasmLabelApi}; -use wasmer_types::{CompileError, CpuFeature}; +use wasmer_compiler::types::target::CpuFeature; +use wasmer_types::CompileError; /// Force `dynasm!` to use the correct arch (x64) when cross-compiling. /// `dynasm!` proc-macro tries to auto-detect it by default by looking at the diff --git a/lib/compiler-singlepass/src/machine.rs b/lib/compiler-singlepass/src/machine.rs index e0d6486e586..21ef776920c 100644 --- a/lib/compiler-singlepass/src/machine.rs +++ b/lib/compiler-singlepass/src/machine.rs @@ -1,19 +1,25 @@ -use crate::common_decl::*; -use crate::location::{Location, Reg}; -use crate::machine_arm64::MachineARM64; -use crate::machine_x64::MachineX86_64; -use crate::unwind::UnwindInstructions; +use crate::{ + common_decl::*, + location::{Location, Reg}, + machine_arm64::MachineARM64, + machine_x64::MachineX86_64, + unwind::UnwindInstructions, +}; use dynasmrt::{AssemblyOffset, DynamicLabel}; -use std::collections::BTreeMap; -use std::fmt::Debug; -pub use wasmer_compiler::wasmparser::MemArg; -use wasmer_compiler::wasmparser::ValType as WpType; +use std::{collections::BTreeMap, fmt::Debug}; +use wasmer_compiler::{ + types::{ + address_map::InstructionAddressMap, + function::FunctionBody, + relocation::{Relocation, RelocationTarget}, + section::CustomSection, + target::{Architecture, CallingConvention, Target}, + }, + wasmparser::{MemArg, ValType as WpType}, +}; use wasmer_types::{ - Architecture, CallingConvention, CompileError, CustomSection, FunctionBody, FunctionIndex, - FunctionType, InstructionAddressMap, Relocation, RelocationTarget, Target, TrapCode, - TrapInformation, VMOffsets, + CompileError, FunctionIndex, FunctionType, TrapCode, TrapInformation, VMOffsets, }; - pub type Label = DynamicLabel; pub type Offset = AssemblyOffset; diff --git a/lib/compiler-singlepass/src/machine_arm64.rs b/lib/compiler-singlepass/src/machine_arm64.rs index a5341dd512e..e036f12c4b5 100644 --- a/lib/compiler-singlepass/src/machine_arm64.rs +++ b/lib/compiler-singlepass/src/machine_arm64.rs @@ -2,22 +2,29 @@ use dynasmrt::{aarch64::Aarch64Relocation, VecAssembler}; #[cfg(feature = "unwind")] use gimli::{write::CallFrameInstruction, AArch64}; -use wasmer_compiler::wasmparser::ValType as WpType; +use wasmer_compiler::{ + types::{ + address_map::InstructionAddressMap, + function::FunctionBody, + relocation::{Relocation, RelocationKind, RelocationTarget}, + section::CustomSection, + target::{CallingConvention, CpuFeature, Target}, + }, + wasmparser::{MemArg, ValType as WpType}, +}; use wasmer_types::{ - CallingConvention, CompileError, CpuFeature, CustomSection, FunctionBody, FunctionIndex, - FunctionType, InstructionAddressMap, Relocation, RelocationKind, RelocationTarget, SourceLoc, - Target, TrapCode, TrapInformation, VMOffsets, + CompileError, FunctionIndex, FunctionType, SourceLoc, TrapCode, TrapInformation, VMOffsets, }; -use crate::arm64_decl::new_machine_state; -use crate::arm64_decl::{GPR, NEON}; -use crate::codegen_error; -use crate::common_decl::*; -use crate::emitter_arm64::*; -use crate::location::Location as AbstractLocation; -use crate::location::Reg; -use crate::machine::*; -use crate::unwind::{UnwindInstructions, UnwindOps}; +use crate::{ + arm64_decl::{new_machine_state, GPR, NEON}, + codegen_error, + common_decl::*, + emitter_arm64::*, + location::{Location as AbstractLocation, Reg}, + machine::*, + unwind::{UnwindInstructions, UnwindOps}, +}; type Assembler = VecAssembler; type Location = AbstractLocation; diff --git a/lib/compiler-singlepass/src/machine_x64.rs b/lib/compiler-singlepass/src/machine_x64.rs index f5e8c4d1022..b1266238109 100644 --- a/lib/compiler-singlepass/src/machine_x64.rs +++ b/lib/compiler-singlepass/src/machine_x64.rs @@ -1,25 +1,32 @@ -use crate::codegen_error; -use crate::common_decl::*; -use crate::emitter_x64::*; -use crate::location::Location as AbstractLocation; -use crate::location::Reg; -use crate::machine::*; -use crate::unwind::{UnwindInstructions, UnwindOps}; #[cfg(feature = "unwind")] use crate::unwind_winx64::create_unwind_info_from_insts; -use crate::x64_decl::new_machine_state; -use crate::x64_decl::{ArgumentRegisterAllocator, X64Register, GPR, XMM}; +use crate::{ + codegen_error, + common_decl::*, + emitter_x64::*, + location::{Location as AbstractLocation, Reg}, + machine::*, + unwind::{UnwindInstructions, UnwindOps}, + x64_decl::{new_machine_state, ArgumentRegisterAllocator, X64Register, GPR, XMM}, +}; use dynasmrt::{x64::X64Relocation, DynasmError, VecAssembler}; #[cfg(feature = "unwind")] use gimli::{write::CallFrameInstruction, X86_64}; use std::ops::{Deref, DerefMut}; -use wasmer_compiler::wasmparser::ValType as WpType; +use wasmer_compiler::{ + types::{ + address_map::InstructionAddressMap, + function::FunctionBody, + relocation::{Relocation, RelocationKind, RelocationTarget}, + section::{CustomSection, CustomSectionProtection, SectionBody}, + target::{CallingConvention, CpuFeature, Target}, + }, + wasmparser::{MemArg, ValType as WpType}, +}; use wasmer_types::{ - CallingConvention, CompileError, CpuFeature, CustomSection, CustomSectionProtection, - Relocation, RelocationKind, RelocationTarget, SectionBody, Target, + CompileError, FunctionIndex, FunctionType, SourceLoc, TrapCode, TrapInformation, Type, + VMOffsets, }; -use wasmer_types::{FunctionBody, InstructionAddressMap, SourceLoc, TrapInformation}; -use wasmer_types::{FunctionIndex, FunctionType, TrapCode, Type, VMOffsets}; type Assembler = VecAssembler; diff --git a/lib/compiler-singlepass/src/unwind.rs b/lib/compiler-singlepass/src/unwind.rs index ffda4500a97..2045cdf1721 100644 --- a/lib/compiler-singlepass/src/unwind.rs +++ b/lib/compiler-singlepass/src/unwind.rs @@ -4,7 +4,7 @@ use gimli::write::{Address, CallFrameInstruction, CommonInformationEntry, FrameD use gimli::{AArch64, Encoding, Format, X86_64}; use std::fmt::Debug; #[cfg(feature = "unwind")] -use wasmer_types::Architecture; +use wasmer_compiler::types::target::Architecture; #[derive(Clone, Debug)] pub enum UnwindOps { diff --git a/lib/compiler-singlepass/src/x64_decl.rs b/lib/compiler-singlepass/src/x64_decl.rs index b60ee172400..e39a7fcf731 100644 --- a/lib/compiler-singlepass/src/x64_decl.rs +++ b/lib/compiler-singlepass/src/x64_decl.rs @@ -6,7 +6,8 @@ use crate::location::CombinedRegister; use crate::location::Reg as AbstractReg; use std::collections::BTreeMap; use std::slice::Iter; -use wasmer_types::{CallingConvention, Type}; +use wasmer_compiler::types::target::CallingConvention; +use wasmer_types::Type; /// General-purpose registers. #[repr(u8)] diff --git a/lib/compiler/Cargo.toml b/lib/compiler/Cargo.toml index f8adbb0b87e..97cecd18a6e 100644 --- a/lib/compiler/Cargo.toml +++ b/lib/compiler/Cargo.toml @@ -14,7 +14,6 @@ version.workspace = true [dependencies] wasmer-types = { path = "../types", version = "=5.0.0", default-features = false } -wasmer-object = { path = "../object", version = "=5.0.0", optional = true } wasmparser = { workspace = true, optional = true, default-features = false } enumset.workspace = true hashbrown = { version = "0.11", optional = true } @@ -42,7 +41,9 @@ bytes = "1.0" self_cell = "1.0" rkyv = { workspace = true } shared-buffer = { workspace = true } -libc.workspace = true +libc = { workspace = true } +target-lexicon = { workspace = true } +object = { workspace = true, features = ["write"] } [target.'cfg(not(target_arch = "wasm32"))'.dependencies] wasmer-vm = { path = "../vm", version = "=5.0.0" } @@ -63,7 +64,7 @@ compiler = ["translator"] wasmer-artifact-load = [] wasmer-artifact-create = [] static-artifact-load = [] -static-artifact-create = ["wasmer-object"] +static-artifact-create = [] std = ["wasmer-types/std"] core = ["hashbrown", "wasmer-types/core"] enable-serde = ["serde", "serde_bytes", "wasmer-types/enable-serde"] diff --git a/lib/compiler/src/artifact_builders/artifact_builder.rs b/lib/compiler/src/artifact_builders/artifact_builder.rs index b28c69a3227..3ca3483a580 100644 --- a/lib/compiler/src/artifact_builders/artifact_builder.rs +++ b/lib/compiler/src/artifact_builders/artifact_builder.rs @@ -3,39 +3,40 @@ #[cfg(feature = "compiler")] use super::trampoline::{libcall_trampoline_len, make_libcall_trampolines}; -use crate::ArtifactCreate; -#[cfg(feature = "compiler")] -use crate::EngineInner; -use crate::Features; + #[cfg(feature = "compiler")] -use crate::{ModuleEnvironment, ModuleMiddlewareChain}; +use crate::{ + serialize::SerializableCompilation, types::target::Target, EngineInner, ModuleEnvironment, + ModuleMiddlewareChain, +}; +use crate::{ + serialize::{ + ArchivedSerializableCompilation, ArchivedSerializableModule, MetadataHeader, + SerializableModule, + }, + types::{ + function::{CompiledFunctionFrameInfo, Dwarf, FunctionBody}, + module::CompileModuleInfo, + relocation::Relocation, + section::{CustomSection, SectionIndex}, + target::CpuFeature, + }, + ArtifactCreate, Features, +}; use core::mem::MaybeUninit; use enumset::EnumSet; use rkyv::{option::ArchivedOption, rancor::Error as RkyvError}; use self_cell::self_cell; use shared_buffer::OwnedBuffer; use std::sync::Arc; -use wasmer_types::entity::{ArchivedPrimaryMap, PrimaryMap}; -use wasmer_types::ArchivedOwnedDataInitializer; -use wasmer_types::ArchivedSerializableCompilation; -use wasmer_types::ArchivedSerializableModule; -use wasmer_types::CompileModuleInfo; -use wasmer_types::DeserializeError; - -// Not every compiler backend uses these. -#[allow(unused)] use wasmer_types::{ - CompileError, CpuFeature, CustomSection, Dwarf, FunctionIndex, LocalFunctionIndex, MemoryIndex, - MemoryStyle, ModuleHash, ModuleInfo, OwnedDataInitializer, Relocation, SectionIndex, - SignatureIndex, TableIndex, TableStyle, Target, + entity::{ArchivedPrimaryMap, PrimaryMap}, + DeserializeError, }; +// Not every compiler backend uses these. #[allow(unused)] -use wasmer_types::{ - CompiledFunctionFrameInfo, FunctionBody, HashAlgorithm, SerializableCompilation, - SerializableModule, -}; -use wasmer_types::{MetadataHeader, SerializeError}; +use wasmer_types::*; /// A compiled wasm module, ready to be instantiated. #[cfg_attr(feature = "artifact-size", derive(loupe::MemoryUsage))] diff --git a/lib/compiler/src/artifact_builders/trampoline.rs b/lib/compiler/src/artifact_builders/trampoline.rs index 3fbfa245a9e..3206155e15f 100644 --- a/lib/compiler/src/artifact_builders/trampoline.rs +++ b/lib/compiler/src/artifact_builders/trampoline.rs @@ -4,9 +4,13 @@ //! through normal branch instructions. use enum_iterator::IntoEnumIterator; -use wasmer_types::{ - Architecture, CustomSection, CustomSectionProtection, LibCall, Relocation, RelocationKind, - RelocationTarget, SectionBody, Target, +use target_lexicon::Architecture; +use wasmer_types::LibCall; + +use crate::types::{ + relocation::{Relocation, RelocationKind, RelocationTarget}, + section::{CustomSection, CustomSectionProtection, SectionBody}, + target::Target, }; // SystemV says that both x16 and x17 are available as intra-procedural scratch diff --git a/lib/compiler/src/compiler.rs b/lib/compiler/src/compiler.rs index 3a81a84f9b1..8904f32f91b 100644 --- a/lib/compiler/src/compiler.rs +++ b/lib/compiler/src/compiler.rs @@ -1,19 +1,15 @@ //! This module mainly outputs the `Compiler` trait that custom //! compilers will need to implement. -use crate::lib::std::boxed::Box; -use crate::lib::std::sync::Arc; -use crate::translator::ModuleMiddleware; -use crate::FunctionBodyData; -use crate::ModuleTranslationState; +use crate::types::{module::CompileModuleInfo, symbols::SymbolRegistry, target::Target}; +use crate::{ + lib::std::{boxed::Box, sync::Arc}, + translator::ModuleMiddleware, + types::{function::Compilation, target::CpuFeature}, + FunctionBodyData, ModuleTranslationState, +}; use enumset::EnumSet; -use wasmer_types::compilation::function::Compilation; -use wasmer_types::compilation::module::CompileModuleInfo; -use wasmer_types::compilation::symbols::SymbolRegistry; -use wasmer_types::compilation::target::Target; -use wasmer_types::entity::PrimaryMap; -use wasmer_types::error::CompileError; -use wasmer_types::{CpuFeature, Features, LocalFunctionIndex}; +use wasmer_types::{entity::PrimaryMap, error::CompileError, Features, LocalFunctionIndex}; use wasmparser::{Validator, WasmFeatures}; /// The compiler configuration options. diff --git a/lib/compiler/src/engine/artifact.rs b/lib/compiler/src/engine/artifact.rs index ee5f5679e8e..1d11085b011 100644 --- a/lib/compiler/src/engine/artifact.rs +++ b/lib/compiler/src/engine/artifact.rs @@ -1,48 +1,47 @@ //! Define `Artifact`, based on `ArtifactBuild` //! to allow compiling and instantiating to be done as separate steps. -use crate::engine::link::link_module; -use crate::lib::std::vec::IntoIter; -use crate::ArtifactBuild; -use crate::ArtifactBuildFromArchive; -use crate::ArtifactCreate; -use crate::Features; -use crate::FrameInfosVariant; -use crate::ModuleEnvironment; +use std::sync::{ + atomic::{AtomicUsize, Ordering::SeqCst}, + Arc, +}; + use crate::{ - register_frame_info, resolve_imports, FunctionExtent, GlobalFrameInfoRegistration, - InstantiationError, Tunables, + engine::link::link_module, + lib::std::vec::IntoIter, + register_frame_info, resolve_imports, + serialize::{MetadataHeader, SerializableModule}, + types::target::{CpuFeature, Target}, + ArtifactBuild, ArtifactBuildFromArchive, ArtifactCreate, Engine, EngineInner, Features, + FrameInfosVariant, FunctionExtent, GlobalFrameInfoRegistration, InstantiationError, + ModuleEnvironment, Tunables, }; +#[cfg(any(feature = "static-artifact-create", feature = "static-artifact-load"))] +use crate::{serialize::SerializableCompilation, types::symbols::ModuleMetadata}; #[cfg(feature = "static-artifact-create")] -use crate::{Compiler, FunctionBodyData, ModuleTranslationState}; -use crate::{Engine, EngineInner}; +use crate::{types::module::CompileModuleInfo, Compiler, FunctionBodyData, ModuleTranslationState}; + use enumset::EnumSet; use shared_buffer::OwnedBuffer; + #[cfg(any(feature = "static-artifact-create", feature = "static-artifact-load"))] use std::mem; -use std::sync::atomic::{AtomicUsize, Ordering::SeqCst}; -use std::sync::Arc; -#[cfg(feature = "static-artifact-create")] -use wasmer_object::{emit_compilation, emit_data, get_object_for_target, Object}; -#[cfg(any(feature = "static-artifact-create", feature = "static-artifact-load"))] -use wasmer_types::compilation::symbols::ModuleMetadata; -use wasmer_types::entity::{BoxedSlice, PrimaryMap}; -use wasmer_types::ArchivedDataInitializerLocation; -use wasmer_types::ArchivedOwnedDataInitializer; + #[cfg(feature = "static-artifact-create")] -use wasmer_types::CompileModuleInfo; -use wasmer_types::DataInitializerLike; -use wasmer_types::DataInitializerLocation; -use wasmer_types::DataInitializerLocationLike; -use wasmer_types::MetadataHeader; +use crate::object::{emit_compilation, emit_data, get_object_for_target, Object}; + use wasmer_types::{ - CompileError, CpuFeature, DataInitializer, DeserializeError, FunctionIndex, HashAlgorithm, - LocalFunctionIndex, MemoryIndex, ModuleInfo, OwnedDataInitializer, SignatureIndex, TableIndex, - Target, + entity::{BoxedSlice, PrimaryMap}, + ArchivedDataInitializerLocation, ArchivedOwnedDataInitializer, CompileError, DataInitializer, + DataInitializerLike, DataInitializerLocation, DataInitializerLocationLike, DeserializeError, + FunctionIndex, HashAlgorithm, LocalFunctionIndex, MemoryIndex, ModuleInfo, + OwnedDataInitializer, SerializeError, SignatureIndex, TableIndex, +}; + +use wasmer_vm::{ + FunctionBodyPtr, InstanceAllocator, MemoryStyle, StoreObjects, TableStyle, TrapHandlerFn, + VMConfig, VMExtern, VMInstance, VMSharedSignatureIndex, VMTrampoline, }; -use wasmer_types::{SerializableModule, SerializeError}; -use wasmer_vm::{FunctionBodyPtr, MemoryStyle, TableStyle, VMSharedSignatureIndex, VMTrampoline}; -use wasmer_vm::{InstanceAllocator, StoreObjects, TrapHandlerFn, VMConfig, VMExtern, VMInstance}; #[cfg_attr(feature = "artifact-size", derive(loupe::MemoryUsage))] pub struct AllocatedArtifact { @@ -975,11 +974,11 @@ impl Artifact { ModuleInfo, Object<'data>, usize, - Box, + Box, ), CompileError, > { - use wasmer_types::{compilation::symbols::ModuleMetadataSymbolRegistry, SymbolRegistry}; + use crate::types::symbols::{ModuleMetadataSymbolRegistry, SymbolRegistry}; fn to_compile_error(err: impl std::error::Error) -> CompileError { CompileError::Codegen(format!("{}", err)) @@ -1014,19 +1013,18 @@ impl Artifact { let (_compile_info, symbol_registry) = metadata.split(); - let compilation: wasmer_types::compilation::function::Compilation = compiler - .compile_module( - target, - &metadata.compile_info, - module_translation.as_ref().unwrap(), - function_body_inputs, - )?; + let compilation: crate::types::function::Compilation = compiler.compile_module( + target, + &metadata.compile_info, + module_translation.as_ref().unwrap(), + function_body_inputs, + )?; let mut obj = get_object_for_target(target_triple).map_err(to_compile_error)?; let object_name = ModuleMetadataSymbolRegistry { prefix: metadata_prefix.unwrap_or_default().to_string(), } - .symbol_to_name(wasmer_types::Symbol::Metadata); + .symbol_to_name(crate::types::symbols::Symbol::Metadata); emit_data(&mut obj, object_name.as_bytes(), &metadata_binary, 1) .map_err(to_compile_error)?; @@ -1077,8 +1075,6 @@ impl Artifact { engine: &Engine, bytes: OwnedBuffer, ) -> Result { - use wasmer_types::SerializableCompilation; - let bytes = bytes.as_slice(); let metadata_len = MetadataHeader::parse(bytes)?; let metadata_slice = Self::get_byte_slice(bytes, MetadataHeader::LEN, bytes.len())?; diff --git a/lib/compiler/src/engine/builder.rs b/lib/compiler/src/engine/builder.rs index 5cb356526b5..3ff0d5cdb8a 100644 --- a/lib/compiler/src/engine/builder.rs +++ b/lib/compiler/src/engine/builder.rs @@ -1,6 +1,6 @@ use super::Engine; -use crate::CompilerConfig; -use wasmer_types::{Features, HashAlgorithm, Target}; +use crate::{types::target::Target, CompilerConfig}; +use wasmer_types::{Features, HashAlgorithm}; /// The Builder contents of `Engine` pub struct EngineBuilder { diff --git a/lib/compiler/src/engine/code_memory.rs b/lib/compiler/src/engine/code_memory.rs index 99e413243ed..a4ab625d9db 100644 --- a/lib/compiler/src/engine/code_memory.rs +++ b/lib/compiler/src/engine/code_memory.rs @@ -3,10 +3,13 @@ //! Memory management for executable code. use super::unwind::UnwindRegistry; -use crate::GlobalFrameInfoRegistration; -use wasmer_types::{ - compilation::unwind::CompiledFunctionUnwindInfoLike, CompiledFunctionUnwindInfoReference, - CustomSectionLike, FunctionBodyLike, +use crate::{ + types::{ + function::FunctionBodyLike, + section::CustomSectionLike, + unwind::{CompiledFunctionUnwindInfoLike, CompiledFunctionUnwindInfoReference}, + }, + GlobalFrameInfoRegistration, }; use wasmer_vm::{Mmap, VMFunctionBody}; diff --git a/lib/compiler/src/engine/inner.rs b/lib/compiler/src/engine/inner.rs index d7528f41f73..df9d58e9541 100644 --- a/lib/compiler/src/engine/inner.rs +++ b/lib/compiler/src/engine/inner.rs @@ -1,33 +1,32 @@ //! Universal compilation. -use crate::engine::builder::EngineBuilder; +use crate::{engine::builder::EngineBuilder, types::target::Target}; #[cfg(not(target_arch = "wasm32"))] -use crate::Artifact; -#[cfg(not(target_arch = "wasm32"))] -use crate::BaseTunables; -#[cfg(not(target_arch = "wasm32"))] -use crate::CodeMemory; -#[cfg(not(target_arch = "wasm32"))] -use crate::GlobalFrameInfoRegistration; +use crate::{ + types::{ + function::FunctionBodyLike, + section::{CustomSectionLike, CustomSectionProtection, SectionIndex}, + }, + Artifact, BaseTunables, CodeMemory, FunctionExtent, GlobalFrameInfoRegistration, Tunables, +}; #[cfg(feature = "compiler")] use crate::{Compiler, CompilerConfig}; -#[cfg(not(target_arch = "wasm32"))] -use crate::{FunctionExtent, Tunables}; + #[cfg(not(target_arch = "wasm32"))] use shared_buffer::OwnedBuffer; + #[cfg(not(target_arch = "wasm32"))] use std::path::Path; use std::sync::atomic::{AtomicUsize, Ordering::SeqCst}; use std::sync::{Arc, Mutex}; -use wasmer_types::HashAlgorithm; + #[cfg(not(target_arch = "wasm32"))] use wasmer_types::{ - entity::PrimaryMap, DeserializeError, FunctionBodyLike, FunctionIndex, FunctionType, - LocalFunctionIndex, SignatureIndex, + entity::PrimaryMap, DeserializeError, FunctionIndex, FunctionType, LocalFunctionIndex, + SignatureIndex, }; -use wasmer_types::{CompileError, Features, ModuleInfo, Target}; -#[cfg(not(target_arch = "wasm32"))] -use wasmer_types::{CustomSectionLike, CustomSectionProtection, SectionIndex}; +use wasmer_types::{CompileError, Features, HashAlgorithm, ModuleInfo}; + #[cfg(not(target_arch = "wasm32"))] use wasmer_vm::{ FunctionBodyPtr, SectionBodyPtr, SignatureRegistry, VMFunctionBody, VMSharedSignatureIndex, diff --git a/lib/compiler/src/engine/link.rs b/lib/compiler/src/engine/link.rs index a3fc64dd2da..e14f70b641b 100644 --- a/lib/compiler/src/engine/link.rs +++ b/lib/compiler/src/engine/link.rs @@ -1,15 +1,20 @@ //! Linking for Universal-compiled code. -use crate::get_libcall_trampoline; -use crate::FunctionExtent; -use std::collections::HashMap; -use std::ptr::{read_unaligned, write_unaligned}; -use wasmer_types::entity::PrimaryMap; -use wasmer_types::RelocationLike; -use wasmer_types::{LocalFunctionIndex, ModuleInfo}; -use wasmer_types::{RelocationKind, RelocationTarget, SectionIndex}; -use wasmer_vm::libcalls::function_pointer; -use wasmer_vm::SectionBodyPtr; +use crate::{ + get_libcall_trampoline, + types::{ + relocation::{RelocationKind, RelocationLike, RelocationTarget}, + section::SectionIndex, + }, + FunctionExtent, +}; +use std::{ + collections::HashMap, + ptr::{read_unaligned, write_unaligned}, +}; + +use wasmer_types::{entity::PrimaryMap, LocalFunctionIndex, ModuleInfo}; +use wasmer_vm::{libcalls::function_pointer, SectionBodyPtr}; fn apply_relocation( body: usize, diff --git a/lib/compiler/src/engine/trap/frame_info.rs b/lib/compiler/src/engine/trap/frame_info.rs index c411339b206..9b4799aefcf 100644 --- a/lib/compiler/src/engine/trap/frame_info.rs +++ b/lib/compiler/src/engine/trap/frame_info.rs @@ -11,24 +11,23 @@ //! let module: ModuleInfo = ...; //! FRAME_INFO.register(module, compiled_functions); //! ``` -use core::ops::Deref; + +use crate::types::address_map::{ + ArchivedFunctionAddressMap, ArchivedInstructionAddressMap, FunctionAddressMap, + InstructionAddressMap, +}; +use crate::types::function::{ArchivedCompiledFunctionFrameInfo, CompiledFunctionFrameInfo}; +use crate::ArtifactBuildFromArchive; use rkyv::vec::ArchivedVec; -use std::cmp; use std::collections::BTreeMap; use std::sync::{Arc, RwLock}; -use wasmer_types::compilation::address_map::{ - ArchivedFunctionAddressMap, ArchivedInstructionAddressMap, -}; -use wasmer_types::compilation::function::ArchivedCompiledFunctionFrameInfo; -use wasmer_types::entity::{BoxedSlice, EntityRef, PrimaryMap}; +use wasmer_types::lib::std::{cmp, ops::Deref}; use wasmer_types::{ - CompiledFunctionFrameInfo, FrameInfo, FunctionAddressMap, InstructionAddressMap, - LocalFunctionIndex, ModuleInfo, SourceLoc, TrapInformation, + entity::{BoxedSlice, EntityRef, PrimaryMap}, + FrameInfo, LocalFunctionIndex, ModuleInfo, SourceLoc, TrapInformation, }; use wasmer_vm::FunctionBodyPtr; -use crate::ArtifactBuildFromArchive; - lazy_static::lazy_static! { /// This is a global cache of backtrace frame information for all active /// @@ -259,6 +258,7 @@ pub enum VecTrapInformationVariant<'a> { Owned(Vec), } +// We need to implement it for the `Deref` in `wasmer_types` to support both `core` and `std`. impl Deref for VecTrapInformationVariant<'_> { type Target = [TrapInformation]; diff --git a/lib/compiler/src/engine/tunables.rs b/lib/compiler/src/engine/tunables.rs index 266c3bdaf87..0c617fcb558 100644 --- a/lib/compiler/src/engine/tunables.rs +++ b/lib/compiler/src/engine/tunables.rs @@ -1,9 +1,10 @@ use crate::engine::error::LinkError; +use crate::types::target::{PointerWidth, Target}; use std::ptr::NonNull; use wasmer_types::entity::{EntityRef, PrimaryMap}; use wasmer_types::{ GlobalType, LocalGlobalIndex, LocalMemoryIndex, LocalTableIndex, MemoryIndex, MemoryType, - ModuleInfo, Pages, PointerWidth, TableIndex, TableType, Target, + ModuleInfo, Pages, TableIndex, TableType, }; use wasmer_vm::{InternalStoreHandle, MemoryError, StoreObjects}; use wasmer_vm::{MemoryStyle, TableStyle}; diff --git a/lib/compiler/src/engine/unwind/systemv.rs b/lib/compiler/src/engine/unwind/systemv.rs index 3b0f06a5ce8..545c71aa6a8 100644 --- a/lib/compiler/src/engine/unwind/systemv.rs +++ b/lib/compiler/src/engine/unwind/systemv.rs @@ -5,7 +5,7 @@ use core::sync::atomic::{AtomicUsize, Ordering::Relaxed}; -use wasmer_types::CompiledFunctionUnwindInfoReference; +use crate::types::unwind::CompiledFunctionUnwindInfoReference; /// Represents a registry of function unwind information for System V ABI. pub struct UnwindRegistry { diff --git a/lib/compiler/src/lib.rs b/lib/compiler/src/lib.rs index 0afb9514354..533c6704c0a 100644 --- a/lib/compiler/src/lib.rs +++ b/lib/compiler/src/lib.rs @@ -49,6 +49,10 @@ mod lib { mod engine; mod traits; +pub mod serialize; +pub mod types; +pub mod object; + pub use crate::engine::*; pub use crate::traits::*; diff --git a/lib/object/src/error.rs b/lib/compiler/src/object/error.rs similarity index 100% rename from lib/object/src/error.rs rename to lib/compiler/src/object/error.rs diff --git a/lib/object/src/lib.rs b/lib/compiler/src/object/mod.rs similarity index 83% rename from lib/object/src/lib.rs rename to lib/compiler/src/object/mod.rs index 946101e966e..fffb85f7f3c 100644 --- a/lib/object/src/lib.rs +++ b/lib/compiler/src/object/mod.rs @@ -20,6 +20,6 @@ mod error; mod module; -pub use crate::error::ObjectError; -pub use crate::module::{emit_compilation, emit_data, emit_serialized, get_object_for_target}; +pub use self::error::ObjectError; +pub use self::module::{emit_compilation, emit_data, emit_serialized, get_object_for_target}; pub use object::{self, write::Object}; diff --git a/lib/object/src/module.rs b/lib/compiler/src/object/module.rs similarity index 96% rename from lib/object/src/module.rs rename to lib/compiler/src/object/module.rs index af1017b13b7..1b340160878 100644 --- a/lib/object/src/module.rs +++ b/lib/compiler/src/object/module.rs @@ -1,18 +1,21 @@ -use crate::error::ObjectError; -use object::write::{ - Object, Relocation, StandardSection, StandardSegment, Symbol as ObjSymbol, SymbolSection, +use super::error::ObjectError; +use crate::types::{ + function::Compilation, + relocation::{RelocationKind as Reloc, RelocationTarget}, + section::{CustomSectionProtection, SectionIndex}, + symbols::{Symbol, SymbolRegistry}, + target::{Architecture, BinaryFormat, Endianness, Triple}, }; use object::{ - elf, macho, FileFlags, RelocationEncoding, RelocationKind, SectionKind, SymbolFlags, - SymbolKind, SymbolScope, + elf, macho, + write::{ + Object, Relocation, StandardSection, StandardSegment, Symbol as ObjSymbol, SymbolSection, + }, + FileFlags, RelocationEncoding, RelocationKind, SectionKind, SymbolFlags, SymbolKind, + SymbolScope, }; use wasmer_types::entity::PrimaryMap; use wasmer_types::LocalFunctionIndex; -use wasmer_types::{ - Architecture, BinaryFormat, Compilation, CustomSectionProtection, Endianness, - RelocationKind as Reloc, RelocationTarget, SectionIndex, Triple, -}; -use wasmer_types::{Symbol, SymbolRegistry}; const DWARF_SECTION_NAME: &[u8] = b".eh_frame"; @@ -21,7 +24,7 @@ const DWARF_SECTION_NAME: &[u8] = b".eh_frame"; /// # Usage /// /// ```rust -/// # use wasmer_types::Triple; +/// # use wasmer_compiler::types::target::Triple; /// # use wasmer_object::ObjectError; /// use wasmer_object::get_object_for_target; /// diff --git a/lib/compiler/src/serialize.rs b/lib/compiler/src/serialize.rs new file mode 100644 index 00000000000..ca8d85550b3 --- /dev/null +++ b/lib/compiler/src/serialize.rs @@ -0,0 +1,175 @@ +/* + * ! Remove me once rkyv generates doc-comments for fields or generates an #[allow(missing_docs)] + * on their own. + */ +#![allow(missing_docs)] + +use crate::types::{ + function::{CompiledFunctionFrameInfo, Dwarf, FunctionBody}, + module::CompileModuleInfo, + relocation::Relocation, + section::{CustomSection, SectionIndex}, + target::CpuFeature, +}; +use enumset::EnumSet; +use rkyv::{Archive, Deserialize as RkyvDeserialize, Serialize as RkyvSerialize}; +use wasmer_types::{ + entity::PrimaryMap, DeserializeError, Features, FunctionIndex, LocalFunctionIndex, MemoryIndex, + ModuleInfo, OwnedDataInitializer, SerializeError, SignatureIndex, TableIndex, +}; +use wasmer_vm::{MemoryStyle, TableStyle}; + +pub use wasmer_types::MetadataHeader; + +/// The compilation related data for a serialized modules +#[derive(Archive, Default, RkyvDeserialize, RkyvSerialize)] +#[cfg_attr(feature = "artifact-size", derive(loupe::MemoryUsage))] +#[allow(missing_docs)] +#[rkyv(derive(Debug))] +pub struct SerializableCompilation { + pub function_bodies: PrimaryMap, + pub function_relocations: PrimaryMap>, + pub function_frame_info: PrimaryMap, + pub function_call_trampolines: PrimaryMap, + pub dynamic_function_trampolines: PrimaryMap, + pub custom_sections: PrimaryMap, + pub custom_section_relocations: PrimaryMap>, + // The section indices corresponding to the Dwarf debug info + pub debug: Option, + // Custom section containing libcall trampolines. + pub libcall_trampolines: SectionIndex, + // Length of each libcall trampoline. + pub libcall_trampoline_len: u32, +} + +impl SerializableCompilation { + /// Serialize a Compilation into bytes + /// The bytes will have the following format: + /// RKYV serialization (any length) + POS (8 bytes) + pub fn serialize(&self) -> Result, SerializeError> { + rkyv::to_bytes::(self) + .map(|v| v.into_vec()) + .map_err(|e| SerializeError::Generic(e.to_string())) + } +} + +/// Serializable struct that is able to serialize from and to a `ArtifactInfo`. +#[derive(Archive, RkyvDeserialize, RkyvSerialize)] +#[cfg_attr(feature = "artifact-size", derive(loupe::MemoryUsage))] +#[allow(missing_docs)] +#[rkyv(derive(Debug))] +pub struct SerializableModule { + /// The main serializable compilation object + pub compilation: SerializableCompilation, + /// Compilation informations + pub compile_info: CompileModuleInfo, + /// Datas initializers + pub data_initializers: Box<[OwnedDataInitializer]>, + /// CPU Feature flags for this compilation + pub cpu_features: u64, +} + +impl SerializableModule { + /// Serialize a Module into bytes + /// The bytes will have the following format: + /// RKYV serialization (any length) + POS (8 bytes) + pub fn serialize(&self) -> Result, SerializeError> { + rkyv::to_bytes::(self) + .map(|v| v.into_vec()) + .map_err(|e| SerializeError::Generic(e.to_string())) + } + + /// Deserialize a Module from a slice. + /// The slice must have the following format: + /// RKYV serialization (any length) + POS (8 bytes) + /// + /// # Safety + /// + /// This method is unsafe since it deserializes data directly + /// from memory. + /// Right now we are not doing any extra work for validation, but + /// `rkyv` has an option to do bytecheck on the serialized data before + /// serializing (via `rkyv::check_archived_value`). + pub unsafe fn deserialize_unchecked(metadata_slice: &[u8]) -> Result { + let archived = Self::archive_from_slice(metadata_slice)?; + Self::deserialize_from_archive(archived) + } + + /// Deserialize a Module from a slice. + /// The slice must have the following format: + /// RKYV serialization (any length) + POS (8 bytes) + /// + /// Unlike [`Self::deserialize`], this function will validate the data. + /// + /// # Safety + /// Unsafe because it loads executable code into memory. + /// The loaded bytes must be trusted. + pub unsafe fn deserialize(metadata_slice: &[u8]) -> Result { + let archived = Self::archive_from_slice_checked(metadata_slice)?; + Self::deserialize_from_archive(archived) + } + + /// # Safety + /// + /// This method is unsafe. + /// Please check `SerializableModule::deserialize` for more details. + pub unsafe fn archive_from_slice( + metadata_slice: &[u8], + ) -> Result<&ArchivedSerializableModule, DeserializeError> { + Ok(rkyv::access_unchecked(metadata_slice)) + } + + /// Deserialize an archived module. + /// + /// In contrast to [`Self::deserialize`], this method performs validation + /// and is not unsafe. + pub fn archive_from_slice_checked( + metadata_slice: &[u8], + ) -> Result<&ArchivedSerializableModule, DeserializeError> { + rkyv::access::<_, rkyv::rancor::Error>(metadata_slice) + .map_err(|e| DeserializeError::CorruptedBinary(e.to_string())) + } + + /// Deserialize a compilation module from an archive + pub fn deserialize_from_archive( + archived: &ArchivedSerializableModule, + ) -> Result { + rkyv::deserialize::<_, rkyv::rancor::Error>(archived) + .map_err(|e| DeserializeError::CorruptedBinary(e.to_string())) + } + + /// Create a `ModuleInfo` for instantiation + pub fn create_module_info(&self) -> ModuleInfo { + self.compile_info.module.as_ref().clone() + } + + /// Returns the `ModuleInfo` for instantiation + pub fn module_info(&self) -> &ModuleInfo { + &self.compile_info.module + } + + /// Returns the features for this Artifact + pub fn features(&self) -> &Features { + &self.compile_info.features + } + + /// Returns the CPU features for this Artifact + pub fn cpu_features(&self) -> EnumSet { + EnumSet::from_u64(self.cpu_features) + } + + /// Returns data initializers to pass to `VMInstance::initialize` + pub fn data_initializers(&self) -> &[OwnedDataInitializer] { + &self.data_initializers + } + + /// Returns the memory styles associated with this `Artifact`. + pub fn memory_styles(&self) -> &PrimaryMap { + &self.compile_info.memory_styles + } + + /// Returns the table plans associated with this `Artifact`. + pub fn table_styles(&self) -> &PrimaryMap { + &self.compile_info.table_styles + } +} diff --git a/lib/compiler/src/traits.rs b/lib/compiler/src/traits.rs index 308a29f942d..a2b95259331 100644 --- a/lib/compiler/src/traits.rs +++ b/lib/compiler/src/traits.rs @@ -1,5 +1,6 @@ //! Generic Artifact abstraction for Wasmer Engines. +use crate::types::target::CpuFeature; use crate::Features; use enumset::EnumSet; use std::any::Any; @@ -7,7 +8,7 @@ use std::sync::Arc; use wasmer_types::entity::PrimaryMap; use wasmer_types::SerializeError; use wasmer_types::{ - CpuFeature, DataInitializerLike, MemoryIndex, MemoryStyle, ModuleInfo, TableIndex, TableStyle, + DataInitializerLike, MemoryIndex, MemoryStyle, ModuleInfo, TableIndex, TableStyle, }; /// An `Artifact` is the product that the `Engine` diff --git a/lib/types/src/compilation/address_map.rs b/lib/compiler/src/types/address_map.rs similarity index 98% rename from lib/types/src/compilation/address_map.rs rename to lib/compiler/src/types/address_map.rs index b4bd81a5955..48a0ecf2207 100644 --- a/lib/types/src/compilation/address_map.rs +++ b/lib/compiler/src/types/address_map.rs @@ -8,10 +8,10 @@ // addresses of a WebAssembly module into the native code. use crate::lib::std::vec::Vec; -use crate::SourceLoc; use rkyv::{Archive, Deserialize as RkyvDeserialize, Serialize as RkyvSerialize}; #[cfg(feature = "enable-serde")] use serde::{Deserialize, Serialize}; +use wasmer_types::SourceLoc; /// Single source location to generated address mapping. #[cfg_attr(feature = "enable-serde", derive(Serialize, Deserialize))] diff --git a/lib/types/src/compilation/function.rs b/lib/compiler/src/types/function.rs similarity index 92% rename from lib/types/src/compilation/function.rs rename to lib/compiler/src/types/function.rs index fbb66334763..4b4f8d45e1f 100644 --- a/lib/types/src/compilation/function.rs +++ b/lib/compiler/src/types/function.rs @@ -9,19 +9,23 @@ //! A `Compilation` contains the compiled function bodies for a WebAssembly //! module (`CompiledFunction`). -use crate::entity::PrimaryMap; -use crate::lib::std::vec::Vec; -use crate::{ArchivedCompiledFunctionUnwindInfo, TrapInformation}; -use crate::{CompiledFunctionUnwindInfo, FunctionAddressMap}; -use crate::{ - CustomSection, FunctionIndex, LocalFunctionIndex, Relocation, SectionIndex, SignatureIndex, +use super::{ + address_map::FunctionAddressMap, + relocation::Relocation, + section::{CustomSection, SectionIndex}, + unwind::{ + ArchivedCompiledFunctionUnwindInfo, CompiledFunctionUnwindInfo, + CompiledFunctionUnwindInfoLike, + }, +}; +use rkyv::{ + option::ArchivedOption, Archive, Deserialize as RkyvDeserialize, Serialize as RkyvSerialize, }; -use rkyv::option::ArchivedOption; -use rkyv::{Archive, Deserialize as RkyvDeserialize, Serialize as RkyvSerialize}; #[cfg(feature = "enable-serde")] use serde::{Deserialize, Serialize}; - -use super::unwind::CompiledFunctionUnwindInfoLike; +use wasmer_types::{ + entity::PrimaryMap, FunctionIndex, LocalFunctionIndex, SignatureIndex, TrapInformation, +}; /// The frame info for a Compiled function. /// diff --git a/lib/types/src/compilation/mod.rs b/lib/compiler/src/types/mod.rs similarity index 100% rename from lib/types/src/compilation/mod.rs rename to lib/compiler/src/types/mod.rs diff --git a/lib/types/src/compilation/module.rs b/lib/compiler/src/types/module.rs similarity index 91% rename from lib/types/src/compilation/module.rs rename to lib/compiler/src/types/module.rs index cabf6cb85e9..5b0a851a144 100644 --- a/lib/types/src/compilation/module.rs +++ b/lib/compiler/src/types/module.rs @@ -5,12 +5,13 @@ #![allow(missing_docs)] //! Types for modules. -use crate::entity::PrimaryMap; -use crate::{Features, MemoryIndex, MemoryStyle, ModuleInfo, TableIndex, TableStyle}; use rkyv::{Archive, Deserialize as RkyvDeserialize, Serialize as RkyvSerialize}; #[cfg(feature = "enable-serde")] use serde::{Deserialize, Serialize}; use std::sync::Arc; +use wasmer_types::{ + entity::PrimaryMap, Features, MemoryIndex, MemoryStyle, ModuleInfo, TableIndex, TableStyle, +}; /// The required info for compiling a module. /// diff --git a/lib/types/src/compilation/relocation.rs b/lib/compiler/src/types/relocation.rs similarity index 98% rename from lib/types/src/compilation/relocation.rs rename to lib/compiler/src/types/relocation.rs index 54060c9f6f2..dab568b9f6f 100644 --- a/lib/types/src/compilation/relocation.rs +++ b/lib/compiler/src/types/relocation.rs @@ -16,14 +16,11 @@ //! do the corresponding work to run it. use super::section::SectionIndex; -use crate::entity::PrimaryMap; -use crate::lib::std::fmt; -use crate::lib::std::vec::Vec; use crate::{Addend, CodeOffset}; -use crate::{LibCall, LocalFunctionIndex}; use rkyv::{Archive, Deserialize as RkyvDeserialize, Serialize as RkyvSerialize}; #[cfg(feature = "enable-serde")] use serde::{Deserialize, Serialize}; +use wasmer_types::{entity::PrimaryMap, lib::std::fmt, LibCall, LocalFunctionIndex}; /// Relocation kinds for every ISA. #[cfg_attr(feature = "artifact-size", derive(loupe::MemoryUsage))] diff --git a/lib/types/src/compilation/section.rs b/lib/compiler/src/types/section.rs similarity index 99% rename from lib/types/src/compilation/section.rs rename to lib/compiler/src/types/section.rs index 976b8429ce2..00ced395472 100644 --- a/lib/types/src/compilation/section.rs +++ b/lib/compiler/src/types/section.rs @@ -12,11 +12,11 @@ //! it can be patched later by the engine (native or JIT). use super::relocation::{ArchivedRelocation, Relocation, RelocationLike}; -use crate::entity::entity_impl; use crate::lib::std::vec::Vec; use rkyv::{Archive, Deserialize as RkyvDeserialize, Serialize as RkyvSerialize}; #[cfg(feature = "enable-serde")] use serde::{Deserialize, Serialize}; +use wasmer_types::entity_impl; /// Index type of a Section defined inside a WebAssembly `Compilation`. #[derive( diff --git a/lib/types/src/compilation/symbols.rs b/lib/compiler/src/types/symbols.rs similarity index 97% rename from lib/types/src/compilation/symbols.rs rename to lib/compiler/src/types/symbols.rs index dc0eb7a48cd..92455464a78 100644 --- a/lib/types/src/compilation/symbols.rs +++ b/lib/compiler/src/types/symbols.rs @@ -5,14 +5,16 @@ #![allow(missing_docs)] //! This module define the required structures for compilation symbols. -use crate::{ - entity::{EntityRef, PrimaryMap}, - CompileModuleInfo, DeserializeError, FunctionIndex, LocalFunctionIndex, OwnedDataInitializer, - SectionIndex, SerializeError, SignatureIndex, -}; use rkyv::{Archive, Deserialize as RkyvDeserialize, Serialize as RkyvSerialize}; #[cfg(feature = "enable-serde")] use serde::{Deserialize, Serialize}; +use wasmer_types::{ + entity::{EntityRef, PrimaryMap}, + DeserializeError, FunctionIndex, LocalFunctionIndex, OwnedDataInitializer, SerializeError, + SignatureIndex, +}; + +use super::{module::CompileModuleInfo, section::SectionIndex}; /// The kinds of wasmer_types objects that might be found in a native object file. #[derive( diff --git a/lib/types/src/compilation/target.rs b/lib/compiler/src/types/target.rs similarity index 99% rename from lib/types/src/compilation/target.rs rename to lib/compiler/src/types/target.rs index 5aec0d0e63b..bf6bbd2893d 100644 --- a/lib/types/src/compilation/target.rs +++ b/lib/compiler/src/types/target.rs @@ -8,13 +8,13 @@ // Same things is now happening with unused-unit for the EnumSetType derivative #![allow(clippy::unused_unit, clippy::use_self)] -use crate::error::ParseCpuFeatureError; use enumset::{EnumSet, EnumSetType}; use std::str::FromStr; pub use target_lexicon::{ Aarch64Architecture, Architecture, BinaryFormat, CallingConvention, Endianness, Environment, OperatingSystem, PointerWidth, Triple, Vendor, }; +use wasmer_types::error::ParseCpuFeatureError; /// The nomenclature is inspired by the [`cpuid` crate]. /// The list of supported features was initially retrieved from diff --git a/lib/types/src/compilation/unwind.rs b/lib/compiler/src/types/unwind.rs similarity index 100% rename from lib/types/src/compilation/unwind.rs rename to lib/compiler/src/types/unwind.rs diff --git a/lib/object/Cargo.toml b/lib/object/Cargo.toml deleted file mode 100644 index a8695d1c959..00000000000 --- a/lib/object/Cargo.toml +++ /dev/null @@ -1,21 +0,0 @@ -[package] -name = "wasmer-object" -description = "Wasmer Native Object generator" -categories = ["wasm"] -keywords = ["wasm", "webassembly"] -readme = "README.md" -authors.workspace = true -edition.workspace = true -homepage.workspace = true -license.workspace = true -repository.workspace = true -rust-version.workspace = true -version.workspace = true - -[dependencies] -wasmer-types = { path = "../types", version = "=5.0.0" } -object = { version = "0.29.0", default-features = false, features = ["write"] } -thiserror = "1.0" - -[package.metadata.docs.rs] -rustc-args = ["--cfg", "docsrs"] diff --git a/lib/object/README.md b/lib/object/README.md deleted file mode 100644 index 273a2cb2cc8..00000000000 --- a/lib/object/README.md +++ /dev/null @@ -1,10 +0,0 @@ -# `wasmer-object` [![Build Status](https://github.com/wasmerio/wasmer/workflows/build/badge.svg?style=flat-square)](https://github.com/wasmerio/wasmer/actions?query=workflow%3Abuild) [![Join Wasmer Slack](https://img.shields.io/static/v1?label=Slack&message=join%20chat&color=brighgreen&style=flat-square)](https://slack.wasmer.io) [![MIT License](https://img.shields.io/github/license/wasmerio/wasmer.svg?style=flat-square)](https://github.com/wasmerio/wasmer/blob/main/LICENSE) - -The Wasmer Native Object crate aims at cross-generating native objects -for various platforms. - -Given a compilation result, i.e. the result -of `wasmer_compiler::Compiler::compile_module`, this crate exposes -functions to create an `Object` file for a given target. It is a -useful thin layer on top of [the `object` -crate](https://github.com/gimli-rs/object). diff --git a/lib/package/src/package/mod.rs b/lib/package/src/package/mod.rs index 6a9955330a0..c14625ee0be 100644 --- a/lib/package/src/package/mod.rs +++ b/lib/package/src/package/mod.rs @@ -275,7 +275,7 @@ mod tests { let out_dir = temp.path().join("out"); container.unpack(&out_dir, false).unwrap(); - let expected_entries = vec![ + let expected_entries = [ "bar", // the volume "metadata", // the metadata volume "foo", // the atom diff --git a/lib/package/src/package/volume/fs.rs b/lib/package/src/package/volume/fs.rs index 28db0de3033..5460119aa22 100644 --- a/lib/package/src/package/volume/fs.rs +++ b/lib/package/src/package/volume/fs.rs @@ -446,7 +446,7 @@ mod tests { let volume = FsVolume::new_metadata(&manifest, temp.path().to_path_buf()).unwrap(); let entries = volume.read_dir(&PathSegments::ROOT).unwrap(); - let expected = vec![ + let expected = [ PathSegment::parse("README.md").unwrap(), PathSegment::parse("asdf.wai").unwrap(), PathSegment::parse("browser.wai").unwrap(), @@ -497,12 +497,12 @@ mod tests { let manifest: Manifest = toml::from_str(wasmer_toml).unwrap(); - let volume = FsVolume::new_assets(&manifest, &temp.path()).unwrap(); + let volume = FsVolume::new_assets(&manifest, temp.path()).unwrap(); let volume = &volume["/etc"]; let entries = volume.read_dir(&PathSegments::ROOT).unwrap(); - let expected = vec![PathSegment::parse("share").unwrap()]; + let expected = [PathSegment::parse("share").unwrap()]; for i in 0..expected.len() { assert_eq!(entries[i].0, expected[i]); diff --git a/lib/types/Cargo.toml b/lib/types/Cargo.toml index 53421ea9592..17500b87671 100644 --- a/lib/types/Cargo.toml +++ b/lib/types/Cargo.toml @@ -23,7 +23,7 @@ more-asserts = "0.2" indexmap = { workspace = true } rkyv = { workspace = true } enum-iterator = "0.7.0" -target-lexicon = { version = "0.12.2", default-features = false } +target-lexicon = { workspace = true} enumset.workspace = true bytecheck = "0.6.8" xxhash-rust = { version = "0.8.8", features = ["xxh64"] } diff --git a/lib/types/src/lib.rs b/lib/types/src/lib.rs index 0e1d4f1a946..2c999797f78 100644 --- a/lib/types/src/lib.rs +++ b/lib/types/src/lib.rs @@ -50,7 +50,6 @@ pub mod lib { } } -pub mod compilation; pub mod error; mod features; mod indexes; @@ -70,14 +69,6 @@ mod utils; mod value; mod vmoffsets; -pub use crate::compilation::target::{ - Aarch64Architecture, Architecture, BinaryFormat, CallingConvention, CpuFeature, Endianness, - Environment, OperatingSystem, PointerWidth, Target, Triple, Vendor, -}; -pub use crate::serialize::{ - ArchivedSerializableCompilation, ArchivedSerializableModule, MetadataHeader, - SerializableCompilation, SerializableModule, -}; pub use error::{ CompileError, DeserializeError, ImportError, MemoryError, MiddlewareError, ParseCpuFeatureError, PreInstantiationError, SerializeError, WasmError, WasmResult, @@ -111,34 +102,13 @@ pub use value::{RawValue, ValueType}; pub use crate::libcalls::LibCall; pub use crate::memory::MemoryStyle; pub use crate::table::TableStyle; +pub use serialize::MetadataHeader; // TODO: OnCalledAction is needed for asyncify. It will be refactored with https://github.com/wasmerio/wasmer/issues/3451 -pub use crate::trapcode::{OnCalledAction, TrapCode}; -pub use crate::vmoffsets::{TargetSharedSignatureIndex, VMBuiltinFunctionIndex, VMOffsets}; - -pub use crate::utils::is_wasm; - -pub use crate::compilation::relocation::{ - ArchivedRelocation, Relocation, RelocationKind, RelocationLike, RelocationTarget, Relocations, -}; -pub use crate::compilation::section::{ - ArchivedCustomSection, CustomSection, CustomSectionLike, CustomSectionProtection, SectionBody, - SectionIndex, -}; - -pub use crate::compilation::address_map::{FunctionAddressMap, InstructionAddressMap}; -pub use crate::compilation::function::{ - ArchivedFunctionBody, Compilation, CompiledFunction, CompiledFunctionFrameInfo, CustomSections, - Dwarf, FunctionBody, FunctionBodyLike, Functions, -}; -pub use crate::compilation::module::CompileModuleInfo; -pub use crate::compilation::symbols::{Symbol, SymbolRegistry}; -pub use crate::compilation::unwind::{ - ArchivedCompiledFunctionUnwindInfo, CompiledFunctionUnwindInfo, CompiledFunctionUnwindInfoLike, - CompiledFunctionUnwindInfoReference, -}; - pub use crate::stack::{FrameInfo, SourceLoc, TrapInformation}; pub use crate::store_id::StoreId; +pub use crate::trapcode::{OnCalledAction, TrapCode}; +pub use crate::utils::is_wasm; +pub use crate::vmoffsets::{TargetSharedSignatureIndex, VMBuiltinFunctionIndex, VMOffsets}; /// Offset in bytes from the beginning of the function. pub type CodeOffset = u32; diff --git a/lib/types/src/serialize.rs b/lib/types/src/serialize.rs index c9ccc938686..5993618d062 100644 --- a/lib/types/src/serialize.rs +++ b/lib/types/src/serialize.rs @@ -1,173 +1,4 @@ -/* - * ! Remove me once rkyv generates doc-comments for fields or generates an #[allow(missing_docs)] - * on their own. - */ -#![allow(missing_docs)] - -use crate::entity::PrimaryMap; -use crate::{ - compilation::target::CpuFeature, CompileModuleInfo, CompiledFunctionFrameInfo, CustomSection, - DeserializeError, Dwarf, Features, FunctionBody, FunctionIndex, LocalFunctionIndex, - MemoryIndex, MemoryStyle, ModuleInfo, OwnedDataInitializer, Relocation, SectionIndex, - SerializeError, SignatureIndex, TableIndex, TableStyle, -}; -use enumset::EnumSet; -use rkyv::{Archive, Deserialize as RkyvDeserialize, Serialize as RkyvSerialize}; -use std::convert::TryInto; -use std::mem; - -/// The compilation related data for a serialized modules -#[derive(Archive, Default, RkyvDeserialize, RkyvSerialize)] -#[cfg_attr(feature = "artifact-size", derive(loupe::MemoryUsage))] -#[allow(missing_docs)] -#[rkyv(derive(Debug))] -pub struct SerializableCompilation { - pub function_bodies: PrimaryMap, - pub function_relocations: PrimaryMap>, - pub function_frame_info: PrimaryMap, - pub function_call_trampolines: PrimaryMap, - pub dynamic_function_trampolines: PrimaryMap, - pub custom_sections: PrimaryMap, - pub custom_section_relocations: PrimaryMap>, - // The section indices corresponding to the Dwarf debug info - pub debug: Option, - // Custom section containing libcall trampolines. - pub libcall_trampolines: SectionIndex, - // Length of each libcall trampoline. - pub libcall_trampoline_len: u32, -} - -impl SerializableCompilation { - /// Serialize a Compilation into bytes - /// The bytes will have the following format: - /// RKYV serialization (any length) + POS (8 bytes) - pub fn serialize(&self) -> Result, SerializeError> { - rkyv::to_bytes::(self) - .map(|v| v.into_vec()) - .map_err(|e| SerializeError::Generic(e.to_string())) - } -} - -/// Serializable struct that is able to serialize from and to a `ArtifactInfo`. -#[derive(Archive, RkyvDeserialize, RkyvSerialize)] -#[cfg_attr(feature = "artifact-size", derive(loupe::MemoryUsage))] -#[allow(missing_docs)] -#[rkyv(derive(Debug))] -pub struct SerializableModule { - /// The main serializable compilation object - pub compilation: SerializableCompilation, - /// Compilation informations - pub compile_info: CompileModuleInfo, - /// Datas initializers - pub data_initializers: Box<[OwnedDataInitializer]>, - /// CPU Feature flags for this compilation - pub cpu_features: u64, -} - -impl SerializableModule { - /// Serialize a Module into bytes - /// The bytes will have the following format: - /// RKYV serialization (any length) + POS (8 bytes) - pub fn serialize(&self) -> Result, SerializeError> { - rkyv::to_bytes::(self) - .map(|v| v.into_vec()) - .map_err(|e| SerializeError::Generic(e.to_string())) - } - - /// Deserialize a Module from a slice. - /// The slice must have the following format: - /// RKYV serialization (any length) + POS (8 bytes) - /// - /// # Safety - /// - /// This method is unsafe since it deserializes data directly - /// from memory. - /// Right now we are not doing any extra work for validation, but - /// `rkyv` has an option to do bytecheck on the serialized data before - /// serializing (via `rkyv::check_archived_value`). - pub unsafe fn deserialize_unchecked(metadata_slice: &[u8]) -> Result { - let archived = Self::archive_from_slice(metadata_slice)?; - Self::deserialize_from_archive(archived) - } - - /// Deserialize a Module from a slice. - /// The slice must have the following format: - /// RKYV serialization (any length) + POS (8 bytes) - /// - /// Unlike [`Self::deserialize`], this function will validate the data. - /// - /// # Safety - /// Unsafe because it loads executable code into memory. - /// The loaded bytes must be trusted. - pub unsafe fn deserialize(metadata_slice: &[u8]) -> Result { - let archived = Self::archive_from_slice_checked(metadata_slice)?; - Self::deserialize_from_archive(archived) - } - - /// # Safety - /// - /// This method is unsafe. - /// Please check `SerializableModule::deserialize` for more details. - pub unsafe fn archive_from_slice( - metadata_slice: &[u8], - ) -> Result<&ArchivedSerializableModule, DeserializeError> { - Ok(rkyv::access_unchecked(metadata_slice)) - } - - /// Deserialize an archived module. - /// - /// In contrast to [`Self::deserialize`], this method performs validation - /// and is not unsafe. - pub fn archive_from_slice_checked( - metadata_slice: &[u8], - ) -> Result<&ArchivedSerializableModule, DeserializeError> { - rkyv::access::<_, rkyv::rancor::Error>(metadata_slice) - .map_err(|e| DeserializeError::CorruptedBinary(e.to_string())) - } - - /// Deserialize a compilation module from an archive - pub fn deserialize_from_archive( - archived: &ArchivedSerializableModule, - ) -> Result { - rkyv::deserialize::<_, rkyv::rancor::Error>(archived) - .map_err(|e| DeserializeError::CorruptedBinary(e.to_string())) - } - - /// Create a `ModuleInfo` for instantiation - pub fn create_module_info(&self) -> ModuleInfo { - self.compile_info.module.as_ref().clone() - } - - /// Returns the `ModuleInfo` for instantiation - pub fn module_info(&self) -> &ModuleInfo { - &self.compile_info.module - } - - /// Returns the features for this Artifact - pub fn features(&self) -> &Features { - &self.compile_info.features - } - - /// Returns the CPU features for this Artifact - pub fn cpu_features(&self) -> EnumSet { - EnumSet::from_u64(self.cpu_features) - } - - /// Returns data initializers to pass to `VMInstance::initialize` - pub fn data_initializers(&self) -> &[OwnedDataInitializer] { - &self.data_initializers - } - - /// Returns the memory styles associated with this `Artifact`. - pub fn memory_styles(&self) -> &PrimaryMap { - &self.compile_info.memory_styles - } - - /// Returns the table plans associated with this `Artifact`. - pub fn table_styles(&self) -> &PrimaryMap { - &self.compile_info.table_styles - } -} +use crate::{lib::std::mem, DeserializeError}; /// Metadata header which holds an ABI version and the length of the remaining /// metadata. diff --git a/lib/virtual-fs/src/mem_fs/stdio.rs b/lib/virtual-fs/src/mem_fs/stdio.rs index 6153994529b..ca107b5a003 100644 --- a/lib/virtual-fs/src/mem_fs/stdio.rs +++ b/lib/virtual-fs/src/mem_fs/stdio.rs @@ -204,11 +204,7 @@ mod test_read_write_seek { matches!(stdin.read_to_end(&mut buffer).await, Ok(3)), "reading bytes again from `stdin`", ); - assert_eq!( - buffer, - &[b'b', b'a', b'r'], - "checking the bytes read from `stdin`" - ); + assert_eq!(buffer, b"bar", "checking the bytes read from `stdin`"); let mut buffer = [0; 1]; @@ -265,11 +261,7 @@ mod test_read_write_seek { matches!(stdout.write(b"qux").await, Ok(3)), "writing again into `stdout`", ); - assert_eq!( - stdout.buf, - &[b'b', b'a', b'z', b'q', b'u', b'x'], - "checking the content of `stdout`", - ); + assert_eq!(stdout.buf, b"bazqux", "checking the content of `stdout`",); } #[tokio::test] @@ -309,11 +301,7 @@ mod test_read_write_seek { matches!(stderr.write(b"qux").await, Ok(3)), "writing again into `stderr`", ); - assert_eq!( - stderr.buf, - &[b'b', b'a', b'z', b'q', b'u', b'x'], - "checking the content of `stderr`", - ); + assert_eq!(stderr.buf, b"bazqux", "checking the content of `stderr`",); } #[tokio::test] diff --git a/tests/integration/cli/tests/run.rs b/tests/integration/cli/tests/run.rs index 8bff885c7e7..d47dca29758 100644 --- a/tests/integration/cli/tests/run.rs +++ b/tests/integration/cli/tests/run.rs @@ -1248,7 +1248,7 @@ fn wait_for(text: &str, reader: &mut dyn Read) -> String { fn read_line(reader: &mut dyn Read) -> Result { let mut line = Vec::new(); - while !line.ends_with(&[b'\n']) { + while !line.ends_with(b"\n") { let mut buffer = [0_u8]; match reader.read_exact(&mut buffer) { Ok(_) => { diff --git a/tests/integration/cli/tests/snapshot.rs b/tests/integration/cli/tests/snapshot.rs index 7761092699b..570c1b390a0 100644 --- a/tests/integration/cli/tests/snapshot.rs +++ b/tests/integration/cli/tests/snapshot.rs @@ -762,7 +762,7 @@ fn test_snapshot_web_server_epoll() { .arg("--log-level") .arg("warn") .arg("--port") - .arg(&format!("{}", port)); + .arg(format!("{}", port)); let snapshot = builder.run_wasm_with( include_bytes!("./wasm/web-server-epoll.wasm"), From 921a2c64c0681cf2745d7b7ec35dae4e83abf0f1 Mon Sep 17 00:00:00 2001 From: Edoardo Marangoni Date: Wed, 6 Nov 2024 17:23:09 +0100 Subject: [PATCH 02/16] chore: Fix examples --- examples/engine_cross_compilation.rs | 2 +- examples/platform_ios_headless.rs | 2 +- examples/table.rs | 1 - 3 files changed, 2 insertions(+), 3 deletions(-) diff --git a/examples/engine_cross_compilation.rs b/examples/engine_cross_compilation.rs index 3196c8f6394..14215c13877 100644 --- a/examples/engine_cross_compilation.rs +++ b/examples/engine_cross_compilation.rs @@ -20,8 +20,8 @@ use std::str::FromStr; use wasmer::{sys::EngineBuilder, wat2wasm, Module, RuntimeError, Store}; +use wasmer_compiler::types::target::{CpuFeature, Target, Triple}; use wasmer_compiler_cranelift::Cranelift; -use wasmer_types::{CpuFeature, Target, Triple}; fn main() -> Result<(), Box> { // Let's declare the Wasm module with the text representation. diff --git a/examples/platform_ios_headless.rs b/examples/platform_ios_headless.rs index 7b133b2db03..0dfe9348380 100644 --- a/examples/platform_ios_headless.rs +++ b/examples/platform_ios_headless.rs @@ -15,8 +15,8 @@ use std::path::Path; use std::str::FromStr; use wasmer::{wat2wasm, Module, RuntimeError, Store}; +use wasmer_compiler::types::target::{CpuFeature, Target, Triple}; use wasmer_compiler_cranelift::Cranelift; -use wasmer_types::{CpuFeature, Target, Triple}; /* use wasmer_engine_dylib::Dylib; */ diff --git a/examples/table.rs b/examples/table.rs index cd74083694e..52e5b9f4589 100644 --- a/examples/table.rs +++ b/examples/table.rs @@ -154,7 +154,6 @@ fn main() -> anyhow::Result<()> { // This test is currently failing with: // not implemented: Native function definitions can't be directly called from the host yet -#[cfg(FALSE)] #[test] fn test_table() -> anyhow::Result<()> { main() From 84b8ced6ddffa557ba8b4659699223ad50081c16 Mon Sep 17 00:00:00 2001 From: Edoardo Marangoni Date: Wed, 6 Nov 2024 17:23:27 +0100 Subject: [PATCH 03/16] chore: Fix tests --- lib/compiler-singlepass/src/compiler.rs | 7 +++++-- lib/compiler-singlepass/src/machine_x64.rs | 2 +- lib/compiler/src/object/module.rs | 20 +++++++------------- 3 files changed, 13 insertions(+), 16 deletions(-) diff --git a/lib/compiler-singlepass/src/compiler.rs b/lib/compiler-singlepass/src/compiler.rs index a76a05030a1..d5b5ae93541 100644 --- a/lib/compiler-singlepass/src/compiler.rs +++ b/lib/compiler-singlepass/src/compiler.rs @@ -294,8 +294,11 @@ mod tests { use super::*; use std::str::FromStr; use target_lexicon::triple; - use wasmer_compiler::Features; - use wasmer_types::{CpuFeature, MemoryStyle, TableStyle, Triple}; + use wasmer_compiler::{ + types::target::{CpuFeature, Triple}, + Features, + }; + use wasmer_types::{MemoryStyle, TableStyle}; fn dummy_compilation_ingredients<'a>() -> ( CompileModuleInfo, diff --git a/lib/compiler-singlepass/src/machine_x64.rs b/lib/compiler-singlepass/src/machine_x64.rs index b1266238109..6dc01771cca 100644 --- a/lib/compiler-singlepass/src/machine_x64.rs +++ b/lib/compiler-singlepass/src/machine_x64.rs @@ -8305,7 +8305,7 @@ mod test { use super::*; use enumset::enum_set; use std::str::FromStr; - use wasmer_types::{CpuFeature, Target, Triple}; + use wasmer_compiler::types::target::{CpuFeature, Target, Triple}; fn test_move_location(machine: &mut MachineX86_64) -> Result<(), CompileError> { machine.move_location_for_native( diff --git a/lib/compiler/src/object/module.rs b/lib/compiler/src/object/module.rs index 1b340160878..c93330cb57d 100644 --- a/lib/compiler/src/object/module.rs +++ b/lib/compiler/src/object/module.rs @@ -25,8 +25,7 @@ const DWARF_SECTION_NAME: &[u8] = b".eh_frame"; /// /// ```rust /// # use wasmer_compiler::types::target::Triple; -/// # use wasmer_object::ObjectError; -/// use wasmer_object::get_object_for_target; +/// # use wasmer_compiler::object::{ObjectError, get_object_for_target}; /// /// # fn generate_object_for_target(triple: &Triple) -> Result<(), ObjectError> { /// let mut object = get_object_for_target(&triple)?; @@ -84,9 +83,8 @@ pub fn get_object_for_target(triple: &Triple) -> Result { /// # Usage /// /// ```rust -/// # use wasmer_types::Triple; -/// # use wasmer_object::ObjectError; -/// use wasmer_object::{get_object_for_target, emit_data}; +/// # use wasmer_compiler::types::target::Triple; +/// # use wasmer_compiler::object::{ObjectError, get_object_for_target, emit_data}; /// /// # fn emit_data_into_object(triple: &Triple) -> Result<(), ObjectError> { /// let mut object = get_object_for_target(&triple)?; @@ -122,10 +120,8 @@ pub fn emit_data( /// # Usage /// /// ```rust -/// # use wasmer_types::SymbolRegistry; -/// # use wasmer_types::{Compilation, Triple}; -/// # use wasmer_object::ObjectError; -/// use wasmer_object::{get_object_for_target, emit_compilation}; +/// # use wasmer_compiler::types::{ symbols::SymbolRegistry, target::{Triple}, function::{Compilation} }; +/// # use wasmer_compiler::object::{ObjectError, get_object_for_target, emit_compilation}; /// /// # fn emit_compilation_into_object( /// # triple: &Triple, @@ -407,10 +403,8 @@ pub fn emit_compilation( /// # Usage /// /// ```rust -/// # use wasmer_types::SymbolRegistry; -/// # use wasmer_types::{Compilation, Triple}; -/// # use wasmer_object::{ObjectError, emit_serialized}; -/// use wasmer_object::{get_object_for_target, emit_compilation}; +/// # use wasmer_compiler::types::{ symbols::SymbolRegistry, target::{Triple}, function::{Compilation} }; +/// # use wasmer_compiler::object::{ObjectError, get_object_for_target, emit_serialized}; /// /// # fn emit_compilation_into_object( /// # triple: &Triple, From f2391414c83b4475f2580e7c4db47c6b7176b3c7 Mon Sep 17 00:00:00 2001 From: Edoardo Marangoni Date: Wed, 6 Nov 2024 17:23:35 +0100 Subject: [PATCH 04/16] chore: Make linter happy --- lib/compiler/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/compiler/src/lib.rs b/lib/compiler/src/lib.rs index 533c6704c0a..334977af988 100644 --- a/lib/compiler/src/lib.rs +++ b/lib/compiler/src/lib.rs @@ -49,9 +49,9 @@ mod lib { mod engine; mod traits; +pub mod object; pub mod serialize; pub mod types; -pub mod object; pub use crate::engine::*; pub use crate::traits::*; From 7cfbbad68df7238cdd1db9b45821bf05000970dc Mon Sep 17 00:00:00 2001 From: Edoardo Marangoni Date: Wed, 6 Nov 2024 17:34:42 +0100 Subject: [PATCH 05/16] fix: Remove feature `llvm` from `cli-compiler` --- lib/cli-compiler/Cargo.toml | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/cli-compiler/Cargo.toml b/lib/cli-compiler/Cargo.toml index 03d22e7ba3e..33741464dda 100644 --- a/lib/cli-compiler/Cargo.toml +++ b/lib/cli-compiler/Cargo.toml @@ -72,7 +72,6 @@ engine = [] compiler = ["wasmer-compiler/translator", "wasmer-compiler/compiler"] singlepass = ["wasmer-compiler-singlepass", "compiler"] cranelift = ["wasmer-compiler-cranelift", "compiler"] -llvm = ["wasmer-compiler-llvm", "compiler"] debug = ["fern", "log"] disable-all-logging = [] jit = [] From 55f1867db7c18040fa554fe462293957efdcf8db Mon Sep 17 00:00:00 2001 From: Edoardo Marangoni Date: Wed, 6 Nov 2024 17:38:02 +0100 Subject: [PATCH 06/16] chore: Update Cargo.lock --- Cargo.lock | 1 - 1 file changed, 1 deletion(-) diff --git a/Cargo.lock b/Cargo.lock index 89057653710..6b9a894b5c9 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -6610,7 +6610,6 @@ dependencies = [ "unix_mode", "wasmer-compiler", "wasmer-compiler-cranelift", - "wasmer-compiler-llvm", "wasmer-compiler-singlepass", "wasmer-types", ] From d2ae5e246935683924166cfb10878fba169e6d73 Mon Sep 17 00:00:00 2001 From: Edoardo Marangoni Date: Wed, 6 Nov 2024 17:56:01 +0100 Subject: [PATCH 07/16] fix: Don't use `wasmer_types` in llvm --- lib/compiler-llvm/src/config.rs | 36 ++++++++++++++++----------------- 1 file changed, 17 insertions(+), 19 deletions(-) diff --git a/lib/compiler-llvm/src/config.rs b/lib/compiler-llvm/src/config.rs index 73689326820..417488c3f3b 100644 --- a/lib/compiler-llvm/src/config.rs +++ b/lib/compiler-llvm/src/config.rs @@ -109,25 +109,23 @@ impl LLVM { // Hack: we're using is_pic to determine whether this is a native // build or not. - let operating_system = if target.triple().operating_system - == wasmer_types::OperatingSystem::Darwin - && !self.is_pic - { - // LLVM detects static relocation + darwin + 64-bit and - // force-enables PIC because MachO doesn't support that - // combination. They don't check whether they're targeting - // MachO, they check whether the OS is set to Darwin. - // - // Since both linux and darwin use SysV ABI, this should work. - // but not in the case of Aarch64, there the ABI is slightly different - #[allow(clippy::match_single_binding)] - match target.triple().architecture { - Architecture::Aarch64(_) => wasmer_types::OperatingSystem::Darwin, - _ => wasmer_types::OperatingSystem::Linux, - } - } else { - target.triple().operating_system - }; + let operating_system = + if target.triple().operating_system == OperatingSystem::Darwin && !self.is_pic { + // LLVM detects static relocation + darwin + 64-bit and + // force-enables PIC because MachO doesn't support that + // combination. They don't check whether they're targeting + // MachO, they check whether the OS is set to Darwin. + // + // Since both linux and darwin use SysV ABI, this should work. + // but not in the case of Aarch64, there the ABI is slightly different + #[allow(clippy::match_single_binding)] + match target.triple().architecture { + Architecture::Aarch64(_) => OperatingSystem::Darwin, + _ => OperatingSystem::Linux, + } + } else { + target.triple().operating_system + }; let binary_format = if self.is_pic { target.triple().binary_format From 1b497706ec19085bd0ae2c80fe43a38f696ae57b Mon Sep 17 00:00:00 2001 From: Edoardo Marangoni Date: Wed, 6 Nov 2024 17:56:34 +0100 Subject: [PATCH 08/16] fix: Don't use `wasmer_compiler` with `js` feature --- lib/api/src/lib.rs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lib/api/src/lib.rs b/lib/api/src/lib.rs index ffb83fc1c37..567195ae56b 100644 --- a/lib/api/src/lib.rs +++ b/lib/api/src/lib.rs @@ -520,7 +520,11 @@ pub use value::Value; pub use wasmer_derive::ValueType; // TODO: OnCalledAction is needed for asyncify. It will be refactored with https://github.com/wasmerio/wasmer/issues/3451 +#[cfg(feature == "js")] +pub use target_lexicon::{CpuFeature, Target}; +#[cfg(not(feature == "js"))] pub use wasmer_compiler::types::target::{CpuFeature, Target}; + pub use wasmer_types::{ is_wasm, Bytes, CompileError, DeserializeError, ExportIndex, ExportType, ExternType, FrameInfo, FunctionType, GlobalInit, GlobalType, ImportType, LocalFunctionIndex, MemoryError, MemoryType, From fda1d31120ef4fb0c5199261f50d4d0cd2ebc316 Mon Sep 17 00:00:00 2001 From: Edoardo Marangoni Date: Wed, 6 Nov 2024 18:00:57 +0100 Subject: [PATCH 09/16] fix typo --- lib/api/src/lib.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/api/src/lib.rs b/lib/api/src/lib.rs index 567195ae56b..6f7621ae919 100644 --- a/lib/api/src/lib.rs +++ b/lib/api/src/lib.rs @@ -520,9 +520,9 @@ pub use value::Value; pub use wasmer_derive::ValueType; // TODO: OnCalledAction is needed for asyncify. It will be refactored with https://github.com/wasmerio/wasmer/issues/3451 -#[cfg(feature == "js")] +#[cfg(feature = "js")] pub use target_lexicon::{CpuFeature, Target}; -#[cfg(not(feature == "js"))] +#[cfg(not(feature = "js"))] pub use wasmer_compiler::types::target::{CpuFeature, Target}; pub use wasmer_types::{ From 8f798c03eec9a7bda9e73efb6d8b2cfca7a18b49 Mon Sep 17 00:00:00 2001 From: Edoardo Marangoni Date: Wed, 6 Nov 2024 18:13:03 +0100 Subject: [PATCH 10/16] fix: Use `target-lexicon` when compiling with `js` feature --- lib/api/Cargo.toml | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/lib/api/Cargo.toml b/lib/api/Cargo.toml index a2fd6570075..04400640433 100644 --- a/lib/api/Cargo.toml +++ b/lib/api/Cargo.toml @@ -90,6 +90,7 @@ wasmparser = { workspace = true, default-features = false, optional = true } hashbrown = { version = "0.11", optional = true } serde-wasm-bindgen = { version = "0.4.5" } serde = { version = "1.0", features = ["derive"] } +target-lexicon = { workspace = true } # - Development Dependencies for `js`. [target.'cfg(target_arch = "wasm32")'.dev-dependencies] @@ -168,7 +169,11 @@ xz = "0.1.0" zip = "2.2.0" [target.'cfg(target_env = "musl")'.build-dependencies] -bindgen = { version = "0.70.1", default-features = false, features = ["static", "logging", "prettyplease"] } +bindgen = { version = "0.70.1", default-features = false, features = [ + "static", + "logging", + "prettyplease", +] } [target.'cfg(not(target_env = "musl"))'.build-dependencies] bindgen = { version = "0.70.1" } From 86c766746d414f231144789b6d36f7fca5d09a34 Mon Sep 17 00:00:00 2001 From: Edoardo Marangoni Date: Wed, 6 Nov 2024 18:13:25 +0100 Subject: [PATCH 11/16] fix(compiler/windows): Remove `wasmer_types` import --- lib/compiler/src/engine/unwind/windows_x64.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/compiler/src/engine/unwind/windows_x64.rs b/lib/compiler/src/engine/unwind/windows_x64.rs index 9ef4a9840e3..d2e17a02cba 100644 --- a/lib/compiler/src/engine/unwind/windows_x64.rs +++ b/lib/compiler/src/engine/unwind/windows_x64.rs @@ -3,7 +3,7 @@ //! Module for Windows x64 ABI unwind registry. use std::collections::HashMap; -use wasmer_types::CompiledFunctionUnwindInfoReference; +use crate::types::unwind::CompiledFunctionUnwindInfoReference; use windows_sys::Win32::System::Diagnostics::Debug::{ RtlAddFunctionTable, RtlDeleteFunctionTable, IMAGE_RUNTIME_FUNCTION_ENTRY, }; From ef0ace0e6a56b0913fa2e54f3929a02dda1dcac9 Mon Sep 17 00:00:00 2001 From: Edoardo Marangoni Date: Wed, 6 Nov 2024 18:15:16 +0100 Subject: [PATCH 12/16] fix: Remove `object` crate --- lib/object/Cargo.toml | 21 --------------------- 1 file changed, 21 deletions(-) delete mode 100644 lib/object/Cargo.toml diff --git a/lib/object/Cargo.toml b/lib/object/Cargo.toml deleted file mode 100644 index 417a06bdb2e..00000000000 --- a/lib/object/Cargo.toml +++ /dev/null @@ -1,21 +0,0 @@ -[package] -name = "wasmer-object" -description = "Wasmer Native Object generator" -categories = ["wasm"] -keywords = ["wasm", "webassembly"] -readme = "README.md" -authors.workspace = true -edition.workspace = true -homepage.workspace = true -license.workspace = true -repository.workspace = true -rust-version.workspace = true -version.workspace = true - -[dependencies] -wasmer-types = { path = "../types", version = "=5.0.1" } -object = { version = "0.29.0", default-features = false, features = ["write"] } -thiserror = "1.0" - -[package.metadata.docs.rs] -rustc-args = ["--cfg", "docsrs"] From eeed74ea30a48c3af72902ba1725dc8ff658c740 Mon Sep 17 00:00:00 2001 From: Edoardo Marangoni Date: Wed, 6 Nov 2024 18:31:22 +0100 Subject: [PATCH 13/16] chore: Make linter happy --- lib/compiler/src/engine/unwind/windows_x64.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/compiler/src/engine/unwind/windows_x64.rs b/lib/compiler/src/engine/unwind/windows_x64.rs index d2e17a02cba..7d351e78c02 100644 --- a/lib/compiler/src/engine/unwind/windows_x64.rs +++ b/lib/compiler/src/engine/unwind/windows_x64.rs @@ -2,8 +2,8 @@ // Attributions: https://github.com/wasmerio/wasmer/blob/main/docs/ATTRIBUTIONS.md //! Module for Windows x64 ABI unwind registry. -use std::collections::HashMap; use crate::types::unwind::CompiledFunctionUnwindInfoReference; +use std::collections::HashMap; use windows_sys::Win32::System::Diagnostics::Debug::{ RtlAddFunctionTable, RtlDeleteFunctionTable, IMAGE_RUNTIME_FUNCTION_ENTRY, }; From 8e8506857263c2f7384838f02ea7a007c0789b97 Mon Sep 17 00:00:00 2001 From: Edoardo Marangoni Date: Thu, 7 Nov 2024 09:26:19 +0100 Subject: [PATCH 14/16] fix: Use types from `wasmer_types` --- lib/compiler/src/serialize.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/compiler/src/serialize.rs b/lib/compiler/src/serialize.rs index ca8d85550b3..a05a272b10e 100644 --- a/lib/compiler/src/serialize.rs +++ b/lib/compiler/src/serialize.rs @@ -15,9 +15,9 @@ use enumset::EnumSet; use rkyv::{Archive, Deserialize as RkyvDeserialize, Serialize as RkyvSerialize}; use wasmer_types::{ entity::PrimaryMap, DeserializeError, Features, FunctionIndex, LocalFunctionIndex, MemoryIndex, - ModuleInfo, OwnedDataInitializer, SerializeError, SignatureIndex, TableIndex, + MemoryStyle, ModuleInfo, OwnedDataInitializer, SerializeError, SignatureIndex, TableIndex, + TableStyle, }; -use wasmer_vm::{MemoryStyle, TableStyle}; pub use wasmer_types::MetadataHeader; From 2f2925b5374ae5aba586f49ace1119e95c3530af Mon Sep 17 00:00:00 2001 From: Edoardo Marangoni Date: Thu, 7 Nov 2024 10:23:45 +0100 Subject: [PATCH 15/16] fix(api): Remove use `CpuFeature` and `Target` exports for `js` feature --- lib/api/src/lib.rs | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/lib/api/src/lib.rs b/lib/api/src/lib.rs index 6f7621ae919..7ecce625a74 100644 --- a/lib/api/src/lib.rs +++ b/lib/api/src/lib.rs @@ -519,12 +519,11 @@ pub use value::Value; // Reexport from other modules pub use wasmer_derive::ValueType; -// TODO: OnCalledAction is needed for asyncify. It will be refactored with https://github.com/wasmerio/wasmer/issues/3451 -#[cfg(feature = "js")] -pub use target_lexicon::{CpuFeature, Target}; -#[cfg(not(feature = "js"))] + +#[cfg(any(feature = "sys", feature = "jsc", feature = "wasm-c-api"))] pub use wasmer_compiler::types::target::{CpuFeature, Target}; +// TODO: OnCalledAction is needed for asyncify. It will be refactored with https://github.com/wasmerio/wasmer/issues/3451 pub use wasmer_types::{ is_wasm, Bytes, CompileError, DeserializeError, ExportIndex, ExportType, ExternType, FrameInfo, FunctionType, GlobalInit, GlobalType, ImportType, LocalFunctionIndex, MemoryError, MemoryType, From f4f75bbe168ed4602423711f57ceb868b8e134e2 Mon Sep 17 00:00:00 2001 From: Edoardo Marangoni Date: Thu, 7 Nov 2024 10:32:01 +0100 Subject: [PATCH 16/16] fix(api): Gate `c_gen` module under `static-artifact-create` feature --- lib/cli/src/lib.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/cli/src/lib.rs b/lib/cli/src/lib.rs index 39883c527f0..a7bae62da71 100644 --- a/lib/cli/src/lib.rs +++ b/lib/cli/src/lib.rs @@ -23,6 +23,7 @@ mod common; mod config; #[macro_use] mod error; +#[cfg(feature = "static-artifact-create")] mod c_gen; mod logging; mod opts;