From 599f0d137cb861ce9becf61f145497c51a88c9cc Mon Sep 17 00:00:00 2001 From: Ivan Enderlin Date: Thu, 27 May 2021 14:12:47 +0200 Subject: [PATCH 1/6] doc: Update link to the Zig integration. --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 784cd1a420a..1dd4c54f748 100644 --- a/README.md +++ b/README.md @@ -172,7 +172,7 @@ qjs > [swift integration]: https://github.com/AlwaysRightInstitute/SwiftyWasmer [zig logo]: https://raw.githubusercontent.com/ziglang/logo/master/zig-favicon.png -[zig integration]: https://github.com/kubkon/wasmer-zig +[zig integration]: https://github.com/zigwasm/wasmer-zig ## Contribute From c882c4b53315d3223b218efd5971a517188daf22 Mon Sep 17 00:00:00 2001 From: Ivan Enderlin Date: Thu, 27 May 2021 14:13:04 +0200 Subject: [PATCH 2/6] doc: Add the Zig integration in all languages. --- docs/cn/README.md | 6 +++++- docs/es/README.md | 4 ++++ docs/fr/README.md | 4 ++++ docs/ja/README.md | 4 ++++ 4 files changed, 17 insertions(+), 1 deletion(-) diff --git a/docs/cn/README.md b/docs/cn/README.md index 9bbb640586f..dab9ba7370b 100644 --- a/docs/cn/README.md +++ b/docs/cn/README.md @@ -101,6 +101,7 @@ qjs > | ![R logo] | [**R**][R integration] | *没有已发布的软件包* | [文档][r docs] | | ![Postgres logo] | [**Postgres**][Postgres integration] | *没有已发布的软件包* | [文档][postgres docs] | | | [**Swift**][Swift integration] | *没有已发布的软件包* | | +| ![Zig logo] | [**Zig**][Zig integration] | *no published package* | | [👋 缺少语言?](https://github.com/wasmerio/wasmer/issues/new?assignees=&labels=%F0%9F%8E%89+enhancement&template=---feature-request.md&title=) @@ -169,6 +170,9 @@ qjs > [swift integration]: https://github.com/AlwaysRightInstitute/SwiftyWasmer +[zig logo]: https://raw.githubusercontent.com/ziglang/logo/master/zig-favicon.png +[zig integration]: https://github.com/zigwasm/wasmer-zig + ## 贡献 **我们欢迎任何形式的贡献,尤其是来自社区新成员的贡献** 💜 @@ -188,4 +192,4 @@ Wasmer 拥有一个由出色的开发人员和贡献者组成的社区。 欢迎 - [Slack](https://slack.wasmer.io/) - [Twitter](https://twitter.com/wasmerio) - [Facebook](https://www.facebook.com/wasmerio) -- [Email](mailto:hello@wasmer.io) \ No newline at end of file +- [Email](mailto:hello@wasmer.io) diff --git a/docs/es/README.md b/docs/es/README.md index 970092ce959..79411675e6c 100644 --- a/docs/es/README.md +++ b/docs/es/README.md @@ -101,6 +101,7 @@ qjs > | ![R logo] | [**R**][R integration] | *sin paquete publicado* | [Documentación][r docs] | | ![Postgres logo] | [**Postgres**][Postgres integration] | *sin paquete publicado* | [Documentación][postgres docs] | | | [**Swift**][Swift integration] | *sin paquete publicado* | | +| ![Zig logo] | [**Zig**][Zig integration] | *no published package* | | [👋 Falta algún lenguaje?](https://github.com/wasmerio/wasmer/issues/new?assignees=&labels=%F0%9F%8E%89+enhancement&template=---feature-request.md&title=) @@ -169,6 +170,9 @@ qjs > [swift integration]: https://github.com/AlwaysRightInstitute/SwiftyWasmer +[zig logo]: https://raw.githubusercontent.com/ziglang/logo/master/zig-favicon.png +[zig integration]: https://github.com/zigwasm/wasmer-zig + ## Contribuye **Damos la bienvenida a cualquier forma de contribución, especialmente a los nuevos miembros de la comunidad** 💜 diff --git a/docs/fr/README.md b/docs/fr/README.md index 67b97711d22..a209c145d96 100644 --- a/docs/fr/README.md +++ b/docs/fr/README.md @@ -101,6 +101,7 @@ qjs > | ![R logo] | [**R**][R integration] | *no published package* | [Docs][r docs] | | ![Postgres logo] | [**Postgres**][Postgres integration] | *no published package* | [Docs][postgres docs] | | | [**Swift**][Swift integration] | *no published package* | | +| ![Zig logo] | [**Zig**][Zig integration] | *no published package* | | [👋 Il manque un langage ?](https://github.com/wasmerio/wasmer/issues/new?assignees=&labels=%F0%9F%8E%89+enhancement&template=---feature-request.md&title=) @@ -169,6 +170,9 @@ qjs > [swift integration]: https://github.com/AlwaysRightInstitute/SwiftyWasmer +[zig logo]: https://raw.githubusercontent.com/ziglang/logo/master/zig-favicon.png +[zig integration]: https://github.com/zigwasm/wasmer-zig + ## Contribuer **Nous accueillons toutes formes de contributions, en particulier de la part des nouveaux membres de notre communauté**. 💜 diff --git a/docs/ja/README.md b/docs/ja/README.md index c937407d9e9..7ada49c2c66 100644 --- a/docs/ja/README.md +++ b/docs/ja/README.md @@ -101,6 +101,7 @@ qjs > | ![R logo] | [**R**][R integration] | *公開パッケージなし* | [Docs][r docs] | | ![Postgres logo] | [**Postgres**][Postgres integration] | *公開パッケージなし* | [Docs][postgres docs] | | | [**Swift**][Swift integration] | *公開パッケージなし* | | +| ![Zig logo] | [**Zig**][Zig integration] | *no published package* | | [👋 言語が見当たらない?](https://github.com/wasmerio/wasmer/issues/new?assignees=&labels=%F0%9F%8E%89+enhancement&template=---feature-request.md&title=) @@ -169,6 +170,9 @@ qjs > [swift integration]: https://github.com/AlwaysRightInstitute/SwiftyWasmer +[zig logo]: https://raw.githubusercontent.com/ziglang/logo/master/zig-favicon.png +[zig integration]: https://github.com/zigwasm/wasmer-zig + ## コントリビューション **どんな形での貢献も歓迎です。コミュニティの新しいメンバーからの貢献は特に歓迎します。** 💜 From fe4948e3dd0cbd56a34d6c4ec51807a85be63824 Mon Sep 17 00:00:00 2001 From: Jakub Konka Date: Thu, 27 May 2021 17:26:33 +0200 Subject: [PATCH 3/6] Update link to wasmer-zig bindings --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 784cd1a420a..1dd4c54f748 100644 --- a/README.md +++ b/README.md @@ -172,7 +172,7 @@ qjs > [swift integration]: https://github.com/AlwaysRightInstitute/SwiftyWasmer [zig logo]: https://raw.githubusercontent.com/ziglang/logo/master/zig-favicon.png -[zig integration]: https://github.com/kubkon/wasmer-zig +[zig integration]: https://github.com/zigwasm/wasmer-zig ## Contribute From 79d5f20301118260300ededc4660ea7bfe8b5765 Mon Sep 17 00:00:00 2001 From: Ivan Enderlin Date: Thu, 27 May 2021 15:57:55 +0200 Subject: [PATCH 4/6] feat: Rename `wasmer-engine-native` to `wasmer-engine-shared-object`. --- Cargo.lock | 22 +-- Cargo.toml | 22 +-- Makefile | 85 ++++----- docs/deps_dedup.dot | 4 +- docs/deps_dedup.svg | 162 +++++++++--------- examples/README.md | 6 +- examples/engine_cross_compilation.rs | 4 +- examples/engine_headless.rs | 4 +- ...gine_native.rs => engine_shared_object.rs} | 10 +- fuzz/Cargo.toml | 10 +- fuzz/README.md | 27 ++- ...ranelift.rs => shared_object_cranelift.rs} | 6 +- lib/api/Cargo.toml | 12 +- lib/api/src/lib.rs | 6 +- lib/api/src/store.rs | 2 +- lib/c-api/Cargo.toml | 8 +- lib/c-api/src/wasm_c_api/engine.rs | 48 +++--- lib/c-api/src/wasm_c_api/unstable/engine.rs | 15 +- lib/c-api/tests/wasm.h | 6 +- lib/c-api/wasmer_wasm.h | 2 +- lib/cache/Cargo.toml | 2 +- lib/cache/benches/bench_filesystem_cache.rs | 2 +- lib/cli/Cargo.toml | 12 +- lib/cli/README.md | 6 +- lib/cli/src/commands/compile.rs | 14 +- lib/cli/src/commands/run.rs | 24 +-- lib/cli/src/store.rs | 50 +++--- lib/deprecated/runtime-core/Cargo.lock | 4 +- lib/deprecated/runtime/Cargo.lock | 4 +- lib/engine-native/README.md | 59 ------- .../Cargo.toml | 6 +- lib/engine-shared-object/README.md | 60 +++++++ .../src/artifact.rs | 64 +++---- .../src/builder.rs | 30 ++-- .../src/engine.rs | 52 +++--- .../src/lib.rs | 8 +- .../src/serialize.rs | 0 lib/engine/README.md | 4 +- lib/object/README.md | 4 +- scripts/publish.py | 8 +- tests/compilers/config.rs | 14 +- tests/compilers/wast.rs | 10 +- tests/ignores.txt | 28 +-- tests/integration/cli/src/util.rs | 4 +- tests/lib/compiler-test-derive/src/ignores.rs | 2 +- tests/lib/compiler-test-derive/src/lib.rs | 33 ++-- tests/lib/compiler-test-derive/src/tests.rs | 18 +- tests/lib/test-generator/Cargo.toml | 2 +- 48 files changed, 515 insertions(+), 470 deletions(-) rename examples/{engine_native.rs => engine_shared_object.rs} (88%) rename fuzz/fuzz_targets/{native_cranelift.rs => shared_object_cranelift.rs} (91%) delete mode 100644 lib/engine-native/README.md rename lib/{engine-native => engine-shared-object}/Cargo.toml (86%) create mode 100644 lib/engine-shared-object/README.md rename lib/{engine-native => engine-shared-object}/src/artifact.rs (94%) rename lib/{engine-native => engine-shared-object}/src/builder.rs (78%) rename lib/{engine-native => engine-shared-object}/src/engine.rs (85%) rename lib/{engine-native => engine-shared-object}/src/lib.rs (83%) rename lib/{engine-native => engine-shared-object}/src/serialize.rs (100%) diff --git a/Cargo.lock b/Cargo.lock index b4b2c6a8462..09711aae463 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2437,7 +2437,7 @@ dependencies = [ "wasmer-compiler-singlepass", "wasmer-derive", "wasmer-engine", - "wasmer-engine-native", + "wasmer-engine-shared-object", "wasmer-engine-universal", "wasmer-types", "wasmer-vm", @@ -2456,7 +2456,7 @@ dependencies = [ "wasmer-compiler-cranelift", "wasmer-compiler-llvm", "wasmer-compiler-singlepass", - "wasmer-engine-native", + "wasmer-engine-shared-object", "wasmer-engine-universal", "wasmer-middlewares", "wasmprinter", @@ -2484,8 +2484,8 @@ dependencies = [ "wasmer-compiler-singlepass", "wasmer-emscripten", "wasmer-engine", - "wasmer-engine-native", "wasmer-engine-object-file", + "wasmer-engine-shared-object", "wasmer-engine-universal", "wasmer-middlewares", "wasmer-types", @@ -2504,7 +2504,7 @@ dependencies = [ "thiserror", "wasmer", "wasmer-compiler-singlepass", - "wasmer-engine-native", + "wasmer-engine-shared-object", "wasmer-engine-universal", ] @@ -2530,8 +2530,8 @@ dependencies = [ "wasmer-compiler-singlepass", "wasmer-emscripten", "wasmer-engine", - "wasmer-engine-native", "wasmer-engine-object-file", + "wasmer-engine-shared-object", "wasmer-engine-universal", "wasmer-types", "wasmer-vm", @@ -2680,14 +2680,14 @@ dependencies = [ ] [[package]] -name = "wasmer-engine-native" +name = "wasmer-engine-object-file" version = "1.0.2" dependencies = [ + "bincode", "cfg-if 1.0.0", "leb128", "libloading", "loupe", - "rkyv", "serde", "tempfile", "tracing", @@ -2696,18 +2696,17 @@ dependencies = [ "wasmer-object", "wasmer-types", "wasmer-vm", - "which 4.1.0", ] [[package]] -name = "wasmer-engine-object-file" +name = "wasmer-engine-shared-object" version = "1.0.2" dependencies = [ - "bincode", "cfg-if 1.0.0", "leb128", "libloading", "loupe", + "rkyv", "serde", "tempfile", "tracing", @@ -2716,6 +2715,7 @@ dependencies = [ "wasmer-object", "wasmer-types", "wasmer-vm", + "which 4.1.0", ] [[package]] @@ -2863,8 +2863,8 @@ dependencies = [ "wasmer-emscripten", "wasmer-engine", "wasmer-engine-dummy", - "wasmer-engine-native", "wasmer-engine-object-file", + "wasmer-engine-shared-object", "wasmer-engine-universal", "wasmer-middlewares", "wasmer-types", diff --git a/Cargo.toml b/Cargo.toml index 9f3d0ce98af..7898eb2ef93 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -18,7 +18,7 @@ wasmer-compiler-llvm = { version = "1.0.2", path = "lib/compiler-llvm", optional wasmer-emscripten = { version = "1.0.2", path = "lib/emscripten", optional = true } wasmer-engine = { version = "1.0.2", path = "lib/engine" } wasmer-engine-universal = { version = "1.0.2", path = "lib/engine-universal", optional = true } -wasmer-engine-native = { version = "1.0.2", path = "lib/engine-native", optional = true } +wasmer-engine-shared-object = { version = "1.0.2", path = "lib/engine-shared-object", optional = true } wasmer-engine-object-file = { version = "1.0.2", path = "lib/engine-object-file", 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 } @@ -41,7 +41,7 @@ members = [ "lib/emscripten", "lib/engine", "lib/engine-universal", - "lib/engine-native", + "lib/engine-shared-object", "lib/engine-object-file", "lib/object", "lib/vm", @@ -82,7 +82,7 @@ default = [ "wat", "wast", "universal", - "native", + "shared-object", "object-file", "cache", "wasi", @@ -94,8 +94,8 @@ universal = [ "wasmer-engine-universal", "engine", ] -native = [ - "wasmer-engine-native", +shared-object = [ + "wasmer-engine-shared-object", "engine", ] object-file = [ @@ -111,7 +111,7 @@ compiler = [ "wasmer/compiler", "wasmer-compiler/translator", "wasmer-engine-universal/compiler", - "wasmer-engine-native/compiler", + "wasmer-engine-shared-object/compiler", "wasmer-engine-object-file/compiler", ] singlepass = [ @@ -139,9 +139,9 @@ test-llvm = [ "llvm", ] -test-native = [ - "native", - "test-generator/test-native", +test-shared-object = [ + "shared-object", + "test-generator/test-shared-object", ] test-universal = [ "universal", @@ -170,8 +170,8 @@ path = "examples/engine_universal.rs" required-features = ["cranelift"] [[example]] -name = "engine-native" -path = "examples/engine_native.rs" +name = "engine-shared-object" +path = "examples/engine_shared_object.rs" required-features = ["cranelift"] [[example]] diff --git a/Makefile b/Makefile index b3ce39880c9..d645ddfa6ea 100644 --- a/Makefile +++ b/Makefile @@ -9,32 +9,33 @@ SHELL=/bin/bash # The matrix is the product of the following columns: # -# |------------|-----------|----------|--------------|-------| -# | Compiler ⨯ Engine ⨯ Platform ⨯ Architecture ⨯ libc | -# |------------|-----------|----------|--------------|-------| -# | Cranelift | Universal | Linux | amd64 | glibc | -# | LLVM | Native | Darwin | aarch64 | musl | -# | Singlepass | | Windows | | | -# |------------|-----------|----------|--------------|-------| +# |------------|---------------|----------|--------------|-------| +# | Compiler ⨯ Engine ⨯ Platform ⨯ Architecture ⨯ libc | +# |------------|---------------|----------|--------------|-------| +# | Cranelift | Universal | Linux | amd64 | glibc | +# | LLVM | Shared Object | Darwin | aarch64 | musl | +# | Singlepass | | Windows | | | +# |------------|---------------|----------|--------------|-------| # # Here is what works and what doesn't: # # * Cranelift with the Universal engine works everywhere, # -# * Cranelift with the Native engine works on Linux+Darwin/`amd64`, -# but it doesn't work on */`aarch64` or Windows/*. +# * Cranelift with the Shared Object engine works on +# Linux+Darwin/`amd64`, but it doesn't work on */`aarch64` or +# Windows/*. # # * LLVM with the Universal engine works on Linux+Darwin/`amd64`, # but it doesn't work on */`aarch64` or Windows/*. # -# * LLVM with the Native engine works on +# * LLVM with the Shared Object engine works on # Linux+Darwin/`amd64`+`aarch64`, but it doesn't work on Windows/*. # # * Singlepass with the Universal engine works on Linux+Darwin/`amd64`, but # it doesn't work on */`aarch64` or Windows/*. # -# * Singlepass with the Native engine doesn't work because it doesn't -# know how to output object files for the moment. +# * Singlepass with the Shared Object engine doesn't work because it +# doesn't know how to output object files for the moment. # # * Windows isn't tested on `aarch64`, that's why we consider it's not # working, but it might possibly be. @@ -210,12 +211,12 @@ ifeq ($(ENABLE_CRANELIFT), 1) ifneq (, $(filter 1, $(IS_DARWIN) $(IS_LINUX))) ifeq ($(IS_AMD64), 1) ifneq ($(LIBC), musl) - compilers_engines += cranelift-native + compilers_engines += cranelift-shared-object endif else ifeq ($(IS_AARCH64), 1) # The object crate doesn't support yet Darwin + Aarch64 relocations ifneq ($(IS_DARWIN), 1) - compilers_engines += cranelift-native + compilers_engines += cranelift-shared-object endif endif endif @@ -229,9 +230,9 @@ ifeq ($(ENABLE_LLVM), 1) ifneq (, $(filter 1, $(IS_DARWIN) $(IS_LINUX))) ifeq ($(IS_AMD64), 1) compilers_engines += llvm-universal - compilers_engines += llvm-native + compilers_engines += llvm-shared-object else ifeq ($(IS_AARCH64), 1) - compilers_engines += llvm-native + compilers_engines += llvm-shared-object endif endif endif @@ -297,10 +298,10 @@ compiler_features := --features $(subst $(space),$(comma),$(compilers)) capi_compilers_engines_exclude := # Define the compiler Cargo features for the C API. It always excludes -# LLVM for the moment because it causes the linker to fail since llvm is not statically linked. -# TODO: Reenable llvm in C-API +# LLVM for the moment because it causes the linker to fail since LLVM is not statically linked. +# TODO: Reenable LLVM in C-API capi_compiler_features := --features $(subst $(space),$(comma),$(filter-out llvm, $(compilers))) -capi_compilers_engines_exclude += llvm-universal llvm-native +capi_compilers_engines_exclude += llvm-universal llvm-shared-object # We exclude singlepass-universal because it doesn't support multivalue (required in wasm-c-api tests) capi_compilers_engines_exclude += singlepass-universal @@ -423,23 +424,23 @@ 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,native,cranelift,wasi $(capi_default_features) + RUSTFLAGS="${RUSTFLAGS}" cargo doc --manifest-path lib/c-api/Cargo.toml --no-deps --features wat,universal,object-file,shared-object,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,native,object-file,wasi,middlewares $(capi_default_features) $(capi_compiler_features) + --no-default-features --features deprecated,wat,universal,shared-object,object-file,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,native,object-file,singlepass,wasi,middlewares $(capi_default_features) + --no-default-features --features deprecated,wat,universal,shared-object,object-file,singlepass,wasi,middlewares $(capi_default_features) build-capi-singlepass-universal: capi-setup RUSTFLAGS="${RUSTFLAGS}" cargo build --manifest-path lib/c-api/Cargo.toml --release \ --no-default-features --features deprecated,wat,universal,singlepass,wasi,middlewares $(capi_default_features) -build-capi-singlepass-native: capi-setup +build-capi-singlepass-shared-object: capi-setup RUSTFLAGS="${RUSTFLAGS}" cargo build --manifest-path lib/c-api/Cargo.toml --release \ - --no-default-features --features deprecated,wat,native,singlepass,wasi,middlewares $(capi_default_features) + --no-default-features --features deprecated,wat,shared-object,singlepass,wasi,middlewares $(capi_default_features) build-capi-singlepass-object-file: capi-setup RUSTFLAGS="${RUSTFLAGS}" cargo build --manifest-path lib/c-api/Cargo.toml --release \ @@ -447,35 +448,35 @@ build-capi-singlepass-object-file: capi-setup build-capi-cranelift: capi-setup RUSTFLAGS="${RUSTFLAGS}" cargo build --manifest-path lib/c-api/Cargo.toml --release \ - --no-default-features --features deprecated,wat,universal,native,object-file,cranelift,wasi,middlewares $(capi_default_features) + --no-default-features --features deprecated,wat,universal,shared-object,object-file,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,native,object-file,cranelift,wasi,middlewares,system-libffi $(capi_default_features) + --no-default-features --features deprecated,wat,universal,shared-object,object-file,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 \ --no-default-features --features deprecated,wat,universal,cranelift,wasi,middlewares $(capi_default_features) -build-capi-cranelift-native: capi-setup +build-capi-cranelift-shared-object: capi-setup RUSTFLAGS="${RUSTFLAGS}" cargo build --manifest-path lib/c-api/Cargo.toml --release \ - --no-default-features --features deprecated,wat,native,cranelift,wasi,middlewares $(capi_default_features) + --no-default-features --features deprecated,wat,shared-object,cranelift,wasi,middlewares $(capi_default_features) build-capi-cranelift-object-file: capi-setup RUSTFLAGS="${RUSTFLAGS}" cargo build --manifest-path lib/c-api/Cargo.toml --release \ - --no-default-features --features deprecated,wat,native,object-file,cranelift,wasi,middlewares $(capi_default_features) + --no-default-features --features deprecated,wat,shared-object,object-file,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,native,object-file,llvm,wasi,middlewares $(capi_default_features) + --no-default-features --features deprecated,wat,universal,shared-object,object-file,llvm,wasi,middlewares $(capi_default_features) build-capi-llvm-universal: capi-setup RUSTFLAGS="${RUSTFLAGS}" cargo build --manifest-path lib/c-api/Cargo.toml --release \ --no-default-features --features deprecated,wat,universal,llvm,wasi,middlewares $(capi_default_features) -build-capi-llvm-native: capi-setup +build-capi-llvm-shared-object: capi-setup RUSTFLAGS="${RUSTFLAGS}" cargo build --manifest-path lib/c-api/Cargo.toml --release \ - --no-default-features --features deprecated,wat,native,llvm,wasi,middlewares $(capi_default_features) + --no-default-features --features deprecated,wat,shared-object,llvm,wasi,middlewares $(capi_default_features) build-capi-llvm-object-file: capi-setup RUSTFLAGS="${RUSTFLAGS}" cargo build --manifest-path lib/c-api/Cargo.toml --release \ @@ -487,9 +488,9 @@ build-capi-headless-universal: capi-setup RUSTFLAGS="${RUSTFLAGS}" cargo build --manifest-path lib/c-api/Cargo.toml --release \ --no-default-features --features universal,wasi -build-capi-headless-native: capi-setup +build-capi-headless-shared-object: capi-setup RUSTFLAGS="${RUSTFLAGS}" cargo build --manifest-path lib/c-api/Cargo.toml --release \ - --no-default-features --features native,wasi + --no-default-features --features shared-object,wasi build-capi-headless-object-file: capi-setup RUSTFLAGS="${RUSTFLAGS}" cargo build --manifest-path lib/c-api/Cargo.toml --release \ @@ -497,7 +498,7 @@ build-capi-headless-object-file: capi-setup build-capi-headless-all: capi-setup RUSTFLAGS="${RUSTFLAGS}" cargo build --manifest-path lib/c-api/Cargo.toml --release \ - --no-default-features --features universal,native,object-file,wasi + --no-default-features --features universal,shared-object,object-file,wasi ########### # Testing # @@ -520,20 +521,20 @@ test-packages: test-compilers-compat: $(foreach compiler,$(compilers),test-$(compiler)) -test-singlepass-native: - cargo test --release --tests $(compiler_features) -- singlepass::native +test-singlepass-shared-object: + cargo test --release --tests $(compiler_features) -- singlepass::shared-object test-singlepass-universal: cargo test --release --tests $(compiler_features) -- singlepass::universal -test-cranelift-native: - cargo test --release --tests $(compiler_features) -- cranelift::native +test-cranelift-shared-object: + cargo test --release --tests $(compiler_features) -- cranelift::shared-object test-cranelift-universal: cargo test --release --tests $(compiler_features) -- cranelift::universal -test-llvm-native: - cargo test --release --tests $(compiler_features) -- llvm::native +test-llvm-shared-object: + cargo test --release --tests $(compiler_features) -- llvm::shared-object test-llvm-universal: cargo test --release --tests $(compiler_features) -- llvm::universal @@ -550,7 +551,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,native,object-file,wasi,middlewares $(capi_default_features) $(capi_compiler_features) -- --nocapture + --no-default-features --features deprecated,wat,universal,shared-object,object-file,wasi,middlewares $(capi_default_features) $(capi_compiler_features) -- --nocapture test-capi-integration-%: # Test the Wasmer C API tests for C diff --git a/docs/deps_dedup.dot b/docs/deps_dedup.dot index 2e561800a8c..f42ea9e1e5b 100644 --- a/docs/deps_dedup.dot +++ b/docs/deps_dedup.dot @@ -5,7 +5,7 @@ digraph dependencies { n1 [label="wasmer-compiler", color=orange]; n5 [label="wasmer-engine", color=orange]; n6 [label="wasmer-engine-universal", color=orange]; - n7 [label="wasmer-engine-native", color=orange]; + n7 [label="wasmer-engine-shared-object", color=orange]; n8 [label="wasmer-types", color=orange]; n9 [label="wasmer-vm", color=orange]; n10 [label="wasmer-c-api", color=orange]; @@ -29,7 +29,7 @@ digraph dependencies { color=brown; n6 [label="wasmer-engine-universal", color=orange]; - n7 [label="wasmer-engine-native", color=orange]; + n7 [label="wasmer-engine-shared-object", color=orange]; } { diff --git a/docs/deps_dedup.svg b/docs/deps_dedup.svg index 1e810aae96f..65f56930e90 100644 --- a/docs/deps_dedup.svg +++ b/docs/deps_dedup.svg @@ -4,241 +4,241 @@ - + dependencies - + cluster_compiler - -Compilers + +Compilers cluster_engine - -Engines + +Engines cluster_abi - -Provided ABIs + +Provided ABIs n0 - -wasmer + +wasmer n6 - -wasmer-engine-universal + +wasmer-engine-universal n0->n6 - - + + n7 - -wasmer-engine-native + +wasmer-engine-shared-object n0->n7 - - + + n2 - -wasmer-compiler-cranelift + +wasmer-compiler-cranelift n0->n2 - - + + n3 - -wasmer-compiler-llvm + +wasmer-compiler-llvm n0->n3 - - + + n4 - -wasmer-compiler-singlepass + +wasmer-compiler-singlepass n0->n4 - - + + n1 - -wasmer-compiler + +wasmer-compiler n9 - -wasmer-vm + +wasmer-vm n1->n9 - - + + n5 - -wasmer-engine + +wasmer-engine n5->n1 - - + + n6->n5 - - + + n7->n5 - - + + n8 - -wasmer-types + +wasmer-types n9->n8 - - + + n10 - -wasmer-c-api + +wasmer-c-api n11 - -wasmer-emscripten + +wasmer-emscripten n10->n11 - - + + n12 - -wasmer-wasi + +wasmer-wasi n10->n12 - - + + n11->n0 - - + + n12->n0 - - + + n13 - -wasmer-cache + +wasmer-cache n13->n0 - - + + n14 - -wasmer-cli + +wasmer-cli n14->n11 - - + + n14->n12 - - + + n14->n13 - - + + n2->n1 - - + + n3->n1 - - + + n4->n1 - - + + diff --git a/examples/README.md b/examples/README.md index c14e2035957..ac8b58c17c6 100644 --- a/examples/README.md +++ b/examples/README.md @@ -236,7 +236,7 @@ example. -2. [**Native engine**][engine-native], explains what a native engine +2. [**Native engine**][engine-shared-object], explains what a native engine is, and how to set it up. The example completes itself with the compilation of the Wasm module, its instantiation, and finally, by calling an exported function. @@ -248,7 +248,7 @@ example. Execute the example ```shell - $ cargo run --example engine-native --release --features "cranelift" + $ cargo run --example engine-shared-object --release --features "cranelift" ``` @@ -376,7 +376,7 @@ example. [hello-world]: ./hello_world.rs [engine-universal]: ./engine_universal.rs -[engine-native]: ./engine_native.rs +[engine-shared-object]: ./engine_shared_object.rs [engine-headless]: ./engine_headless.rs [compiler-singlepass]: ./compiler_singlepass.rs [compiler-cranelift]: ./compiler_cranelift.rs diff --git a/examples/engine_cross_compilation.rs b/examples/engine_cross_compilation.rs index 5bcfa6a9edc..8c1a540e922 100644 --- a/examples/engine_cross_compilation.rs +++ b/examples/engine_cross_compilation.rs @@ -22,7 +22,7 @@ use std::str::FromStr; use wasmer::{wat2wasm, Module, RuntimeError, Store}; use wasmer_compiler::{CpuFeature, Target, Triple}; use wasmer_compiler_cranelift::Cranelift; -use wasmer_engine_native::Native; +use wasmer_engine_shared_object::SharedObject; fn main() -> Result<(), Box> { // Let's declare the Wasm module with the text representation. @@ -67,7 +67,7 @@ fn main() -> Result<(), Box> { // Define the engine that will drive everything. // - // In this case, the engine is `wasmer_engine_native` which means + // In this case, the engine is `wasmer_engine_shared_object` which means // that a native object is going to be generated. // // That's where we specify the target for the compiler. diff --git a/examples/engine_headless.rs b/examples/engine_headless.rs index c4d20a6b0b8..cc8eba0097a 100644 --- a/examples/engine_headless.rs +++ b/examples/engine_headless.rs @@ -52,7 +52,7 @@ use wasmer::Module; use wasmer::Store; use wasmer::Value; use wasmer_compiler_cranelift::Cranelift; -use wasmer_engine_native::Native; +use wasmer_engine_shared_object::SharedObject; fn main() -> Result<(), Box> { // First step, let's compile the Wasm module and serialize it. @@ -82,7 +82,7 @@ fn main() -> Result<(), Box> { println!("Creating Native engine..."); // Define the engine that will drive everything. // - // In this case, the engine is `wasmer_engine_native` which + // In this case, the engine is `wasmer_engine_shared_object` which // means that a native object is going to be generated. So // when we are going to serialize the compiled Wasm module, we // are going to store it in a file with the `.so` extension diff --git a/examples/engine_native.rs b/examples/engine_shared_object.rs similarity index 88% rename from examples/engine_native.rs rename to examples/engine_shared_object.rs index e9f72d1bf97..875b78ea715 100644 --- a/examples/engine_native.rs +++ b/examples/engine_shared_object.rs @@ -1,6 +1,6 @@ //! Defining an engine in Wasmer is one of the fundamental steps. //! -//! This example illustrates how to use the `wasmer_engine_native`, +//! This example illustrates how to use the `wasmer_engine_shared_object`, //! aka the native engine. An engine applies roughly 2 steps: //! //! 1. It compiles the Wasm module bytes to executable code, through @@ -14,14 +14,14 @@ //! You can run the example directly by executing in Wasmer root: //! //! ```shell -//! cargo run --example engine-native --release --features "cranelift" +//! cargo run --example engine-shared-object --release --features "cranelift" //! ``` //! //! Ready? use wasmer::{imports, wat2wasm, Instance, Module, Store, Value}; use wasmer_compiler_cranelift::Cranelift; -use wasmer_engine_native::Native; +use wasmer_engine_shared_object::SharedObject; fn main() -> Result<(), Box> { // Let's declare the Wasm module with the text representation. @@ -48,7 +48,7 @@ fn main() -> Result<(), Box> { println!("Creating Native engine..."); // Define the engine that will drive everything. // - // In this case, the engine is `wasmer_engine_native` which means + // In this case, the engine is `wasmer_engine_shared_object` which means // that a native object is going to be generated. let engine = Native::new(compiler_config).engine(); @@ -88,6 +88,6 @@ fn main() -> Result<(), Box> { #[test] #[cfg(not(any(target_arch = "aarch64", target_env = "musl")))] -fn test_engine_native() -> Result<(), Box> { +fn test_engine_shared_object() -> Result<(), Box> { main() } diff --git a/fuzz/Cargo.toml b/fuzz/Cargo.toml index b0c5a09450e..a6b8da6f424 100644 --- a/fuzz/Cargo.toml +++ b/fuzz/Cargo.toml @@ -17,7 +17,7 @@ wasmer-compiler-cranelift = { path = "../lib/compiler-cranelift", optional = tru wasmer-compiler-llvm = { path = "../lib/compiler-llvm", optional = true } wasmer-compiler-singlepass = { path = "../lib/compiler-singlepass", optional = true } wasmer-engine-universal = { path = "../lib/engine-universal", optional = true } -wasmer-engine-native = { path = "../lib/engine-native", optional = true } +wasmer-engine-shared-object = { path = "../lib/engine-shared-object", optional = true } wasmer-middlewares = { path = "../lib/middlewares" } wasmprinter = "0.2" @@ -26,7 +26,7 @@ cranelift = [ "wasmer-compiler-cranelift" ] llvm = [ "wasmer-compiler-llvm" ] singlepass = [ "wasmer-compiler-singlepass" ] universal = [ "wasmer-engine-universal" ] -native = [ "wasmer-engine-native" ] +shared-object = [ "wasmer-engine-shared-object" ] [[bin]] name = "equivalence_universal" @@ -54,6 +54,6 @@ path = "fuzz_targets/metering.rs" required-features = ["universal", "cranelift"] [[bin]] -name = "native_cranelift" -path = "fuzz_targets/native_cranelift.rs" -required-features = ["native", "cranelift"] +name = "shared_object_cranelift" +path = "fuzz_targets/shared_object_cranelift.rs" +required-features = ["shared-object", "cranelift"] diff --git a/fuzz/README.md b/fuzz/README.md index 23ad4fddc0a..e3315da85b0 100644 --- a/fuzz/README.md +++ b/fuzz/README.md @@ -1,16 +1,19 @@ -This directory contains the fuzz tests for wasmer. To fuzz, we use the `cargo-fuzz` package. +This directory contains the fuzz tests for wasmer. To fuzz, we use the +`cargo-fuzz` package. ## Installation -You may need to install the `cargo-fuzz` package to get the `cargo fuzz` subcommand. Use +You may need to install the `cargo-fuzz` package to get the `cargo +fuzz` subcommand. Use ```sh $ cargo install cargo-fuzz ``` -`cargo-fuzz` is documented in the [Rust Fuzz Book](https://rust-fuzz.github.io/book/cargo-fuzz.html). +`cargo-fuzz` is documented in the [Rust Fuzz +Book](https://rust-fuzz.github.io/book/cargo-fuzz.html). -## Running a fuzzer (`validate`, `universal_llvm`, `native_cranelift`…) +## Running a fuzzer (`validate`, `universal_llvm`, `shared_object_cranelift`…) Once `cargo-fuzz` is installed, you can run the `validate` fuzzer with ```sh @@ -36,11 +39,23 @@ You should see output that looks something like this: #1409042 NEW cov: 115073 ft: 503951 corp: 4667/1814Kb lim: 4096 exec/s: 884 rss: 857Mb L: 174/4096 MS: 2 ChangeByte-ChangeASCIIInt- ``` -It will continue to generate random inputs forever, until it finds a bug or is terminated. The testcases for bugs it finds go into `fuzz/artifacts/universal_cranelift` and you can rerun the fuzzer on a single input by passing it on the command line `cargo fuzz run universal_cranelift /path/to/testcase`. +It will continue to generate random inputs forever, until it finds a +bug or is terminated. The testcases for bugs it finds go into +`fuzz/artifacts/universal_cranelift` and you can rerun the fuzzer on a +single input by passing it on the command line `cargo fuzz run +universal_cranelift /path/to/testcase`. ## The corpus -Each fuzzer has an individual corpus under fuzz/corpus/test_name, created on first run if not already present. The fuzzers use `wasm-smith` which means that the testcase files are random number seeds input to the wasm generator, not `.wasm` files themselves. In order to debug a testcase, you may find that you need to convert it into a `.wasm` file. Using the standalone `wasm-smith` tool doesn't work for this purpose because we use a custom configuration to our `wasm_smith::Module`. Instead, our fuzzers use an environment variable `DUMP_TESTCASE=path`. For example: +Each fuzzer has an individual corpus under fuzz/corpus/test_name, +created on first run if not already present. The fuzzers use +`wasm-smith` which means that the testcase files are random number +seeds input to the wasm generator, not `.wasm` files themselves. In +order to debug a testcase, you may find that you need to convert it +into a `.wasm` file. Using the standalone `wasm-smith` tool doesn't +work for this purpose because we use a custom configuration to our +`wasm_smith::Module`. Instead, our fuzzers use an environment variable +`DUMP_TESTCASE=path`. For example: ``` DUMP_TESTCASE=/tmp/crash.wasm cargo fuzz run --features=universal,singlepass universal_singlepass fuzz/artifacts/universal_singlepass/crash-0966412eab4f89c52ce5d681807c8030349470f6 diff --git a/fuzz/fuzz_targets/native_cranelift.rs b/fuzz/fuzz_targets/shared_object_cranelift.rs similarity index 91% rename from fuzz/fuzz_targets/native_cranelift.rs rename to fuzz/fuzz_targets/shared_object_cranelift.rs index b83328f6f60..7b3b73638ac 100644 --- a/fuzz/fuzz_targets/native_cranelift.rs +++ b/fuzz/fuzz_targets/shared_object_cranelift.rs @@ -4,7 +4,7 @@ use libfuzzer_sys::{arbitrary, arbitrary::Arbitrary, fuzz_target}; use wasm_smith::{Config, ConfiguredModule}; use wasmer::{imports, Instance, Module, Store}; use wasmer_compiler_cranelift::Cranelift; -use wasmer_engine_native::Native; +use wasmer_engine_shared_object::SharedObject; #[derive(Arbitrary, Debug, Default, Copy, Clone)] struct NoImportsConfig; @@ -41,12 +41,12 @@ fuzz_target!(|module: WasmSmithModule| { } let compiler = Cranelift::default(); - let store = Store::new(&Native::new(compiler).engine()); + let store = Store::new(&SharedObject::new(compiler).engine()); let module = Module::new(&store, &wasm_bytes).unwrap(); module.serialize().unwrap() }; - let engine = Native::headless().engine(); + let engine = SharedObject::headless().engine(); let store = Store::new(&engine); let module = unsafe { Module::deserialize(&store, serialized.as_slice()) }.unwrap(); match Instance::new(&module, &imports! {}) { diff --git a/lib/api/Cargo.toml b/lib/api/Cargo.toml index fbbfbea21ad..5665e2a7b9c 100644 --- a/lib/api/Cargo.toml +++ b/lib/api/Cargo.toml @@ -19,7 +19,7 @@ wasmer-compiler = { path = "../compiler", version = "1.0.2" } wasmer-derive = { path = "../derive", version = "1.0.2" } wasmer-engine = { path = "../engine", version = "1.0.2" } wasmer-engine-universal = { path = "../engine-universal", version = "1.0.2", optional = true } -wasmer-engine-native = { path = "../engine-native", version = "1.0.2", optional = true } +wasmer-engine-shared-object = { path = "../engine-shared-object", version = "1.0.2", optional = true } wasmer-types = { path = "../types", version = "1.0.2" } indexmap = { version = "1.6", features = ["serde-1"] } cfg-if = "1.0" @@ -47,15 +47,15 @@ default = ["wat", "default-cranelift", "default-universal"] compiler = [ "wasmer-compiler/translator", "wasmer-engine-universal/compiler", - "wasmer-engine-native/compiler", + "wasmer-engine-shared-object/compiler", ] engine = [] universal = [ "wasmer-engine-universal", "engine" ] -native = [ - "wasmer-engine-native", +shared-object = [ + "wasmer-engine-shared-object", "engine" ] singlepass = [ @@ -91,8 +91,8 @@ default-universal = [ "universal", "default-engine" ] -default-native = [ - "native", +default-shared-object = [ + "shared-object", "default-engine" ] diff --git a/lib/api/src/lib.rs b/lib/api/src/lib.rs index 0d6a8195663..b52e9365023 100644 --- a/lib/api/src/lib.rs +++ b/lib/api/src/lib.rs @@ -248,7 +248,7 @@ //! [wasmer-emscripten]: https://docs.rs/wasmer-emscripten/*/wasmer_emscripten/ //! [wasmer-engine]: https://docs.rs/wasmer-engine/*/wasmer_engine/ //! [wasmer-universal]: https://docs.rs/wasmer-engine-universal/*/wasmer_engine_universal/ -//! [wasmer-native]: https://docs.rs/wasmer-engine-native/*/wasmer_engine_native/ +//! [wasmer-native]: https://docs.rs/wasmer-engine-shared-object/*/wasmer_engine_shared_object/ //! [wasmer-singlepass]: https://docs.rs/wasmer-compiler-singlepass/*/wasmer_compiler_singlepass/ //! [wasmer-llvm]: https://docs.rs/wasmer-compiler-llvm/*/wasmer_compiler_llvm/ //! [wasmer-wasi]: https://docs.rs/wasmer-wasi/*/wasmer_wasi/ @@ -367,8 +367,8 @@ pub use wasmer_compiler_llvm::{LLVMOptLevel, LLVM}; #[cfg(feature = "universal")] pub use wasmer_engine_universal::{Universal, UniversalArtifact, UniversalEngine}; -#[cfg(feature = "native")] -pub use wasmer_engine_native::{Native, NativeArtifact, NativeEngine}; +#[cfg(feature = "shared-object")] +pub use wasmer_engine_shared_object::{SharedObject, SharedObjectArtifact, SharedObjectEngine}; /// Version number of this crate. pub const VERSION: &str = env!("CARGO_PKG_VERSION"); diff --git a/lib/api/src/store.rs b/lib/api/src/store.rs index 7578b20e929..b72e4812080 100644 --- a/lib/api/src/store.rs +++ b/lib/api/src/store.rs @@ -130,7 +130,7 @@ impl Default for Store { wasmer_engine_universal::Universal::new(config) .engine() } else if #[cfg(feature = "default-native")] { - wasmer_engine_native::Native::new(config) + wasmer_engine_shared_object::SharedObject::new(config) .engine() } else { compile_error!("No default engine chosen") diff --git a/lib/c-api/Cargo.toml b/lib/c-api/Cargo.toml index 3b22fb5a93c..1dc7728c2da 100644 --- a/lib/c-api/Cargo.toml +++ b/lib/c-api/Cargo.toml @@ -22,7 +22,7 @@ wasmer-compiler-llvm = { version = "1.0.2", path = "../compiler-llvm", optional 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-native = { version = "1.0.2", path = "../engine-native", optional = true } +wasmer-engine-shared-object = { version = "1.0.2", path = "../engine-shared-object", optional = true } wasmer-engine-object-file = { version = "1.0.2", path = "../engine-object-file", optional = true } wasmer-middlewares = { version = "1.0.2", path = "../middlewares", optional = true } wasmer-wasi = { version = "1.0.2", path = "../wasi", optional = true } @@ -59,8 +59,8 @@ universal = [ "wasmer-engine-universal", "engine", ] -native = [ - "wasmer-engine-native", +shared-object = [ + "wasmer-engine-shared-object", "engine", ] object-file = [ @@ -70,7 +70,7 @@ object-file = [ compiler = [ "wasmer/compiler", "wasmer-engine-universal/compiler", - "wasmer-engine-native/compiler", + "wasmer-engine-shared-object/compiler", "wasmer-engine-object-file/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 b742c7f353e..44a460df648 100644 --- a/lib/c-api/src/wasm_c_api/engine.rs +++ b/lib/c-api/src/wasm_c_api/engine.rs @@ -12,10 +12,10 @@ use crate::error::{update_last_error, CApiError}; use cfg_if::cfg_if; use std::sync::Arc; use wasmer::Engine; -#[cfg(feature = "native")] -use wasmer_engine_native::Native; #[cfg(feature = "object-file")] use wasmer_engine_object_file::ObjectFile; +#[cfg(feature = "shared-object")] +use wasmer_engine_shared_object::SharedObject; #[cfg(feature = "universal")] use wasmer_engine_universal::Universal; @@ -69,9 +69,9 @@ pub enum wasmer_engine_t { /// [`wasmer_engine_universal`] Rust crate. UNIVERSAL = 0, - /// Variant to represent the Native engine. See the - /// [`wasmer_engine_native`] Rust crate. - NATIVE = 1, + /// Variant to represent the Shared Object engine. See the + /// [`wasmer_engine_shared_object`] Rust crate. + SHARED_OBJECT = 1, /// Variant to represent the Object File engine. See the /// [`wasmer_engine_object_file`] Rust crate. @@ -83,8 +83,8 @@ impl Default for wasmer_engine_t { cfg_if! { if #[cfg(feature = "universal")] { Self::UNIVERSAL - } else if #[cfg(feature = "native")] { - Self::NATIVE + } else if #[cfg(feature = "shared-object")] { + Self::SHARED_OBJECT } else if #[cfg(feature = "object-file")] { Self::OBJECT_FILE } else { @@ -249,9 +249,9 @@ pub extern "C" fn wasm_config_set_compiler( /// if (wasmer_is_engine_available(UNIVERSAL)) { /// wasm_config_set_engine(config, UNIVERSAL); /// } -/// // Or maybe the Native engine? -/// else if (wasmer_is_engine_available(NATIVE)) { -/// wasm_config_set_engine(config, NATIVE); +/// // Or maybe the Shared Object engine? +/// else if (wasmer_is_engine_available(SHARED_OBJECT)) { +/// wasm_config_set_engine(config, SHARED_OBJECT); /// } /// // OK, let's do not specify any particular engine. /// @@ -330,8 +330,8 @@ cfg_if! { let engine: Arc = Arc::new(Universal::headless().engine()); Box::new(wasm_engine_t { inner: engine }) } - } else if #[cfg(all(feature = "native", feature = "compiler"))] { - /// Creates a new native engine with the default compiler. + } else if #[cfg(all(feature = "shared-object", feature = "compiler"))] { + /// Creates a new shared object engine with the default compiler. /// /// # Example /// @@ -341,11 +341,11 @@ cfg_if! { #[no_mangle] pub extern "C" fn wasm_engine_new() -> Box { let compiler_config: Box = get_default_compiler_config(); - let engine: Arc = Arc::new(Native::new(compiler_config).engine()); + let engine: Arc = Arc::new(SharedObject::new(compiler_config).engine()); Box::new(wasm_engine_t { inner: engine }) } - } else if #[cfg(feature = "native")] { - /// Creates a new headless native engine. + } else if #[cfg(feature = "shared-object")] { + /// Creates a new headless shared object engine. /// /// # Example /// @@ -354,7 +354,7 @@ cfg_if! { /// cbindgen:ignore #[no_mangle] pub extern "C" fn wasm_engine_new() -> Box { - let engine: Arc = Arc::new(Native::headless().engine()); + let engine: Arc = Arc::new(SharedObject::headless().engine()); Box::new(wasm_engine_t { inner: engine }) } } @@ -502,10 +502,10 @@ pub extern "C" fn wasm_engine_new_with_config( } } }, - wasmer_engine_t::NATIVE => { + wasmer_engine_t::SHARED_OBJECT => { cfg_if! { - if #[cfg(feature = "native")] { - let mut builder = Native::new(compiler_config); + if #[cfg(feature = "shared-object")] { + let mut builder = SharedObject::new(compiler_config); if let Some(target) = config.target { builder = builder.target(target.inner); @@ -517,7 +517,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 `native` feature."); + return return_with_error("Wasmer has not been compiled with the `shared-object` feature."); } } }, @@ -565,10 +565,10 @@ pub extern "C" fn wasm_engine_new_with_config( } } }, - wasmer_engine_t::NATIVE => { + wasmer_engine_t::SHARED_OBJECT => { cfg_if! { - if #[cfg(feature = "native")] { - let mut builder = Native::headless(); + if #[cfg(feature = "shared-object")] { + let mut builder = SharedObject::headless(); if let Some(target) = config.target { builder = builder.target(target.inner); @@ -580,7 +580,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 `native` feature."); + return return_with_error("Wasmer has not been compiled with the `shared-object` 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 f07d9ec1795..dfa0df54a86 100644 --- a/lib/c-api/src/wasm_c_api/unstable/engine.rs +++ b/lib/c-api/src/wasm_c_api/unstable/engine.rs @@ -120,7 +120,7 @@ pub extern "C" fn wasmer_is_headless() -> bool { 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::NATIVE if cfg!(feature = "native") => true, + wasmer_engine_t::SHARED_OBJECT if cfg!(feature = "shared-object") => true, wasmer_engine_t::OBJECT_FILE if cfg!(feature = "object-file") => true, _ => false, } @@ -202,7 +202,14 @@ mod tests { "0" }, ); - set_var("NATIVE", if cfg!(feature = "native") { "1" } else { "0" }); + set_var( + "SHARED_OBJECT", + if cfg!(feature = "shared-object") { + "1" + } else { + "0" + }, + ); set_var( "OBJECT_FILE", if cfg!(feature = "object-file") { @@ -218,7 +225,7 @@ mod tests { int main() { assert(wasmer_is_engine_available(UNIVERSAL) == (getenv("UNIVERSAL")[0] == '1')); - assert(wasmer_is_engine_available(NATIVE) == (getenv("NATIVE")[0] == '1')); + assert(wasmer_is_engine_available(SHARED_OBJECT) == (getenv("SHARED_OBJECT")[0] == '1')); assert(wasmer_is_engine_available(OBJECT_FILE) == (getenv("OBJECT_FILE")[0] == '1')); return 0; @@ -227,7 +234,7 @@ mod tests { .success(); remove_var("UNIVERSAL"); - remove_var("NATIVE"); + remove_var("SHARED_OBJECT"); remove_var("OBJECT_FILE"); } } diff --git a/lib/c-api/tests/wasm.h b/lib/c-api/tests/wasm.h index 01a546b8041..0ec6fd92468 100644 --- a/lib/c-api/tests/wasm.h +++ b/lib/c-api/tests/wasm.h @@ -34,9 +34,9 @@ wasm_engine_t *wasm_engine_new() { if (strcmp(wasmer_test_engine, "universal") == 0) { assert(wasmer_is_engine_available(UNIVERSAL)); wasm_config_set_engine(config, UNIVERSAL); - } else if (strcmp(wasmer_test_engine, "native") == 0) { - assert(wasmer_is_engine_available(NATIVE)); - wasm_config_set_engine(config, NATIVE); + } else if (strcmp(wasmer_test_engine, "shared-object") == 0) { + assert(wasmer_is_engine_available(SHARED_OBJECT)); + wasm_config_set_engine(config, SHARED_OBJECT); } else if (wasmer_test_engine) { printf("Engine %s not recognized\n", wasmer_test_engine); abort(); diff --git a/lib/c-api/wasmer_wasm.h b/lib/c-api/wasmer_wasm.h index 8cfc242d058..2d66682d626 100644 --- a/lib/c-api/wasmer_wasm.h +++ b/lib/c-api/wasmer_wasm.h @@ -125,7 +125,7 @@ typedef enum wasmer_compiler_t { typedef enum wasmer_engine_t { UNIVERSAL = 0, - NATIVE = 1, + SHARED_OBJECT = 1, OBJECT_FILE = 2, } wasmer_engine_t; diff --git a/lib/cache/Cargo.toml b/lib/cache/Cargo.toml index 82d769ab9da..af73fe7588d 100644 --- a/lib/cache/Cargo.toml +++ b/lib/cache/Cargo.toml @@ -22,7 +22,7 @@ tempfile = "3" rand = "0.8.3" wasmer-compiler-singlepass = { path = "../compiler-singlepass", version = "1.0.2" } wasmer-engine-universal = { path = "../engine-universal", version = "1.0.2" } -wasmer-engine-native = { path = "../engine-native", version = "1.0.2" } +wasmer-engine-shared-object = { path = "../engine-shared-object", version = "1.0.2" } [[bench]] name = "bench_filesystem_cache" diff --git a/lib/cache/benches/bench_filesystem_cache.rs b/lib/cache/benches/bench_filesystem_cache.rs index 98cab045396..594b87ed255 100644 --- a/lib/cache/benches/bench_filesystem_cache.rs +++ b/lib/cache/benches/bench_filesystem_cache.rs @@ -6,7 +6,7 @@ use wasmer::{Module, Store}; use wasmer_cache::Cache; use wasmer_cache::{FileSystemCache, Hash}; use wasmer_compiler_singlepass::Singlepass; -use wasmer_engine_native::Native; +use wasmer_engine_shared_object::SharedObject; use wasmer_engine_universal::Universal; fn random_key() -> Hash { diff --git a/lib/cli/Cargo.toml b/lib/cli/Cargo.toml index c38fdbc06e1..48e8245aea0 100644 --- a/lib/cli/Cargo.toml +++ b/lib/cli/Cargo.toml @@ -32,7 +32,7 @@ wasmer-compiler-llvm = { version = "1.0.2", path = "../compiler-llvm", optional 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-native = { version = "1.0.2", path = "../engine-native", optional = true } +wasmer-engine-shared-object = { version = "1.0.2", path = "../engine-shared-object", optional = true } wasmer-engine-object-file = { version = "1.0.2", path = "../engine-object-file", optional = true } wasmer-vm = { version = "1.0.2", path = "../vm" } wasmer-wasi = { version = "1.0.2", path = "../wasi", default-features = false, optional = true } @@ -61,7 +61,7 @@ default = [ "wat", "wast", "universal", - "native", + "shared-object", "object-file", "cache", "wasi", @@ -72,8 +72,8 @@ universal = [ "wasmer-engine-universal", "engine", ] -native = [ - "wasmer-engine-native", +shared-object = [ + "wasmer-engine-shared-object", "engine", ] object-file = [ @@ -88,7 +88,7 @@ wat = ["wasmer/wat"] compiler = [ "wasmer-compiler/translator", "wasmer-engine-universal/compiler", - "wasmer-engine-native/compiler", + "wasmer-engine-shared-object/compiler", "wasmer-engine-object-file/compiler", ] experimental-io-devices = [ @@ -110,4 +110,4 @@ llvm = [ debug = ["fern", "log", "wasmer-wasi/logging"] disable-all-logging = ["wasmer-wasi/disable-all-logging"] headless = [] -headless-minimal = ["headless", "disable-all-logging", "wasi", "native", "universal"] +headless-minimal = ["headless", "disable-all-logging", "wasi", "shared-object", "universal"] diff --git a/lib/cli/README.md b/lib/cli/README.md index 01e9a1952c4..31f858aa972 100644 --- a/lib/cli/README.md +++ b/lib/cli/README.md @@ -26,7 +26,7 @@ The Wasmer supports the following features: * `wat` (default): support for executing WebAssembly text files. * `wast`(default): support for running wast test files. * `universal` (default): support for the [Universal engine]. -* `native` (default): support for the [Native engine]. +* `shared-object` (default): support for the [Shared Object engine]. * `cache` (default): support or automatically caching compiled artifacts. * `wasi` (default): support for [WASI]. * `experimental-io-devices`: support for experimental IO devices in WASI. @@ -36,7 +36,7 @@ The Wasmer supports the following features: * `llvm`: support for the [LLVM compiler]. [Universal engine]: https://github.com/wasmerio/wasmer/tree/master/lib/engine-universal/ -[Native Engine]: https://github.com/wasmerio/wasmer/tree/master/lib/engine-native/ +[Shared Object engine]: https://github.com/wasmerio/wasmer/tree/master/lib/engine-shared-object/ [WASI]: https://github.com/wasmerio/wasmer/tree/master/lib/wasi/ [Emscripten]: https://github.com/wasmerio/wasmer/tree/master/lib/emscripten/ [Singlepass compiler]: https://github.com/wasmerio/wasmer/tree/master/lib/compiler-singlepass/ @@ -62,7 +62,7 @@ wasmer run myfile.wasm Compile a WebAssembly file: ```bash -wasmer compile myfile.wasm -o myfile.so --native +wasmer compile myfile.wasm -o myfile.so --shared-object ``` Run a compiled WebAssembly file (fastest): diff --git a/lib/cli/src/commands/compile.rs b/lib/cli/src/commands/compile.rs index 499a2d108fd..9769ade2ea7 100644 --- a/lib/cli/src/commands/compile.rs +++ b/lib/cli/src/commands/compile.rs @@ -43,9 +43,11 @@ impl Compile { target_triple: &Triple, ) -> Result<&'static str> { Ok(match engine_type { - #[cfg(feature = "native")] - EngineType::Native => { - wasmer_engine_native::NativeArtifact::get_default_extension(target_triple) + #[cfg(feature = "shared-object")] + EngineType::SharedObject => { + wasmer_engine_shared_object::SharedObjectArtifact::get_default_extension( + target_triple, + ) } #[cfg(feature = "universal")] EngineType::Universal => { @@ -55,7 +57,11 @@ impl Compile { EngineType::ObjectFile => { wasmer_engine_object_file::ObjectFileArtifact::get_default_extension(target_triple) } - #[cfg(not(all(feature = "native", feature = "universal", feature = "object-file")))] + #[cfg(not(all( + feature = "shared-object", + feature = "universal", + feature = "object-file" + )))] _ => bail!("selected engine type is not compiled in"), }) } diff --git a/lib/cli/src/commands/run.rs b/lib/cli/src/commands/run.rs index f73f1397e96..68d06c9db1a 100644 --- a/lib/cli/src/commands/run.rs +++ b/lib/cli/src/commands/run.rs @@ -205,10 +205,10 @@ impl Run { fn get_module(&self) -> Result { let contents = std::fs::read(self.path.clone())?; - #[cfg(feature = "native")] + #[cfg(feature = "shared-object")] { - if wasmer_engine_native::NativeArtifact::is_deserializable(&contents) { - let engine = wasmer_engine_native::Native::headless().engine(); + if wasmer_engine_shared_object::SharedObjectArtifact::is_deserializable(&contents) { + let engine = wasmer_engine_shared_object::SharedObject::headless().engine(); let store = Store::new(&engine); let module = unsafe { Module::deserialize_from_file(&store, &self.path)? }; return Ok(module); @@ -295,15 +295,19 @@ impl Run { let mut cache_dir_root = get_cache_dir(); cache_dir_root.push(compiler_type.to_string()); let mut cache = FileSystemCache::new(cache_dir_root)?; - // Important: Native files need to have a `.dll` extension on Windows, otherwise - // they will not load, so we just add an extension always to make it easier - // to recognize as well. + + // Important: Shared object files need to have a `.dll` + // extension on Windows, otherwise they will not load, so we + // just add an extension always to make it easier to recognize + // as well. #[allow(unreachable_patterns)] let extension = match *engine_type { - #[cfg(feature = "native")] - EngineType::Native => { - wasmer_engine_native::NativeArtifact::get_default_extension(&Triple::host()) - .to_string() + #[cfg(feature = "shared-object")] + EngineType::SharedObject => { + wasmer_engine_shared_object::SharedObjectArtifact::get_default_extension( + &Triple::host(), + ) + .to_string() } #[cfg(feature = "universal")] EngineType::Universal => { diff --git a/lib/cli/src/store.rs b/lib/cli/src/store.rs index bf61f55e3d0..da9a44d56a7 100644 --- a/lib/cli/src/store.rs +++ b/lib/cli/src/store.rs @@ -19,16 +19,16 @@ pub struct StoreOptions { #[clap(flatten)] compiler: CompilerOptions, - /// Use Universal Engine. - #[clap(long, conflicts_with_all = &["native", "object-file"])] + /// Use the Universal Engine. + #[clap(long, conflicts_with_all = &["shared-object", "object-file"])] universal: bool, - /// Use Native Engine. + /// Use the Shared Object Engine. #[clap(long, conflicts_with_all = &["universal", "object-file"])] - native: bool, + shared_object: bool, - /// Use ObjectFile Engine. - #[clap(long, conflicts_with_all = &["universal", "native"])] + /// Use the ObjectFile Engine. + #[clap(long, conflicts_with_all = &["universal", "shared-object"])] object_file: bool, } @@ -143,9 +143,9 @@ impl CompilerOptions { .target(target) .engine(), ), - #[cfg(feature = "native")] - EngineType::Native => Box::new( - wasmer_engine_native::Native::new(compiler_config) + #[cfg(feature = "shared-object")] + EngineType::SharedObject => Box::new( + wasmer_engine_shared_object::SharedObject::new(compiler_config) .target(target) .features(features) .engine(), @@ -157,7 +157,11 @@ impl CompilerOptions { .features(features) .engine(), ), - #[cfg(not(all(feature = "universal", feature = "native", feature = "object-file")))] + #[cfg(not(all( + feature = "universal", + feature = "shared-object", + feature = "object-file" + )))] engine => bail!( "The `{}` engine is not included in this binary.", engine.to_string() @@ -362,8 +366,8 @@ impl FromStr for CompilerType { pub enum EngineType { /// Universal Engine Universal, - /// Native Engine - Native, + /// Shared Object Engine + SharedObject, /// Object File Engine ObjectFile, } @@ -372,7 +376,7 @@ impl ToString for EngineType { fn to_string(&self) -> String { match self { Self::Universal => "universal".to_string(), - Self::Native => "native".to_string(), + Self::SharedObject => "shared_object".to_string(), Self::ObjectFile => "objectfile".to_string(), } } @@ -416,16 +420,16 @@ impl StoreOptions { fn get_engine(&self) -> Result { if self.universal { Ok(EngineType::Universal) - } else if self.native { - Ok(EngineType::Native) + } else if self.shared_object { + Ok(EngineType::SharedObject) } else if self.object_file { Ok(EngineType::ObjectFile) } else { // Auto mode, we choose the best engine for that platform if cfg!(feature = "universal") { Ok(EngineType::Universal) - } else if cfg!(feature = "native") { - Ok(EngineType::Native) + } else if cfg!(feature = "shared-object") { + Ok(EngineType::SharedObject) } else if cfg!(feature = "object-file") { Ok(EngineType::ObjectFile) } else { @@ -445,13 +449,19 @@ impl StoreOptions { EngineType::Universal => { Arc::new(wasmer_engine_universal::Universal::headless().engine()) } - #[cfg(feature = "native")] - EngineType::Native => Arc::new(wasmer_engine_native::Native::headless().engine()), + #[cfg(feature = "shared-object")] + EngineType::SharedObject => { + Arc::new(wasmer_engine_shared_object::SharedObject::headless().engine()) + } #[cfg(feature = "object-file")] EngineType::ObjectFile => { Arc::new(wasmer_engine_object_file::ObjectFile::headless().engine()) } - #[cfg(not(all(feature = "universal", feature = "native", feature = "object-file")))] + #[cfg(not(all( + feature = "universal", + feature = "shared-object", + feature = "object-file" + )))] engine => bail!( "The `{}` engine is not included in this binary.", engine.to_string() diff --git a/lib/deprecated/runtime-core/Cargo.lock b/lib/deprecated/runtime-core/Cargo.lock index b9e2af5268f..5b4c6dd9e4c 100644 --- a/lib/deprecated/runtime-core/Cargo.lock +++ b/lib/deprecated/runtime-core/Cargo.lock @@ -1179,7 +1179,7 @@ dependencies = [ "wasmer-compiler-singlepass", "wasmer-derive", "wasmer-engine", - "wasmer-engine-native", + "wasmer-engine-shared-object", "wasmer-engine-universal", "wasmer-types", "wasmer-vm", @@ -1302,7 +1302,7 @@ dependencies = [ ] [[package]] -name = "wasmer-engine-native" +name = "wasmer-engine-shared-object" version = "1.0.2" dependencies = [ "cfg-if 0.1.10", diff --git a/lib/deprecated/runtime/Cargo.lock b/lib/deprecated/runtime/Cargo.lock index 67c4b1943e1..a4901a5b25a 100644 --- a/lib/deprecated/runtime/Cargo.lock +++ b/lib/deprecated/runtime/Cargo.lock @@ -1183,7 +1183,7 @@ dependencies = [ "wasmer-derive", "wasmer-engine", "wasmer-engine-universal", - "wasmer-engine-native", + "wasmer-engine-shared-object", "wasmer-types", "wasmer-vm", "wat", @@ -1321,7 +1321,7 @@ dependencies = [ ] [[package]] -name = "wasmer-engine-native" +name = "wasmer-engine-shared-object" version = "1.0.2" dependencies = [ "cfg-if 0.1.10", diff --git a/lib/engine-native/README.md b/lib/engine-native/README.md deleted file mode 100644 index 497014edadf..00000000000 --- a/lib/engine-native/README.md +++ /dev/null @@ -1,59 +0,0 @@ -# `wasmer-engine-native` [![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/master/LICENSE) - -The Wasmer Native engine is usable with any compiler implementation -based on [`wasmer-compiler`] that is able to emit -[Position-independent Code][PIC] (PIC). - -After the compiler generates the machine code for the functions, the -Native engine generates a shared object file and links it via -[`dlsym`] so it can be usable by the [`wasmer`] API. - -This allows Wasmer to achieve *blazing fast* **native startup times**. - -*Note: you can find a [full working example using the Native engine -here][example].* - -### Difference with `wasmer-engine-universal` - -The Native Engine and Universal Engine mainly differ on how the Modules are loaded/stored. -Using the same compilers, both will have the same runtime speed. - -However, the Native engine uses the Operating System shared library loader (via `dlopen`) -and as such is able to achieve a much faster startup time when deserializing a serialized -Module. - -## Requirements - -The `wasmer-engine-native` crate requires a linker available on your -system to generate the shared object file. - -We recommend having [`gcc`] or [`clang`] installed. - -> Note: when **cross-compiling** to other targets, `clang` will be the -> default command used for compiling. - -You can install LLVM (that provides `clang`) easily on your -Debian-like system via this command: - -```bash -bash -c "$(wget -O - https://apt.llvm.org/llvm.sh)" -``` - -Or in macOS: - -```bash -brew install llvm -``` - -Or via any of the [pre-built binaries that LLVM -offers][llvm-pre-built]. - - -[`wasmer-compiler`]: https://github.com/wasmerio/wasmer/tree/master/lib/compiler -[PIC]: https://en.wikipedia.org/wiki/Position-independent_code -[`dlsym`]: https://www.freebsd.org/cgi/man.cgi?query=dlsym -[`wasmer`]: https://github.com/wasmerio/wasmer/tree/master/lib/api -[example]: https://github.com/wasmerio/wasmer/blob/master/examples/engine_native.rs -[`gcc`]: https://gcc.gnu.org/ -[`clang`]: https://clang.llvm.org/ -[llvm-pre-built]: https://releases.llvm.org/download.html diff --git a/lib/engine-native/Cargo.toml b/lib/engine-shared-object/Cargo.toml similarity index 86% rename from lib/engine-native/Cargo.toml rename to lib/engine-shared-object/Cargo.toml index 28c371c27cb..aafdc9af579 100644 --- a/lib/engine-native/Cargo.toml +++ b/lib/engine-shared-object/Cargo.toml @@ -1,9 +1,9 @@ [package] -name = "wasmer-engine-native" +name = "wasmer-engine-shared-object" version = "1.0.2" -description = "Wasmer Native Engine" +description = "Wasmer Shared Object Engine" categories = ["wasm"] -keywords = ["wasm", "webassembly", "engine", "native"] +keywords = ["wasm", "webassembly", "engine", "shared-object"] authors = ["Wasmer Engineering Team "] repository = "https://github.com/wasmerio/wasmer" license = "MIT" diff --git a/lib/engine-shared-object/README.md b/lib/engine-shared-object/README.md new file mode 100644 index 00000000000..448d533305f --- /dev/null +++ b/lib/engine-shared-object/README.md @@ -0,0 +1,60 @@ +# `wasmer-engine-shared-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/master/LICENSE) + +The Wasmer Shared Object engine is usable with any compiler +implementation based on [`wasmer-compiler`] that is able to emit +[Position-Independent Code][PIC] (PIC). + +After the compiler generates the machine code for the functions, the +Shared Object Engine generates a shared object file and links it via +[`dlsym`] so it can be usable by the [`wasmer`] API. + +This allows Wasmer to achieve *blazing fast* **native startup times**. + +*Note: you can find a [full working example using the Shared Object +engine here][example].* + +### Difference with `wasmer-engine-universal` + +The Shared Object Engine and Universal Engine mainly differ on how the +Modules are loaded/stored. Using the same compilers, both will have +the same runtime speed. + +However, the Shared Object Engine uses the Operating System shared +library loader (via `dlopen`) and as such is able to achieve a much +faster startup time when deserializing a serialized `Module`. + +## Requirements + +The `wasmer-engine-shared-object` crate requires a linker available on +your system to generate the shared object file. + +We recommend having [`gcc`] or [`clang`] installed. + +> Note: when **cross-compiling** to other targets, `clang` will be the +> default command used for compiling. + +You can install LLVM (that provides `clang`) easily on your +Debian-like system via this command: + +```bash +bash -c "$(wget -O - https://apt.llvm.org/llvm.sh)" +``` + +Or in macOS: + +```bash +brew install llvm +``` + +Or via any of the [pre-built binaries that LLVM +offers][llvm-pre-built]. + + +[`wasmer-compiler`]: https://github.com/wasmerio/wasmer/tree/master/lib/compiler +[PIC]: https://en.wikipedia.org/wiki/Position-independent_code +[`dlsym`]: https://www.freebsd.org/cgi/man.cgi?query=dlsym +[`wasmer`]: https://github.com/wasmerio/wasmer/tree/master/lib/api +[example]: https://github.com/wasmerio/wasmer/blob/master/examples/engine_shared_object.rs +[`gcc`]: https://gcc.gnu.org/ +[`clang`]: https://clang.llvm.org/ +[llvm-pre-built]: https://releases.llvm.org/download.html diff --git a/lib/engine-native/src/artifact.rs b/lib/engine-shared-object/src/artifact.rs similarity index 94% rename from lib/engine-native/src/artifact.rs rename to lib/engine-shared-object/src/artifact.rs index d2b1d821a22..ebf690d2ef7 100644 --- a/lib/engine-native/src/artifact.rs +++ b/lib/engine-shared-object/src/artifact.rs @@ -1,7 +1,7 @@ -//! Define `NativeArtifact` to allow compiling and instantiating to be -//! done as separate steps. +//! Define `SharedObjectArtifact` to allow compiling and instantiating +//! to be done as separate steps. -use crate::engine::{NativeEngine, NativeEngineInner}; +use crate::engine::{SharedObjectEngine, SharedObjectEngineInner}; use crate::serialize::{ArchivedModuleMetadata, ModuleMetadata}; use libloading::{Library, Symbol as LibrarySymbol}; use loupe::MemoryUsage; @@ -44,10 +44,10 @@ use wasmer_vm::{ VMSharedSignatureIndex, VMTrampoline, }; -/// A compiled wasm module, ready to be instantiated. +/// A compiled Wasm module, ready to be instantiated. #[derive(MemoryUsage)] -pub struct NativeArtifact { - sharedobject_path: PathBuf, +pub struct SharedObjectArtifact { + shared_object_path: PathBuf, metadata: ModuleMetadata, finished_functions: BoxedSlice, #[loupe(skip)] @@ -64,7 +64,7 @@ fn to_compile_error(err: impl Error) -> CompileError { const WASMER_METADATA_SYMBOL: &[u8] = b"WASMER_METADATA"; -impl NativeArtifact { +impl SharedObjectArtifact { // Mach-O header in Mac #[allow(dead_code)] const MAGIC_HEADER_MH_CIGAM_64: &'static [u8] = &[207, 250, 237, 254]; @@ -81,7 +81,7 @@ impl NativeArtifact { #[allow(dead_code)] const MAGIC_HEADER_COFF_64: &'static [u8] = &[b'M', b'Z']; - /// Check if the provided bytes look like `NativeArtifact`. + /// Check if the provided bytes look like `SharedObjectArtifact`. /// /// This means, if the bytes look like a shared object file in the target /// system. @@ -154,10 +154,11 @@ impl NativeArtifact { )) } - /// Compile a data buffer into a `NativeArtifact`, which may then be instantiated. + /// Compile a data buffer into a `SharedObjectArtifact`, which may + /// then be instantiated. #[cfg(feature = "compiler")] pub fn new( - engine: &NativeEngine, + engine: &SharedObjectEngine, data: &[u8], tunables: &dyn Tunables, ) -> Result { @@ -223,7 +224,7 @@ impl NativeArtifact { Some(obj_bytes) => { let obj_bytes = obj_bytes?; let file = tempfile::Builder::new() - .prefix("wasmer_native") + .prefix("wasmer_shared_object_") .suffix(".o") .tempfile() .map_err(to_compile_error)?; @@ -251,7 +252,7 @@ impl NativeArtifact { emit_compilation(&mut obj, compilation, &symbol_registry, &target_triple) .map_err(to_compile_error)?; let file = tempfile::Builder::new() - .prefix("wasmer_native") + .prefix("wasmer_shared_object_") .suffix(".o") .tempfile() .map_err(to_compile_error)?; @@ -268,7 +269,7 @@ impl NativeArtifact { let shared_filepath = { let suffix = format!(".{}", Self::get_default_extension(&target_triple)); let shared_file = tempfile::Builder::new() - .prefix("wasmer_native") + .prefix("wasmer_shared_object_") .suffix(&suffix) .tempfile() .map_err(to_compile_error)?; @@ -357,10 +358,10 @@ impl NativeArtifact { } } - /// Construct a `NativeArtifact` from component parts. + /// Construct a `SharedObjectArtifact` from component parts. pub fn from_parts_crosscompiled( metadata: ModuleMetadata, - sharedobject_path: PathBuf, + shared_object_path: PathBuf, ) -> Result { let finished_functions: PrimaryMap = PrimaryMap::new(); let finished_function_call_trampolines: PrimaryMap = @@ -369,7 +370,7 @@ impl NativeArtifact { PrimaryMap::new(); let signatures: PrimaryMap = PrimaryMap::new(); Ok(Self { - sharedobject_path, + shared_object_path, metadata, finished_functions: finished_functions.into_boxed_slice(), finished_function_call_trampolines: finished_function_call_trampolines @@ -382,11 +383,11 @@ impl NativeArtifact { }) } - /// Construct a `NativeArtifact` from component parts. + /// Construct a `SharedObjectArtifact` from component parts. pub fn from_parts( - engine_inner: &mut NativeEngineInner, + engine_inner: &mut SharedObjectEngineInner, metadata: ModuleMetadata, - sharedobject_path: PathBuf, + shared_object_path: PathBuf, lib: Library, ) -> Result { let mut finished_functions: PrimaryMap = @@ -474,7 +475,7 @@ impl NativeArtifact { engine_inner.add_library(lib); Ok(Self { - sharedobject_path, + shared_object_path, metadata, finished_functions: finished_functions.into_boxed_slice(), finished_function_call_trampolines: finished_function_call_trampolines @@ -487,21 +488,22 @@ impl NativeArtifact { }) } - /// Compile a data buffer into a `NativeArtifact`, which may then be instantiated. + /// Compile a data buffer into a `SharedObjectArtifact`, which may + /// then be instantiated. #[cfg(not(feature = "compiler"))] - pub fn new(_engine: &NativeEngine, _data: &[u8]) -> Result { + pub fn new(_engine: &SharedObjectEngine, _data: &[u8]) -> Result { Err(CompileError::Codegen( "Compilation is not enabled in the engine".to_string(), )) } - /// Deserialize a `NativeArtifact` from bytes. + /// Deserialize a `SharedObjectArtifact` from bytes. /// /// # Safety /// /// The bytes must represent a serialized WebAssembly module. pub unsafe fn deserialize( - engine: &NativeEngine, + engine: &SharedObjectEngine, bytes: &[u8], ) -> Result { if !Self::is_deserializable(&bytes) { @@ -518,13 +520,13 @@ impl NativeArtifact { Self::deserialize_from_file_unchecked(&engine, &path) } - /// Deserialize a `NativeArtifact` from a file path. + /// Deserialize a `SharedObjectArtifact` from a file path. /// /// # Safety /// /// The file's content must represent a serialized WebAssembly module. pub unsafe fn deserialize_from_file( - engine: &NativeEngine, + engine: &SharedObjectEngine, path: &Path, ) -> Result { let mut file = File::open(&path)?; @@ -539,13 +541,13 @@ impl NativeArtifact { Self::deserialize_from_file_unchecked(&engine, &path) } - /// Deserialize a `NativeArtifact` from a file path (unchecked). + /// Deserialize a `SharedObjectArtifact` from a file path (unchecked). /// /// # Safety /// /// The file's content must represent a serialized WebAssembly module. pub unsafe fn deserialize_from_file_unchecked( - engine: &NativeEngine, + engine: &SharedObjectEngine, path: &Path, ) -> Result { let lib = Library::new(&path).map_err(|e| { @@ -588,7 +590,7 @@ impl NativeArtifact { } } -impl Artifact for NativeArtifact { +impl Artifact for SharedObjectArtifact { fn module(&self) -> Arc { self.metadata.compile_info.module.clone() } @@ -767,8 +769,8 @@ impl Artifact for NativeArtifact { Ok(()) } - /// Serialize a NativeArtifact + /// Serialize a `SharedObjectArtifact`. fn serialize(&self) -> Result, SerializeError> { - Ok(std::fs::read(&self.sharedobject_path)?) + Ok(std::fs::read(&self.shared_object_path)?) } } diff --git a/lib/engine-native/src/builder.rs b/lib/engine-shared-object/src/builder.rs similarity index 78% rename from lib/engine-native/src/builder.rs rename to lib/engine-shared-object/src/builder.rs index b3d856e91dc..3b19dde7a11 100644 --- a/lib/engine-native/src/builder.rs +++ b/lib/engine-shared-object/src/builder.rs @@ -1,16 +1,16 @@ -use crate::NativeEngine; +use crate::SharedObjectEngine; use wasmer_compiler::{CompilerConfig, Features, Target}; -/// The Native builder -pub struct Native { +/// The Shared Object builder +pub struct SharedObject { compiler_config: Option>, target: Option, features: Option, } -impl Native { +impl SharedObject { #[cfg(feature = "compiler")] - /// Create a new Native + /// Create a new Shared Object builder. pub fn new(compiler_config: T) -> Self where T: Into>, @@ -25,7 +25,7 @@ impl Native { } } - /// Create a new headless Native + /// Create a new headless Shared Object builder. pub fn headless() -> Self { Self { compiler_config: None, @@ -46,8 +46,8 @@ impl Native { self } - /// Build the `NativeEngine` for this configuration - pub fn engine(self) -> NativeEngine { + /// Build the `SharedObjectEngine` for this configuration + pub fn engine(self) -> SharedObjectEngine { if let Some(_compiler_config) = self.compiler_config { #[cfg(feature = "compiler")] { @@ -57,15 +57,15 @@ impl Native { .features .unwrap_or_else(|| compiler_config.default_features_for_target(&target)); let compiler = compiler_config.compiler(); - NativeEngine::new(compiler, target, features) + SharedObjectEngine::new(compiler, target, features) } #[cfg(not(feature = "compiler"))] { - unreachable!("Cannot call `NativeEngine::new` without the `compiler` feature") + unreachable!("Cannot call `SharedObjectEngine::new` without the `compiler` feature") } } else { - NativeEngine::headless() + SharedObjectEngine::headless() } } } @@ -105,13 +105,13 @@ mod tests { #[should_panic(expected = "compiler not implemented")] fn build_engine() { let compiler_config = TestCompilerConfig::default(); - let native = Native::new(compiler_config); - let _engine = native.engine(); + let shared_object = SharedObject::new(compiler_config); + let _engine = shared_object.engine(); } #[test] fn build_headless_engine() { - let native = Native::headless(); - let _engine = native.engine(); + let shared_object = SharedObject::headless(); + let _engine = shared_object.engine(); } } diff --git a/lib/engine-native/src/engine.rs b/lib/engine-shared-object/src/engine.rs similarity index 85% rename from lib/engine-native/src/engine.rs rename to lib/engine-shared-object/src/engine.rs index 196f743a0d2..0c0c9e3004a 100644 --- a/lib/engine-native/src/engine.rs +++ b/lib/engine-shared-object/src/engine.rs @@ -1,6 +1,6 @@ -//! Native Engine. +//! Shared Object Engine. -use crate::NativeArtifact; +use crate::SharedObjectArtifact; use libloading::Library; use loupe::MemoryUsage; use std::path::Path; @@ -17,24 +17,24 @@ use wasmer_vm::{ FuncDataRegistry, SignatureRegistry, VMCallerCheckedAnyfunc, VMFuncRef, VMSharedSignatureIndex, }; -/// A WebAssembly `Native` Engine. +/// A WebAssembly `SharedObject` Engine. #[derive(Clone, MemoryUsage)] -pub struct NativeEngine { - inner: Arc>, +pub struct SharedObjectEngine { + inner: Arc>, /// The target for the compiler target: Arc, engine_id: EngineId, } -impl NativeEngine { - /// Create a new `NativeEngine` with the given config +impl SharedObjectEngine { + /// Create a new `SharedObjectEngine` with the given config #[cfg(feature = "compiler")] pub fn new(compiler: Box, target: Target, features: Features) -> Self { let is_cross_compiling = *target.triple() != Triple::host(); let linker = Linker::find_linker(is_cross_compiling); Self { - inner: Arc::new(Mutex::new(NativeEngineInner { + inner: Arc::new(Mutex::new(SharedObjectEngineInner { compiler: Some(compiler), signatures: SignatureRegistry::new(), func_data: Arc::new(FuncDataRegistry::new()), @@ -49,7 +49,7 @@ impl NativeEngine { } } - /// Create a headless `NativeEngine` + /// Create a headless `SharedObjectEngine` /// /// A headless engine is an engine without any compiler attached. /// This is useful for assuring a minimal runtime for running @@ -64,7 +64,7 @@ impl NativeEngine { /// they just take already processed Modules (via `Module::serialize`). pub fn headless() -> Self { Self { - inner: Arc::new(Mutex::new(NativeEngineInner { + inner: Arc::new(Mutex::new(SharedObjectEngineInner { #[cfg(feature = "compiler")] compiler: None, #[cfg(feature = "compiler")] @@ -99,16 +99,16 @@ impl NativeEngine { inner.prefixer = Some(Box::new(prefixer)); } - pub(crate) fn inner(&self) -> std::sync::MutexGuard<'_, NativeEngineInner> { + pub(crate) fn inner(&self) -> std::sync::MutexGuard<'_, SharedObjectEngineInner> { self.inner.lock().unwrap() } - pub(crate) fn inner_mut(&self) -> std::sync::MutexGuard<'_, NativeEngineInner> { + pub(crate) fn inner_mut(&self) -> std::sync::MutexGuard<'_, SharedObjectEngineInner> { self.inner.lock().unwrap() } } -impl Engine for NativeEngine { +impl Engine for SharedObjectEngine { /// The target fn target(&self) -> &Target { &self.target @@ -143,7 +143,9 @@ impl Engine for NativeEngine { binary: &[u8], tunables: &dyn Tunables, ) -> Result, CompileError> { - Ok(Arc::new(NativeArtifact::new(&self, binary, tunables)?)) + Ok(Arc::new(SharedObjectArtifact::new( + &self, binary, tunables, + )?)) } /// Compile a WebAssembly binary (it will fail because the `compiler` flag is disabled). @@ -154,14 +156,14 @@ impl Engine for NativeEngine { _tunables: &dyn Tunables, ) -> Result, CompileError> { Err(CompileError::Codegen( - "The `NativeEngine` is operating in headless mode, so it cannot compile a module." + "The `SharedObjectEngine` is operating in headless mode, so it cannot compile a module." .to_string(), )) } /// Deserializes a WebAssembly module (binary content of a Shared Object file) unsafe fn deserialize(&self, bytes: &[u8]) -> Result, DeserializeError> { - Ok(Arc::new(NativeArtifact::deserialize(&self, &bytes)?)) + Ok(Arc::new(SharedObjectArtifact::deserialize(&self, &bytes)?)) } /// Deserializes a WebAssembly module from a path @@ -170,7 +172,7 @@ impl Engine for NativeEngine { &self, file_ref: &Path, ) -> Result, DeserializeError> { - Ok(Arc::new(NativeArtifact::deserialize_from_file( + Ok(Arc::new(SharedObjectArtifact::deserialize_from_file( &self, &file_ref, )?)) } @@ -210,7 +212,7 @@ impl Linker { .next() .unwrap_or_else(|| { panic!( - "Need {} installed in order to use `NativeEngine` when {}cross-compiling", + "Need {} installed in order to use `SharedObjectEngine` when {}cross-compiling", requirements, if is_cross_compiling { "" } else { "not " } ) @@ -228,9 +230,9 @@ impl Linker { } } -/// The inner contents of `NativeEngine` +/// The inner contents of `SharedObjectEngine` #[derive(MemoryUsage)] -pub struct NativeEngineInner { +pub struct SharedObjectEngineInner { /// The compiler #[cfg(feature = "compiler")] compiler: Option>, @@ -249,12 +251,12 @@ pub struct NativeEngineInner { func_data: Arc, /// The prefixer returns the a String to prefix each of - /// the functions in the shared object generated by the `NativeEngine`, + /// the functions in the shared object generated by the `SharedObjectEngine`, /// so we can assure no collisions. #[loupe(skip)] prefixer: Option String + Send>>, - /// Whether the native engine will cross-compile. + /// Whether the shared object engine will cross-compile. is_cross_compiling: bool, /// The linker to use. @@ -265,12 +267,12 @@ pub struct NativeEngineInner { libraries: Vec, } -impl NativeEngineInner { +impl SharedObjectEngineInner { /// 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 `NativeEngine` is operating in headless mode, so it can only execute already compiled Modules.".to_string())); + return Err(CompileError::Codegen("The `SharedObjectEngine` is operating in headless mode, so it can only execute already compiled Modules.".to_string())); } Ok(&**self .compiler @@ -302,7 +304,7 @@ impl NativeEngineInner { #[cfg(not(feature = "compiler"))] pub fn validate<'data>(&self, _data: &'data [u8]) -> Result<(), CompileError> { Err(CompileError::Validate( - "The `NativeEngine` is not compiled with compiler support, which is required for validating".to_string(), + "The `SharedObjectEngine` is not compiled with compiler support, which is required for validating".to_string(), )) } diff --git a/lib/engine-native/src/lib.rs b/lib/engine-shared-object/src/lib.rs similarity index 83% rename from lib/engine-native/src/lib.rs rename to lib/engine-shared-object/src/lib.rs index 8692e2c508b..41aff63d8ed 100644 --- a/lib/engine-native/src/lib.rs +++ b/lib/engine-shared-object/src/lib.rs @@ -1,4 +1,4 @@ -//! Native backend for Wasmer compilers. +//! Shared Object Engine for Wasmer compilers. //! //! Given a compiler (such as `CraneliftCompiler` or `LLVMCompiler`) //! it generates a shared object file (`.so` or `.dylib` depending on @@ -27,9 +27,9 @@ mod builder; mod engine; mod serialize; -pub use crate::artifact::NativeArtifact; -pub use crate::builder::Native; -pub use crate::engine::NativeEngine; +pub use crate::artifact::SharedObjectArtifact; +pub use crate::builder::SharedObject; +pub use crate::engine::SharedObjectEngine; /// Version number of this crate. pub const VERSION: &str = env!("CARGO_PKG_VERSION"); diff --git a/lib/engine-native/src/serialize.rs b/lib/engine-shared-object/src/serialize.rs similarity index 100% rename from lib/engine-native/src/serialize.rs rename to lib/engine-shared-object/src/serialize.rs diff --git a/lib/engine/README.md b/lib/engine/README.md index 7d19e75d6f3..c45d47a61e8 100644 --- a/lib/engine/README.md +++ b/lib/engine/README.md @@ -11,7 +11,7 @@ Wasmer Engines are mainly responsible for two things: It currently has three implementations: 1. Universal with [`wasmer-engine-universal`], -2. Native with [`wasmer-engine-native`], +2. Native with [`wasmer-engine-shared-object`], 3. Object with [`wasmer-engine-object-file`]. ## Example Implementation @@ -29,7 +29,7 @@ attributions of the project. [`wasmer-engine-universal`]: https://github.com/wasmerio/wasmer/tree/master/lib/engine-universal -[`wasmer-engine-native`]: https://github.com/wasmerio/wasmer/tree/master/lib/engine-native +[`wasmer-engine-shared-object`]: https://github.com/wasmerio/wasmer/tree/master/lib/engine-shared-object [`wasmer-engine-object-file`]: https://github.com/wasmerio/wasmer/tree/master/lib/engine-object-file [`wasmer-engine-dummy`]: https://github.com/wasmerio/wasmer/tree/master/tests/lib/engine-dummy [`wasmtime-api`]: https://crates.io/crates/wasmtime diff --git a/lib/object/README.md b/lib/object/README.md index 62a3c5a9eab..626fb23ad2e 100644 --- a/lib/object/README.md +++ b/lib/object/README.md @@ -3,8 +3,8 @@ The Wasmer Native Object crate aims at cross-generating native objects for various platforms. -This crate is the foundation of [the `wasmer-engine-native` -crate](../engine-native/). Given a compilation result, i.e. the result +This crate is the foundation of [the `wasmer-engine-shared-object` +crate](../engine-shared-object/). 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` diff --git a/scripts/publish.py b/scripts/publish.py index 2831936306a..997f539f2f6 100644 --- a/scripts/publish.py +++ b/scripts/publish.py @@ -35,20 +35,20 @@ "wasmer-compiler-cranelift": set(["wasmer-types", "wasmer-vm", "wasmer-compiler"]), "wasmer-compiler-llvm": set(["wasmer-types", "wasmer-vm", "wasmer-compiler"]), "wasmer-engine-universal": set(["wasmer-types", "wasmer-vm", "wasmer-compiler", "wasmer-engine"]), - "wasmer-engine-native": set(["wasmer-types", "wasmer-vm", "wasmer-compiler", "wasmer-engine", + "wasmer-engine-shared-object": 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-object"]), "wasmer": set(["wasmer-vm", "wasmer-compiler-singlepass", "wasmer-compiler-cranelift", "wasmer-compiler-llvm", "wasmer-compiler", "wasmer-engine", "wasmer-engine-universal", - "wasmer-engine-native", "wasmer-engine-object-file", "wasmer-types", "wasmer-derive"]), + "wasmer-engine-shared-object", "wasmer-engine-object-file", "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-native", "wasmer-engine-object-file", "wasmer-wasi", "wasmer-types"]), + "wasmer-engine-shared-object", "wasmer-engine-object-file", "wasmer-wasi", "wasmer-types"]), "wasmer-middlewares": set(["wasmer", "wasmer-types", "wasmer-vm"]), } @@ -66,7 +66,7 @@ "wasmer-compiler-llvm": "compiler-llvm", "wasmer-engine": "engine", "wasmer-engine-universal": "engine-universal", - "wasmer-engine-native": "engine-native", + "wasmer-engine-shared-object": "engine-shared-object", "wasmer-engine-object-file": "engine-object-file", "wasmer-cache": "cache", "wasmer": "api", diff --git a/tests/compilers/config.rs b/tests/compilers/config.rs index f3dbe2c0d3d..c6ae9674a4c 100644 --- a/tests/compilers/config.rs +++ b/tests/compilers/config.rs @@ -10,7 +10,7 @@ pub enum Compiler { #[derive(Clone, Debug, PartialEq)] pub enum Engine { - Native, + SharedObject, Universal, } @@ -61,9 +61,9 @@ impl Config { #[cfg(not(feature = "engine"))] compile_error!("Plese enable at least one engine via the features"); match &self.engine { - #[cfg(feature = "native")] - Engine::Native => { - let mut engine = wasmer_engine_native::Native::new(compiler_config); + #[cfg(feature = "shared-object")] + Engine::SharedObject => { + let mut engine = wasmer_engine_shared_object::SharedObject::new(compiler_config); if let Some(ref features) = self.features { engine = engine.features(features.clone()) } @@ -87,8 +87,10 @@ impl Config { pub fn engine_headless(&self) -> Box { match &self.engine { - #[cfg(feature = "native")] - Engine::Native => Box::new(wasmer_engine_native::Native::headless().engine()), + #[cfg(feature = "shared-object")] + Engine::SharedObject => { + Box::new(wasmer_engine_shared_object::SharedObject::headless().engine()) + } #[cfg(feature = "universal")] Engine::Universal => Box::new(wasmer_engine_universal::Universal::headless().engine()), #[allow(dead_code)] diff --git a/tests/compilers/wast.rs b/tests/compilers/wast.rs index c5785209988..144d1aca1d6 100644 --- a/tests/compilers/wast.rs +++ b/tests/compilers/wast.rs @@ -14,13 +14,6 @@ use wasmer_wast::Wast; // } include!(concat!(env!("OUT_DIR"), "/generated_spectests.rs")); -// This prefixer returns the hash of the module to prefix each of -// the functions in the shared object generated by the `NativeEngine`. -fn _native_prefixer(bytes: &[u8]) -> String { - let hash = blake3::hash(bytes); - format!("{}", hash.to_hex()) -} - pub fn run_wast(mut config: crate::Config, wast_path: &str) -> anyhow::Result<()> { println!("Running wast `{}`", wast_path); let try_nan_canonicalization = wast_path.contains("nan-canonicalization"); @@ -47,7 +40,8 @@ pub fn run_wast(mut config: crate::Config, wast_path: &str) -> anyhow::Result<() wast.allow_trap_message("uninitialized element 2", "uninitialized element"); // `liking.wast` has different wording but the same meaning wast.allow_trap_message("out of bounds memory access", "memory out of bounds"); - if config.compiler == crate::Compiler::Cranelift && config.engine == crate::Engine::Native { + if config.compiler == crate::Compiler::Cranelift && config.engine == crate::Engine::SharedObject + { wast.allow_trap_message("call stack exhausted", "out of bounds memory access"); wast.allow_trap_message("indirect call type mismatch", "call stack exhausted"); wast.allow_trap_message("integer divide by zero", "call stack exhausted"); diff --git a/tests/ignores.txt b/tests/ignores.txt index c633c8a9afd..0d1984482a9 100644 --- a/tests/ignores.txt +++ b/tests/ignores.txt @@ -3,36 +3,36 @@ singlepass spec::multi_value singlepass spec::simd singlepass+windows * -singlepass+native * -windows+native * -musl+native * # Dynamic loading not supported in Musl +singlepass+shared-object * +windows+shared-object * +musl+shared-object * # Dynamic loading not supported in Musl # Traps singlepass traps::test_trap_trace -native traps::test_trap_trace +shared-object traps::test_trap_trace aarch64 traps::test_trap_trace singlepass traps::test_trap_stack_overflow -native traps::test_trap_stack_overflow +shared-object traps::test_trap_stack_overflow aarch64 traps::test_trap_stack_overflow singlepass traps::trap_display_pretty llvm traps::trap_display_pretty -native traps::trap_display_pretty +shared-object traps::trap_display_pretty aarch64 traps::trap_display_pretty singlepass traps::trap_display_multi_module llvm traps::trap_display_multi_module -native traps::trap_display_multi_module +shared-object traps::trap_display_multi_module aarch64 traps::trap_display_multi_module singlepass traps::call_signature_mismatch llvm traps::call_signature_mismatch -native traps::call_signature_mismatch +shared-object traps::call_signature_mismatch macos+aarch64 traps::call_signature_mismatch singlepass traps::start_trap_pretty llvm traps::start_trap_pretty -native traps::start_trap_pretty +shared-object traps::start_trap_pretty aarch64 traps::start_trap_pretty -cranelift multi_value_imports::native -singlepass multi_value_imports::native +cranelift multi_value_imports::shared-object +singlepass multi_value_imports::shared-object singlepass multi_value_imports::dynamic @@ -45,9 +45,9 @@ llvm+universal+macos+aarch64 * cranelift spec::skip_stack_guard_page llvm spec::skip_stack_guard_page -# TODO(https://github.com/wasmerio/wasmer/issues/1727): Traps in native engine -cranelift+native spec::linking -cranelift+native spec::bulk +# TODO(https://github.com/wasmerio/wasmer/issues/1727): Traps in shared-object engine +cranelift+shared-object spec::linking +cranelift+shared-object spec::bulk # Some SIMD opperations are not yet supported by Cranelift cranelift+aarch64 spec::simd::simd_boolean diff --git a/tests/integration/cli/src/util.rs b/tests/integration/cli/src/util.rs index 15cedee4bb4..ded87dfd69d 100644 --- a/tests/integration/cli/src/util.rs +++ b/tests/integration/cli/src/util.rs @@ -22,7 +22,7 @@ impl Compiler { #[derive(Debug, Copy, Clone)] pub enum Engine { Universal, - Native, + SharedObject, ObjectFile, } @@ -30,7 +30,7 @@ impl Engine { pub const fn to_flag(self) -> &'static str { match self { Engine::Universal => "--universal", - Engine::Native => "--native", + Engine::SharedObject => "--shared-object", Engine::ObjectFile => "--object-file", } } diff --git a/tests/lib/compiler-test-derive/src/ignores.rs b/tests/lib/compiler-test-derive/src/ignores.rs index c2c0474126a..349711b1716 100644 --- a/tests/lib/compiler-test-derive/src/ignores.rs +++ b/tests/lib/compiler-test-derive/src/ignores.rs @@ -115,7 +115,7 @@ impl Ignores { arch = Some(alias.to_string()); } // Engines - "universal" | "native" => { + "universal" | "shared-object" => { engine = Some(alias.to_string()); } // Compilers diff --git a/tests/lib/compiler-test-derive/src/lib.rs b/tests/lib/compiler-test-derive/src/lib.rs index a30473e6129..cb1fe923b3c 100644 --- a/tests/lib/compiler-test-derive/src/lib.rs +++ b/tests/lib/compiler-test-derive/src/lib.rs @@ -107,23 +107,24 @@ pub fn compiler_test(attrs: TokenStream, input: TokenStream) -> TokenStream { } }; - let construct_compiler_test = - |func: &::syn::ItemFn, compiler_name: &str| -> ::proc_macro2::TokenStream { - let mod_name = ::quote::format_ident!("{}", compiler_name.to_lowercase()); - let universal_engine_test = construct_engine_test(func, compiler_name, "Universal"); - let native_engine_test = construct_engine_test(func, compiler_name, "Native"); - let compiler_name_lowercase = compiler_name.to_lowercase(); - - quote! { - #[cfg(feature = #compiler_name_lowercase)] - mod #mod_name { - use super::*; - - #universal_engine_test - #native_engine_test - } + let construct_compiler_test = |func: &::syn::ItemFn, + compiler_name: &str| + -> ::proc_macro2::TokenStream { + let mod_name = ::quote::format_ident!("{}", compiler_name.to_lowercase()); + let universal_engine_test = construct_engine_test(func, compiler_name, "Universal"); + let shared_object_engine_test = construct_engine_test(func, compiler_name, "SharedObject"); + let compiler_name_lowercase = compiler_name.to_lowercase(); + + quote! { + #[cfg(feature = #compiler_name_lowercase)] + mod #mod_name { + use super::*; + + #universal_engine_test + #shared_object_engine_test } - }; + } + }; let singlepass_compiler_test = construct_compiler_test(&my_fn, "Singlepass"); let cranelift_compiler_test = construct_compiler_test(&my_fn, "Cranelift"); diff --git a/tests/lib/compiler-test-derive/src/tests.rs b/tests/lib/compiler-test-derive/src/tests.rs index 6d16ebe25b2..f37370acc95 100644 --- a/tests/lib/compiler-test-derive/src/tests.rs +++ b/tests/lib/compiler-test-derive/src/tests.rs @@ -71,10 +71,10 @@ gen_tests! { } #[test] #[cold] - #[cfg(feature = "native")] - fn native() { + #[cfg(feature = "shared-object")] + fn shared_object() { add(crate::Config::new( - crate::Engine::Native, + crate::Engine::SharedObject, crate::Compiler::Singlepass )) } @@ -94,10 +94,10 @@ gen_tests! { } #[test] #[cold] - #[cfg(feature = "native")] - fn native() { + #[cfg(feature = "shared-object")] + fn shared_object() { add(crate::Config::new( - crate::Engine::Native, + crate::Engine::SharedObject, crate::Compiler::Cranelift )) } @@ -117,10 +117,10 @@ gen_tests! { } #[test] #[cold] - #[cfg(feature = "native")] - fn native() { + #[cfg(feature = "shared-object")] + fn shared_object() { add(crate::Config::new( - crate::Engine::Native, + crate::Engine::SharedObject, crate::Compiler::LLVM )) } diff --git a/tests/lib/test-generator/Cargo.toml b/tests/lib/test-generator/Cargo.toml index 495f2e7d6e4..ded1ef31b78 100644 --- a/tests/lib/test-generator/Cargo.toml +++ b/tests/lib/test-generator/Cargo.toml @@ -10,5 +10,5 @@ anyhow = "1.0" target-lexicon = "0.12" [features] -test-native = [] +test-shared-object = [] test-universal = [] From e11fc26df67b3639a504e870b0bcbba537d37028 Mon Sep 17 00:00:00 2001 From: Ivan Enderlin Date: Thu, 27 May 2021 17:07:49 +0200 Subject: [PATCH 5/6] test: Patch `compiler-test` to create the feature name correctly. --- tests/lib/compiler-test-derive/src/lib.rs | 43 ++++++++++++----------- 1 file changed, 22 insertions(+), 21 deletions(-) diff --git a/tests/lib/compiler-test-derive/src/lib.rs b/tests/lib/compiler-test-derive/src/lib.rs index cb1fe923b3c..13b67e7e7ab 100644 --- a/tests/lib/compiler-test-derive/src/lib.rs +++ b/tests/lib/compiler-test-derive/src/lib.rs @@ -70,12 +70,12 @@ pub fn compiler_test(attrs: TokenStream, input: TokenStream) -> TokenStream { }; let construct_engine_test = |func: &::syn::ItemFn, compiler_name: &str, - engine_name: &str| + engine_name: &str, + engine_feature_name: &str| -> ::proc_macro2::TokenStream { let config_compiler = ::quote::format_ident!("{}", compiler_name); let config_engine = ::quote::format_ident!("{}", engine_name); - let engine_name_lowercase = engine_name.to_lowercase(); - let test_name = ::quote::format_ident!("{}", engine_name_lowercase); + let test_name = ::quote::format_ident!("{}", engine_name.to_lowercase()); let mut new_sig = func.sig.clone(); let attrs = func .attrs @@ -87,7 +87,7 @@ pub fn compiler_test(attrs: TokenStream, input: TokenStream) -> TokenStream { let f = quote! { #[test] #attrs - #[cfg(feature = #engine_name_lowercase)] + #[cfg(feature = #engine_feature_name)] #new_sig { #fn_name(crate::Config::new(crate::Engine::#config_engine, crate::Compiler::#config_compiler)) } @@ -107,24 +107,25 @@ pub fn compiler_test(attrs: TokenStream, input: TokenStream) -> TokenStream { } }; - let construct_compiler_test = |func: &::syn::ItemFn, - compiler_name: &str| - -> ::proc_macro2::TokenStream { - let mod_name = ::quote::format_ident!("{}", compiler_name.to_lowercase()); - let universal_engine_test = construct_engine_test(func, compiler_name, "Universal"); - let shared_object_engine_test = construct_engine_test(func, compiler_name, "SharedObject"); - let compiler_name_lowercase = compiler_name.to_lowercase(); - - quote! { - #[cfg(feature = #compiler_name_lowercase)] - mod #mod_name { - use super::*; - - #universal_engine_test - #shared_object_engine_test + let construct_compiler_test = + |func: &::syn::ItemFn, compiler_name: &str| -> ::proc_macro2::TokenStream { + let mod_name = ::quote::format_ident!("{}", compiler_name.to_lowercase()); + let universal_engine_test = + construct_engine_test(func, compiler_name, "Universal", "universal"); + let shared_object_engine_test = + construct_engine_test(func, compiler_name, "SharedObject", "shared-object"); + let compiler_name_lowercase = compiler_name.to_lowercase(); + + quote! { + #[cfg(feature = #compiler_name_lowercase)] + mod #mod_name { + use super::*; + + #universal_engine_test + #shared_object_engine_test + } } - } - }; + }; let singlepass_compiler_test = construct_compiler_test(&my_fn, "Singlepass"); let cranelift_compiler_test = construct_compiler_test(&my_fn, "Cranelift"); From 3d66a2e3604aa30151f52945248a62a56ff87b56 Mon Sep 17 00:00:00 2001 From: Ivan Enderlin Date: Fri, 28 May 2021 09:13:23 +0200 Subject: [PATCH 6/6] feat: Rename `wasmer-engine-native` to `wasmer-engine-dylib`. --- Cargo.lock | 22 +-- Cargo.toml | 22 +-- Makefile | 81 +++++---- docs/deps_dedup.dot | 4 +- docs/deps_dedup.svg | 162 +++++++++--------- examples/README.md | 6 +- examples/engine_cross_compilation.rs | 11 +- ...ngine_shared_object.rs => engine_dylib.rs} | 25 ++- examples/engine_headless.rs | 23 +-- fuzz/Cargo.toml | 10 +- fuzz/README.md | 2 +- ...object_cranelift.rs => dylib_cranelift.rs} | 6 +- lib/api/Cargo.toml | 12 +- lib/api/src/lib.rs | 6 +- lib/api/src/store.rs | 2 +- lib/c-api/Cargo.toml | 8 +- lib/c-api/src/wasm_c_api/engine.rs | 48 +++--- lib/c-api/src/wasm_c_api/unstable/engine.rs | 15 +- lib/c-api/tests/wasm.h | 6 +- lib/c-api/wasmer_wasm.h | 2 +- lib/cache/Cargo.toml | 2 +- lib/cache/benches/bench_filesystem_cache.rs | 2 +- lib/cli/Cargo.toml | 12 +- lib/cli/README.md | 6 +- lib/cli/src/commands/compile.rs | 14 +- lib/cli/src/commands/run.rs | 23 ++- lib/cli/src/compilers/llvm.rs | 2 - lib/cli/src/store.rs | 46 ++--- lib/deprecated/runtime-core/Cargo.lock | 4 +- lib/deprecated/runtime/Cargo.lock | 4 +- .../tests/compile-fail/bad-attribute.rs | 4 +- .../tests/compile-fail/bad-export-arg.rs | 7 +- lib/derive/tests/compile-fail/no-lazy-init.rs | 2 +- .../Cargo.toml | 6 +- lib/engine-dylib/README.md | 60 +++++++ .../src/artifact.rs | 58 +++---- .../src/builder.rs | 30 ++-- .../src/engine.rs | 56 +++--- .../src/lib.rs | 15 +- .../src/serialize.rs | 0 lib/engine-shared-object/README.md | 60 ------- lib/engine/README.md | 4 +- lib/object/README.md | 4 +- scripts/publish.py | 8 +- tests/compilers/config.rs | 14 +- tests/compilers/wast.rs | 3 +- tests/ignores.txt | 28 +-- tests/integration/cli/src/util.rs | 4 +- tests/lib/compiler-test-derive/src/ignores.rs | 2 +- tests/lib/compiler-test-derive/src/lib.rs | 19 +- tests/lib/compiler-test-derive/src/tests.rs | 20 +-- tests/lib/test-generator/Cargo.toml | 2 +- tests/wasi-wast/wasi/tests/isatty.rs | 6 +- tests/wasi-wast/wasi/tests/writing.rs | 5 +- 54 files changed, 486 insertions(+), 519 deletions(-) rename examples/{engine_shared_object.rs => engine_dylib.rs} (76%) rename fuzz/fuzz_targets/{shared_object_cranelift.rs => dylib_cranelift.rs} (91%) rename lib/{engine-shared-object => engine-dylib}/Cargo.toml (86%) create mode 100644 lib/engine-dylib/README.md rename lib/{engine-shared-object => engine-dylib}/src/artifact.rs (95%) rename lib/{engine-shared-object => engine-dylib}/src/builder.rs (78%) rename lib/{engine-shared-object => engine-dylib}/src/engine.rs (83%) rename lib/{engine-shared-object => engine-dylib}/src/lib.rs (65%) rename lib/{engine-shared-object => engine-dylib}/src/serialize.rs (100%) delete mode 100644 lib/engine-shared-object/README.md diff --git a/Cargo.lock b/Cargo.lock index 09711aae463..3404980917b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2437,7 +2437,7 @@ dependencies = [ "wasmer-compiler-singlepass", "wasmer-derive", "wasmer-engine", - "wasmer-engine-shared-object", + "wasmer-engine-dylib", "wasmer-engine-universal", "wasmer-types", "wasmer-vm", @@ -2456,7 +2456,7 @@ dependencies = [ "wasmer-compiler-cranelift", "wasmer-compiler-llvm", "wasmer-compiler-singlepass", - "wasmer-engine-shared-object", + "wasmer-engine-dylib", "wasmer-engine-universal", "wasmer-middlewares", "wasmprinter", @@ -2484,8 +2484,8 @@ dependencies = [ "wasmer-compiler-singlepass", "wasmer-emscripten", "wasmer-engine", + "wasmer-engine-dylib", "wasmer-engine-object-file", - "wasmer-engine-shared-object", "wasmer-engine-universal", "wasmer-middlewares", "wasmer-types", @@ -2504,7 +2504,7 @@ dependencies = [ "thiserror", "wasmer", "wasmer-compiler-singlepass", - "wasmer-engine-shared-object", + "wasmer-engine-dylib", "wasmer-engine-universal", ] @@ -2530,8 +2530,8 @@ dependencies = [ "wasmer-compiler-singlepass", "wasmer-emscripten", "wasmer-engine", + "wasmer-engine-dylib", "wasmer-engine-object-file", - "wasmer-engine-shared-object", "wasmer-engine-universal", "wasmer-types", "wasmer-vm", @@ -2680,14 +2680,14 @@ dependencies = [ ] [[package]] -name = "wasmer-engine-object-file" +name = "wasmer-engine-dylib" version = "1.0.2" dependencies = [ - "bincode", "cfg-if 1.0.0", "leb128", "libloading", "loupe", + "rkyv", "serde", "tempfile", "tracing", @@ -2696,17 +2696,18 @@ dependencies = [ "wasmer-object", "wasmer-types", "wasmer-vm", + "which 4.1.0", ] [[package]] -name = "wasmer-engine-shared-object" +name = "wasmer-engine-object-file" version = "1.0.2" dependencies = [ + "bincode", "cfg-if 1.0.0", "leb128", "libloading", "loupe", - "rkyv", "serde", "tempfile", "tracing", @@ -2715,7 +2716,6 @@ dependencies = [ "wasmer-object", "wasmer-types", "wasmer-vm", - "which 4.1.0", ] [[package]] @@ -2863,8 +2863,8 @@ dependencies = [ "wasmer-emscripten", "wasmer-engine", "wasmer-engine-dummy", + "wasmer-engine-dylib", "wasmer-engine-object-file", - "wasmer-engine-shared-object", "wasmer-engine-universal", "wasmer-middlewares", "wasmer-types", diff --git a/Cargo.toml b/Cargo.toml index 7898eb2ef93..93eab4f6d98 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -18,7 +18,7 @@ wasmer-compiler-llvm = { version = "1.0.2", path = "lib/compiler-llvm", optional wasmer-emscripten = { version = "1.0.2", path = "lib/emscripten", optional = true } wasmer-engine = { version = "1.0.2", path = "lib/engine" } wasmer-engine-universal = { version = "1.0.2", path = "lib/engine-universal", optional = true } -wasmer-engine-shared-object = { version = "1.0.2", path = "lib/engine-shared-object", 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-wasi = { version = "1.0.2", path = "lib/wasi", optional = true } wasmer-wast = { version = "1.0.2", path = "tests/lib/wast", optional = true } @@ -41,7 +41,7 @@ members = [ "lib/emscripten", "lib/engine", "lib/engine-universal", - "lib/engine-shared-object", + "lib/engine-dylib", "lib/engine-object-file", "lib/object", "lib/vm", @@ -82,7 +82,7 @@ default = [ "wat", "wast", "universal", - "shared-object", + "dylib", "object-file", "cache", "wasi", @@ -94,8 +94,8 @@ universal = [ "wasmer-engine-universal", "engine", ] -shared-object = [ - "wasmer-engine-shared-object", +dylib = [ + "wasmer-engine-dylib", "engine", ] object-file = [ @@ -111,7 +111,7 @@ compiler = [ "wasmer/compiler", "wasmer-compiler/translator", "wasmer-engine-universal/compiler", - "wasmer-engine-shared-object/compiler", + "wasmer-engine-dylib/compiler", "wasmer-engine-object-file/compiler", ] singlepass = [ @@ -139,9 +139,9 @@ test-llvm = [ "llvm", ] -test-shared-object = [ - "shared-object", - "test-generator/test-shared-object", +test-dylib = [ + "dylib", + "test-generator/test-dylib", ] test-universal = [ "universal", @@ -170,8 +170,8 @@ path = "examples/engine_universal.rs" required-features = ["cranelift"] [[example]] -name = "engine-shared-object" -path = "examples/engine_shared_object.rs" +name = "engine-dylib" +path = "examples/engine_dylib.rs" required-features = ["cranelift"] [[example]] diff --git a/Makefile b/Makefile index d645ddfa6ea..6b9b1194e67 100644 --- a/Makefile +++ b/Makefile @@ -9,33 +9,32 @@ SHELL=/bin/bash # The matrix is the product of the following columns: # -# |------------|---------------|----------|--------------|-------| -# | Compiler ⨯ Engine ⨯ Platform ⨯ Architecture ⨯ libc | -# |------------|---------------|----------|--------------|-------| -# | Cranelift | Universal | Linux | amd64 | glibc | -# | LLVM | Shared Object | Darwin | aarch64 | musl | -# | Singlepass | | Windows | | | -# |------------|---------------|----------|--------------|-------| +# |------------|-----------|----------|--------------|-------| +# | Compiler ⨯ Engine ⨯ Platform ⨯ Architecture ⨯ libc | +# |------------|-----------|----------|--------------|-------| +# | Cranelift | Universal | Linux | amd64 | glibc | +# | LLVM | Dylib | Darwin | aarch64 | musl | +# | Singlepass | | Windows | | | +# |------------|-----------|----------|--------------|-------| # # Here is what works and what doesn't: # # * Cranelift with the Universal engine works everywhere, # -# * Cranelift with the Shared Object engine works on -# Linux+Darwin/`amd64`, but it doesn't work on */`aarch64` or -# Windows/*. +# * Cranelift with the Dylib engine works on Linux+Darwin/`amd64`, but +# it doesn't work on */`aarch64` or Windows/*. # # * LLVM with the Universal engine works on Linux+Darwin/`amd64`, # but it doesn't work on */`aarch64` or Windows/*. # -# * LLVM with the Shared Object engine works on +# * LLVM with the Dylib engine works on # Linux+Darwin/`amd64`+`aarch64`, but it doesn't work on Windows/*. # # * Singlepass with the Universal engine works on Linux+Darwin/`amd64`, but # it doesn't work on */`aarch64` or Windows/*. # -# * Singlepass with the Shared Object engine doesn't work because it -# doesn't know how to output object files for the moment. +# * Singlepass with the Dylib engine doesn't work because it doesn't +# know how to output object files for the moment. # # * Windows isn't tested on `aarch64`, that's why we consider it's not # working, but it might possibly be. @@ -211,12 +210,12 @@ ifeq ($(ENABLE_CRANELIFT), 1) ifneq (, $(filter 1, $(IS_DARWIN) $(IS_LINUX))) ifeq ($(IS_AMD64), 1) ifneq ($(LIBC), musl) - compilers_engines += cranelift-shared-object + compilers_engines += cranelift-dylib endif else ifeq ($(IS_AARCH64), 1) # The object crate doesn't support yet Darwin + Aarch64 relocations ifneq ($(IS_DARWIN), 1) - compilers_engines += cranelift-shared-object + compilers_engines += cranelift-dylib endif endif endif @@ -230,9 +229,9 @@ ifeq ($(ENABLE_LLVM), 1) ifneq (, $(filter 1, $(IS_DARWIN) $(IS_LINUX))) ifeq ($(IS_AMD64), 1) compilers_engines += llvm-universal - compilers_engines += llvm-shared-object + compilers_engines += llvm-dylib else ifeq ($(IS_AARCH64), 1) - compilers_engines += llvm-shared-object + compilers_engines += llvm-dylib endif endif endif @@ -301,7 +300,7 @@ capi_compilers_engines_exclude := # LLVM for the moment because it causes the linker to fail since LLVM is not statically linked. # TODO: Reenable LLVM in C-API capi_compiler_features := --features $(subst $(space),$(comma),$(filter-out llvm, $(compilers))) -capi_compilers_engines_exclude += llvm-universal llvm-shared-object +capi_compilers_engines_exclude += llvm-universal llvm-dylib # We exclude singlepass-universal because it doesn't support multivalue (required in wasm-c-api tests) capi_compilers_engines_exclude += singlepass-universal @@ -424,23 +423,23 @@ 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,shared-object,cranelift,wasi $(capi_default_features) + RUSTFLAGS="${RUSTFLAGS}" cargo doc --manifest-path lib/c-api/Cargo.toml --no-deps --features wat,universal,object-file,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,shared-object,object-file,wasi,middlewares $(capi_default_features) $(capi_compiler_features) + --no-default-features --features deprecated,wat,universal,dylib,object-file,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,shared-object,object-file,singlepass,wasi,middlewares $(capi_default_features) + --no-default-features --features deprecated,wat,universal,dylib,object-file,singlepass,wasi,middlewares $(capi_default_features) build-capi-singlepass-universal: capi-setup RUSTFLAGS="${RUSTFLAGS}" cargo build --manifest-path lib/c-api/Cargo.toml --release \ --no-default-features --features deprecated,wat,universal,singlepass,wasi,middlewares $(capi_default_features) -build-capi-singlepass-shared-object: capi-setup +build-capi-singlepass-dylib: capi-setup RUSTFLAGS="${RUSTFLAGS}" cargo build --manifest-path lib/c-api/Cargo.toml --release \ - --no-default-features --features deprecated,wat,shared-object,singlepass,wasi,middlewares $(capi_default_features) + --no-default-features --features deprecated,wat,dylib,singlepass,wasi,middlewares $(capi_default_features) build-capi-singlepass-object-file: capi-setup RUSTFLAGS="${RUSTFLAGS}" cargo build --manifest-path lib/c-api/Cargo.toml --release \ @@ -448,35 +447,35 @@ build-capi-singlepass-object-file: capi-setup build-capi-cranelift: capi-setup RUSTFLAGS="${RUSTFLAGS}" cargo build --manifest-path lib/c-api/Cargo.toml --release \ - --no-default-features --features deprecated,wat,universal,shared-object,object-file,cranelift,wasi,middlewares $(capi_default_features) + --no-default-features --features deprecated,wat,universal,dylib,object-file,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,shared-object,object-file,cranelift,wasi,middlewares,system-libffi $(capi_default_features) + --no-default-features --features deprecated,wat,universal,dylib,object-file,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 \ --no-default-features --features deprecated,wat,universal,cranelift,wasi,middlewares $(capi_default_features) -build-capi-cranelift-shared-object: capi-setup +build-capi-cranelift-dylib: capi-setup RUSTFLAGS="${RUSTFLAGS}" cargo build --manifest-path lib/c-api/Cargo.toml --release \ - --no-default-features --features deprecated,wat,shared-object,cranelift,wasi,middlewares $(capi_default_features) + --no-default-features --features deprecated,wat,dylib,cranelift,wasi,middlewares $(capi_default_features) build-capi-cranelift-object-file: capi-setup RUSTFLAGS="${RUSTFLAGS}" cargo build --manifest-path lib/c-api/Cargo.toml --release \ - --no-default-features --features deprecated,wat,shared-object,object-file,cranelift,wasi,middlewares $(capi_default_features) + --no-default-features --features deprecated,wat,dylib,object-file,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,shared-object,object-file,llvm,wasi,middlewares $(capi_default_features) + --no-default-features --features deprecated,wat,universal,dylib,object-file,llvm,wasi,middlewares $(capi_default_features) build-capi-llvm-universal: capi-setup RUSTFLAGS="${RUSTFLAGS}" cargo build --manifest-path lib/c-api/Cargo.toml --release \ --no-default-features --features deprecated,wat,universal,llvm,wasi,middlewares $(capi_default_features) -build-capi-llvm-shared-object: capi-setup +build-capi-llvm-dylib: capi-setup RUSTFLAGS="${RUSTFLAGS}" cargo build --manifest-path lib/c-api/Cargo.toml --release \ - --no-default-features --features deprecated,wat,shared-object,llvm,wasi,middlewares $(capi_default_features) + --no-default-features --features deprecated,wat,dylib,llvm,wasi,middlewares $(capi_default_features) build-capi-llvm-object-file: capi-setup RUSTFLAGS="${RUSTFLAGS}" cargo build --manifest-path lib/c-api/Cargo.toml --release \ @@ -488,9 +487,9 @@ build-capi-headless-universal: capi-setup RUSTFLAGS="${RUSTFLAGS}" cargo build --manifest-path lib/c-api/Cargo.toml --release \ --no-default-features --features universal,wasi -build-capi-headless-shared-object: capi-setup +build-capi-headless-dylib: capi-setup RUSTFLAGS="${RUSTFLAGS}" cargo build --manifest-path lib/c-api/Cargo.toml --release \ - --no-default-features --features shared-object,wasi + --no-default-features --features dylib,wasi build-capi-headless-object-file: capi-setup RUSTFLAGS="${RUSTFLAGS}" cargo build --manifest-path lib/c-api/Cargo.toml --release \ @@ -498,7 +497,7 @@ build-capi-headless-object-file: capi-setup build-capi-headless-all: capi-setup RUSTFLAGS="${RUSTFLAGS}" cargo build --manifest-path lib/c-api/Cargo.toml --release \ - --no-default-features --features universal,shared-object,object-file,wasi + --no-default-features --features universal,dylib,object-file,wasi ########### # Testing # @@ -521,20 +520,20 @@ test-packages: test-compilers-compat: $(foreach compiler,$(compilers),test-$(compiler)) -test-singlepass-shared-object: - cargo test --release --tests $(compiler_features) -- singlepass::shared-object +test-singlepass-dylib: + cargo test --release --tests $(compiler_features) -- singlepass::dylib test-singlepass-universal: cargo test --release --tests $(compiler_features) -- singlepass::universal -test-cranelift-shared-object: - cargo test --release --tests $(compiler_features) -- cranelift::shared-object +test-cranelift-dylib: + cargo test --release --tests $(compiler_features) -- cranelift::dylib test-cranelift-universal: cargo test --release --tests $(compiler_features) -- cranelift::universal -test-llvm-shared-object: - cargo test --release --tests $(compiler_features) -- llvm::shared-object +test-llvm-dylib: + cargo test --release --tests $(compiler_features) -- llvm::dylib test-llvm-universal: cargo test --release --tests $(compiler_features) -- llvm::universal @@ -551,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,shared-object,object-file,wasi,middlewares $(capi_default_features) $(capi_compiler_features) -- --nocapture + --no-default-features --features deprecated,wat,universal,dylib,object-file,wasi,middlewares $(capi_default_features) $(capi_compiler_features) -- --nocapture test-capi-integration-%: # Test the Wasmer C API tests for C diff --git a/docs/deps_dedup.dot b/docs/deps_dedup.dot index f42ea9e1e5b..a9231d309fd 100644 --- a/docs/deps_dedup.dot +++ b/docs/deps_dedup.dot @@ -5,7 +5,7 @@ digraph dependencies { n1 [label="wasmer-compiler", color=orange]; n5 [label="wasmer-engine", color=orange]; n6 [label="wasmer-engine-universal", color=orange]; - n7 [label="wasmer-engine-shared-object", color=orange]; + n7 [label="wasmer-engine-dylib", color=orange]; n8 [label="wasmer-types", color=orange]; n9 [label="wasmer-vm", color=orange]; n10 [label="wasmer-c-api", color=orange]; @@ -29,7 +29,7 @@ digraph dependencies { color=brown; n6 [label="wasmer-engine-universal", color=orange]; - n7 [label="wasmer-engine-shared-object", color=orange]; + n7 [label="wasmer-engine-dylib", color=orange]; } { diff --git a/docs/deps_dedup.svg b/docs/deps_dedup.svg index 65f56930e90..1280e3d0faf 100644 --- a/docs/deps_dedup.svg +++ b/docs/deps_dedup.svg @@ -4,241 +4,241 @@ - + dependencies - + cluster_compiler - -Compilers + +Compilers cluster_engine - -Engines + +Engines cluster_abi - -Provided ABIs + +Provided ABIs n0 - -wasmer + +wasmer n6 - -wasmer-engine-universal + +wasmer-engine-universal n0->n6 - - + + n7 - -wasmer-engine-shared-object + +wasmer-engine-dylib n0->n7 - - + + n2 - -wasmer-compiler-cranelift + +wasmer-compiler-cranelift n0->n2 - - + + n3 - -wasmer-compiler-llvm + +wasmer-compiler-llvm n0->n3 - - + + n4 - -wasmer-compiler-singlepass + +wasmer-compiler-singlepass n0->n4 - - + + n1 - -wasmer-compiler + +wasmer-compiler n9 - -wasmer-vm + +wasmer-vm n1->n9 - - + + n5 - -wasmer-engine + +wasmer-engine n5->n1 - - + + n6->n5 - - + + n7->n5 - - + + n8 - -wasmer-types + +wasmer-types n9->n8 - - + + n10 - -wasmer-c-api + +wasmer-c-api n11 - -wasmer-emscripten + +wasmer-emscripten n10->n11 - - + + n12 - -wasmer-wasi + +wasmer-wasi n10->n12 - - + + n11->n0 - - + + n12->n0 - - + + n13 - -wasmer-cache + +wasmer-cache n13->n0 - - + + n14 - -wasmer-cli + +wasmer-cli n14->n11 - - + + n14->n12 - - + + n14->n13 - - + + n2->n1 - - + + n3->n1 - - + + n4->n1 - - + + diff --git a/examples/README.md b/examples/README.md index ac8b58c17c6..8f48687be3a 100644 --- a/examples/README.md +++ b/examples/README.md @@ -236,7 +236,7 @@ example. -2. [**Native engine**][engine-shared-object], explains what a native engine +2. [**Dylib engine**][engine-dylib], explains what a Dylib engine is, and how to set it up. The example completes itself with the compilation of the Wasm module, its instantiation, and finally, by calling an exported function. @@ -248,7 +248,7 @@ example. Execute the example ```shell - $ cargo run --example engine-shared-object --release --features "cranelift" + $ cargo run --example engine-dylib --release --features "cranelift" ``` @@ -376,7 +376,7 @@ example. [hello-world]: ./hello_world.rs [engine-universal]: ./engine_universal.rs -[engine-shared-object]: ./engine_shared_object.rs +[engine-dylib]: ./engine_dylib.rs [engine-headless]: ./engine_headless.rs [compiler-singlepass]: ./compiler_singlepass.rs [compiler-cranelift]: ./compiler_cranelift.rs diff --git a/examples/engine_cross_compilation.rs b/examples/engine_cross_compilation.rs index 8c1a540e922..618d24d68ff 100644 --- a/examples/engine_cross_compilation.rs +++ b/examples/engine_cross_compilation.rs @@ -22,7 +22,7 @@ use std::str::FromStr; use wasmer::{wat2wasm, Module, RuntimeError, Store}; use wasmer_compiler::{CpuFeature, Target, Triple}; use wasmer_compiler_cranelift::Cranelift; -use wasmer_engine_shared_object::SharedObject; +use wasmer_engine_dylib::Dylib; fn main() -> Result<(), Box> { // Let's declare the Wasm module with the text representation. @@ -67,12 +67,13 @@ fn main() -> Result<(), Box> { // Define the engine that will drive everything. // - // In this case, the engine is `wasmer_engine_shared_object` which means - // that a native object is going to be generated. + // In this case, the engine is `wasmer_engine_dylib` which means + // that a shared object is going to be generated. // // That's where we specify the target for the compiler. - // Use the native engine. - let engine = Native::new(compiler_config) + // + // Use the Dylib engine. + let engine = Dylib::new(compiler_config) // Here we go. // Pass the target to the engine! The engine will share // this information with the compiler. diff --git a/examples/engine_shared_object.rs b/examples/engine_dylib.rs similarity index 76% rename from examples/engine_shared_object.rs rename to examples/engine_dylib.rs index 875b78ea715..4381ea08723 100644 --- a/examples/engine_shared_object.rs +++ b/examples/engine_dylib.rs @@ -1,27 +1,26 @@ //! Defining an engine in Wasmer is one of the fundamental steps. //! -//! This example illustrates how to use the `wasmer_engine_shared_object`, -//! aka the native engine. An engine applies roughly 2 steps: +//! This example illustrates how to use the `wasmer_engine_dylib`, +//! aka the Dylib engine. An engine applies roughly 2 steps: //! //! 1. It compiles the Wasm module bytes to executable code, through //! the intervention of a compiler, //! 2. It stores the executable code somewhere. //! -//! In the particular context of the native engine, the executable -//! code is stored in a native object, more precisely in a dynamic -//! library. +//! In the particular context of the Dylib engine, the executable code +//! is stored in a shared object (`.dylib`, `.so` or `.dll` file). //! //! You can run the example directly by executing in Wasmer root: //! //! ```shell -//! cargo run --example engine-shared-object --release --features "cranelift" +//! cargo run --example engine-dylib --release --features "cranelift" //! ``` //! //! Ready? use wasmer::{imports, wat2wasm, Instance, Module, Store, Value}; use wasmer_compiler_cranelift::Cranelift; -use wasmer_engine_shared_object::SharedObject; +use wasmer_engine_dylib::Dylib; fn main() -> Result<(), Box> { // Let's declare the Wasm module with the text representation. @@ -45,12 +44,12 @@ fn main() -> Result<(), Box> { // compile the Wasm module into executable code. let compiler_config = Cranelift::default(); - println!("Creating Native engine..."); + println!("Creating Dylib engine..."); // Define the engine that will drive everything. // - // In this case, the engine is `wasmer_engine_shared_object` which means - // that a native object is going to be generated. - let engine = Native::new(compiler_config).engine(); + // In this case, the engine is `wasmer_engine_dylib` which means + // that a shared object is going to be generated. + let engine = Dylib::new(compiler_config).engine(); // Create a store, that holds the engine. let store = Store::new(&engine); @@ -61,7 +60,7 @@ fn main() -> Result<(), Box> { // Let's compile the Wasm module. It is at this step that the Wasm // text is transformed into Wasm bytes (if necessary), and then // compiled to executable code by the compiler, which is then - // stored into a native object by the engine. + // stored into a shared object by the engine. let module = Module::new(&store, wasm_bytes)?; // Congrats, the Wasm module is compiled! Now let's execute it for @@ -88,6 +87,6 @@ fn main() -> Result<(), Box> { #[test] #[cfg(not(any(target_arch = "aarch64", target_env = "musl")))] -fn test_engine_shared_object() -> Result<(), Box> { +fn test_engine_dylib() -> Result<(), Box> { main() } diff --git a/examples/engine_headless.rs b/examples/engine_headless.rs index cc8eba0097a..41f8b3fcded 100644 --- a/examples/engine_headless.rs +++ b/examples/engine_headless.rs @@ -8,9 +8,10 @@ //! What problem does it solve, and what does it mean? //! //! Once a Wasm module is compiled into executable code and stored -//! somewhere (e.g. in memory with the Universal engine, or in a native -//! shared object file with the native engine), the module can be instantiated and -//! executed. But imagine for a second the following scenario: +//! somewhere (e.g. in memory with the Universal engine, or in a +//! shared object file with the Dylib engine), the module can be +//! instantiated and executed. But imagine for a second the following +//! scenario: //! //! * Modules are compiled ahead of time, to be instantiated later //! on. @@ -52,7 +53,7 @@ use wasmer::Module; use wasmer::Store; use wasmer::Value; use wasmer_compiler_cranelift::Cranelift; -use wasmer_engine_shared_object::SharedObject; +use wasmer_engine_dylib::Dylib; fn main() -> Result<(), Box> { // First step, let's compile the Wasm module and serialize it. @@ -79,16 +80,16 @@ fn main() -> Result<(), Box> { // compile the Wasm module into executable code. let compiler_config = Cranelift::default(); - println!("Creating Native engine..."); + println!("Creating Dylib engine..."); // Define the engine that will drive everything. // - // In this case, the engine is `wasmer_engine_shared_object` which - // means that a native object is going to be generated. So + // In this case, the engine is `wasmer_engine_dylib` which + // means that a shared object is going to be generated. So // when we are going to serialize the compiled Wasm module, we // are going to store it in a file with the `.so` extension // for example (or `.dylib`, or `.dll` depending of the // platform). - let engine = Native::new(compiler_config).engine(); + let engine = Dylib::new(compiler_config).engine(); // Create a store, that holds the engine. let store = Store::new(&engine); @@ -109,9 +110,9 @@ fn main() -> Result<(), Box> { // Second step, deserialize the compiled Wasm module, and execute // it, for example with Wasmer without a compiler. { - println!("Creating headless Native engine..."); - // We create a headless Native engine. - let engine = Native::headless().engine(); + println!("Creating headless Dylib engine..."); + // We create a headless Dylib engine. + let engine = Dylib::headless().engine(); let store = Store::new(&engine); println!("Deserializing module..."); diff --git a/fuzz/Cargo.toml b/fuzz/Cargo.toml index a6b8da6f424..891de355229 100644 --- a/fuzz/Cargo.toml +++ b/fuzz/Cargo.toml @@ -17,7 +17,7 @@ wasmer-compiler-cranelift = { path = "../lib/compiler-cranelift", optional = tru wasmer-compiler-llvm = { path = "../lib/compiler-llvm", optional = true } wasmer-compiler-singlepass = { path = "../lib/compiler-singlepass", optional = true } wasmer-engine-universal = { path = "../lib/engine-universal", optional = true } -wasmer-engine-shared-object = { path = "../lib/engine-shared-object", optional = true } +wasmer-engine-dylib = { path = "../lib/engine-dylib", optional = true } wasmer-middlewares = { path = "../lib/middlewares" } wasmprinter = "0.2" @@ -26,7 +26,7 @@ cranelift = [ "wasmer-compiler-cranelift" ] llvm = [ "wasmer-compiler-llvm" ] singlepass = [ "wasmer-compiler-singlepass" ] universal = [ "wasmer-engine-universal" ] -shared-object = [ "wasmer-engine-shared-object" ] +dylib = [ "wasmer-engine-dylib" ] [[bin]] name = "equivalence_universal" @@ -54,6 +54,6 @@ path = "fuzz_targets/metering.rs" required-features = ["universal", "cranelift"] [[bin]] -name = "shared_object_cranelift" -path = "fuzz_targets/shared_object_cranelift.rs" -required-features = ["shared-object", "cranelift"] +name = "dylib_cranelift" +path = "fuzz_targets/dylib_cranelift.rs" +required-features = ["dylib", "cranelift"] diff --git a/fuzz/README.md b/fuzz/README.md index e3315da85b0..a187b5cc229 100644 --- a/fuzz/README.md +++ b/fuzz/README.md @@ -13,7 +13,7 @@ $ cargo install cargo-fuzz `cargo-fuzz` is documented in the [Rust Fuzz Book](https://rust-fuzz.github.io/book/cargo-fuzz.html). -## Running a fuzzer (`validate`, `universal_llvm`, `shared_object_cranelift`…) +## Running a fuzzer (`validate`, `universal_llvm`, `dylib_cranelift`…) Once `cargo-fuzz` is installed, you can run the `validate` fuzzer with ```sh diff --git a/fuzz/fuzz_targets/shared_object_cranelift.rs b/fuzz/fuzz_targets/dylib_cranelift.rs similarity index 91% rename from fuzz/fuzz_targets/shared_object_cranelift.rs rename to fuzz/fuzz_targets/dylib_cranelift.rs index 7b3b73638ac..66be05383d5 100644 --- a/fuzz/fuzz_targets/shared_object_cranelift.rs +++ b/fuzz/fuzz_targets/dylib_cranelift.rs @@ -4,7 +4,7 @@ use libfuzzer_sys::{arbitrary, arbitrary::Arbitrary, fuzz_target}; use wasm_smith::{Config, ConfiguredModule}; use wasmer::{imports, Instance, Module, Store}; use wasmer_compiler_cranelift::Cranelift; -use wasmer_engine_shared_object::SharedObject; +use wasmer_engine_dylib::Dylib; #[derive(Arbitrary, Debug, Default, Copy, Clone)] struct NoImportsConfig; @@ -41,12 +41,12 @@ fuzz_target!(|module: WasmSmithModule| { } let compiler = Cranelift::default(); - let store = Store::new(&SharedObject::new(compiler).engine()); + let store = Store::new(&Dylib::new(compiler).engine()); let module = Module::new(&store, &wasm_bytes).unwrap(); module.serialize().unwrap() }; - let engine = SharedObject::headless().engine(); + let engine = Dylib::headless().engine(); let store = Store::new(&engine); let module = unsafe { Module::deserialize(&store, serialized.as_slice()) }.unwrap(); match Instance::new(&module, &imports! {}) { diff --git a/lib/api/Cargo.toml b/lib/api/Cargo.toml index 5665e2a7b9c..b46ebf3a2ea 100644 --- a/lib/api/Cargo.toml +++ b/lib/api/Cargo.toml @@ -19,7 +19,7 @@ wasmer-compiler = { path = "../compiler", version = "1.0.2" } wasmer-derive = { path = "../derive", version = "1.0.2" } wasmer-engine = { path = "../engine", version = "1.0.2" } wasmer-engine-universal = { path = "../engine-universal", version = "1.0.2", optional = true } -wasmer-engine-shared-object = { path = "../engine-shared-object", version = "1.0.2", optional = true } +wasmer-engine-dylib = { path = "../engine-dylib", version = "1.0.2", optional = true } wasmer-types = { path = "../types", version = "1.0.2" } indexmap = { version = "1.6", features = ["serde-1"] } cfg-if = "1.0" @@ -47,15 +47,15 @@ default = ["wat", "default-cranelift", "default-universal"] compiler = [ "wasmer-compiler/translator", "wasmer-engine-universal/compiler", - "wasmer-engine-shared-object/compiler", + "wasmer-engine-dylib/compiler", ] engine = [] universal = [ "wasmer-engine-universal", "engine" ] -shared-object = [ - "wasmer-engine-shared-object", +dylib = [ + "wasmer-engine-dylib", "engine" ] singlepass = [ @@ -91,8 +91,8 @@ default-universal = [ "universal", "default-engine" ] -default-shared-object = [ - "shared-object", +default-dylib = [ + "dylib", "default-engine" ] diff --git a/lib/api/src/lib.rs b/lib/api/src/lib.rs index b52e9365023..65d12a4c534 100644 --- a/lib/api/src/lib.rs +++ b/lib/api/src/lib.rs @@ -248,7 +248,7 @@ //! [wasmer-emscripten]: https://docs.rs/wasmer-emscripten/*/wasmer_emscripten/ //! [wasmer-engine]: https://docs.rs/wasmer-engine/*/wasmer_engine/ //! [wasmer-universal]: https://docs.rs/wasmer-engine-universal/*/wasmer_engine_universal/ -//! [wasmer-native]: https://docs.rs/wasmer-engine-shared-object/*/wasmer_engine_shared_object/ +//! [wasmer-native]: https://docs.rs/wasmer-engine-dylib/*/wasmer_engine_dylib/ //! [wasmer-singlepass]: https://docs.rs/wasmer-compiler-singlepass/*/wasmer_compiler_singlepass/ //! [wasmer-llvm]: https://docs.rs/wasmer-compiler-llvm/*/wasmer_compiler_llvm/ //! [wasmer-wasi]: https://docs.rs/wasmer-wasi/*/wasmer_wasi/ @@ -367,8 +367,8 @@ pub use wasmer_compiler_llvm::{LLVMOptLevel, LLVM}; #[cfg(feature = "universal")] pub use wasmer_engine_universal::{Universal, UniversalArtifact, UniversalEngine}; -#[cfg(feature = "shared-object")] -pub use wasmer_engine_shared_object::{SharedObject, SharedObjectArtifact, SharedObjectEngine}; +#[cfg(feature = "dylib")] +pub use wasmer_engine_dylib::{Dylib, DylibArtifact, DylibEngine}; /// Version number of this crate. pub const VERSION: &str = env!("CARGO_PKG_VERSION"); diff --git a/lib/api/src/store.rs b/lib/api/src/store.rs index b72e4812080..d78f63e1381 100644 --- a/lib/api/src/store.rs +++ b/lib/api/src/store.rs @@ -130,7 +130,7 @@ impl Default for Store { wasmer_engine_universal::Universal::new(config) .engine() } else if #[cfg(feature = "default-native")] { - wasmer_engine_shared_object::SharedObject::new(config) + wasmer_engine_dylib::Dylib::new(config) .engine() } else { compile_error!("No default engine chosen") diff --git a/lib/c-api/Cargo.toml b/lib/c-api/Cargo.toml index 1dc7728c2da..0d29787e1de 100644 --- a/lib/c-api/Cargo.toml +++ b/lib/c-api/Cargo.toml @@ -22,7 +22,7 @@ wasmer-compiler-llvm = { version = "1.0.2", path = "../compiler-llvm", optional 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-shared-object = { version = "1.0.2", path = "../engine-shared-object", 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-middlewares = { version = "1.0.2", path = "../middlewares", optional = true } wasmer-wasi = { version = "1.0.2", path = "../wasi", optional = true } @@ -59,8 +59,8 @@ universal = [ "wasmer-engine-universal", "engine", ] -shared-object = [ - "wasmer-engine-shared-object", +dylib = [ + "wasmer-engine-dylib", "engine", ] object-file = [ @@ -70,7 +70,7 @@ object-file = [ compiler = [ "wasmer/compiler", "wasmer-engine-universal/compiler", - "wasmer-engine-shared-object/compiler", + "wasmer-engine-dylib/compiler", "wasmer-engine-object-file/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 44a460df648..72c47864bbe 100644 --- a/lib/c-api/src/wasm_c_api/engine.rs +++ b/lib/c-api/src/wasm_c_api/engine.rs @@ -12,10 +12,10 @@ use crate::error::{update_last_error, CApiError}; use cfg_if::cfg_if; 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 = "shared-object")] -use wasmer_engine_shared_object::SharedObject; #[cfg(feature = "universal")] use wasmer_engine_universal::Universal; @@ -69,9 +69,9 @@ pub enum wasmer_engine_t { /// [`wasmer_engine_universal`] Rust crate. UNIVERSAL = 0, - /// Variant to represent the Shared Object engine. See the - /// [`wasmer_engine_shared_object`] Rust crate. - SHARED_OBJECT = 1, + /// Variant to represent the Dylib engine. See the + /// [`wasmer_engine_dylib`] Rust crate. + DYLIB = 1, /// Variant to represent the Object File engine. See the /// [`wasmer_engine_object_file`] Rust crate. @@ -83,8 +83,8 @@ impl Default for wasmer_engine_t { cfg_if! { if #[cfg(feature = "universal")] { Self::UNIVERSAL - } else if #[cfg(feature = "shared-object")] { - Self::SHARED_OBJECT + } else if #[cfg(feature = "dylib")] { + Self::DYLIB } else if #[cfg(feature = "object-file")] { Self::OBJECT_FILE } else { @@ -249,9 +249,9 @@ pub extern "C" fn wasm_config_set_compiler( /// if (wasmer_is_engine_available(UNIVERSAL)) { /// wasm_config_set_engine(config, UNIVERSAL); /// } -/// // Or maybe the Shared Object engine? -/// else if (wasmer_is_engine_available(SHARED_OBJECT)) { -/// wasm_config_set_engine(config, SHARED_OBJECT); +/// // Or maybe the Dylib engine? +/// else if (wasmer_is_engine_available(DYLIB)) { +/// wasm_config_set_engine(config, DYLIB); /// } /// // OK, let's do not specify any particular engine. /// @@ -330,8 +330,8 @@ cfg_if! { let engine: Arc = Arc::new(Universal::headless().engine()); Box::new(wasm_engine_t { inner: engine }) } - } else if #[cfg(all(feature = "shared-object", feature = "compiler"))] { - /// Creates a new shared object engine with the default compiler. + } else if #[cfg(all(feature = "dylib", feature = "compiler"))] { + /// Creates a new Dylib engine with the default compiler. /// /// # Example /// @@ -341,11 +341,11 @@ cfg_if! { #[no_mangle] pub extern "C" fn wasm_engine_new() -> Box { let compiler_config: Box = get_default_compiler_config(); - let engine: Arc = Arc::new(SharedObject::new(compiler_config).engine()); + let engine: Arc = Arc::new(Dylib::new(compiler_config).engine()); Box::new(wasm_engine_t { inner: engine }) } - } else if #[cfg(feature = "shared-object")] { - /// Creates a new headless shared object engine. + } else if #[cfg(feature = "dylib")] { + /// Creates a new headless Dylib engine. /// /// # Example /// @@ -354,7 +354,7 @@ cfg_if! { /// cbindgen:ignore #[no_mangle] pub extern "C" fn wasm_engine_new() -> Box { - let engine: Arc = Arc::new(SharedObject::headless().engine()); + let engine: Arc = Arc::new(Dylib::headless().engine()); Box::new(wasm_engine_t { inner: engine }) } } @@ -502,10 +502,10 @@ pub extern "C" fn wasm_engine_new_with_config( } } }, - wasmer_engine_t::SHARED_OBJECT => { + wasmer_engine_t::DYLIB => { cfg_if! { - if #[cfg(feature = "shared-object")] { - let mut builder = SharedObject::new(compiler_config); + if #[cfg(feature = "dylib")] { + let mut builder = Dylib::new(compiler_config); if let Some(target) = config.target { builder = builder.target(target.inner); @@ -517,7 +517,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 `shared-object` feature."); + return return_with_error("Wasmer has not been compiled with the `dylib` feature."); } } }, @@ -565,10 +565,10 @@ pub extern "C" fn wasm_engine_new_with_config( } } }, - wasmer_engine_t::SHARED_OBJECT => { + wasmer_engine_t::DYLIB => { cfg_if! { - if #[cfg(feature = "shared-object")] { - let mut builder = SharedObject::headless(); + if #[cfg(feature = "dylib")] { + let mut builder = Dylib::headless(); if let Some(target) = config.target { builder = builder.target(target.inner); @@ -580,7 +580,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 `shared-object` feature."); + return return_with_error("Wasmer has not been compiled with the `dylib` 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 dfa0df54a86..66c53dfe733 100644 --- a/lib/c-api/src/wasm_c_api/unstable/engine.rs +++ b/lib/c-api/src/wasm_c_api/unstable/engine.rs @@ -120,7 +120,7 @@ pub extern "C" fn wasmer_is_headless() -> bool { 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::SHARED_OBJECT if cfg!(feature = "shared-object") => true, + wasmer_engine_t::DYLIB if cfg!(feature = "dylib") => true, wasmer_engine_t::OBJECT_FILE if cfg!(feature = "object-file") => true, _ => false, } @@ -202,14 +202,7 @@ mod tests { "0" }, ); - set_var( - "SHARED_OBJECT", - if cfg!(feature = "shared-object") { - "1" - } else { - "0" - }, - ); + set_var("DYLIB", if cfg!(feature = "dylib") { "1" } else { "0" }); set_var( "OBJECT_FILE", if cfg!(feature = "object-file") { @@ -225,7 +218,7 @@ mod tests { int main() { assert(wasmer_is_engine_available(UNIVERSAL) == (getenv("UNIVERSAL")[0] == '1')); - assert(wasmer_is_engine_available(SHARED_OBJECT) == (getenv("SHARED_OBJECT")[0] == '1')); + assert(wasmer_is_engine_available(DYLIB) == (getenv("DYLIB")[0] == '1')); assert(wasmer_is_engine_available(OBJECT_FILE) == (getenv("OBJECT_FILE")[0] == '1')); return 0; @@ -234,7 +227,7 @@ mod tests { .success(); remove_var("UNIVERSAL"); - remove_var("SHARED_OBJECT"); + remove_var("DYLIB"); remove_var("OBJECT_FILE"); } } diff --git a/lib/c-api/tests/wasm.h b/lib/c-api/tests/wasm.h index 0ec6fd92468..b993b8400b7 100644 --- a/lib/c-api/tests/wasm.h +++ b/lib/c-api/tests/wasm.h @@ -34,9 +34,9 @@ wasm_engine_t *wasm_engine_new() { if (strcmp(wasmer_test_engine, "universal") == 0) { assert(wasmer_is_engine_available(UNIVERSAL)); wasm_config_set_engine(config, UNIVERSAL); - } else if (strcmp(wasmer_test_engine, "shared-object") == 0) { - assert(wasmer_is_engine_available(SHARED_OBJECT)); - wasm_config_set_engine(config, SHARED_OBJECT); + } else if (strcmp(wasmer_test_engine, "dylib") == 0) { + assert(wasmer_is_engine_available(DYLIB)); + wasm_config_set_engine(config, DYLIB); } else if (wasmer_test_engine) { printf("Engine %s not recognized\n", wasmer_test_engine); abort(); diff --git a/lib/c-api/wasmer_wasm.h b/lib/c-api/wasmer_wasm.h index 2d66682d626..13d01c11809 100644 --- a/lib/c-api/wasmer_wasm.h +++ b/lib/c-api/wasmer_wasm.h @@ -125,7 +125,7 @@ typedef enum wasmer_compiler_t { typedef enum wasmer_engine_t { UNIVERSAL = 0, - SHARED_OBJECT = 1, + DYLIB = 1, OBJECT_FILE = 2, } wasmer_engine_t; diff --git a/lib/cache/Cargo.toml b/lib/cache/Cargo.toml index af73fe7588d..b10a79e1656 100644 --- a/lib/cache/Cargo.toml +++ b/lib/cache/Cargo.toml @@ -22,7 +22,7 @@ tempfile = "3" rand = "0.8.3" wasmer-compiler-singlepass = { path = "../compiler-singlepass", version = "1.0.2" } wasmer-engine-universal = { path = "../engine-universal", version = "1.0.2" } -wasmer-engine-shared-object = { path = "../engine-shared-object", version = "1.0.2" } +wasmer-engine-dylib = { path = "../engine-dylib", version = "1.0.2" } [[bench]] name = "bench_filesystem_cache" diff --git a/lib/cache/benches/bench_filesystem_cache.rs b/lib/cache/benches/bench_filesystem_cache.rs index 594b87ed255..20c89ccafc5 100644 --- a/lib/cache/benches/bench_filesystem_cache.rs +++ b/lib/cache/benches/bench_filesystem_cache.rs @@ -6,7 +6,7 @@ use wasmer::{Module, Store}; use wasmer_cache::Cache; use wasmer_cache::{FileSystemCache, Hash}; use wasmer_compiler_singlepass::Singlepass; -use wasmer_engine_shared_object::SharedObject; +use wasmer_engine_dylib::Dylib; use wasmer_engine_universal::Universal; fn random_key() -> Hash { diff --git a/lib/cli/Cargo.toml b/lib/cli/Cargo.toml index 48e8245aea0..65d6afcc471 100644 --- a/lib/cli/Cargo.toml +++ b/lib/cli/Cargo.toml @@ -32,7 +32,7 @@ wasmer-compiler-llvm = { version = "1.0.2", path = "../compiler-llvm", optional 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-shared-object = { version = "1.0.2", path = "../engine-shared-object", 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-vm = { version = "1.0.2", path = "../vm" } wasmer-wasi = { version = "1.0.2", path = "../wasi", default-features = false, optional = true } @@ -61,7 +61,7 @@ default = [ "wat", "wast", "universal", - "shared-object", + "dylib", "object-file", "cache", "wasi", @@ -72,8 +72,8 @@ universal = [ "wasmer-engine-universal", "engine", ] -shared-object = [ - "wasmer-engine-shared-object", +dylib = [ + "wasmer-engine-dylib", "engine", ] object-file = [ @@ -88,7 +88,7 @@ wat = ["wasmer/wat"] compiler = [ "wasmer-compiler/translator", "wasmer-engine-universal/compiler", - "wasmer-engine-shared-object/compiler", + "wasmer-engine-dylib/compiler", "wasmer-engine-object-file/compiler", ] experimental-io-devices = [ @@ -110,4 +110,4 @@ llvm = [ debug = ["fern", "log", "wasmer-wasi/logging"] disable-all-logging = ["wasmer-wasi/disable-all-logging"] headless = [] -headless-minimal = ["headless", "disable-all-logging", "wasi", "shared-object", "universal"] +headless-minimal = ["headless", "disable-all-logging", "wasi", "dylib", "universal"] diff --git a/lib/cli/README.md b/lib/cli/README.md index 31f858aa972..e02ddf67bd2 100644 --- a/lib/cli/README.md +++ b/lib/cli/README.md @@ -26,7 +26,7 @@ The Wasmer supports the following features: * `wat` (default): support for executing WebAssembly text files. * `wast`(default): support for running wast test files. * `universal` (default): support for the [Universal engine]. -* `shared-object` (default): support for the [Shared Object engine]. +* `dylib` (default): support for the [Dylib engine]. * `cache` (default): support or automatically caching compiled artifacts. * `wasi` (default): support for [WASI]. * `experimental-io-devices`: support for experimental IO devices in WASI. @@ -36,7 +36,7 @@ The Wasmer supports the following features: * `llvm`: support for the [LLVM compiler]. [Universal engine]: https://github.com/wasmerio/wasmer/tree/master/lib/engine-universal/ -[Shared Object engine]: https://github.com/wasmerio/wasmer/tree/master/lib/engine-shared-object/ +[Dylib engine]: https://github.com/wasmerio/wasmer/tree/master/lib/engine-dylib/ [WASI]: https://github.com/wasmerio/wasmer/tree/master/lib/wasi/ [Emscripten]: https://github.com/wasmerio/wasmer/tree/master/lib/emscripten/ [Singlepass compiler]: https://github.com/wasmerio/wasmer/tree/master/lib/compiler-singlepass/ @@ -62,7 +62,7 @@ wasmer run myfile.wasm Compile a WebAssembly file: ```bash -wasmer compile myfile.wasm -o myfile.so --shared-object +wasmer compile myfile.wasm -o myfile.so --dylib ``` Run a compiled WebAssembly file (fastest): diff --git a/lib/cli/src/commands/compile.rs b/lib/cli/src/commands/compile.rs index 9769ade2ea7..713d35dca0d 100644 --- a/lib/cli/src/commands/compile.rs +++ b/lib/cli/src/commands/compile.rs @@ -43,11 +43,9 @@ impl Compile { target_triple: &Triple, ) -> Result<&'static str> { Ok(match engine_type { - #[cfg(feature = "shared-object")] - EngineType::SharedObject => { - wasmer_engine_shared_object::SharedObjectArtifact::get_default_extension( - target_triple, - ) + #[cfg(feature = "dylib")] + EngineType::Dylib => { + wasmer_engine_dylib::DylibArtifact::get_default_extension(target_triple) } #[cfg(feature = "universal")] EngineType::Universal => { @@ -57,11 +55,7 @@ impl Compile { EngineType::ObjectFile => { wasmer_engine_object_file::ObjectFileArtifact::get_default_extension(target_triple) } - #[cfg(not(all( - feature = "shared-object", - feature = "universal", - feature = "object-file" - )))] + #[cfg(not(all(feature = "dylib", feature = "universal", feature = "object-file")))] _ => bail!("selected engine type is not compiled in"), }) } diff --git a/lib/cli/src/commands/run.rs b/lib/cli/src/commands/run.rs index 68d06c9db1a..bd853a6f730 100644 --- a/lib/cli/src/commands/run.rs +++ b/lib/cli/src/commands/run.rs @@ -205,10 +205,10 @@ impl Run { fn get_module(&self) -> Result { let contents = std::fs::read(self.path.clone())?; - #[cfg(feature = "shared-object")] + #[cfg(feature = "dylib")] { - if wasmer_engine_shared_object::SharedObjectArtifact::is_deserializable(&contents) { - let engine = wasmer_engine_shared_object::SharedObject::headless().engine(); + if wasmer_engine_dylib::DylibArtifact::is_deserializable(&contents) { + let engine = wasmer_engine_dylib::Dylib::headless().engine(); let store = Store::new(&engine); let module = unsafe { Module::deserialize_from_file(&store, &self.path)? }; return Ok(module); @@ -296,18 +296,15 @@ impl Run { cache_dir_root.push(compiler_type.to_string()); let mut cache = FileSystemCache::new(cache_dir_root)?; - // Important: Shared object files need to have a `.dll` - // extension on Windows, otherwise they will not load, so we - // just add an extension always to make it easier to recognize - // as well. + // Important: Dylib files need to have a `.dll` extension on + // Windows, otherwise they will not load, so we just add an + // extension always to make it easier to recognize as well. #[allow(unreachable_patterns)] let extension = match *engine_type { - #[cfg(feature = "shared-object")] - EngineType::SharedObject => { - wasmer_engine_shared_object::SharedObjectArtifact::get_default_extension( - &Triple::host(), - ) - .to_string() + #[cfg(feature = "dylib")] + EngineType::Dylib => { + wasmer_engine_dylib::DylibArtifact::get_default_extension(&Triple::host()) + .to_string() } #[cfg(feature = "universal")] EngineType::Universal => { diff --git a/lib/cli/src/compilers/llvm.rs b/lib/cli/src/compilers/llvm.rs index 99ff9bbd158..92e964a021e 100644 --- a/lib/cli/src/compilers/llvm.rs +++ b/lib/cli/src/compilers/llvm.rs @@ -1,4 +1,3 @@ - #[derive(Debug, Clap, Clone)] /// LLVM backend flags. pub struct LLVMCLIOptions { @@ -15,7 +14,6 @@ pub struct LLVMCLIOptions { obj_file: Option, } - impl LLVMCallbacks for LLVMCLIOptions { fn preopt_ir_callback(&mut self, module: &InkwellModule) { if let Some(filename) = &self.pre_opt_ir { diff --git a/lib/cli/src/store.rs b/lib/cli/src/store.rs index da9a44d56a7..4870e2dee72 100644 --- a/lib/cli/src/store.rs +++ b/lib/cli/src/store.rs @@ -20,15 +20,15 @@ pub struct StoreOptions { compiler: CompilerOptions, /// Use the Universal Engine. - #[clap(long, conflicts_with_all = &["shared-object", "object-file"])] + #[clap(long, conflicts_with_all = &["dylib", "object-file"])] universal: bool, - /// Use the Shared Object Engine. + /// Use the Dylib Engine. #[clap(long, conflicts_with_all = &["universal", "object-file"])] - shared_object: bool, + dylib: bool, /// Use the ObjectFile Engine. - #[clap(long, conflicts_with_all = &["universal", "shared-object"])] + #[clap(long, conflicts_with_all = &["universal", "dylib"])] object_file: bool, } @@ -143,9 +143,9 @@ impl CompilerOptions { .target(target) .engine(), ), - #[cfg(feature = "shared-object")] - EngineType::SharedObject => Box::new( - wasmer_engine_shared_object::SharedObject::new(compiler_config) + #[cfg(feature = "dylib")] + EngineType::Dylib => Box::new( + wasmer_engine_dylib::Dylib::new(compiler_config) .target(target) .features(features) .engine(), @@ -157,11 +157,7 @@ impl CompilerOptions { .features(features) .engine(), ), - #[cfg(not(all( - feature = "universal", - feature = "shared-object", - feature = "object-file" - )))] + #[cfg(not(all(feature = "universal", feature = "dylib", feature = "object-file")))] engine => bail!( "The `{}` engine is not included in this binary.", engine.to_string() @@ -366,8 +362,8 @@ impl FromStr for CompilerType { pub enum EngineType { /// Universal Engine Universal, - /// Shared Object Engine - SharedObject, + /// Dylib Engine + Dylib, /// Object File Engine ObjectFile, } @@ -376,7 +372,7 @@ impl ToString for EngineType { fn to_string(&self) -> String { match self { Self::Universal => "universal".to_string(), - Self::SharedObject => "shared_object".to_string(), + Self::Dylib => "dylib".to_string(), Self::ObjectFile => "objectfile".to_string(), } } @@ -420,16 +416,16 @@ impl StoreOptions { fn get_engine(&self) -> Result { if self.universal { Ok(EngineType::Universal) - } else if self.shared_object { - Ok(EngineType::SharedObject) + } else if self.dylib { + Ok(EngineType::Dylib) } else if self.object_file { Ok(EngineType::ObjectFile) } else { // Auto mode, we choose the best engine for that platform if cfg!(feature = "universal") { Ok(EngineType::Universal) - } else if cfg!(feature = "shared-object") { - Ok(EngineType::SharedObject) + } else if cfg!(feature = "dylib") { + Ok(EngineType::Dylib) } else if cfg!(feature = "object-file") { Ok(EngineType::ObjectFile) } else { @@ -449,19 +445,13 @@ impl StoreOptions { EngineType::Universal => { Arc::new(wasmer_engine_universal::Universal::headless().engine()) } - #[cfg(feature = "shared-object")] - EngineType::SharedObject => { - Arc::new(wasmer_engine_shared_object::SharedObject::headless().engine()) - } + #[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(not(all( - feature = "universal", - feature = "shared-object", - feature = "object-file" - )))] + #[cfg(not(all(feature = "universal", feature = "dylib", feature = "object-file")))] engine => bail!( "The `{}` engine is not included in this binary.", engine.to_string() diff --git a/lib/deprecated/runtime-core/Cargo.lock b/lib/deprecated/runtime-core/Cargo.lock index 5b4c6dd9e4c..2e7b46dcbe1 100644 --- a/lib/deprecated/runtime-core/Cargo.lock +++ b/lib/deprecated/runtime-core/Cargo.lock @@ -1179,7 +1179,7 @@ dependencies = [ "wasmer-compiler-singlepass", "wasmer-derive", "wasmer-engine", - "wasmer-engine-shared-object", + "wasmer-engine-dylib", "wasmer-engine-universal", "wasmer-types", "wasmer-vm", @@ -1302,7 +1302,7 @@ dependencies = [ ] [[package]] -name = "wasmer-engine-shared-object" +name = "wasmer-engine-dylib" version = "1.0.2" dependencies = [ "cfg-if 0.1.10", diff --git a/lib/deprecated/runtime/Cargo.lock b/lib/deprecated/runtime/Cargo.lock index a4901a5b25a..144ae2339c4 100644 --- a/lib/deprecated/runtime/Cargo.lock +++ b/lib/deprecated/runtime/Cargo.lock @@ -1183,7 +1183,7 @@ dependencies = [ "wasmer-derive", "wasmer-engine", "wasmer-engine-universal", - "wasmer-engine-shared-object", + "wasmer-engine-dylib", "wasmer-types", "wasmer-vm", "wat", @@ -1321,7 +1321,7 @@ dependencies = [ ] [[package]] -name = "wasmer-engine-shared-object" +name = "wasmer-engine-dylib" version = "1.0.2" dependencies = [ "cfg-if 0.1.10", diff --git a/lib/derive/tests/compile-fail/bad-attribute.rs b/lib/derive/tests/compile-fail/bad-attribute.rs index 9da62cbac08..9766dd10c12 100644 --- a/lib/derive/tests/compile-fail/bad-attribute.rs +++ b/lib/derive/tests/compile-fail/bad-attribute.rs @@ -1,6 +1,6 @@ extern crate wasmer; -use wasmer::{LazyInit, WasmerEnv, Memory}; +use wasmer::{LazyInit, Memory, WasmerEnv}; #[derive(WasmerEnv)] struct BadAttribute { @@ -8,4 +8,4 @@ struct BadAttribute { memory: LazyInit, } -fn main() {} \ No newline at end of file +fn main() {} diff --git a/lib/derive/tests/compile-fail/bad-export-arg.rs b/lib/derive/tests/compile-fail/bad-export-arg.rs index 1e133dfb91b..e2e5e947dfd 100644 --- a/lib/derive/tests/compile-fail/bad-export-arg.rs +++ b/lib/derive/tests/compile-fail/bad-export-arg.rs @@ -1,10 +1,11 @@ extern crate wasmer; -use wasmer::{LazyInit, WasmerEnv, Memory}; +use wasmer::{LazyInit, Memory, WasmerEnv}; #[derive(WasmerEnv)] struct BadExportArg { - #[wasmer(export(this_is_not_a_real_argument="hello, world"))] //~ Unrecognized argument in export options: expected `name` found `this_is_not_a_real_argument + #[wasmer(export(this_is_not_a_real_argument = "hello, world"))] + //~ Unrecognized argument in export options: expected `name` found `this_is_not_a_real_argument memory: LazyInit, } @@ -14,4 +15,4 @@ struct BadExportArgRawString { memory: LazyInit, } -fn main() {} \ No newline at end of file +fn main() {} diff --git a/lib/derive/tests/compile-fail/no-lazy-init.rs b/lib/derive/tests/compile-fail/no-lazy-init.rs index 90f919005c0..baeeb1e438c 100644 --- a/lib/derive/tests/compile-fail/no-lazy-init.rs +++ b/lib/derive/tests/compile-fail/no-lazy-init.rs @@ -1,6 +1,6 @@ extern crate wasmer; -use wasmer::{LazyInit, WasmerEnv, Memory}; +use wasmer::{LazyInit, Memory, WasmerEnv}; #[derive(WasmerEnv)] struct ExportNotWrappedInLazyInit { diff --git a/lib/engine-shared-object/Cargo.toml b/lib/engine-dylib/Cargo.toml similarity index 86% rename from lib/engine-shared-object/Cargo.toml rename to lib/engine-dylib/Cargo.toml index aafdc9af579..6b59fe509cd 100644 --- a/lib/engine-shared-object/Cargo.toml +++ b/lib/engine-dylib/Cargo.toml @@ -1,9 +1,9 @@ [package] -name = "wasmer-engine-shared-object" +name = "wasmer-engine-dylib" version = "1.0.2" -description = "Wasmer Shared Object Engine" +description = "Wasmer Dylib Engine" categories = ["wasm"] -keywords = ["wasm", "webassembly", "engine", "shared-object"] +keywords = ["wasm", "webassembly", "engine", "dylib"] authors = ["Wasmer Engineering Team "] repository = "https://github.com/wasmerio/wasmer" license = "MIT" diff --git a/lib/engine-dylib/README.md b/lib/engine-dylib/README.md new file mode 100644 index 00000000000..90987642a78 --- /dev/null +++ b/lib/engine-dylib/README.md @@ -0,0 +1,60 @@ +# `wasmer-engine-dylib` [![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/master/LICENSE) + +The Wasmer Dylib engine is usable with any compiler implementation +based on [`wasmer-compiler`] that is able to emit +[Position-Independent Code][PIC] (PIC). + +After the compiler generates the machine code for the functions, the +Dylib Engine generates a shared object file and links it via [`dlsym`] +so it can be usable by the [`wasmer`] API. + +This allows Wasmer to achieve *blazing fast* **native startup times**. + +*Note: you can find a [full working example using the Dylib engine +here][example].* + +### Difference with `wasmer-engine-universal` + +The Dylib Engine and Universal Engine mainly differ on how the Modules +are loaded/stored. Using the same compilers, both will have the same +runtime speed. + +However, the Dylib Engine uses the Operating System shared library +loader (via `dlopen`) and as such is able to achieve a much faster +startup time when deserializing a serialized `Module`. + +## Requirements + +The `wasmer-engine-dylib` crate requires a linker available on +your system to generate the shared object file. + +We recommend having [`gcc`] or [`clang`] installed. + +> Note: when **cross-compiling** to other targets, `clang` will be the +> default command used for compiling. + +You can install LLVM (that provides `clang`) easily on your +Debian-like system via this command: + +```bash +bash -c "$(wget -O - https://apt.llvm.org/llvm.sh)" +``` + +Or in macOS: + +```bash +brew install llvm +``` + +Or via any of the [pre-built binaries that LLVM +offers][llvm-pre-built]. + + +[`wasmer-compiler`]: https://github.com/wasmerio/wasmer/tree/master/lib/compiler +[PIC]: https://en.wikipedia.org/wiki/Position-independent_code +[`dlsym`]: https://www.freebsd.org/cgi/man.cgi?query=dlsym +[`wasmer`]: https://github.com/wasmerio/wasmer/tree/master/lib/api +[example]: https://github.com/wasmerio/wasmer/blob/master/examples/engine_dylib.rs +[`gcc`]: https://gcc.gnu.org/ +[`clang`]: https://clang.llvm.org/ +[llvm-pre-built]: https://releases.llvm.org/download.html diff --git a/lib/engine-shared-object/src/artifact.rs b/lib/engine-dylib/src/artifact.rs similarity index 95% rename from lib/engine-shared-object/src/artifact.rs rename to lib/engine-dylib/src/artifact.rs index ebf690d2ef7..e15220c8921 100644 --- a/lib/engine-shared-object/src/artifact.rs +++ b/lib/engine-dylib/src/artifact.rs @@ -1,7 +1,7 @@ -//! Define `SharedObjectArtifact` to allow compiling and instantiating +//! Define `DylibArtifact` to allow compiling and instantiating //! to be done as separate steps. -use crate::engine::{SharedObjectEngine, SharedObjectEngineInner}; +use crate::engine::{DylibEngine, DylibEngineInner}; use crate::serialize::{ArchivedModuleMetadata, ModuleMetadata}; use libloading::{Library, Symbol as LibrarySymbol}; use loupe::MemoryUsage; @@ -46,8 +46,8 @@ use wasmer_vm::{ /// A compiled Wasm module, ready to be instantiated. #[derive(MemoryUsage)] -pub struct SharedObjectArtifact { - shared_object_path: PathBuf, +pub struct DylibArtifact { + dylib_path: PathBuf, metadata: ModuleMetadata, finished_functions: BoxedSlice, #[loupe(skip)] @@ -64,7 +64,7 @@ fn to_compile_error(err: impl Error) -> CompileError { const WASMER_METADATA_SYMBOL: &[u8] = b"WASMER_METADATA"; -impl SharedObjectArtifact { +impl DylibArtifact { // Mach-O header in Mac #[allow(dead_code)] const MAGIC_HEADER_MH_CIGAM_64: &'static [u8] = &[207, 250, 237, 254]; @@ -81,7 +81,7 @@ impl SharedObjectArtifact { #[allow(dead_code)] const MAGIC_HEADER_COFF_64: &'static [u8] = &[b'M', b'Z']; - /// Check if the provided bytes look like `SharedObjectArtifact`. + /// Check if the provided bytes look like `DylibArtifact`. /// /// This means, if the bytes look like a shared object file in the target /// system. @@ -154,11 +154,11 @@ impl SharedObjectArtifact { )) } - /// Compile a data buffer into a `SharedObjectArtifact`, which may + /// Compile a data buffer into a `DylibArtifact`, which may /// then be instantiated. #[cfg(feature = "compiler")] pub fn new( - engine: &SharedObjectEngine, + engine: &DylibEngine, data: &[u8], tunables: &dyn Tunables, ) -> Result { @@ -224,7 +224,7 @@ impl SharedObjectArtifact { Some(obj_bytes) => { let obj_bytes = obj_bytes?; let file = tempfile::Builder::new() - .prefix("wasmer_shared_object_") + .prefix("wasmer_dylib_") .suffix(".o") .tempfile() .map_err(to_compile_error)?; @@ -252,7 +252,7 @@ impl SharedObjectArtifact { emit_compilation(&mut obj, compilation, &symbol_registry, &target_triple) .map_err(to_compile_error)?; let file = tempfile::Builder::new() - .prefix("wasmer_shared_object_") + .prefix("wasmer_dylib_") .suffix(".o") .tempfile() .map_err(to_compile_error)?; @@ -269,7 +269,7 @@ impl SharedObjectArtifact { let shared_filepath = { let suffix = format!(".{}", Self::get_default_extension(&target_triple)); let shared_file = tempfile::Builder::new() - .prefix("wasmer_shared_object_") + .prefix("wasmer_dylib_") .suffix(&suffix) .tempfile() .map_err(to_compile_error)?; @@ -358,10 +358,10 @@ impl SharedObjectArtifact { } } - /// Construct a `SharedObjectArtifact` from component parts. + /// Construct a `DylibArtifact` from component parts. pub fn from_parts_crosscompiled( metadata: ModuleMetadata, - shared_object_path: PathBuf, + dylib_path: PathBuf, ) -> Result { let finished_functions: PrimaryMap = PrimaryMap::new(); let finished_function_call_trampolines: PrimaryMap = @@ -370,7 +370,7 @@ impl SharedObjectArtifact { PrimaryMap::new(); let signatures: PrimaryMap = PrimaryMap::new(); Ok(Self { - shared_object_path, + dylib_path, metadata, finished_functions: finished_functions.into_boxed_slice(), finished_function_call_trampolines: finished_function_call_trampolines @@ -383,11 +383,11 @@ impl SharedObjectArtifact { }) } - /// Construct a `SharedObjectArtifact` from component parts. + /// Construct a `DylibArtifact` from component parts. pub fn from_parts( - engine_inner: &mut SharedObjectEngineInner, + engine_inner: &mut DylibEngineInner, metadata: ModuleMetadata, - shared_object_path: PathBuf, + dylib_path: PathBuf, lib: Library, ) -> Result { let mut finished_functions: PrimaryMap = @@ -475,7 +475,7 @@ impl SharedObjectArtifact { engine_inner.add_library(lib); Ok(Self { - shared_object_path, + dylib_path, metadata, finished_functions: finished_functions.into_boxed_slice(), finished_function_call_trampolines: finished_function_call_trampolines @@ -488,22 +488,22 @@ impl SharedObjectArtifact { }) } - /// Compile a data buffer into a `SharedObjectArtifact`, which may + /// Compile a data buffer into a `DylibArtifact`, which may /// then be instantiated. #[cfg(not(feature = "compiler"))] - pub fn new(_engine: &SharedObjectEngine, _data: &[u8]) -> Result { + pub fn new(_engine: &DylibEngine, _data: &[u8]) -> Result { Err(CompileError::Codegen( "Compilation is not enabled in the engine".to_string(), )) } - /// Deserialize a `SharedObjectArtifact` from bytes. + /// Deserialize a `DylibArtifact` from bytes. /// /// # Safety /// /// The bytes must represent a serialized WebAssembly module. pub unsafe fn deserialize( - engine: &SharedObjectEngine, + engine: &DylibEngine, bytes: &[u8], ) -> Result { if !Self::is_deserializable(&bytes) { @@ -520,13 +520,13 @@ impl SharedObjectArtifact { Self::deserialize_from_file_unchecked(&engine, &path) } - /// Deserialize a `SharedObjectArtifact` from a file path. + /// Deserialize a `DylibArtifact` from a file path. /// /// # Safety /// /// The file's content must represent a serialized WebAssembly module. pub unsafe fn deserialize_from_file( - engine: &SharedObjectEngine, + engine: &DylibEngine, path: &Path, ) -> Result { let mut file = File::open(&path)?; @@ -541,13 +541,13 @@ impl SharedObjectArtifact { Self::deserialize_from_file_unchecked(&engine, &path) } - /// Deserialize a `SharedObjectArtifact` from a file path (unchecked). + /// Deserialize a `DylibArtifact` from a file path (unchecked). /// /// # Safety /// /// The file's content must represent a serialized WebAssembly module. pub unsafe fn deserialize_from_file_unchecked( - engine: &SharedObjectEngine, + engine: &DylibEngine, path: &Path, ) -> Result { let lib = Library::new(&path).map_err(|e| { @@ -590,7 +590,7 @@ impl SharedObjectArtifact { } } -impl Artifact for SharedObjectArtifact { +impl Artifact for DylibArtifact { fn module(&self) -> Arc { self.metadata.compile_info.module.clone() } @@ -769,8 +769,8 @@ impl Artifact for SharedObjectArtifact { Ok(()) } - /// Serialize a `SharedObjectArtifact`. + /// Serialize a `DylibArtifact`. fn serialize(&self) -> Result, SerializeError> { - Ok(std::fs::read(&self.shared_object_path)?) + Ok(std::fs::read(&self.dylib_path)?) } } diff --git a/lib/engine-shared-object/src/builder.rs b/lib/engine-dylib/src/builder.rs similarity index 78% rename from lib/engine-shared-object/src/builder.rs rename to lib/engine-dylib/src/builder.rs index 3b19dde7a11..b751f33e001 100644 --- a/lib/engine-shared-object/src/builder.rs +++ b/lib/engine-dylib/src/builder.rs @@ -1,16 +1,16 @@ -use crate::SharedObjectEngine; +use crate::DylibEngine; use wasmer_compiler::{CompilerConfig, Features, Target}; -/// The Shared Object builder -pub struct SharedObject { +/// The Dylib builder +pub struct Dylib { compiler_config: Option>, target: Option, features: Option, } -impl SharedObject { +impl Dylib { #[cfg(feature = "compiler")] - /// Create a new Shared Object builder. + /// Create a new Dylib builder. pub fn new(compiler_config: T) -> Self where T: Into>, @@ -25,7 +25,7 @@ impl SharedObject { } } - /// Create a new headless Shared Object builder. + /// Create a new headless Dylib builder. pub fn headless() -> Self { Self { compiler_config: None, @@ -46,8 +46,8 @@ impl SharedObject { self } - /// Build the `SharedObjectEngine` for this configuration - pub fn engine(self) -> SharedObjectEngine { + /// Build the `DylibEngine` for this configuration + pub fn engine(self) -> DylibEngine { if let Some(_compiler_config) = self.compiler_config { #[cfg(feature = "compiler")] { @@ -57,15 +57,15 @@ impl SharedObject { .features .unwrap_or_else(|| compiler_config.default_features_for_target(&target)); let compiler = compiler_config.compiler(); - SharedObjectEngine::new(compiler, target, features) + DylibEngine::new(compiler, target, features) } #[cfg(not(feature = "compiler"))] { - unreachable!("Cannot call `SharedObjectEngine::new` without the `compiler` feature") + unreachable!("Cannot call `DylibEngine::new` without the `compiler` feature") } } else { - SharedObjectEngine::headless() + DylibEngine::headless() } } } @@ -105,13 +105,13 @@ mod tests { #[should_panic(expected = "compiler not implemented")] fn build_engine() { let compiler_config = TestCompilerConfig::default(); - let shared_object = SharedObject::new(compiler_config); - let _engine = shared_object.engine(); + let dylib = Dylib::new(compiler_config); + let _engine = dylib.engine(); } #[test] fn build_headless_engine() { - let shared_object = SharedObject::headless(); - let _engine = shared_object.engine(); + let dylib = Dylib::headless(); + let _engine = dylib.engine(); } } diff --git a/lib/engine-shared-object/src/engine.rs b/lib/engine-dylib/src/engine.rs similarity index 83% rename from lib/engine-shared-object/src/engine.rs rename to lib/engine-dylib/src/engine.rs index 0c0c9e3004a..7825ae18987 100644 --- a/lib/engine-shared-object/src/engine.rs +++ b/lib/engine-dylib/src/engine.rs @@ -1,6 +1,6 @@ -//! Shared Object Engine. +//! Dylib Engine. -use crate::SharedObjectArtifact; +use crate::DylibArtifact; use libloading::Library; use loupe::MemoryUsage; use std::path::Path; @@ -17,24 +17,24 @@ use wasmer_vm::{ FuncDataRegistry, SignatureRegistry, VMCallerCheckedAnyfunc, VMFuncRef, VMSharedSignatureIndex, }; -/// A WebAssembly `SharedObject` Engine. +/// A WebAssembly `Dylib` Engine. #[derive(Clone, MemoryUsage)] -pub struct SharedObjectEngine { - inner: Arc>, +pub struct DylibEngine { + inner: Arc>, /// The target for the compiler target: Arc, engine_id: EngineId, } -impl SharedObjectEngine { - /// Create a new `SharedObjectEngine` with the given config +impl DylibEngine { + /// Create a new `DylibEngine` with the given config #[cfg(feature = "compiler")] pub fn new(compiler: Box, target: Target, features: Features) -> Self { let is_cross_compiling = *target.triple() != Triple::host(); let linker = Linker::find_linker(is_cross_compiling); Self { - inner: Arc::new(Mutex::new(SharedObjectEngineInner { + inner: Arc::new(Mutex::new(DylibEngineInner { compiler: Some(compiler), signatures: SignatureRegistry::new(), func_data: Arc::new(FuncDataRegistry::new()), @@ -49,7 +49,7 @@ impl SharedObjectEngine { } } - /// Create a headless `SharedObjectEngine` + /// Create a headless `DylibEngine` /// /// A headless engine is an engine without any compiler attached. /// This is useful for assuring a minimal runtime for running @@ -64,7 +64,7 @@ impl SharedObjectEngine { /// they just take already processed Modules (via `Module::serialize`). pub fn headless() -> Self { Self { - inner: Arc::new(Mutex::new(SharedObjectEngineInner { + inner: Arc::new(Mutex::new(DylibEngineInner { #[cfg(feature = "compiler")] compiler: None, #[cfg(feature = "compiler")] @@ -99,16 +99,16 @@ impl SharedObjectEngine { inner.prefixer = Some(Box::new(prefixer)); } - pub(crate) fn inner(&self) -> std::sync::MutexGuard<'_, SharedObjectEngineInner> { + pub(crate) fn inner(&self) -> std::sync::MutexGuard<'_, DylibEngineInner> { self.inner.lock().unwrap() } - pub(crate) fn inner_mut(&self) -> std::sync::MutexGuard<'_, SharedObjectEngineInner> { + pub(crate) fn inner_mut(&self) -> std::sync::MutexGuard<'_, DylibEngineInner> { self.inner.lock().unwrap() } } -impl Engine for SharedObjectEngine { +impl Engine for DylibEngine { /// The target fn target(&self) -> &Target { &self.target @@ -143,9 +143,7 @@ impl Engine for SharedObjectEngine { binary: &[u8], tunables: &dyn Tunables, ) -> Result, CompileError> { - Ok(Arc::new(SharedObjectArtifact::new( - &self, binary, tunables, - )?)) + Ok(Arc::new(DylibArtifact::new(&self, binary, tunables)?)) } /// Compile a WebAssembly binary (it will fail because the `compiler` flag is disabled). @@ -156,23 +154,23 @@ impl Engine for SharedObjectEngine { _tunables: &dyn Tunables, ) -> Result, CompileError> { Err(CompileError::Codegen( - "The `SharedObjectEngine` is operating in headless mode, so it cannot compile a module." + "The `DylibEngine` 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 shared object file) unsafe fn deserialize(&self, bytes: &[u8]) -> Result, DeserializeError> { - Ok(Arc::new(SharedObjectArtifact::deserialize(&self, &bytes)?)) + Ok(Arc::new(DylibArtifact::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 shared object file generated by this engine. unsafe fn deserialize_from_file( &self, file_ref: &Path, ) -> Result, DeserializeError> { - Ok(Arc::new(SharedObjectArtifact::deserialize_from_file( + Ok(Arc::new(DylibArtifact::deserialize_from_file( &self, &file_ref, )?)) } @@ -212,7 +210,7 @@ impl Linker { .next() .unwrap_or_else(|| { panic!( - "Need {} installed in order to use `SharedObjectEngine` when {}cross-compiling", + "Need {} installed in order to use `DylibEngine` when {}cross-compiling", requirements, if is_cross_compiling { "" } else { "not " } ) @@ -230,9 +228,9 @@ impl Linker { } } -/// The inner contents of `SharedObjectEngine` +/// The inner contents of `DylibEngine` #[derive(MemoryUsage)] -pub struct SharedObjectEngineInner { +pub struct DylibEngineInner { /// The compiler #[cfg(feature = "compiler")] compiler: Option>, @@ -251,12 +249,12 @@ pub struct SharedObjectEngineInner { func_data: Arc, /// The prefixer returns the a String to prefix each of - /// the functions in the shared object generated by the `SharedObjectEngine`, + /// the functions in the shared object generated by the `DylibEngine`, /// so we can assure no collisions. #[loupe(skip)] prefixer: Option String + Send>>, - /// Whether the shared object engine will cross-compile. + /// Whether the Dylib engine will cross-compile. is_cross_compiling: bool, /// The linker to use. @@ -267,12 +265,12 @@ pub struct SharedObjectEngineInner { libraries: Vec, } -impl SharedObjectEngineInner { +impl DylibEngineInner { /// 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 `SharedObjectEngine` is operating in headless mode, so it can only execute already compiled Modules.".to_string())); + return Err(CompileError::Codegen("The `DylibEngine` is operating in headless mode, so it can only execute already compiled Modules.".to_string())); } Ok(&**self .compiler @@ -304,7 +302,7 @@ impl SharedObjectEngineInner { #[cfg(not(feature = "compiler"))] pub fn validate<'data>(&self, _data: &'data [u8]) -> Result<(), CompileError> { Err(CompileError::Validate( - "The `SharedObjectEngine` is not compiled with compiler support, which is required for validating".to_string(), + "The `DylibEngine` is not compiled with compiler support, which is required for validating".to_string(), )) } diff --git a/lib/engine-shared-object/src/lib.rs b/lib/engine-dylib/src/lib.rs similarity index 65% rename from lib/engine-shared-object/src/lib.rs rename to lib/engine-dylib/src/lib.rs index 41aff63d8ed..c454ff67e09 100644 --- a/lib/engine-shared-object/src/lib.rs +++ b/lib/engine-dylib/src/lib.rs @@ -1,9 +1,10 @@ -//! Shared Object Engine for Wasmer compilers. +//! Ddylib Engine for Wasmer compilers. //! //! Given a compiler (such as `CraneliftCompiler` or `LLVMCompiler`) -//! it generates a shared object file (`.so` or `.dylib` depending on -//! the target), saves it temporarily to disk and uses it natively -//! via `dlopen` and `dlsym` (using the `libloading` library). +//! it generates a dylib/shared object file (`.so` or `.dylib` +//! depending on the target), saves it temporarily to disk and uses it +//! natively via `dlopen` and `dlsym` (using the `libloading` +//! library). #![deny(missing_docs, trivial_numeric_casts, unused_extern_crates)] #![warn(unused_import_braces)] @@ -27,9 +28,9 @@ mod builder; mod engine; mod serialize; -pub use crate::artifact::SharedObjectArtifact; -pub use crate::builder::SharedObject; -pub use crate::engine::SharedObjectEngine; +pub use crate::artifact::DylibArtifact; +pub use crate::builder::Dylib; +pub use crate::engine::DylibEngine; /// Version number of this crate. pub const VERSION: &str = env!("CARGO_PKG_VERSION"); diff --git a/lib/engine-shared-object/src/serialize.rs b/lib/engine-dylib/src/serialize.rs similarity index 100% rename from lib/engine-shared-object/src/serialize.rs rename to lib/engine-dylib/src/serialize.rs diff --git a/lib/engine-shared-object/README.md b/lib/engine-shared-object/README.md deleted file mode 100644 index 448d533305f..00000000000 --- a/lib/engine-shared-object/README.md +++ /dev/null @@ -1,60 +0,0 @@ -# `wasmer-engine-shared-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/master/LICENSE) - -The Wasmer Shared Object engine is usable with any compiler -implementation based on [`wasmer-compiler`] that is able to emit -[Position-Independent Code][PIC] (PIC). - -After the compiler generates the machine code for the functions, the -Shared Object Engine generates a shared object file and links it via -[`dlsym`] so it can be usable by the [`wasmer`] API. - -This allows Wasmer to achieve *blazing fast* **native startup times**. - -*Note: you can find a [full working example using the Shared Object -engine here][example].* - -### Difference with `wasmer-engine-universal` - -The Shared Object Engine and Universal Engine mainly differ on how the -Modules are loaded/stored. Using the same compilers, both will have -the same runtime speed. - -However, the Shared Object Engine uses the Operating System shared -library loader (via `dlopen`) and as such is able to achieve a much -faster startup time when deserializing a serialized `Module`. - -## Requirements - -The `wasmer-engine-shared-object` crate requires a linker available on -your system to generate the shared object file. - -We recommend having [`gcc`] or [`clang`] installed. - -> Note: when **cross-compiling** to other targets, `clang` will be the -> default command used for compiling. - -You can install LLVM (that provides `clang`) easily on your -Debian-like system via this command: - -```bash -bash -c "$(wget -O - https://apt.llvm.org/llvm.sh)" -``` - -Or in macOS: - -```bash -brew install llvm -``` - -Or via any of the [pre-built binaries that LLVM -offers][llvm-pre-built]. - - -[`wasmer-compiler`]: https://github.com/wasmerio/wasmer/tree/master/lib/compiler -[PIC]: https://en.wikipedia.org/wiki/Position-independent_code -[`dlsym`]: https://www.freebsd.org/cgi/man.cgi?query=dlsym -[`wasmer`]: https://github.com/wasmerio/wasmer/tree/master/lib/api -[example]: https://github.com/wasmerio/wasmer/blob/master/examples/engine_shared_object.rs -[`gcc`]: https://gcc.gnu.org/ -[`clang`]: https://clang.llvm.org/ -[llvm-pre-built]: https://releases.llvm.org/download.html diff --git a/lib/engine/README.md b/lib/engine/README.md index c45d47a61e8..e5f25ac0171 100644 --- a/lib/engine/README.md +++ b/lib/engine/README.md @@ -11,7 +11,7 @@ Wasmer Engines are mainly responsible for two things: It currently has three implementations: 1. Universal with [`wasmer-engine-universal`], -2. Native with [`wasmer-engine-shared-object`], +2. Native with [`wasmer-engine-dylib`], 3. Object with [`wasmer-engine-object-file`]. ## Example Implementation @@ -29,7 +29,7 @@ attributions of the project. [`wasmer-engine-universal`]: https://github.com/wasmerio/wasmer/tree/master/lib/engine-universal -[`wasmer-engine-shared-object`]: https://github.com/wasmerio/wasmer/tree/master/lib/engine-shared-object +[`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-dummy`]: https://github.com/wasmerio/wasmer/tree/master/tests/lib/engine-dummy [`wasmtime-api`]: https://crates.io/crates/wasmtime diff --git a/lib/object/README.md b/lib/object/README.md index 626fb23ad2e..99e9c86204d 100644 --- a/lib/object/README.md +++ b/lib/object/README.md @@ -3,8 +3,8 @@ The Wasmer Native Object crate aims at cross-generating native objects for various platforms. -This crate is the foundation of [the `wasmer-engine-shared-object` -crate](../engine-shared-object/). Given a compilation result, i.e. the result +This crate is the foundation of [the `wasmer-engine-dylib` +crate](../engine-dylib/). 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` diff --git a/scripts/publish.py b/scripts/publish.py index 997f539f2f6..ed5d1667b95 100644 --- a/scripts/publish.py +++ b/scripts/publish.py @@ -35,20 +35,20 @@ "wasmer-compiler-cranelift": set(["wasmer-types", "wasmer-vm", "wasmer-compiler"]), "wasmer-compiler-llvm": set(["wasmer-types", "wasmer-vm", "wasmer-compiler"]), "wasmer-engine-universal": set(["wasmer-types", "wasmer-vm", "wasmer-compiler", "wasmer-engine"]), - "wasmer-engine-shared-object": 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-object"]), "wasmer": set(["wasmer-vm", "wasmer-compiler-singlepass", "wasmer-compiler-cranelift", "wasmer-compiler-llvm", "wasmer-compiler", "wasmer-engine", "wasmer-engine-universal", - "wasmer-engine-shared-object", "wasmer-engine-object-file", "wasmer-types", "wasmer-derive"]), + "wasmer-engine-dylib", "wasmer-engine-object-file", "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-shared-object", "wasmer-engine-object-file", "wasmer-wasi", "wasmer-types"]), + "wasmer-engine-dylib", "wasmer-engine-object-file", "wasmer-wasi", "wasmer-types"]), "wasmer-middlewares": set(["wasmer", "wasmer-types", "wasmer-vm"]), } @@ -66,7 +66,7 @@ "wasmer-compiler-llvm": "compiler-llvm", "wasmer-engine": "engine", "wasmer-engine-universal": "engine-universal", - "wasmer-engine-shared-object": "engine-shared-object", + "wasmer-engine-dylib": "engine-dylib", "wasmer-engine-object-file": "engine-object-file", "wasmer-cache": "cache", "wasmer": "api", diff --git a/tests/compilers/config.rs b/tests/compilers/config.rs index c6ae9674a4c..a4a77bd951b 100644 --- a/tests/compilers/config.rs +++ b/tests/compilers/config.rs @@ -10,7 +10,7 @@ pub enum Compiler { #[derive(Clone, Debug, PartialEq)] pub enum Engine { - SharedObject, + Dylib, Universal, } @@ -61,9 +61,9 @@ impl Config { #[cfg(not(feature = "engine"))] compile_error!("Plese enable at least one engine via the features"); match &self.engine { - #[cfg(feature = "shared-object")] - Engine::SharedObject => { - let mut engine = wasmer_engine_shared_object::SharedObject::new(compiler_config); + #[cfg(feature = "dylib")] + Engine::Dylib => { + let mut engine = wasmer_engine_dylib::Dylib::new(compiler_config); if let Some(ref features) = self.features { engine = engine.features(features.clone()) } @@ -87,10 +87,8 @@ impl Config { pub fn engine_headless(&self) -> Box { match &self.engine { - #[cfg(feature = "shared-object")] - Engine::SharedObject => { - Box::new(wasmer_engine_shared_object::SharedObject::headless().engine()) - } + #[cfg(feature = "dylib")] + Engine::Dylib => Box::new(wasmer_engine_dylib::Dylib::headless().engine()), #[cfg(feature = "universal")] Engine::Universal => Box::new(wasmer_engine_universal::Universal::headless().engine()), #[allow(dead_code)] diff --git a/tests/compilers/wast.rs b/tests/compilers/wast.rs index 144d1aca1d6..5978dbdb2b6 100644 --- a/tests/compilers/wast.rs +++ b/tests/compilers/wast.rs @@ -40,8 +40,7 @@ pub fn run_wast(mut config: crate::Config, wast_path: &str) -> anyhow::Result<() wast.allow_trap_message("uninitialized element 2", "uninitialized element"); // `liking.wast` has different wording but the same meaning wast.allow_trap_message("out of bounds memory access", "memory out of bounds"); - if config.compiler == crate::Compiler::Cranelift && config.engine == crate::Engine::SharedObject - { + if config.compiler == crate::Compiler::Cranelift && config.engine == crate::Engine::Dylib { wast.allow_trap_message("call stack exhausted", "out of bounds memory access"); wast.allow_trap_message("indirect call type mismatch", "call stack exhausted"); wast.allow_trap_message("integer divide by zero", "call stack exhausted"); diff --git a/tests/ignores.txt b/tests/ignores.txt index 0d1984482a9..cde3fb4d640 100644 --- a/tests/ignores.txt +++ b/tests/ignores.txt @@ -3,36 +3,36 @@ singlepass spec::multi_value singlepass spec::simd singlepass+windows * -singlepass+shared-object * -windows+shared-object * -musl+shared-object * # Dynamic loading not supported in Musl +singlepass+dylib * +windows+dylib * +musl+dylib * # Dynamic loading not supported in Musl # Traps singlepass traps::test_trap_trace -shared-object traps::test_trap_trace +dylib traps::test_trap_trace aarch64 traps::test_trap_trace singlepass traps::test_trap_stack_overflow -shared-object traps::test_trap_stack_overflow +dylib traps::test_trap_stack_overflow aarch64 traps::test_trap_stack_overflow singlepass traps::trap_display_pretty llvm traps::trap_display_pretty -shared-object traps::trap_display_pretty +dylib traps::trap_display_pretty aarch64 traps::trap_display_pretty singlepass traps::trap_display_multi_module llvm traps::trap_display_multi_module -shared-object traps::trap_display_multi_module +dylib traps::trap_display_multi_module aarch64 traps::trap_display_multi_module singlepass traps::call_signature_mismatch llvm traps::call_signature_mismatch -shared-object traps::call_signature_mismatch +dylib traps::call_signature_mismatch macos+aarch64 traps::call_signature_mismatch singlepass traps::start_trap_pretty llvm traps::start_trap_pretty -shared-object traps::start_trap_pretty +dylib traps::start_trap_pretty aarch64 traps::start_trap_pretty -cranelift multi_value_imports::shared-object -singlepass multi_value_imports::shared-object +cranelift multi_value_imports::dylib +singlepass multi_value_imports::dylib singlepass multi_value_imports::dynamic @@ -45,9 +45,9 @@ llvm+universal+macos+aarch64 * cranelift spec::skip_stack_guard_page llvm spec::skip_stack_guard_page -# TODO(https://github.com/wasmerio/wasmer/issues/1727): Traps in shared-object engine -cranelift+shared-object spec::linking -cranelift+shared-object spec::bulk +# TODO(https://github.com/wasmerio/wasmer/issues/1727): Traps in dylib engine +cranelift+dylib spec::linking +cranelift+dylib spec::bulk # Some SIMD opperations are not yet supported by Cranelift cranelift+aarch64 spec::simd::simd_boolean diff --git a/tests/integration/cli/src/util.rs b/tests/integration/cli/src/util.rs index ded87dfd69d..6172d89514e 100644 --- a/tests/integration/cli/src/util.rs +++ b/tests/integration/cli/src/util.rs @@ -22,7 +22,7 @@ impl Compiler { #[derive(Debug, Copy, Clone)] pub enum Engine { Universal, - SharedObject, + Dylib, ObjectFile, } @@ -30,7 +30,7 @@ impl Engine { pub const fn to_flag(self) -> &'static str { match self { Engine::Universal => "--universal", - Engine::SharedObject => "--shared-object", + Engine::Dylib => "--dylib", Engine::ObjectFile => "--object-file", } } diff --git a/tests/lib/compiler-test-derive/src/ignores.rs b/tests/lib/compiler-test-derive/src/ignores.rs index 349711b1716..e33ca4febd5 100644 --- a/tests/lib/compiler-test-derive/src/ignores.rs +++ b/tests/lib/compiler-test-derive/src/ignores.rs @@ -115,7 +115,7 @@ impl Ignores { arch = Some(alias.to_string()); } // Engines - "universal" | "shared-object" => { + "universal" | "dylib" => { engine = Some(alias.to_string()); } // Compilers diff --git a/tests/lib/compiler-test-derive/src/lib.rs b/tests/lib/compiler-test-derive/src/lib.rs index 13b67e7e7ab..8aa0f6c065a 100644 --- a/tests/lib/compiler-test-derive/src/lib.rs +++ b/tests/lib/compiler-test-derive/src/lib.rs @@ -1,16 +1,16 @@ #[cfg(not(test))] extern crate proc_macro; #[cfg(not(test))] -use ::proc_macro::TokenStream; +use proc_macro::TokenStream; #[cfg(test)] -use ::proc_macro2::TokenStream; -use ::quote::quote; +use proc_macro2::TokenStream; +use quote::quote; +use std::path::PathBuf; #[cfg(not(test))] -use ::syn::parse; +use syn::parse; #[cfg(test)] -use ::syn::parse2 as parse; -use ::syn::*; -use std::path::PathBuf; +use syn::parse2 as parse; +use syn::*; mod ignores; @@ -112,8 +112,7 @@ pub fn compiler_test(attrs: TokenStream, input: TokenStream) -> TokenStream { let mod_name = ::quote::format_ident!("{}", compiler_name.to_lowercase()); let universal_engine_test = construct_engine_test(func, compiler_name, "Universal", "universal"); - let shared_object_engine_test = - construct_engine_test(func, compiler_name, "SharedObject", "shared-object"); + let dylib_engine_test = construct_engine_test(func, compiler_name, "Dylib", "dylib"); let compiler_name_lowercase = compiler_name.to_lowercase(); quote! { @@ -122,7 +121,7 @@ pub fn compiler_test(attrs: TokenStream, input: TokenStream) -> TokenStream { use super::*; #universal_engine_test - #shared_object_engine_test + #dylib_engine_test } } }; diff --git a/tests/lib/compiler-test-derive/src/tests.rs b/tests/lib/compiler-test-derive/src/tests.rs index f37370acc95..fe2dd0720c6 100644 --- a/tests/lib/compiler-test-derive/src/tests.rs +++ b/tests/lib/compiler-test-derive/src/tests.rs @@ -1,5 +1,5 @@ use super::*; -use ::pretty_assertions::assert_eq; +use pretty_assertions::assert_eq; macro_rules! gen_tests {( $( @@ -71,10 +71,10 @@ gen_tests! { } #[test] #[cold] - #[cfg(feature = "shared-object")] - fn shared_object() { + #[cfg(feature = "dylib")] + fn dylib() { add(crate::Config::new( - crate::Engine::SharedObject, + crate::Engine::Dylib, crate::Compiler::Singlepass )) } @@ -94,10 +94,10 @@ gen_tests! { } #[test] #[cold] - #[cfg(feature = "shared-object")] - fn shared_object() { + #[cfg(feature = "dylib")] + fn dylib() { add(crate::Config::new( - crate::Engine::SharedObject, + crate::Engine::Dylib, crate::Compiler::Cranelift )) } @@ -117,10 +117,10 @@ gen_tests! { } #[test] #[cold] - #[cfg(feature = "shared-object")] - fn shared_object() { + #[cfg(feature = "dylib")] + fn dylib() { add(crate::Config::new( - crate::Engine::SharedObject, + crate::Engine::Dylib, crate::Compiler::LLVM )) } diff --git a/tests/lib/test-generator/Cargo.toml b/tests/lib/test-generator/Cargo.toml index ded1ef31b78..4b4886bb75b 100644 --- a/tests/lib/test-generator/Cargo.toml +++ b/tests/lib/test-generator/Cargo.toml @@ -10,5 +10,5 @@ anyhow = "1.0" target-lexicon = "0.12" [features] -test-shared-object = [] +test-dylib = [] test-universal = [] diff --git a/tests/wasi-wast/wasi/tests/isatty.rs b/tests/wasi-wast/wasi/tests/isatty.rs index 57d343568bf..422880fd8ff 100644 --- a/tests/wasi-wast/wasi/tests/isatty.rs +++ b/tests/wasi-wast/wasi/tests/isatty.rs @@ -7,12 +7,14 @@ extern "C" { } fn main() { - #[cfg(target = "wasi")] { + #[cfg(target = "wasi")] + { println!("stdin: {}", unsafe { isatty(0) }); println!("stdout: {}", unsafe { isatty(1) }); println!("stderr: {}", unsafe { isatty(2) }); } - #[cfg(not(target = "wasi"))] { + #[cfg(not(target = "wasi"))] + { println!("stdin: 1"); println!("stdout: 1"); println!("stderr: 1"); diff --git a/tests/wasi-wast/wasi/tests/writing.rs b/tests/wasi-wast/wasi/tests/writing.rs index 8921fbab96a..5887e5cea1c 100644 --- a/tests/wasi-wast/wasi/tests/writing.rs +++ b/tests/wasi-wast/wasi/tests/writing.rs @@ -10,10 +10,7 @@ pub const BYTE_STR: &'static [u8] = b"abcdefghijklmnopqrstuvwxyz"; fn main() { #[cfg(not(target_os = "wasi"))] - do_logic_on_path( - "test_fs/hamlet/act1/abc", - "test_fs/hamlet/act1/abc", - ); + do_logic_on_path("test_fs/hamlet/act1/abc", "test_fs/hamlet/act1/abc"); #[cfg(target_os = "wasi")] do_logic_on_path("/act1/abc", "act1-again/abc");