From 5d302f0d4a7aab8d47840fa914f15713cd9438fd Mon Sep 17 00:00:00 2001 From: Ivan Enderlin Date: Mon, 31 May 2021 14:19:14 +0200 Subject: [PATCH] feat: Rename `wasmer-engine-object-file` to `wasmer-engine-staticlib`. --- Cargo.lock | 8 +-- Cargo.toml | 12 ++-- Makefile | 34 +++++----- lib/c-api/Cargo.toml | 8 +-- lib/c-api/src/wasm_c_api/engine.rs | 40 ++++++------ lib/c-api/src/wasm_c_api/unstable/engine.rs | 10 +-- lib/c-api/wasmer_wasm.h | 2 +- lib/cli/Cargo.toml | 10 +-- lib/cli/src/c_gen/mod.rs | 2 +- ...ect_file_header.rs => staticlib_header.rs} | 6 +- lib/cli/src/cli.rs | 6 +- lib/cli/src/commands.rs | 4 +- lib/cli/src/commands/compile.rs | 18 ++--- lib/cli/src/commands/create_exe.rs | 8 +-- lib/cli/src/commands/wasmer_create_exe_main.c | 5 +- lib/cli/src/store.rs | 38 +++++------ .../Cargo.toml | 2 +- .../README.md | 32 +++++---- .../src/artifact.rs | 34 +++++----- .../src/builder.rs | 30 ++++----- .../src/engine.rs | 65 ++++++++++--------- .../src/lib.rs | 12 ++-- .../src/serialize.rs | 0 lib/engine/README.md | 4 +- scripts/publish.py | 8 +-- tests/integration/cli/src/util.rs | 4 +- tests/integration/cli/tests/compile.rs | 19 +++--- ...rce.c => staticlib_engine_test_c_source.c} | 4 +- 28 files changed, 216 insertions(+), 209 deletions(-) rename lib/cli/src/c_gen/{object_file_header.rs => staticlib_header.rs} (97%) rename lib/{engine-object-file => engine-staticlib}/Cargo.toml (96%) rename lib/{engine-object-file => engine-staticlib}/README.md (82%) rename lib/{engine-object-file => engine-staticlib}/src/artifact.rs (95%) rename lib/{engine-object-file => engine-staticlib}/src/builder.rs (79%) rename lib/{engine-object-file => engine-staticlib}/src/engine.rs (77%) rename lib/{engine-object-file => engine-staticlib}/src/lib.rs (70%) rename lib/{engine-object-file => engine-staticlib}/src/serialize.rs (100%) rename tests/integration/cli/tests/{object_file_engine_test_c_source.c => staticlib_engine_test_c_source.c} (95%) diff --git a/Cargo.lock b/Cargo.lock index 3404980917b..f0fb8a07fb0 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2485,7 +2485,7 @@ dependencies = [ "wasmer-emscripten", "wasmer-engine", "wasmer-engine-dylib", - "wasmer-engine-object-file", + "wasmer-engine-staticlib", "wasmer-engine-universal", "wasmer-middlewares", "wasmer-types", @@ -2531,7 +2531,7 @@ dependencies = [ "wasmer-emscripten", "wasmer-engine", "wasmer-engine-dylib", - "wasmer-engine-object-file", + "wasmer-engine-staticlib", "wasmer-engine-universal", "wasmer-types", "wasmer-vm", @@ -2700,7 +2700,7 @@ dependencies = [ ] [[package]] -name = "wasmer-engine-object-file" +name = "wasmer-engine-staticlib" version = "1.0.2" dependencies = [ "bincode", @@ -2864,7 +2864,7 @@ dependencies = [ "wasmer-engine", "wasmer-engine-dummy", "wasmer-engine-dylib", - "wasmer-engine-object-file", + "wasmer-engine-staticlib", "wasmer-engine-universal", "wasmer-middlewares", "wasmer-types", diff --git a/Cargo.toml b/Cargo.toml index 93eab4f6d98..68f4995519f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -19,7 +19,7 @@ wasmer-emscripten = { version = "1.0.2", path = "lib/emscripten", optional = tru wasmer-engine = { version = "1.0.2", path = "lib/engine" } wasmer-engine-universal = { version = "1.0.2", path = "lib/engine-universal", optional = true } wasmer-engine-dylib = { version = "1.0.2", path = "lib/engine-dylib", optional = true } -wasmer-engine-object-file = { version = "1.0.2", path = "lib/engine-object-file", optional = true } +wasmer-engine-staticlib = { version = "1.0.2", path = "lib/engine-staticlib", optional = true } wasmer-wasi = { version = "1.0.2", path = "lib/wasi", optional = true } wasmer-wast = { version = "1.0.2", path = "tests/lib/wast", optional = true } wasmer-cache = { version = "1.0.2", path = "lib/cache", optional = true } @@ -42,7 +42,7 @@ members = [ "lib/engine", "lib/engine-universal", "lib/engine-dylib", - "lib/engine-object-file", + "lib/engine-staticlib", "lib/object", "lib/vm", "lib/wasi", @@ -83,7 +83,7 @@ default = [ "wast", "universal", "dylib", - "object-file", + "staticlib", "cache", "wasi", "emscripten", @@ -98,8 +98,8 @@ dylib = [ "wasmer-engine-dylib", "engine", ] -object-file = [ - "wasmer-engine-object-file", +staticlib = [ + "wasmer-engine-staticlib", "engine", ] cache = ["wasmer-cache"] @@ -112,7 +112,7 @@ compiler = [ "wasmer-compiler/translator", "wasmer-engine-universal/compiler", "wasmer-engine-dylib/compiler", - "wasmer-engine-object-file/compiler", + "wasmer-engine-staticlib/compiler", ] singlepass = [ "wasmer-compiler-singlepass", diff --git a/Makefile b/Makefile index 6b9b1194e67..f4cd6906e65 100644 --- a/Makefile +++ b/Makefile @@ -14,7 +14,7 @@ SHELL=/bin/bash # |------------|-----------|----------|--------------|-------| # | Cranelift | Universal | Linux | amd64 | glibc | # | LLVM | Dylib | Darwin | aarch64 | musl | -# | Singlepass | | Windows | | | +# | Singlepass | Staticlib | Windows | | | # |------------|-----------|----------|--------------|-------| # # Here is what works and what doesn't: @@ -423,15 +423,15 @@ endif build-docs-capi: capi-setup cd lib/c-api/doc/deprecated/ && doxygen doxyfile - RUSTFLAGS="${RUSTFLAGS}" cargo doc --manifest-path lib/c-api/Cargo.toml --no-deps --features wat,universal,object-file,dylib,cranelift,wasi $(capi_default_features) + RUSTFLAGS="${RUSTFLAGS}" cargo doc --manifest-path lib/c-api/Cargo.toml --no-deps --features wat,universal,staticlib,dylib,cranelift,wasi $(capi_default_features) build-capi: capi-setup RUSTFLAGS="${RUSTFLAGS}" cargo build --manifest-path lib/c-api/Cargo.toml --release \ - --no-default-features --features deprecated,wat,universal,dylib,object-file,wasi,middlewares $(capi_default_features) $(capi_compiler_features) + --no-default-features --features deprecated,wat,universal,dylib,staticlib,wasi,middlewares $(capi_default_features) $(capi_compiler_features) build-capi-singlepass: capi-setup RUSTFLAGS="${RUSTFLAGS}" cargo build --manifest-path lib/c-api/Cargo.toml --release \ - --no-default-features --features deprecated,wat,universal,dylib,object-file,singlepass,wasi,middlewares $(capi_default_features) + --no-default-features --features deprecated,wat,universal,dylib,staticlib,singlepass,wasi,middlewares $(capi_default_features) build-capi-singlepass-universal: capi-setup RUSTFLAGS="${RUSTFLAGS}" cargo build --manifest-path lib/c-api/Cargo.toml --release \ @@ -441,17 +441,17 @@ build-capi-singlepass-dylib: capi-setup RUSTFLAGS="${RUSTFLAGS}" cargo build --manifest-path lib/c-api/Cargo.toml --release \ --no-default-features --features deprecated,wat,dylib,singlepass,wasi,middlewares $(capi_default_features) -build-capi-singlepass-object-file: capi-setup +build-capi-singlepass-staticlib: capi-setup RUSTFLAGS="${RUSTFLAGS}" cargo build --manifest-path lib/c-api/Cargo.toml --release \ - --no-default-features --features deprecated,wat,object-file,singlepass,wasi,middlewares $(capi_default_features) + --no-default-features --features deprecated,wat,staticlib,singlepass,wasi,middlewares $(capi_default_features) build-capi-cranelift: capi-setup RUSTFLAGS="${RUSTFLAGS}" cargo build --manifest-path lib/c-api/Cargo.toml --release \ - --no-default-features --features deprecated,wat,universal,dylib,object-file,cranelift,wasi,middlewares $(capi_default_features) + --no-default-features --features deprecated,wat,universal,dylib,staticlib,cranelift,wasi,middlewares $(capi_default_features) build-capi-cranelift-system-libffi: capi-setup RUSTFLAGS="${RUSTFLAGS}" cargo build --manifest-path lib/c-api/Cargo.toml --release \ - --no-default-features --features deprecated,wat,universal,dylib,object-file,cranelift,wasi,middlewares,system-libffi $(capi_default_features) + --no-default-features --features deprecated,wat,universal,dylib,staticlib,cranelift,wasi,middlewares,system-libffi $(capi_default_features) build-capi-cranelift-universal: capi-setup RUSTFLAGS="${RUSTFLAGS}" cargo build --manifest-path lib/c-api/Cargo.toml --release \ @@ -461,13 +461,13 @@ build-capi-cranelift-dylib: capi-setup RUSTFLAGS="${RUSTFLAGS}" cargo build --manifest-path lib/c-api/Cargo.toml --release \ --no-default-features --features deprecated,wat,dylib,cranelift,wasi,middlewares $(capi_default_features) -build-capi-cranelift-object-file: capi-setup +build-capi-cranelift-staticlib: capi-setup RUSTFLAGS="${RUSTFLAGS}" cargo build --manifest-path lib/c-api/Cargo.toml --release \ - --no-default-features --features deprecated,wat,dylib,object-file,cranelift,wasi,middlewares $(capi_default_features) + --no-default-features --features deprecated,wat,dylib,staticlib,cranelift,wasi,middlewares $(capi_default_features) build-capi-llvm: capi-setup RUSTFLAGS="${RUSTFLAGS}" cargo build --manifest-path lib/c-api/Cargo.toml --release \ - --no-default-features --features deprecated,wat,universal,dylib,object-file,llvm,wasi,middlewares $(capi_default_features) + --no-default-features --features deprecated,wat,universal,dylib,staticlib,llvm,wasi,middlewares $(capi_default_features) build-capi-llvm-universal: capi-setup RUSTFLAGS="${RUSTFLAGS}" cargo build --manifest-path lib/c-api/Cargo.toml --release \ @@ -477,9 +477,9 @@ build-capi-llvm-dylib: capi-setup RUSTFLAGS="${RUSTFLAGS}" cargo build --manifest-path lib/c-api/Cargo.toml --release \ --no-default-features --features deprecated,wat,dylib,llvm,wasi,middlewares $(capi_default_features) -build-capi-llvm-object-file: capi-setup +build-capi-llvm-staticlib: capi-setup RUSTFLAGS="${RUSTFLAGS}" cargo build --manifest-path lib/c-api/Cargo.toml --release \ - --no-default-features --features deprecated,wat,object-file,llvm,wasi,middlewares $(capi_default_features) + --no-default-features --features deprecated,wat,staticlib,llvm,wasi,middlewares $(capi_default_features) # Headless (we include the minimal to be able to run) @@ -491,13 +491,13 @@ build-capi-headless-dylib: capi-setup RUSTFLAGS="${RUSTFLAGS}" cargo build --manifest-path lib/c-api/Cargo.toml --release \ --no-default-features --features dylib,wasi -build-capi-headless-object-file: capi-setup +build-capi-headless-staticlib: capi-setup RUSTFLAGS="${RUSTFLAGS}" cargo build --manifest-path lib/c-api/Cargo.toml --release \ - --no-default-features --features object-file,wasi + --no-default-features --features staticlib,wasi build-capi-headless-all: capi-setup RUSTFLAGS="${RUSTFLAGS}" cargo build --manifest-path lib/c-api/Cargo.toml --release \ - --no-default-features --features universal,dylib,object-file,wasi + --no-default-features --features universal,dylib,staticlib,wasi ########### # Testing # @@ -550,7 +550,7 @@ test-capi: build-capi package-capi $(foreach compiler_engine,$(capi_compilers_en test-capi-crate-%: WASMER_CAPI_CONFIG=$(shell echo $@ | sed -e s/test-capi-crate-//) cargo test --manifest-path lib/c-api/Cargo.toml --release \ - --no-default-features --features deprecated,wat,universal,dylib,object-file,wasi,middlewares $(capi_default_features) $(capi_compiler_features) -- --nocapture + --no-default-features --features deprecated,wat,universal,dylib,staticlib,wasi,middlewares $(capi_default_features) $(capi_compiler_features) -- --nocapture test-capi-integration-%: # Test the Wasmer C API tests for C diff --git a/lib/c-api/Cargo.toml b/lib/c-api/Cargo.toml index 0d29787e1de..157e95a2cb9 100644 --- a/lib/c-api/Cargo.toml +++ b/lib/c-api/Cargo.toml @@ -23,7 +23,7 @@ wasmer-emscripten = { version = "1.0.2", path = "../emscripten", optional = true wasmer-engine = { version = "1.0.2", path = "../engine" } wasmer-engine-universal = { version = "1.0.2", path = "../engine-universal", optional = true } wasmer-engine-dylib = { version = "1.0.2", path = "../engine-dylib", optional = true } -wasmer-engine-object-file = { version = "1.0.2", path = "../engine-object-file", optional = true } +wasmer-engine-staticlib = { version = "1.0.2", path = "../engine-staticlib", optional = true } wasmer-middlewares = { version = "1.0.2", path = "../middlewares", optional = true } wasmer-wasi = { version = "1.0.2", path = "../wasi", optional = true } wasmer-types = { version = "1.0.2", path = "../types" } @@ -63,15 +63,15 @@ dylib = [ "wasmer-engine-dylib", "engine", ] -object-file = [ - "wasmer-engine-object-file", +staticlib = [ + "wasmer-engine-staticlib", "engine", ] compiler = [ "wasmer/compiler", "wasmer-engine-universal/compiler", "wasmer-engine-dylib/compiler", - "wasmer-engine-object-file/compiler" + "wasmer-engine-staticlib/compiler" ] singlepass = [ "wasmer-compiler-singlepass", diff --git a/lib/c-api/src/wasm_c_api/engine.rs b/lib/c-api/src/wasm_c_api/engine.rs index 72c47864bbe..b94e8fe49ab 100644 --- a/lib/c-api/src/wasm_c_api/engine.rs +++ b/lib/c-api/src/wasm_c_api/engine.rs @@ -14,8 +14,8 @@ use std::sync::Arc; use wasmer::Engine; #[cfg(feature = "dylib")] use wasmer_engine_dylib::Dylib; -#[cfg(feature = "object-file")] -use wasmer_engine_object_file::ObjectFile; +#[cfg(feature = "staticlib")] +use wasmer_engine_staticlib::Staticlib; #[cfg(feature = "universal")] use wasmer_engine_universal::Universal; @@ -73,9 +73,9 @@ pub enum wasmer_engine_t { /// [`wasmer_engine_dylib`] Rust crate. DYLIB = 1, - /// Variant to represent the Object File engine. See the - /// [`wasmer_engine_object_file`] Rust crate. - OBJECT_FILE = 2, + /// Variant to represent the Staticlib engine. See the + /// [`wasmer_engine_staticlib`] Rust crate. + STATICLIB = 2, } impl Default for wasmer_engine_t { @@ -85,8 +85,8 @@ impl Default for wasmer_engine_t { Self::UNIVERSAL } else if #[cfg(feature = "dylib")] { Self::DYLIB - } else if #[cfg(feature = "object-file")] { - Self::OBJECT_FILE + } else if #[cfg(feature = "staticlib")] { + Self::STATICLIB } else { compile_error!("Please enable one of the engines") } @@ -358,10 +358,10 @@ cfg_if! { Box::new(wasm_engine_t { inner: engine }) } } - // There are currently no uses of the object-file engine + compiler from the C API. + // There are currently no uses of the Staticlib engine + compiler from the C API. // So if we get here, we default to headless mode regardless of if `compiler` is enabled. - else if #[cfg(feature = "object-file")] { - /// Creates a new headless object-file engine. + else if #[cfg(feature = "staticlib")] { + /// Creates a new headless Staticlib engine. /// /// # Example /// @@ -370,7 +370,7 @@ cfg_if! { /// cbindgen:ignore #[no_mangle] pub extern "C" fn wasm_engine_new() -> Box { - let engine: Arc = Arc::new(ObjectFile::headless().engine()); + let engine: Arc = Arc::new(Staticlib::headless().engine()); Box::new(wasm_engine_t { inner: engine }) } } else { @@ -521,12 +521,12 @@ pub extern "C" fn wasm_engine_new_with_config( } } }, - wasmer_engine_t::OBJECT_FILE => { + wasmer_engine_t::STATICLIB => { cfg_if! { - // There are currently no uses of the object-file engine + compiler from the C API. + // There are currently no uses of the Staticlib engine + compiler from the C API. // So we run in headless mode. - if #[cfg(feature = "object-file")] { - let mut builder = ObjectFile::headless(); + if #[cfg(feature = "staticlib")] { + let mut builder = Staticlib::headless(); if let Some(target) = config.target { builder = builder.target(target.inner); @@ -538,7 +538,7 @@ pub extern "C" fn wasm_engine_new_with_config( Arc::new(builder.engine()) } else { - return return_with_error("Wasmer has not been compiled with the `object-file` feature."); + return return_with_error("Wasmer has not been compiled with the `staticlib` feature."); } } }, @@ -584,10 +584,10 @@ pub extern "C" fn wasm_engine_new_with_config( } } }, - wasmer_engine_t::OBJECT_FILE => { + wasmer_engine_t::STATICLIB => { cfg_if! { - if #[cfg(feature = "object-file")] { - let mut builder = ObjectFile::headless(); + if #[cfg(feature = "staticlib")] { + let mut builder = Staticlib::headless(); if let Some(target) = config.target { builder = builder.target(target.inner); @@ -599,7 +599,7 @@ pub extern "C" fn wasm_engine_new_with_config( Arc::new(builder.engine()) } else { - return return_with_error("Wasmer has not been compiled with the `object-file` feature."); + return return_with_error("Wasmer has not been compiled with the `staticlib` feature."); } } }, diff --git a/lib/c-api/src/wasm_c_api/unstable/engine.rs b/lib/c-api/src/wasm_c_api/unstable/engine.rs index 66c53dfe733..1b2925ed3d6 100644 --- a/lib/c-api/src/wasm_c_api/unstable/engine.rs +++ b/lib/c-api/src/wasm_c_api/unstable/engine.rs @@ -121,7 +121,7 @@ pub extern "C" fn wasmer_is_engine_available(engine: wasmer_engine_t) -> bool { match engine { wasmer_engine_t::UNIVERSAL if cfg!(feature = "universal") => true, wasmer_engine_t::DYLIB if cfg!(feature = "dylib") => true, - wasmer_engine_t::OBJECT_FILE if cfg!(feature = "object-file") => true, + wasmer_engine_t::STATICLIB if cfg!(feature = "staticlib") => true, _ => false, } } @@ -204,8 +204,8 @@ mod tests { ); set_var("DYLIB", if cfg!(feature = "dylib") { "1" } else { "0" }); set_var( - "OBJECT_FILE", - if cfg!(feature = "object-file") { + "STATICLIB", + if cfg!(feature = "staticlib") { "1" } else { "0" @@ -219,7 +219,7 @@ mod tests { int main() { assert(wasmer_is_engine_available(UNIVERSAL) == (getenv("UNIVERSAL")[0] == '1')); assert(wasmer_is_engine_available(DYLIB) == (getenv("DYLIB")[0] == '1')); - assert(wasmer_is_engine_available(OBJECT_FILE) == (getenv("OBJECT_FILE")[0] == '1')); + assert(wasmer_is_engine_available(STATICLIB) == (getenv("STATICLIB")[0] == '1')); return 0; } @@ -228,6 +228,6 @@ mod tests { remove_var("UNIVERSAL"); remove_var("DYLIB"); - remove_var("OBJECT_FILE"); + remove_var("STATICLIB"); } } diff --git a/lib/c-api/wasmer_wasm.h b/lib/c-api/wasmer_wasm.h index 13d01c11809..2f3c99dcd45 100644 --- a/lib/c-api/wasmer_wasm.h +++ b/lib/c-api/wasmer_wasm.h @@ -126,7 +126,7 @@ typedef enum wasmer_compiler_t { typedef enum wasmer_engine_t { UNIVERSAL = 0, DYLIB = 1, - OBJECT_FILE = 2, + STATICLIB = 2, } wasmer_engine_t; typedef enum wasmer_parser_operator_t { diff --git a/lib/cli/Cargo.toml b/lib/cli/Cargo.toml index 65d6afcc471..63f5db770fe 100644 --- a/lib/cli/Cargo.toml +++ b/lib/cli/Cargo.toml @@ -33,7 +33,7 @@ wasmer-emscripten = { version = "1.0.2", path = "../emscripten", optional = true wasmer-engine = { version = "1.0.2", path = "../engine" } wasmer-engine-universal = { version = "1.0.2", path = "../engine-universal", optional = true } wasmer-engine-dylib = { version = "1.0.2", path = "../engine-dylib", optional = true } -wasmer-engine-object-file = { version = "1.0.2", path = "../engine-object-file", optional = true } +wasmer-engine-staticlib = { version = "1.0.2", path = "../engine-staticlib", optional = true } wasmer-vm = { version = "1.0.2", path = "../vm" } wasmer-wasi = { version = "1.0.2", path = "../wasi", default-features = false, optional = true } wasmer-wasi-experimental-io-devices = { version = "1.0.2", path = "../wasi-experimental-io-devices", optional = true } @@ -62,7 +62,7 @@ default = [ "wast", "universal", "dylib", - "object-file", + "staticlib", "cache", "wasi", "emscripten", @@ -76,8 +76,8 @@ dylib = [ "wasmer-engine-dylib", "engine", ] -object-file = [ - "wasmer-engine-object-file", +staticlib = [ + "wasmer-engine-staticlib", "engine", ] cache = ["wasmer-cache"] @@ -89,7 +89,7 @@ compiler = [ "wasmer-compiler/translator", "wasmer-engine-universal/compiler", "wasmer-engine-dylib/compiler", - "wasmer-engine-object-file/compiler", + "wasmer-engine-staticlib/compiler", ] experimental-io-devices = [ "wasmer-wasi-experimental-io-devices", diff --git a/lib/cli/src/c_gen/mod.rs b/lib/cli/src/c_gen/mod.rs index b87b0e22677..58766a4597a 100644 --- a/lib/cli/src/c_gen/mod.rs +++ b/lib/cli/src/c_gen/mod.rs @@ -1,7 +1,7 @@ //! A convenient little abstraction for building up C expressions and generating //! simple C code. -pub mod object_file_header; +pub mod staticlib_header; /// An identifier in C. pub type CIdent = String; diff --git a/lib/cli/src/c_gen/object_file_header.rs b/lib/cli/src/c_gen/staticlib_header.rs similarity index 97% rename from lib/cli/src/c_gen/object_file_header.rs rename to lib/cli/src/c_gen/staticlib_header.rs index f76b189a5fa..2fd5d78ab0f 100644 --- a/lib/cli/src/c_gen/object_file_header.rs +++ b/lib/cli/src/c_gen/staticlib_header.rs @@ -1,10 +1,10 @@ -//! Generate a header file for the object file produced by the ObjectFile engine. +//! Generate a header file for the object file produced by the Staticlib engine. use super::{generate_c, CStatement, CType}; use wasmer_compiler::{Symbol, SymbolRegistry}; use wasmer_vm::ModuleInfo; -/// Helper functions to simplify the usage of the object file engine. +/// Helper functions to simplify the usage of the Staticlib engine. const HELPER_FUNCTIONS: &str = r#" wasm_byte_vec_t generate_serialized_data() { // We need to pass all the bytes as one big buffer so we have to do all this logic to memcpy @@ -58,7 +58,7 @@ wasm_byte_vec_t generate_serialized_data() { return module_byte_vec; } -wasm_module_t* wasmer_object_file_engine_new(wasm_store_t* store, const char* wasm_name) { +wasm_module_t* wasmer_staticlib_engine_new(wasm_store_t* store, const char* wasm_name) { // wasm_name intentionally unused for now: will be used in the future. wasm_byte_vec_t module_byte_vec = generate_serialized_data(); wasm_module_t* module = wasm_module_deserialize(store, &module_byte_vec); diff --git a/lib/cli/src/cli.rs b/lib/cli/src/cli.rs index 00ba6922728..9b4e9c2b8cd 100644 --- a/lib/cli/src/cli.rs +++ b/lib/cli/src/cli.rs @@ -2,7 +2,7 @@ #[cfg(feature = "compiler")] use crate::commands::Compile; -#[cfg(all(feature = "object-file", feature = "compiler"))] +#[cfg(all(feature = "staticlib", feature = "compiler"))] use crate::commands::CreateExe; #[cfg(feature = "wast")] use crate::commands::Wast; @@ -45,7 +45,7 @@ enum WasmerCLIOptions { Compile(Compile), /// Compile a WebAssembly binary into a native executable - #[cfg(all(feature = "object-file", feature = "compiler"))] + #[cfg(all(feature = "staticlib", feature = "compiler"))] #[clap(name = "create-exe")] CreateExe(CreateExe), @@ -77,7 +77,7 @@ impl WasmerCLIOptions { Self::Validate(validate) => validate.execute(), #[cfg(feature = "compiler")] Self::Compile(compile) => compile.execute(), - #[cfg(all(feature = "object-file", feature = "compiler"))] + #[cfg(all(feature = "staticlib", feature = "compiler"))] Self::CreateExe(create_exe) => create_exe.execute(), Self::Config(config) => config.execute(), Self::Inspect(inspect) => inspect.execute(), diff --git a/lib/cli/src/commands.rs b/lib/cli/src/commands.rs index 5e80631d7e0..2e7b2926a8c 100644 --- a/lib/cli/src/commands.rs +++ b/lib/cli/src/commands.rs @@ -3,7 +3,7 @@ mod cache; #[cfg(feature = "compiler")] mod compile; mod config; -#[cfg(all(feature = "object-file", feature = "compiler"))] +#[cfg(all(feature = "staticlib", feature = "compiler"))] mod create_exe; mod inspect; mod run; @@ -14,7 +14,7 @@ mod wast; #[cfg(feature = "compiler")] pub use compile::*; -#[cfg(all(feature = "object-file", feature = "compiler"))] +#[cfg(all(feature = "staticlib", feature = "compiler"))] pub use create_exe::*; #[cfg(feature = "wast")] pub use wast::*; diff --git a/lib/cli/src/commands/compile.rs b/lib/cli/src/commands/compile.rs index 713d35dca0d..f2e7177059d 100644 --- a/lib/cli/src/commands/compile.rs +++ b/lib/cli/src/commands/compile.rs @@ -51,11 +51,11 @@ impl Compile { EngineType::Universal => { wasmer_engine_universal::UniversalArtifact::get_default_extension(target_triple) } - #[cfg(feature = "object-file")] - EngineType::ObjectFile => { - wasmer_engine_object_file::ObjectFileArtifact::get_default_extension(target_triple) + #[cfg(feature = "staticlib")] + EngineType::Staticlib => { + wasmer_engine_staticlib::StaticlibArtifact::get_default_extension(target_triple) } - #[cfg(not(all(feature = "dylib", feature = "universal", feature = "object-file")))] + #[cfg(not(all(feature = "dylib", feature = "universal", feature = "staticlib")))] _ => bail!("selected engine type is not compiled in"), }) } @@ -105,14 +105,14 @@ impl Compile { self.output.display(), ); - #[cfg(feature = "object-file")] - if engine_type == EngineType::ObjectFile { - let artifact: &wasmer_engine_object_file::ObjectFileArtifact = - module.artifact().as_ref().downcast_ref().context("Engine type is ObjectFile but could not downcast artifact into ObjectFileArtifact")?; + #[cfg(feature = "staticlib")] + if engine_type == EngineType::Staticlib { + let artifact: &wasmer_engine_staticlib::StaticlibArtifact = + module.artifact().as_ref().downcast_ref().context("Engine type is Staticlib but could not downcast artifact into StaticlibArtifact")?; let symbol_registry = artifact.symbol_registry(); let metadata_length = artifact.metadata_length(); let module_info = module.info(); - let header_file_src = crate::c_gen::object_file_header::generate_header_file( + let header_file_src = crate::c_gen::staticlib_header::generate_header_file( module_info, symbol_registry, metadata_length, diff --git a/lib/cli/src/commands/create_exe.rs b/lib/cli/src/commands/create_exe.rs index 4de45e92257..45482e3847b 100644 --- a/lib/cli/src/commands/create_exe.rs +++ b/lib/cli/src/commands/create_exe.rs @@ -56,7 +56,7 @@ impl CreateExe { Target::new(target_triple.clone(), features) }) .unwrap_or_default(); - let engine_type = EngineType::ObjectFile; + let engine_type = EngineType::Staticlib; let (store, compiler_type) = self .compiler .get_store_for_target_and_engine(target.clone(), engine_type)?; @@ -81,14 +81,14 @@ impl CreateExe { Module::from_file(&store, &wasm_module_path).context("failed to compile Wasm")?; let _ = module.serialize_to_file(&wasm_object_path)?; - let artifact: &wasmer_engine_object_file::ObjectFileArtifact = + let artifact: &wasmer_engine_staticlib::StaticlibArtifact = module.artifact().as_ref().downcast_ref().context( - "Engine type is ObjectFile but could not downcast artifact into ObjectFileArtifact", + "Engine type is Staticlib but could not downcast artifact into StaticlibArtifact", )?; let symbol_registry = artifact.symbol_registry(); let metadata_length = artifact.metadata_length(); let module_info = module.info(); - let header_file_src = crate::c_gen::object_file_header::generate_header_file( + let header_file_src = crate::c_gen::staticlib_header::generate_header_file( module_info, symbol_registry, metadata_length, diff --git a/lib/cli/src/commands/wasmer_create_exe_main.c b/lib/cli/src/commands/wasmer_create_exe_main.c index cfab834a421..98f50d62737 100644 --- a/lib/cli/src/commands/wasmer_create_exe_main.c +++ b/lib/cli/src/commands/wasmer_create_exe_main.c @@ -89,11 +89,12 @@ static void handle_arguments(wasi_config_t *wasi_config, int argc, int main(int argc, char *argv[]) { wasm_config_t *config = wasm_config_new(); - wasm_config_set_engine(config, OBJECT_FILE); + wasm_config_set_engine(config, STATICLIB); wasm_engine_t *engine = wasm_engine_new_with_config(config); wasm_store_t *store = wasm_store_new(engine); - wasm_module_t *module = wasmer_object_file_engine_new(store, argv[0]); + wasm_module_t *module = wasmer_staticlib_engine_new(store, argv[0]); + if (!module) { fprintf(stderr, "Failed to create module\n"); print_wasmer_error(); diff --git a/lib/cli/src/store.rs b/lib/cli/src/store.rs index 4870e2dee72..2feb1599a23 100644 --- a/lib/cli/src/store.rs +++ b/lib/cli/src/store.rs @@ -20,16 +20,16 @@ pub struct StoreOptions { compiler: CompilerOptions, /// Use the Universal Engine. - #[clap(long, conflicts_with_all = &["dylib", "object-file"])] + #[clap(long, conflicts_with_all = &["dylib", "staticlib"])] universal: bool, /// Use the Dylib Engine. - #[clap(long, conflicts_with_all = &["universal", "object-file"])] + #[clap(long, conflicts_with_all = &["universal", "staticlib"])] dylib: bool, - /// Use the ObjectFile Engine. + /// Use the Staticlib Engine. #[clap(long, conflicts_with_all = &["universal", "dylib"])] - object_file: bool, + staticlib: bool, } #[derive(Debug, Clone, Clap)] @@ -150,14 +150,14 @@ impl CompilerOptions { .features(features) .engine(), ), - #[cfg(feature = "object-file")] - EngineType::ObjectFile => Box::new( - wasmer_engine_object_file::ObjectFile::new(compiler_config) + #[cfg(feature = "staticlib")] + EngineType::Staticlib => Box::new( + wasmer_engine_staticlib::Staticlib::new(compiler_config) .target(target) .features(features) .engine(), ), - #[cfg(not(all(feature = "universal", feature = "dylib", feature = "object-file")))] + #[cfg(not(all(feature = "universal", feature = "dylib", feature = "staticlib")))] engine => bail!( "The `{}` engine is not included in this binary.", engine.to_string() @@ -364,8 +364,8 @@ pub enum EngineType { Universal, /// Dylib Engine Dylib, - /// Object File Engine - ObjectFile, + /// Static Engine + Staticlib, } impl ToString for EngineType { @@ -373,7 +373,7 @@ impl ToString for EngineType { match self { Self::Universal => "universal".to_string(), Self::Dylib => "dylib".to_string(), - Self::ObjectFile => "objectfile".to_string(), + Self::Staticlib => "staticlib".to_string(), } } } @@ -418,16 +418,16 @@ impl StoreOptions { Ok(EngineType::Universal) } else if self.dylib { Ok(EngineType::Dylib) - } else if self.object_file { - Ok(EngineType::ObjectFile) + } else if self.staticlib { + Ok(EngineType::Staticlib) } else { // Auto mode, we choose the best engine for that platform if cfg!(feature = "universal") { Ok(EngineType::Universal) } else if cfg!(feature = "dylib") { Ok(EngineType::Dylib) - } else if cfg!(feature = "object-file") { - Ok(EngineType::ObjectFile) + } else if cfg!(feature = "staticlib") { + Ok(EngineType::Staticlib) } else { bail!("There are no available engines for your architecture") } @@ -447,11 +447,11 @@ impl StoreOptions { } #[cfg(feature = "dylib")] EngineType::Dylib => Arc::new(wasmer_engine_dylib::Dylib::headless().engine()), - #[cfg(feature = "object-file")] - EngineType::ObjectFile => { - Arc::new(wasmer_engine_object_file::ObjectFile::headless().engine()) + #[cfg(feature = "staticlib")] + EngineType::Staticlib => { + Arc::new(wasmer_engine_staticlib::Staticlib::headless().engine()) } - #[cfg(not(all(feature = "universal", feature = "dylib", feature = "object-file")))] + #[cfg(not(all(feature = "universal", feature = "dylib", feature = "staticlib")))] engine => bail!( "The `{}` engine is not included in this binary.", engine.to_string() diff --git a/lib/engine-object-file/Cargo.toml b/lib/engine-staticlib/Cargo.toml similarity index 96% rename from lib/engine-object-file/Cargo.toml rename to lib/engine-staticlib/Cargo.toml index 3e86068d5b3..4046727148e 100644 --- a/lib/engine-object-file/Cargo.toml +++ b/lib/engine-staticlib/Cargo.toml @@ -1,5 +1,5 @@ [package] -name = "wasmer-engine-object-file" +name = "wasmer-engine-staticlib" version = "1.0.2" authors = ["Wasmer Engineering Team "] description = "Wasmer Object File Engine" diff --git a/lib/engine-object-file/README.md b/lib/engine-staticlib/README.md similarity index 82% rename from lib/engine-object-file/README.md rename to lib/engine-staticlib/README.md index d8f87bc86a5..d1736cfae4e 100644 --- a/lib/engine-object-file/README.md +++ b/lib/engine-staticlib/README.md @@ -1,30 +1,34 @@ -# Wasmer Engine Object File +# Wasmer Engine Staticlib -This is an [engine](https://crates.io/crates/wasmer-engine) for the [wasmer](https://crates.io/crates/wasmer) WebAssembly VM. +This is an [engine](https://crates.io/crates/wasmer-engine) for the +[wasmer](https://crates.io/crates/wasmer) WebAssembly VM. -This engine is used to produce a native object file that can be linked -against providing a sandboxed WebAssembly runtime environment for the -compiled module with no need for runtime compilation. +This engine is used to produce a native static object library that can +be linked against providing a sandboxed WebAssembly runtime +environment for the compiled module with no need for runtime +compilation. ## Example of use First we compile our WebAssembly file with Wasmer + ```sh -wasmer compile path/to/wasm/file.wasm --llvm --object-file -o my_wasm.o --header my_wasm.h +wasmer compile path/to/wasm/file.wasm --llvm --staticlib -o my_wasm.o --header my_wasm.h ``` You will then see output like: + ``` -Engine: objectfile +Engine: staticlib Compiler: llvm Target: x86_64-apple-darwin ✔ File compiled successfully to `my_wasm.o`. ✔ Header file generated successfully at `my_wasm.h`. ``` -Now lets create a program to link with this object file. +Now let's create a program to link with this static object file. -```C +```c #include "wasmer_wasm.h" #include "wasm.h" #include "my_wasm.h" @@ -47,11 +51,11 @@ static void print_wasmer_error() int main() { printf("Initializing...\n"); wasm_config_t* config = wasm_config_new(); - wasm_config_set_engine(config, OBJECT_FILE); + wasm_config_set_engine(config, STATICLIB); wasm_engine_t* engine = wasm_engine_new_with_config(config); wasm_store_t* store = wasm_store_new(engine); - wasm_module_t* module = wasmer_object_file_engine_new(store, "qjs.wasm"); + wasm_module_t* module = wasmer_staticlib_engine_new(store, "qjs.wasm"); if (!module) { printf("Failed to create module\n"); print_wasmer_error(); @@ -130,6 +134,6 @@ Now we just need to link everything together: clang -O2 test.o my_wasm.o libwasmer_c_api.a ``` -We link the object file we created with our C code, the object file we -generated with Wasmer, and `libwasmer_c_api` together and produce an -executable that can call into our compiled WebAssembly! +We link the static object file we created with our C code, the object +file we generated with Wasmer, and `libwasmer_c_api` together and +produce an executable that can call into our compiled WebAssembly! diff --git a/lib/engine-object-file/src/artifact.rs b/lib/engine-staticlib/src/artifact.rs similarity index 95% rename from lib/engine-object-file/src/artifact.rs rename to lib/engine-staticlib/src/artifact.rs index 779554052f7..0a7d03350b9 100644 --- a/lib/engine-object-file/src/artifact.rs +++ b/lib/engine-staticlib/src/artifact.rs @@ -1,7 +1,7 @@ -//! Define `ObjectFileArtifact` to allow compiling and instantiating to be +//! Define `StaticlibArtifact` to allow compiling and instantiating to be //! done as separate steps. -use crate::engine::{ObjectFileEngine, ObjectFileEngineInner}; +use crate::engine::{StaticlibEngine, StaticlibEngineInner}; use crate::serialize::{ModuleMetadata, ModuleMetadataSymbolRegistry}; use loupe::MemoryUsage; use std::collections::BTreeMap; @@ -34,7 +34,7 @@ use wasmer_vm::{ /// A compiled wasm module, ready to be instantiated. #[derive(MemoryUsage)] -pub struct ObjectFileArtifact { +pub struct StaticlibArtifact { metadata: ModuleMetadata, module_bytes: Vec, finished_functions: BoxedSlice, @@ -56,7 +56,7 @@ fn to_compile_error(err: impl Error) -> CompileError { #[allow(dead_code)] const WASMER_METADATA_SYMBOL: &[u8] = b"WASMER_METADATA"; -impl ObjectFileArtifact { +impl StaticlibArtifact { // Mach-O header in Mac #[allow(dead_code)] const MAGIC_HEADER_MH_CIGAM_64: &'static [u8] = &[207, 250, 237, 254]; @@ -73,10 +73,10 @@ impl ObjectFileArtifact { #[allow(dead_code)] const MAGIC_HEADER_COFF_64: &'static [u8] = &[b'M', b'Z']; - /// Check if the provided bytes look like `ObjectFileArtifact`. + /// Check if the provided bytes look like `StaticlibArtifact`. /// - /// This means, if the bytes look like a shared object file in the target - /// system. + /// This means, if the bytes look like a static object file in the + /// target system. pub fn is_deserializable(bytes: &[u8]) -> bool { cfg_if::cfg_if! { if #[cfg(all(target_pointer_width = "64", target_os="macos"))] { @@ -146,11 +146,11 @@ impl ObjectFileArtifact { )) } - /// Compile a data buffer into a `ObjectFileArtifact`, which can be statically linked against + /// Compile a data buffer into a `StaticlibArtifact`, which can be statically linked against /// and run later. #[cfg(feature = "compiler")] pub fn new( - engine: &ObjectFileEngine, + engine: &StaticlibEngine, data: &[u8], tunables: &dyn Tunables, ) -> Result { @@ -261,9 +261,9 @@ impl ObjectFileArtifact { } } - /// Construct a `ObjectFileArtifact` from component parts. + /// Construct a `StaticlibArtifact` from component parts. pub fn from_parts_crosscompiled( - engine_inner: &mut ObjectFileEngineInner, + engine_inner: &mut StaticlibEngineInner, metadata: ModuleMetadata, module_bytes: Vec, metadata_length: usize, @@ -298,21 +298,21 @@ impl ObjectFileArtifact { }) } - /// Compile a data buffer into a `ObjectFileArtifact`, which may then be instantiated. + /// Compile a data buffer into a `StaticlibArtifact`, which may then be instantiated. #[cfg(not(feature = "compiler"))] - pub fn new(_engine: &ObjectFileEngine, _data: &[u8]) -> Result { + pub fn new(_engine: &StaticlibEngine, _data: &[u8]) -> Result { Err(CompileError::Codegen( "Compilation is not enabled in the engine".to_string(), )) } - /// Deserialize a `ObjectFileArtifact` from bytes. + /// Deserialize a `StaticlibArtifact` from bytes. /// /// # Safety /// /// The bytes must represent a serialized WebAssembly module. pub unsafe fn deserialize( - engine: &ObjectFileEngine, + engine: &StaticlibEngine, bytes: &[u8], ) -> Result { let mut reader = bytes; @@ -429,7 +429,7 @@ impl ObjectFileArtifact { } } -impl Artifact for ObjectFileArtifact { +impl Artifact for StaticlibArtifact { fn module(&self) -> Arc { self.metadata.compile_info.module.clone() } @@ -486,7 +486,7 @@ impl Artifact for ObjectFileArtifact { Ok(()) } - /// Serialize a ObjectFileArtifact + /// Serialize a StaticlibArtifact fn serialize(&self) -> Result, SerializeError> { Ok(self.module_bytes.clone()) } diff --git a/lib/engine-object-file/src/builder.rs b/lib/engine-staticlib/src/builder.rs similarity index 79% rename from lib/engine-object-file/src/builder.rs rename to lib/engine-staticlib/src/builder.rs index 49a05c2c2d2..1f0a4f7eb6b 100644 --- a/lib/engine-object-file/src/builder.rs +++ b/lib/engine-staticlib/src/builder.rs @@ -1,16 +1,16 @@ -use crate::ObjectFileEngine; +use crate::StaticlibEngine; use wasmer_compiler::{CompilerConfig, Features, Target}; -/// The ObjectFile builder -pub struct ObjectFile { +/// The Staticlib builder +pub struct Staticlib { compiler_config: Option>, target: Option, features: Option, } -impl ObjectFile { +impl Staticlib { #[cfg(feature = "compiler")] - /// Create a new ObjectFile + /// Create a new Staticlib pub fn new(compiler_config: T) -> Self where T: Into>, @@ -25,7 +25,7 @@ impl ObjectFile { } } - /// Create a new headless ObjectFile + /// Create a new headless Staticlib pub fn headless() -> Self { Self { compiler_config: None, @@ -46,8 +46,8 @@ impl ObjectFile { self } - /// Build the `ObjectFileEngine` for this configuration - pub fn engine(self) -> ObjectFileEngine { + /// Build the `StaticlibEngine` for this configuration + pub fn engine(self) -> StaticlibEngine { if let Some(_compiler_config) = self.compiler_config { #[cfg(feature = "compiler")] { @@ -57,15 +57,15 @@ impl ObjectFile { .features .unwrap_or_else(|| compiler_config.default_features_for_target(&target)); let compiler = compiler_config.compiler(); - ObjectFileEngine::new(compiler, target, features) + StaticlibEngine::new(compiler, target, features) } #[cfg(not(feature = "compiler"))] { - unreachable!("Cannot call `ObjectFileEngine::new` without the `compiler` feature") + unreachable!("Cannot call `StaticlibEngine::new` without the `compiler` feature") } } else { - ObjectFileEngine::headless() + StaticlibEngine::headless() } } } @@ -105,13 +105,13 @@ mod tests { #[should_panic(expected = "compiler not implemented")] fn build_engine() { let compiler_config = TestCompilerConfig::default(); - let object_file = ObjectFile::new(compiler_config); - let _engine = object_file.engine(); + let staticlib = Staticlib::new(compiler_config); + let _engine = staticlib.engine(); } #[test] fn build_headless_engine() { - let object_file = ObjectFile::headless(); - let _engine = object_file.engine(); + let staticlib = Staticlib::headless(); + let _engine = staticlib.engine(); } } diff --git a/lib/engine-object-file/src/engine.rs b/lib/engine-staticlib/src/engine.rs similarity index 77% rename from lib/engine-object-file/src/engine.rs rename to lib/engine-staticlib/src/engine.rs index 2a15137bfb6..a0ee4c4d65a 100644 --- a/lib/engine-object-file/src/engine.rs +++ b/lib/engine-staticlib/src/engine.rs @@ -1,4 +1,4 @@ -use crate::ObjectFileArtifact; +use crate::StaticlibArtifact; use loupe::MemoryUsage; use std::io::Read; use std::path::Path; @@ -14,21 +14,21 @@ use wasmer_vm::{ FuncDataRegistry, SignatureRegistry, VMCallerCheckedAnyfunc, VMFuncRef, VMSharedSignatureIndex, }; -/// A WebAssembly `ObjectFile` Engine. +/// A WebAssembly `Staticlib` Engine. #[derive(Clone, MemoryUsage)] -pub struct ObjectFileEngine { - inner: Arc>, +pub struct StaticlibEngine { + inner: Arc>, /// The target for the compiler target: Arc, engine_id: EngineId, } -impl ObjectFileEngine { - /// Create a new `ObjectFileEngine` with the given config +impl StaticlibEngine { + /// Create a new `StaticlibEngine` with the given config #[cfg(feature = "compiler")] pub fn new(compiler: Box, target: Target, features: Features) -> Self { Self { - inner: Arc::new(Mutex::new(ObjectFileEngineInner { + inner: Arc::new(Mutex::new(StaticlibEngineInner { compiler: Some(compiler), signatures: SignatureRegistry::new(), func_data: Arc::new(FuncDataRegistry::new()), @@ -40,7 +40,7 @@ impl ObjectFileEngine { } } - /// Create a headless `ObjectFileEngine` + /// Create a headless `StaticlibEngine` /// /// A headless engine is an engine without any compiler attached. /// This is useful for assuring a minimal runtime for running @@ -55,7 +55,7 @@ impl ObjectFileEngine { /// they just take already processed Modules (via `Module::serialize`). pub fn headless() -> Self { Self { - inner: Arc::new(Mutex::new(ObjectFileEngineInner { + inner: Arc::new(Mutex::new(StaticlibEngineInner { #[cfg(feature = "compiler")] compiler: None, #[cfg(feature = "compiler")] @@ -69,16 +69,17 @@ impl ObjectFileEngine { } } - /// Sets a prefixer for the wasm module, so we can avoid any collisions - /// in the exported function names on the generated shared object. + /// Sets a prefixer for the Wasm module, so we can avoid any + /// collisions in the exported function names on the generated + /// object. /// - /// This, allows us to rather than have functions named `wasmer_function_1` - /// to be named `wasmer_function_PREFIX_1`. + /// This, allows us to rather than have functions named + /// `wasmer_function_1` to be named `wasmer_function_PREFIX_1`. /// /// # Important /// - /// This prefixer function should be deterministic, so the compilation - /// remains deterministic. + /// This prefixer function should be deterministic, so the + /// compilation remains deterministic. pub fn set_deterministic_prefixer(&mut self, prefixer: F) where F: Fn(&[u8]) -> String + Send + 'static, @@ -87,16 +88,16 @@ impl ObjectFileEngine { inner.prefixer = Some(Box::new(prefixer)); } - pub(crate) fn inner(&self) -> std::sync::MutexGuard<'_, ObjectFileEngineInner> { + pub(crate) fn inner(&self) -> std::sync::MutexGuard<'_, StaticlibEngineInner> { self.inner.lock().unwrap() } - pub(crate) fn inner_mut(&self) -> std::sync::MutexGuard<'_, ObjectFileEngineInner> { + pub(crate) fn inner_mut(&self) -> std::sync::MutexGuard<'_, StaticlibEngineInner> { self.inner.lock().unwrap() } } -impl Engine for ObjectFileEngine { +impl Engine for StaticlibEngine { /// The target fn target(&self) -> &Target { &self.target @@ -131,7 +132,7 @@ impl Engine for ObjectFileEngine { binary: &[u8], tunables: &dyn Tunables, ) -> Result, CompileError> { - Ok(Arc::new(ObjectFileArtifact::new(&self, binary, tunables)?)) + Ok(Arc::new(StaticlibArtifact::new(&self, binary, tunables)?)) } /// Compile a WebAssembly binary (it will fail because the `compiler` flag is disabled). @@ -142,18 +143,20 @@ impl Engine for ObjectFileEngine { _tunables: &dyn Tunables, ) -> Result, CompileError> { Err(CompileError::Codegen( - "The `ObjectFileEngine` is operating in headless mode, so it cannot compile a module." + "The `StaticlibEngine` is operating in headless mode, so it cannot compile a module." .to_string(), )) } - /// Deserializes a WebAssembly module (binary content of a Shared Object file) + /// Deserializes a WebAssembly module (binary content of a static object file) unsafe fn deserialize(&self, bytes: &[u8]) -> Result, DeserializeError> { - Ok(Arc::new(ObjectFileArtifact::deserialize(&self, &bytes)?)) + Ok(Arc::new(StaticlibArtifact::deserialize(&self, &bytes)?)) } /// Deserializes a WebAssembly module from a path - /// It should point to a Shared Object file generated by this engine. + /// + /// It should point to a static object file generated by this + /// engine. unsafe fn deserialize_from_file( &self, file_ref: &Path, @@ -174,9 +177,9 @@ impl Engine for ObjectFileEngine { } } -/// The inner contents of `ObjectFileEngine` +/// The inner contents of `StaticlibEngine` #[derive(MemoryUsage)] -pub struct ObjectFileEngineInner { +pub struct StaticlibEngineInner { /// The compiler #[cfg(feature = "compiler")] compiler: Option>, @@ -194,19 +197,19 @@ pub struct ObjectFileEngineInner { /// It also guarantees that the `VMFuncRef`s stay valid until the engine is dropped. func_data: Arc, - /// The prefixer returns the a String to prefix each of - /// the functions in the shared object generated by the `ObjectFileEngine`, - /// so we can assure no collisions. + /// The prefixer returns the a String to prefix each of the + /// functions in the static object generated by the + /// `StaticlibEngine`, so we can assure no collisions. #[loupe(skip)] prefixer: Option String + Send>>, } -impl ObjectFileEngineInner { +impl StaticlibEngineInner { /// Gets the compiler associated to this engine. #[cfg(feature = "compiler")] pub fn compiler(&self) -> Result<&dyn Compiler, CompileError> { if self.compiler.is_none() { - return Err(CompileError::Codegen("The `ObjectFileEngine` is operating in headless mode, so it can only execute already compiled Modules.".to_string())); + return Err(CompileError::Codegen("The `StaticlibEngine` is operating in headless mode, so it can only execute already compiled Modules.".to_string())); } Ok(&**self .compiler @@ -238,7 +241,7 @@ impl ObjectFileEngineInner { #[cfg(not(feature = "compiler"))] pub fn validate<'data>(&self, _data: &'data [u8]) -> Result<(), CompileError> { Err(CompileError::Validate( - "The `ObjectFileEngine` is not compiled with compiler support, which is required for validating".to_string(), + "The `StaticlibEngine` is not compiled with compiler support, which is required for validating".to_string(), )) } diff --git a/lib/engine-object-file/src/lib.rs b/lib/engine-staticlib/src/lib.rs similarity index 70% rename from lib/engine-object-file/src/lib.rs rename to lib/engine-staticlib/src/lib.rs index e3f607811f8..db416de7500 100644 --- a/lib/engine-object-file/src/lib.rs +++ b/lib/engine-staticlib/src/lib.rs @@ -1,8 +1,8 @@ -//! Object file backend for Wasmer compilers. +//! Staticlib engine for Wasmer compilers. //! //! Given a compiler (such as `CraneliftCompiler` or `LLVMCompiler`) -//! it generates a object file (.o file) and metadata which can be used -//! to access it from other programming languages static. +//! it generates a static object file (`.o` file) and metadata which +//! can be used to access it from other programming languages static. #![deny(missing_docs, trivial_numeric_casts, unused_extern_crates)] #![warn(unused_import_braces)] @@ -26,9 +26,9 @@ mod builder; mod engine; mod serialize; -pub use crate::artifact::ObjectFileArtifact; -pub use crate::builder::ObjectFile; -pub use crate::engine::ObjectFileEngine; +pub use crate::artifact::StaticlibArtifact; +pub use crate::builder::Staticlib; +pub use crate::engine::StaticlibEngine; /// Version number of this crate. pub const VERSION: &str = env!("CARGO_PKG_VERSION"); diff --git a/lib/engine-object-file/src/serialize.rs b/lib/engine-staticlib/src/serialize.rs similarity index 100% rename from lib/engine-object-file/src/serialize.rs rename to lib/engine-staticlib/src/serialize.rs diff --git a/lib/engine/README.md b/lib/engine/README.md index e5f25ac0171..c4de85c25dc 100644 --- a/lib/engine/README.md +++ b/lib/engine/README.md @@ -12,7 +12,7 @@ It currently has three implementations: 1. Universal with [`wasmer-engine-universal`], 2. Native with [`wasmer-engine-dylib`], -3. Object with [`wasmer-engine-object-file`]. +3. Object with [`wasmer-engine-staticlib`]. ## Example Implementation @@ -30,7 +30,7 @@ attributions of the project. [`wasmer-engine-universal`]: https://github.com/wasmerio/wasmer/tree/master/lib/engine-universal [`wasmer-engine-dylib`]: https://github.com/wasmerio/wasmer/tree/master/lib/engine-dylib -[`wasmer-engine-object-file`]: https://github.com/wasmerio/wasmer/tree/master/lib/engine-object-file +[`wasmer-engine-staticlib`]: https://github.com/wasmerio/wasmer/tree/master/lib/engine-staticlib [`wasmer-engine-dummy`]: https://github.com/wasmerio/wasmer/tree/master/tests/lib/engine-dummy [`wasmtime-api`]: https://crates.io/crates/wasmtime [Wasmer `ATTRIBUTIONS`]: https://github.com/wasmerio/wasmer/blob/master/ATTRIBUTIONS.md diff --git a/scripts/publish.py b/scripts/publish.py index ed5d1667b95..52d2776d72a 100644 --- a/scripts/publish.py +++ b/scripts/publish.py @@ -37,18 +37,18 @@ "wasmer-engine-universal": set(["wasmer-types", "wasmer-vm", "wasmer-compiler", "wasmer-engine"]), "wasmer-engine-dylib": set(["wasmer-types", "wasmer-vm", "wasmer-compiler", "wasmer-engine", "wasmer-object"]), - "wasmer-engine-object-file": set(["wasmer-types", "wasmer-vm", "wasmer-compiler", "wasmer-engine", + "wasmer-engine-staticlib": set(["wasmer-types", "wasmer-vm", "wasmer-compiler", "wasmer-engine", "wasmer-object"]), "wasmer": set(["wasmer-vm", "wasmer-compiler-singlepass", "wasmer-compiler-cranelift", "wasmer-compiler-llvm", "wasmer-compiler", "wasmer-engine", "wasmer-engine-universal", - "wasmer-engine-dylib", "wasmer-engine-object-file", "wasmer-types", "wasmer-derive"]), + "wasmer-engine-dylib", "wasmer-engine-staticlib", "wasmer-types", "wasmer-derive"]), "wasmer-cache": set(["wasmer"]), "wasmer-wasi": set(["wasmer"]), "wasmer-wasi-experimental-io-devices": set(["wasmer-wasi"]), "wasmer-emscripten": set(["wasmer"]), "wasmer-c-api": set(["wasmer", "wasmer-compiler", "wasmer-compiler-cranelift", "wasmer-compiler-singlepass", "wasmer-compiler-llvm", "wasmer-emscripten", "wasmer-engine", "wasmer-engine-universal", - "wasmer-engine-dylib", "wasmer-engine-object-file", "wasmer-wasi", "wasmer-types"]), + "wasmer-engine-dylib", "wasmer-engine-staticlib", "wasmer-wasi", "wasmer-types"]), "wasmer-middlewares": set(["wasmer", "wasmer-types", "wasmer-vm"]), } @@ -67,7 +67,7 @@ "wasmer-engine": "engine", "wasmer-engine-universal": "engine-universal", "wasmer-engine-dylib": "engine-dylib", - "wasmer-engine-object-file": "engine-object-file", + "wasmer-engine-staticlib": "engine-staticlib", "wasmer-cache": "cache", "wasmer": "api", "wasmer-wasi": "wasi", diff --git a/tests/integration/cli/src/util.rs b/tests/integration/cli/src/util.rs index 6172d89514e..5ec991e3c71 100644 --- a/tests/integration/cli/src/util.rs +++ b/tests/integration/cli/src/util.rs @@ -23,7 +23,7 @@ impl Compiler { pub enum Engine { Universal, Dylib, - ObjectFile, + Staticlib, } impl Engine { @@ -31,7 +31,7 @@ impl Engine { match self { Engine::Universal => "--universal", Engine::Dylib => "--dylib", - Engine::ObjectFile => "--object-file", + Engine::Staticlib => "--staticlib", } } } diff --git a/tests/integration/cli/tests/compile.rs b/tests/integration/cli/tests/compile.rs index b5b767dffc0..5032da9bd84 100644 --- a/tests/integration/cli/tests/compile.rs +++ b/tests/integration/cli/tests/compile.rs @@ -8,10 +8,9 @@ use std::process::Command; use wasmer_integration_tests_cli::link_code::*; use wasmer_integration_tests_cli::*; -const OBJECT_FILE_ENGINE_TEST_C_SOURCE: &[u8] = - include_bytes!("object_file_engine_test_c_source.c"); +const STATICLIB_ENGINE_TEST_C_SOURCE: &[u8] = include_bytes!("staticlib_engine_test_c_source.c"); -fn object_file_engine_test_wasm_path() -> String { +fn staticlib_engine_test_wasm_path() -> String { format!("{}/{}", C_ASSET_PATH, "qjs.wasm") } @@ -24,7 +23,7 @@ struct WasmerCompile { wasmer_path: PathBuf, /// Path to the Wasm file to compile. wasm_path: PathBuf, - /// Path to the object file produced by compiling the Wasm. + /// Path to the static object file produced by compiling the Wasm. wasm_object_path: PathBuf, /// Path to output the generated header to. header_output_path: PathBuf, @@ -43,11 +42,11 @@ impl Default for WasmerCompile { Self { current_dir: std::env::current_dir().unwrap(), wasmer_path: get_wasmer_path(), - wasm_path: PathBuf::from(object_file_engine_test_wasm_path()), + wasm_path: PathBuf::from(staticlib_engine_test_wasm_path()), wasm_object_path: PathBuf::from(wasm_obj_path), header_output_path: PathBuf::from("my_wasm.h"), compiler: Compiler::Cranelift, - engine: Engine::ObjectFile, + engine: Engine::Staticlib, } } } @@ -114,11 +113,11 @@ fn run_c_compile( } #[test] -fn object_file_engine_works() -> anyhow::Result<()> { +fn staticlib_engine_works() -> anyhow::Result<()> { let temp_dir = tempfile::tempdir().context("Making a temp dir")?; let operating_dir: PathBuf = temp_dir.path().to_owned(); - let wasm_path = operating_dir.join(object_file_engine_test_wasm_path()); + let wasm_path = operating_dir.join(staticlib_engine_test_wasm_path()); #[cfg(not(windows))] let wasm_object_path = operating_dir.join("wasm.o"); #[cfg(windows)] @@ -131,7 +130,7 @@ fn object_file_engine_works() -> anyhow::Result<()> { wasm_object_path: wasm_object_path.clone(), header_output_path, compiler: Compiler::Cranelift, - engine: Engine::ObjectFile, + engine: Engine::Staticlib, ..Default::default() } .run() @@ -151,7 +150,7 @@ fn object_file_engine_works() -> anyhow::Result<()> { .write(true) .open(&c_src_file_name) .context("Failed to open C source code file")?; - c_src_file.write_all(OBJECT_FILE_ENGINE_TEST_C_SOURCE)?; + c_src_file.write_all(STATICLIB_ENGINE_TEST_C_SOURCE)?; } run_c_compile(&operating_dir, &c_src_file_name, &c_object_path) .context("Failed to compile C source code")?; diff --git a/tests/integration/cli/tests/object_file_engine_test_c_source.c b/tests/integration/cli/tests/staticlib_engine_test_c_source.c similarity index 95% rename from tests/integration/cli/tests/object_file_engine_test_c_source.c rename to tests/integration/cli/tests/staticlib_engine_test_c_source.c index 070fc465e78..2f813754c8b 100644 --- a/tests/integration/cli/tests/object_file_engine_test_c_source.c +++ b/tests/integration/cli/tests/staticlib_engine_test_c_source.c @@ -19,11 +19,11 @@ static void print_wasmer_error() { int main() { printf("Initializing...\n"); wasm_config_t *config = wasm_config_new(); - wasm_config_set_engine(config, OBJECT_FILE); + wasm_config_set_engine(config, STATICLIB); wasm_engine_t *engine = wasm_engine_new_with_config(config); wasm_store_t *store = wasm_store_new(engine); - wasm_module_t *module = wasmer_object_file_engine_new(store, "qjs.wasm"); + wasm_module_t *module = wasmer_staticlib_engine_new(store, "qjs.wasm"); if (!module) { printf("Failed to create module\n");