feat: Rename wasmer-engine-native to wasmer-engine-dylib.

This commit is contained in:
Ivan Enderlin
2021-05-28 09:13:23 +02:00
parent e11fc26df6
commit 3d66a2e360
54 changed files with 502 additions and 535 deletions

52
Cargo.lock generated
View File

@ -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,26 +2680,7 @@ dependencies = [
]
[[package]]
name = "wasmer-engine-object-file"
version = "1.0.2"
dependencies = [
"bincode",
"cfg-if 1.0.0",
"leb128",
"libloading",
"loupe",
"serde",
"tempfile",
"tracing",
"wasmer-compiler",
"wasmer-engine",
"wasmer-object",
"wasmer-types",
"wasmer-vm",
]
[[package]]
name = "wasmer-engine-shared-object"
name = "wasmer-engine-dylib"
version = "1.0.2"
dependencies = [
"cfg-if 1.0.0",
@ -2718,6 +2699,25 @@ dependencies = [
"which 4.1.0",
]
[[package]]
name = "wasmer-engine-object-file"
version = "1.0.2"
dependencies = [
"bincode",
"cfg-if 1.0.0",
"leb128",
"libloading",
"loupe",
"serde",
"tempfile",
"tracing",
"wasmer-compiler",
"wasmer-engine",
"wasmer-object",
"wasmer-types",
"wasmer-vm",
]
[[package]]
name = "wasmer-engine-universal"
version = "1.0.2"
@ -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",

View File

@ -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]]

View File

@ -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

View File

@ -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];
}
{

View File

@ -4,241 +4,241 @@
<!-- Generated by graphviz version 2.47.1 (20210417.1919)
-->
<!-- Title: dependencies Pages: 1 -->
<svg width="1169pt" height="554pt"
viewBox="0.00 0.00 1169.00 554.00" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
<svg width="1111pt" height="554pt"
viewBox="0.00 0.00 1111.00 554.00" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
<g id="graph0" class="graph" transform="scale(1 1) rotate(0) translate(4 550)">
<title>dependencies</title>
<polygon fill="white" stroke="transparent" points="-4,4 -4,-550 1165,-550 1165,4 -4,4"/>
<polygon fill="white" stroke="transparent" points="-4,4 -4,-550 1107,-550 1107,4 -4,4"/>
<g id="clust1" class="cluster">
<title>cluster_compiler</title>
<polygon fill="none" stroke="brown" points="480,-280 480,-355 1153,-355 1153,-280 480,-280"/>
<text text-anchor="middle" x="816.5" y="-339.8" font-family="Times,serif" font-size="14.00">Compilers</text>
<polygon fill="none" stroke="brown" points="422,-280 422,-355 1095,-355 1095,-280 422,-280"/>
<text text-anchor="middle" x="758.5" y="-339.8" font-family="Times,serif" font-size="14.00">Compilers</text>
</g>
<g id="clust2" class="cluster">
<title>cluster_engine</title>
<polygon fill="none" stroke="brown" points="8,-280 8,-355 472,-355 472,-280 8,-280"/>
<text text-anchor="middle" x="240" y="-339.8" font-family="Times,serif" font-size="14.00">Engines</text>
<polygon fill="none" stroke="brown" points="8,-280 8,-355 414,-355 414,-280 8,-280"/>
<text text-anchor="middle" x="211" y="-339.8" font-family="Times,serif" font-size="14.00">Engines</text>
</g>
<g id="clust4" class="cluster">
<title>cluster_abi</title>
<polygon fill="none" stroke="brown" points="359,-427 359,-502 670,-502 670,-427 359,-427"/>
<text text-anchor="middle" x="514.5" y="-486.8" font-family="Times,serif" font-size="14.00">Provided ABIs</text>
<polygon fill="none" stroke="brown" points="301,-427 301,-502 612,-502 612,-427 301,-427"/>
<text text-anchor="middle" x="456.5" y="-486.8" font-family="Times,serif" font-size="14.00">Provided ABIs</text>
</g>
<!-- n0 -->
<g id="node1" class="node">
<title>n0</title>
<ellipse fill="none" stroke="orange" cx="581" cy="-381" rx="38.19" ry="18"/>
<text text-anchor="middle" x="581" y="-377.3" font-family="Times,serif" font-size="14.00">wasmer</text>
<ellipse fill="none" stroke="orange" cx="523" cy="-381" rx="38.19" ry="18"/>
<text text-anchor="middle" x="523" y="-377.3" font-family="Times,serif" font-size="14.00">wasmer</text>
</g>
<!-- n6 -->
<g id="node4" class="node">
<title>n6</title>
<ellipse fill="none" stroke="orange" cx="364" cy="-306" rx="100.18" ry="18"/>
<text text-anchor="middle" x="364" y="-302.3" font-family="Times,serif" font-size="14.00">wasmer&#45;engine&#45;universal</text>
<ellipse fill="none" stroke="orange" cx="306" cy="-306" rx="100.18" ry="18"/>
<text text-anchor="middle" x="306" y="-302.3" font-family="Times,serif" font-size="14.00">wasmer&#45;engine&#45;universal</text>
</g>
<!-- n0&#45;&gt;n6 -->
<g id="edge12" class="edge">
<title>n0&#45;&gt;n6</title>
<path fill="none" stroke="orange" stroke-dasharray="5,2" d="M546.06,-373.25C525.43,-368.88 498.95,-362.59 476,-355 452.49,-347.23 427.06,-336.52 406.38,-327.2"/>
<polygon fill="orange" stroke="orange" points="407.79,-323.99 397.24,-323.02 404.88,-330.36 407.79,-323.99"/>
<path fill="none" stroke="orange" stroke-dasharray="5,2" d="M488.06,-373.25C467.43,-368.88 440.95,-362.59 418,-355 394.49,-347.23 369.06,-336.52 348.38,-327.2"/>
<polygon fill="orange" stroke="orange" points="349.79,-323.99 339.24,-323.02 346.88,-330.36 349.79,-323.99"/>
</g>
<!-- n7 -->
<g id="node5" class="node">
<title>n7</title>
<ellipse fill="none" stroke="orange" cx="131" cy="-306" rx="115.08" ry="18"/>
<text text-anchor="middle" x="131" y="-302.3" font-family="Times,serif" font-size="14.00">wasmer&#45;engine&#45;shared&#45;object</text>
<ellipse fill="none" stroke="orange" cx="102" cy="-306" rx="85.59" ry="18"/>
<text text-anchor="middle" x="102" y="-302.3" font-family="Times,serif" font-size="14.00">wasmer&#45;engine&#45;dylib</text>
</g>
<!-- n0&#45;&gt;n7 -->
<g id="edge13" class="edge">
<title>n0&#45;&gt;n7</title>
<path fill="none" stroke="orange" stroke-dasharray="5,2" d="M542.32,-380.66C480.71,-380.9 356.86,-378.09 255,-355 227.3,-348.72 197.58,-337.39 174.18,-327.31"/>
<polygon fill="orange" stroke="orange" points="175.46,-324.05 164.89,-323.23 172.64,-330.46 175.46,-324.05"/>
<path fill="none" stroke="orange" stroke-dasharray="5,2" d="M484.8,-378.93C410.73,-376.56 250.17,-369.84 197,-355 175.78,-349.08 153.72,-338.26 136.21,-328.39"/>
<polygon fill="orange" stroke="orange" points="137.9,-325.33 127.49,-323.35 134.39,-331.39 137.9,-325.33"/>
</g>
<!-- n2 -->
<g id="node13" class="node">
<title>n2</title>
<ellipse fill="none" stroke="orange" cx="1040" cy="-306" rx="105.08" ry="18"/>
<text text-anchor="middle" x="1040" y="-302.3" font-family="Times,serif" font-size="14.00">wasmer&#45;compiler&#45;cranelift</text>
<ellipse fill="none" stroke="orange" cx="982" cy="-306" rx="105.08" ry="18"/>
<text text-anchor="middle" x="982" y="-302.3" font-family="Times,serif" font-size="14.00">wasmer&#45;compiler&#45;cranelift</text>
</g>
<!-- n0&#45;&gt;n2 -->
<g id="edge9" class="edge">
<title>n0&#45;&gt;n2</title>
<path fill="none" stroke="orange" stroke-dasharray="5,2" d="M619.13,-378.78C696.16,-376.05 867.84,-368.62 925,-355 950.67,-348.88 977.98,-337.7 999.54,-327.67"/>
<polygon fill="orange" stroke="orange" points="1001.18,-330.76 1008.71,-323.31 998.18,-324.44 1001.18,-330.76"/>
<path fill="none" stroke="orange" stroke-dasharray="5,2" d="M561.13,-378.78C638.16,-376.05 809.84,-368.62 867,-355 892.67,-348.88 919.98,-337.7 941.54,-327.67"/>
<polygon fill="orange" stroke="orange" points="943.18,-330.76 950.71,-323.31 940.18,-324.44 943.18,-330.76"/>
</g>
<!-- n3 -->
<g id="node14" class="node">
<title>n3</title>
<ellipse fill="none" stroke="orange" cx="581" cy="-306" rx="92.88" ry="18"/>
<text text-anchor="middle" x="581" y="-302.3" font-family="Times,serif" font-size="14.00">wasmer&#45;compiler&#45;llvm</text>
<ellipse fill="none" stroke="orange" cx="523" cy="-306" rx="92.88" ry="18"/>
<text text-anchor="middle" x="523" y="-302.3" font-family="Times,serif" font-size="14.00">wasmer&#45;compiler&#45;llvm</text>
</g>
<!-- n0&#45;&gt;n3 -->
<g id="edge10" class="edge">
<title>n0&#45;&gt;n3</title>
<path fill="none" stroke="orange" stroke-dasharray="5,2" d="M581,-362.7C581,-354.25 581,-343.87 581,-334.37"/>
<polygon fill="orange" stroke="orange" points="584.5,-334.18 581,-324.18 577.5,-334.18 584.5,-334.18"/>
<path fill="none" stroke="orange" stroke-dasharray="5,2" d="M523,-362.7C523,-354.25 523,-343.87 523,-334.37"/>
<polygon fill="orange" stroke="orange" points="526.5,-334.18 523,-324.18 519.5,-334.18 526.5,-334.18"/>
</g>
<!-- n4 -->
<g id="node15" class="node">
<title>n4</title>
<ellipse fill="none" stroke="orange" cx="804" cy="-306" rx="112.38" ry="18"/>
<text text-anchor="middle" x="804" y="-302.3" font-family="Times,serif" font-size="14.00">wasmer&#45;compiler&#45;singlepass</text>
<ellipse fill="none" stroke="orange" cx="746" cy="-306" rx="112.38" ry="18"/>
<text text-anchor="middle" x="746" y="-302.3" font-family="Times,serif" font-size="14.00">wasmer&#45;compiler&#45;singlepass</text>
</g>
<!-- n0&#45;&gt;n4 -->
<g id="edge11" class="edge">
<title>n0&#45;&gt;n4</title>
<path fill="none" stroke="orange" stroke-dasharray="5,2" d="M615.33,-372.82C635.27,-368.35 660.77,-362.1 683,-355 708.24,-346.94 735.75,-336.2 758.14,-326.91"/>
<polygon fill="orange" stroke="orange" points="759.53,-330.13 767.41,-323.04 756.83,-323.67 759.53,-330.13"/>
<path fill="none" stroke="orange" stroke-dasharray="5,2" d="M557.33,-372.82C577.27,-368.35 602.77,-362.1 625,-355 650.24,-346.94 677.75,-336.2 700.14,-326.91"/>
<polygon fill="orange" stroke="orange" points="701.53,-330.13 709.41,-323.04 698.83,-323.67 701.53,-330.13"/>
</g>
<!-- n1 -->
<g id="node2" class="node">
<title>n1</title>
<ellipse fill="none" stroke="orange" cx="692" cy="-162" rx="73.39" ry="18"/>
<text text-anchor="middle" x="692" y="-158.3" font-family="Times,serif" font-size="14.00">wasmer&#45;compiler</text>
<ellipse fill="none" stroke="orange" cx="634" cy="-162" rx="73.39" ry="18"/>
<text text-anchor="middle" x="634" y="-158.3" font-family="Times,serif" font-size="14.00">wasmer&#45;compiler</text>
</g>
<!-- n9 -->
<g id="node7" class="node">
<title>n9</title>
<ellipse fill="none" stroke="orange" cx="692" cy="-90" rx="53.09" ry="18"/>
<text text-anchor="middle" x="692" y="-86.3" font-family="Times,serif" font-size="14.00">wasmer&#45;vm</text>
<ellipse fill="none" stroke="orange" cx="634" cy="-90" rx="53.09" ry="18"/>
<text text-anchor="middle" x="634" y="-86.3" font-family="Times,serif" font-size="14.00">wasmer&#45;vm</text>
</g>
<!-- n1&#45;&gt;n9 -->
<g id="edge20" class="edge">
<title>n1&#45;&gt;n9</title>
<path fill="none" stroke="orange" stroke-dasharray="5,2" d="M692,-143.7C692,-135.98 692,-126.71 692,-118.11"/>
<polygon fill="orange" stroke="orange" points="695.5,-118.1 692,-108.1 688.5,-118.1 695.5,-118.1"/>
<path fill="none" stroke="orange" stroke-dasharray="5,2" d="M634,-143.7C634,-135.98 634,-126.71 634,-118.11"/>
<polygon fill="orange" stroke="orange" points="637.5,-118.1 634,-108.1 630.5,-118.1 637.5,-118.1"/>
</g>
<!-- n5 -->
<g id="node3" class="node">
<title>n5</title>
<ellipse fill="none" stroke="orange" cx="364" cy="-234" rx="64.99" ry="18"/>
<text text-anchor="middle" x="364" y="-230.3" font-family="Times,serif" font-size="14.00">wasmer&#45;engine</text>
<ellipse fill="none" stroke="orange" cx="306" cy="-234" rx="64.99" ry="18"/>
<text text-anchor="middle" x="306" y="-230.3" font-family="Times,serif" font-size="14.00">wasmer&#45;engine</text>
</g>
<!-- n5&#45;&gt;n1 -->
<g id="edge19" class="edge">
<title>n5&#45;&gt;n1</title>
<path fill="none" stroke="orange" stroke-dasharray="5,2" d="M413.82,-222.37C471.2,-210.12 565.6,-189.98 628.28,-176.6"/>
<polygon fill="orange" stroke="orange" points="629.39,-179.94 638.44,-174.43 627.93,-173.09 629.39,-179.94"/>
<path fill="none" stroke="orange" stroke-dasharray="5,2" d="M355.82,-222.37C413.2,-210.12 507.6,-189.98 570.28,-176.6"/>
<polygon fill="orange" stroke="orange" points="571.39,-179.94 580.44,-174.43 569.93,-173.09 571.39,-179.94"/>
</g>
<!-- n6&#45;&gt;n5 -->
<g id="edge17" class="edge">
<title>n6&#45;&gt;n5</title>
<path fill="none" stroke="orange" stroke-dasharray="5,2" d="M364,-287.7C364,-279.98 364,-270.71 364,-262.11"/>
<polygon fill="orange" stroke="orange" points="367.5,-262.1 364,-252.1 360.5,-262.1 367.5,-262.1"/>
<path fill="none" stroke="orange" stroke-dasharray="5,2" d="M306,-287.7C306,-279.98 306,-270.71 306,-262.11"/>
<polygon fill="orange" stroke="orange" points="309.5,-262.1 306,-252.1 302.5,-262.1 309.5,-262.1"/>
</g>
<!-- n7&#45;&gt;n5 -->
<g id="edge18" class="edge">
<title>n7&#45;&gt;n5</title>
<path fill="none" stroke="orange" stroke-dasharray="5,2" d="M181.56,-289.81C220.18,-278.21 273.21,-262.28 312.15,-250.58"/>
<polygon fill="orange" stroke="orange" points="313.16,-253.93 321.73,-247.7 311.14,-247.23 313.16,-253.93"/>
<path fill="none" stroke="orange" stroke-dasharray="5,2" d="M144.77,-290.33C177.52,-279.09 222.74,-263.57 256.96,-251.83"/>
<polygon fill="orange" stroke="orange" points="258.42,-255.03 266.75,-248.47 256.15,-248.4 258.42,-255.03"/>
</g>
<!-- n8 -->
<g id="node6" class="node">
<title>n8</title>
<ellipse fill="none" stroke="orange" cx="692" cy="-18" rx="59.59" ry="18"/>
<text text-anchor="middle" x="692" y="-14.3" font-family="Times,serif" font-size="14.00">wasmer&#45;types</text>
<ellipse fill="none" stroke="orange" cx="634" cy="-18" rx="59.59" ry="18"/>
<text text-anchor="middle" x="634" y="-14.3" font-family="Times,serif" font-size="14.00">wasmer&#45;types</text>
</g>
<!-- n9&#45;&gt;n8 -->
<g id="edge21" class="edge">
<title>n9&#45;&gt;n8</title>
<path fill="none" stroke="orange" stroke-dasharray="5,2" d="M692,-71.7C692,-63.98 692,-54.71 692,-46.11"/>
<polygon fill="orange" stroke="orange" points="695.5,-46.1 692,-36.1 688.5,-46.1 695.5,-46.1"/>
<path fill="none" stroke="orange" stroke-dasharray="5,2" d="M634,-71.7C634,-63.98 634,-54.71 634,-46.11"/>
<polygon fill="orange" stroke="orange" points="637.5,-46.1 634,-36.1 630.5,-46.1 637.5,-46.1"/>
</g>
<!-- n10 -->
<g id="node8" class="node">
<title>n10</title>
<ellipse fill="none" stroke="orange" cx="440" cy="-528" rx="59.29" ry="18"/>
<text text-anchor="middle" x="440" y="-524.3" font-family="Times,serif" font-size="14.00">wasmer&#45;c&#45;api</text>
<ellipse fill="none" stroke="orange" cx="382" cy="-528" rx="59.29" ry="18"/>
<text text-anchor="middle" x="382" y="-524.3" font-family="Times,serif" font-size="14.00">wasmer&#45;c&#45;api</text>
</g>
<!-- n11 -->
<g id="node9" class="node">
<title>n11</title>
<ellipse fill="none" stroke="orange" cx="581" cy="-453" rx="80.69" ry="18"/>
<text text-anchor="middle" x="581" y="-449.3" font-family="Times,serif" font-size="14.00">wasmer&#45;emscripten</text>
<ellipse fill="none" stroke="orange" cx="523" cy="-453" rx="80.69" ry="18"/>
<text text-anchor="middle" x="523" y="-449.3" font-family="Times,serif" font-size="14.00">wasmer&#45;emscripten</text>
</g>
<!-- n10&#45;&gt;n11 -->
<g id="edge5" class="edge">
<title>n10&#45;&gt;n11</title>
<path fill="none" stroke="orange" stroke-dasharray="5,2" d="M470.64,-512.56C477.69,-509.16 485.13,-505.5 492,-502 509,-493.34 527.6,-483.38 543.39,-474.79"/>
<polygon fill="orange" stroke="orange" points="545.22,-477.77 552.32,-469.91 541.87,-471.63 545.22,-477.77"/>
<path fill="none" stroke="orange" stroke-dasharray="5,2" d="M412.64,-512.56C419.69,-509.16 427.13,-505.5 434,-502 451,-493.34 469.6,-483.38 485.39,-474.79"/>
<polygon fill="orange" stroke="orange" points="487.22,-477.77 494.32,-469.91 483.87,-471.63 487.22,-477.77"/>
</g>
<!-- n12 -->
<g id="node10" class="node">
<title>n12</title>
<ellipse fill="none" stroke="orange" cx="425" cy="-453" rx="57.69" ry="18"/>
<text text-anchor="middle" x="425" y="-449.3" font-family="Times,serif" font-size="14.00">wasmer&#45;wasi</text>
<ellipse fill="none" stroke="orange" cx="367" cy="-453" rx="57.69" ry="18"/>
<text text-anchor="middle" x="367" y="-449.3" font-family="Times,serif" font-size="14.00">wasmer&#45;wasi</text>
</g>
<!-- n10&#45;&gt;n12 -->
<g id="edge6" class="edge">
<title>n10&#45;&gt;n12</title>
<path fill="none" stroke="orange" stroke-dasharray="5,2" d="M436.45,-509.7C434.69,-501.15 432.53,-490.65 430.56,-481.07"/>
<polygon fill="orange" stroke="orange" points="433.97,-480.27 428.53,-471.18 427.11,-481.68 433.97,-480.27"/>
<path fill="none" stroke="orange" stroke-dasharray="5,2" d="M378.45,-509.7C376.69,-501.15 374.53,-490.65 372.56,-481.07"/>
<polygon fill="orange" stroke="orange" points="375.97,-480.27 370.53,-471.18 369.11,-481.68 375.97,-480.27"/>
</g>
<!-- n11&#45;&gt;n0 -->
<g id="edge7" class="edge">
<title>n11&#45;&gt;n0</title>
<path fill="none" stroke="orange" stroke-dasharray="5,2" d="M581,-434.7C581,-426.98 581,-417.71 581,-409.11"/>
<polygon fill="orange" stroke="orange" points="584.5,-409.1 581,-399.1 577.5,-409.1 584.5,-409.1"/>
<path fill="none" stroke="orange" stroke-dasharray="5,2" d="M523,-434.7C523,-426.98 523,-417.71 523,-409.11"/>
<polygon fill="orange" stroke="orange" points="526.5,-409.1 523,-399.1 519.5,-409.1 526.5,-409.1"/>
</g>
<!-- n12&#45;&gt;n0 -->
<g id="edge8" class="edge">
<title>n12&#45;&gt;n0</title>
<path fill="none" stroke="orange" stroke-dasharray="5,2" d="M456.57,-437.83C482.1,-426.38 518.07,-410.24 544.77,-398.26"/>
<polygon fill="orange" stroke="orange" points="546.46,-401.33 554.15,-394.05 543.6,-394.95 546.46,-401.33"/>
<path fill="none" stroke="orange" stroke-dasharray="5,2" d="M398.57,-437.83C424.1,-426.38 460.07,-410.24 486.77,-398.26"/>
<polygon fill="orange" stroke="orange" points="488.46,-401.33 496.15,-394.05 485.6,-394.95 488.46,-401.33"/>
</g>
<!-- n13 -->
<g id="node11" class="node">
<title>n13</title>
<ellipse fill="none" stroke="orange" cx="741" cy="-453" rx="61.99" ry="18"/>
<text text-anchor="middle" x="741" y="-449.3" font-family="Times,serif" font-size="14.00">wasmer&#45;cache</text>
<ellipse fill="none" stroke="orange" cx="683" cy="-453" rx="61.99" ry="18"/>
<text text-anchor="middle" x="683" y="-449.3" font-family="Times,serif" font-size="14.00">wasmer&#45;cache</text>
</g>
<!-- n13&#45;&gt;n0 -->
<g id="edge4" class="edge">
<title>n13&#45;&gt;n0</title>
<path fill="none" stroke="orange" stroke-dasharray="5,2" d="M708.24,-437.67C681.82,-426.11 644.7,-409.87 617.37,-397.91"/>
<polygon fill="orange" stroke="orange" points="618.71,-394.68 608.14,-393.87 615.9,-401.09 618.71,-394.68"/>
<path fill="none" stroke="orange" stroke-dasharray="5,2" d="M650.24,-437.67C623.82,-426.11 586.7,-409.87 559.37,-397.91"/>
<polygon fill="orange" stroke="orange" points="560.71,-394.68 550.14,-393.87 557.9,-401.09 560.71,-394.68"/>
</g>
<!-- n14 -->
<g id="node12" class="node">
<title>n14</title>
<ellipse fill="none" stroke="orange" cx="581" cy="-528" rx="50.09" ry="18"/>
<text text-anchor="middle" x="581" y="-524.3" font-family="Times,serif" font-size="14.00">wasmer&#45;cli</text>
<ellipse fill="none" stroke="orange" cx="523" cy="-528" rx="50.09" ry="18"/>
<text text-anchor="middle" x="523" y="-524.3" font-family="Times,serif" font-size="14.00">wasmer&#45;cli</text>
</g>
<!-- n14&#45;&gt;n11 -->
<g id="edge3" class="edge">
<title>n14&#45;&gt;n11</title>
<path fill="none" stroke="orange" stroke-dasharray="5,2" d="M581,-509.7C581,-501.25 581,-490.87 581,-481.37"/>
<polygon fill="orange" stroke="orange" points="584.5,-481.18 581,-471.18 577.5,-481.18 584.5,-481.18"/>
<path fill="none" stroke="orange" stroke-dasharray="5,2" d="M523,-509.7C523,-501.25 523,-490.87 523,-481.37"/>
<polygon fill="orange" stroke="orange" points="526.5,-481.18 523,-471.18 519.5,-481.18 526.5,-481.18"/>
</g>
<!-- n14&#45;&gt;n12 -->
<g id="edge2" class="edge">
<title>n14&#45;&gt;n12</title>
<path fill="none" stroke="orange" stroke-dasharray="5,2" d="M538.19,-518.44C522.87,-514.52 505.75,-509.12 491,-502 477.04,-495.26 462.95,-485.51 451.4,-476.55"/>
<polygon fill="orange" stroke="orange" points="453.47,-473.73 443.47,-470.23 449.11,-479.2 453.47,-473.73"/>
<path fill="none" stroke="orange" stroke-dasharray="5,2" d="M480.19,-518.44C464.87,-514.52 447.75,-509.12 433,-502 419.04,-495.26 404.95,-485.51 393.4,-476.55"/>
<polygon fill="orange" stroke="orange" points="395.47,-473.73 385.47,-470.23 391.11,-479.2 395.47,-473.73"/>
</g>
<!-- n14&#45;&gt;n13 -->
<g id="edge1" class="edge">
<title>n14&#45;&gt;n13</title>
<path fill="none" stroke="orange" stroke-dasharray="5,2" d="M624.27,-518.78C640.34,-514.85 658.44,-509.37 674,-502 688.15,-495.3 702.45,-485.56 714.18,-476.6"/>
<polygon fill="orange" stroke="orange" points="716.53,-479.2 722.23,-470.26 712.21,-473.7 716.53,-479.2"/>
<path fill="none" stroke="orange" stroke-dasharray="5,2" d="M566.27,-518.78C582.34,-514.85 600.44,-509.37 616,-502 630.15,-495.3 644.45,-485.56 656.18,-476.6"/>
<polygon fill="orange" stroke="orange" points="658.53,-479.2 664.23,-470.26 654.21,-473.7 658.53,-479.2"/>
</g>
<!-- n2&#45;&gt;n1 -->
<g id="edge14" class="edge">
<title>n2&#45;&gt;n1</title>
<path fill="none" stroke="orange" stroke-dasharray="5,2" d="M1001.09,-289.12C936.21,-262.65 806.27,-209.63 737.35,-181.5"/>
<polygon fill="orange" stroke="orange" points="738.62,-178.24 728.04,-177.71 735.98,-184.72 738.62,-178.24"/>
<path fill="none" stroke="orange" stroke-dasharray="5,2" d="M943.09,-289.12C878.21,-262.65 748.27,-209.63 679.35,-181.5"/>
<polygon fill="orange" stroke="orange" points="680.62,-178.24 670.04,-177.71 677.98,-184.72 680.62,-178.24"/>
</g>
<!-- n3&#45;&gt;n1 -->
<g id="edge15" class="edge">
<title>n3&#45;&gt;n1</title>
<path fill="none" stroke="orange" stroke-dasharray="5,2" d="M594.17,-288.15C613.61,-263.28 650.12,-216.57 672.62,-187.79"/>
<polygon fill="orange" stroke="orange" points="675.45,-189.86 678.85,-179.82 669.93,-185.55 675.45,-189.86"/>
<path fill="none" stroke="orange" stroke-dasharray="5,2" d="M536.17,-288.15C555.61,-263.28 592.12,-216.57 614.62,-187.79"/>
<polygon fill="orange" stroke="orange" points="617.45,-189.86 620.85,-179.82 611.93,-185.55 617.45,-189.86"/>
</g>
<!-- n4&#45;&gt;n1 -->
<g id="edge16" class="edge">
<title>n4&#45;&gt;n1</title>
<path fill="none" stroke="orange" stroke-dasharray="5,2" d="M790.49,-287.87C770.79,-262.9 734.08,-216.35 711.46,-187.68"/>
<polygon fill="orange" stroke="orange" points="714.15,-185.43 705.21,-179.75 708.65,-189.77 714.15,-185.43"/>
<path fill="none" stroke="orange" stroke-dasharray="5,2" d="M732.49,-287.87C712.79,-262.9 676.08,-216.35 653.46,-187.68"/>
<polygon fill="orange" stroke="orange" points="656.15,-185.43 647.21,-179.75 650.65,-189.77 656.15,-185.43"/>
</g>
</g>
</svg>

Before

Width:  |  Height:  |  Size: 12 KiB

After

Width:  |  Height:  |  Size: 12 KiB

View File

@ -236,7 +236,7 @@ example.
</details>
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.
<summary><em>Execute the example</em></summary>
```shell
$ cargo run --example engine-shared-object --release --features "cranelift"
$ cargo run --example engine-dylib --release --features "cranelift"
```
</details>
@ -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

View File

@ -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<dyn std::error::Error>> {
// Let's declare the Wasm module with the text representation.
@ -67,12 +67,13 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
// 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.

View File

@ -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<dyn std::error::Error>> {
// Let's declare the Wasm module with the text representation.
@ -45,12 +44,12 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
// 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<dyn std::error::Error>> {
// 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<dyn std::error::Error>> {
#[test]
#[cfg(not(any(target_arch = "aarch64", target_env = "musl")))]
fn test_engine_shared_object() -> Result<(), Box<dyn std::error::Error>> {
fn test_engine_dylib() -> Result<(), Box<dyn std::error::Error>> {
main()
}

View File

@ -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<dyn std::error::Error>> {
// First step, let's compile the Wasm module and serialize it.
@ -79,16 +80,16 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
// 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<dyn std::error::Error>> {
// 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...");

View File

@ -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"]

View File

@ -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

View File

@ -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! {}) {

View File

@ -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"
]

View File

@ -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");

View File

@ -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")

View File

@ -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 = [

View File

@ -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<dyn Engine + Send + Sync> = 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<wasm_engine_t> {
let compiler_config: Box<dyn CompilerConfig> = get_default_compiler_config();
let engine: Arc<dyn Engine + Send + Sync> = Arc::new(SharedObject::new(compiler_config).engine());
let engine: Arc<dyn Engine + Send + Sync> = 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<wasm_engine_t> {
let engine: Arc<dyn Engine + Send + Sync> = Arc::new(SharedObject::headless().engine());
let engine: Arc<dyn Engine + Send + Sync> = 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.");
}
}
},

View File

@ -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");
}
}

View File

@ -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();

View File

@ -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;

View File

@ -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"

View File

@ -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 {

View File

@ -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"]

View File

@ -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):

View File

@ -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"),
})
}

View File

@ -205,10 +205,10 @@ impl Run {
fn get_module(&self) -> Result<Module> {
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 => {

View File

@ -1,4 +1,3 @@
#[derive(Debug, Clap, Clone)]
/// LLVM backend flags.
pub struct LLVMCLIOptions {
@ -15,7 +14,6 @@ pub struct LLVMCLIOptions {
obj_file: Option<PathBuf>,
}
impl LLVMCallbacks for LLVMCLIOptions {
fn preopt_ir_callback(&mut self, module: &InkwellModule) {
if let Some(filename) = &self.pre_opt_ir {

View File

@ -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<EngineType> {
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()

View File

@ -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",

View File

@ -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",

View File

@ -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<Memory>,
}
fn main() {}
fn main() {}

View File

@ -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<Memory>,
}
@ -14,4 +15,4 @@ struct BadExportArgRawString {
memory: LazyInit<Memory>,
}
fn main() {}
fn main() {}

View File

@ -1,6 +1,6 @@
extern crate wasmer;
use wasmer::{LazyInit, WasmerEnv, Memory};
use wasmer::{LazyInit, Memory, WasmerEnv};
#[derive(WasmerEnv)]
struct ExportNotWrappedInLazyInit {

View File

@ -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 <engineering@wasmer.io>"]
repository = "https://github.com/wasmerio/wasmer"
license = "MIT"

View File

@ -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

View File

@ -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<LocalFunctionIndex, FunctionBodyPtr>,
#[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<Self, CompileError> {
@ -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<Self, CompileError> {
let finished_functions: PrimaryMap<LocalFunctionIndex, FunctionBodyPtr> = PrimaryMap::new();
let finished_function_call_trampolines: PrimaryMap<SignatureIndex, VMTrampoline> =
@ -370,7 +370,7 @@ impl SharedObjectArtifact {
PrimaryMap::new();
let signatures: PrimaryMap<SignatureIndex, VMSharedSignatureIndex> = 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<Self, CompileError> {
let mut finished_functions: PrimaryMap<LocalFunctionIndex, FunctionBodyPtr> =
@ -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<Self, CompileError> {
pub fn new(_engine: &DylibEngine, _data: &[u8]) -> Result<Self, CompileError> {
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<Self, DeserializeError> {
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<Self, DeserializeError> {
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<Self, DeserializeError> {
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<ModuleInfo> {
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<Vec<u8>, SerializeError> {
Ok(std::fs::read(&self.shared_object_path)?)
Ok(std::fs::read(&self.dylib_path)?)
}
}

View File

@ -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<Box<dyn CompilerConfig>>,
target: Option<Target>,
features: Option<Features>,
}
impl SharedObject {
impl Dylib {
#[cfg(feature = "compiler")]
/// Create a new Shared Object builder.
/// Create a new Dylib builder.
pub fn new<T>(compiler_config: T) -> Self
where
T: Into<Box<dyn CompilerConfig>>,
@ -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();
}
}

View File

@ -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<Mutex<SharedObjectEngineInner>>,
pub struct DylibEngine {
inner: Arc<Mutex<DylibEngineInner>>,
/// The target for the compiler
target: Arc<Target>,
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<dyn Compiler>, 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<Arc<dyn Artifact>, 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<Arc<dyn Artifact>, 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<Arc<dyn Artifact>, 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<Arc<dyn Artifact>, 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<Box<dyn Compiler>>,
@ -251,12 +249,12 @@ pub struct SharedObjectEngineInner {
func_data: Arc<FuncDataRegistry>,
/// 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<Box<dyn Fn(&[u8]) -> 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<Library>,
}
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(),
))
}

View File

@ -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");

View File

@ -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

View File

@ -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

View File

@ -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`

View File

@ -35,20 +35,20 @@ dep_graph = {
"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 @@ location = {
"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",

View File

@ -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<dyn WasmerEngine> {
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)]

View File

@ -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");

View File

@ -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

View File

@ -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",
}
}

View File

@ -115,7 +115,7 @@ impl Ignores {
arch = Some(alias.to_string());
}
// Engines
"universal" | "shared-object" => {
"universal" | "dylib" => {
engine = Some(alias.to_string());
}
// Compilers

View File

@ -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;
#[cfg(not(test))]
use ::syn::parse;
#[cfg(test)]
use ::syn::parse2 as parse;
use ::syn::*;
use proc_macro2::TokenStream;
use quote::quote;
use std::path::PathBuf;
#[cfg(not(test))]
use syn::parse;
#[cfg(test)]
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
}
}
};

View File

@ -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
))
}

View File

@ -10,5 +10,5 @@ anyhow = "1.0"
target-lexicon = "0.12"
[features]
test-shared-object = []
test-dylib = []
test-universal = []

View File

@ -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");

View File

@ -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");