mirror of
https://github.com/mii443/wasmer.git
synced 2025-12-09 06:08:29 +00:00
Merge branch 'master' into test-c-api
This commit is contained in:
12
.github/dependabot.yml
vendored
Normal file
12
.github/dependabot.yml
vendored
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
version: 2
|
||||||
|
|
||||||
|
updates:
|
||||||
|
- package-ecosystem: "cargo"
|
||||||
|
directory: "/"
|
||||||
|
allow:
|
||||||
|
- dependency-type: "all"
|
||||||
|
rebase-strategy: "auto"
|
||||||
|
schedule:
|
||||||
|
interval: "weekly"
|
||||||
|
day: "sunday"
|
||||||
|
versioning-strategy: "auto"
|
||||||
2
.github/workflows/lint.yaml
vendored
2
.github/workflows/lint.yaml
vendored
@@ -19,7 +19,7 @@ jobs:
|
|||||||
uses: actions-rs/toolchain@v1
|
uses: actions-rs/toolchain@v1
|
||||||
with:
|
with:
|
||||||
profile: minimal
|
profile: minimal
|
||||||
toolchain: 1.46.0
|
toolchain: 1.47.0
|
||||||
override: true
|
override: true
|
||||||
components: rustfmt, clippy
|
components: rustfmt, clippy
|
||||||
- run: make lint
|
- run: make lint
|
||||||
|
|||||||
91
.github/workflows/main.yaml
vendored
91
.github/workflows/main.yaml
vendored
@@ -26,7 +26,7 @@ jobs:
|
|||||||
run: |
|
run: |
|
||||||
VERSION=${GITHUB_REF/refs\/tags\//}
|
VERSION=${GITHUB_REF/refs\/tags\//}
|
||||||
echo ::set-output name=VERSION::${VERSION}
|
echo ::set-output name=VERSION::${VERSION}
|
||||||
DOING_RELEASE=$(echo $VERSION | grep -c '^[0-9]\+\.[0-9]\+\.[0-9]\+\(-\([a-zA-Z]\+\)?[0-9]*\)\?$' || true)
|
DOING_RELEASE=$(echo $VERSION | grep -c '^[0-9]\+\.[0-9]\+\.[0-9]\+\(-\([a-zA-Z]\+\)\?[0-9]*\)\?$' || true)
|
||||||
echo ::set-output name=DOING_RELEASE::${DOING_RELEASE}
|
echo ::set-output name=DOING_RELEASE::${DOING_RELEASE}
|
||||||
echo $VERSION
|
echo $VERSION
|
||||||
echo $DOING_RELEASE
|
echo $DOING_RELEASE
|
||||||
@@ -38,16 +38,16 @@ jobs:
|
|||||||
strategy:
|
strategy:
|
||||||
fail-fast: false
|
fail-fast: false
|
||||||
matrix:
|
matrix:
|
||||||
build: [linux, macos, macos-arm64, windows, linux-aarch64]
|
build: [linux-x64, macos-x64, macos-arm64, windows-x64, linux-aarch64]
|
||||||
include:
|
include:
|
||||||
- build: linux
|
- build: linux-x64
|
||||||
os: ubuntu-18.04
|
os: ubuntu-18.04
|
||||||
rust: 1.47.0
|
rust: 1.47.0
|
||||||
llvm_url: 'https://github.com/wasmerio/llvm-custom-builds/releases/download/10.x/linux-amd64.tar.gz'
|
llvm_url: 'https://github.com/wasmerio/llvm-custom-builds/releases/download/10.x/linux-amd64.tar.gz'
|
||||||
artifact_name: 'wasmer-linux-amd64'
|
artifact_name: 'wasmer-linux-amd64'
|
||||||
cross_compilation_artifact_name: 'cross_compiled_from_linux'
|
cross_compilation_artifact_name: 'cross_compiled_from_linux'
|
||||||
run_integration_tests: true
|
run_integration_tests: true
|
||||||
- build: macos
|
- build: macos-x64
|
||||||
os: macos-latest
|
os: macos-latest
|
||||||
rust: 1.47.0
|
rust: 1.47.0
|
||||||
llvm_url: 'https://github.com/wasmerio/llvm-custom-builds/releases/download/10.x/darwin-amd64.tar.gz'
|
llvm_url: 'https://github.com/wasmerio/llvm-custom-builds/releases/download/10.x/darwin-amd64.tar.gz'
|
||||||
@@ -59,7 +59,7 @@ jobs:
|
|||||||
rust: nightly
|
rust: nightly
|
||||||
target: aarch64-apple-darwin
|
target: aarch64-apple-darwin
|
||||||
artifact_name: 'wasmer-darwin-arm64'
|
artifact_name: 'wasmer-darwin-arm64'
|
||||||
- build: windows
|
- build: windows-x64
|
||||||
os: windows-latest
|
os: windows-latest
|
||||||
rust: 1.47.0
|
rust: 1.47.0
|
||||||
llvm_url: 'https://github.com/wasmerio/llvm-custom-builds/releases/download/10.x/windows-amd64.tar.gz'
|
llvm_url: 'https://github.com/wasmerio/llvm-custom-builds/releases/download/10.x/windows-amd64.tar.gz'
|
||||||
@@ -68,12 +68,13 @@ jobs:
|
|||||||
run_integration_tests: true
|
run_integration_tests: true
|
||||||
- build: linux-aarch64
|
- build: linux-aarch64
|
||||||
os: [self-hosted, linux, ARM64]
|
os: [self-hosted, linux, ARM64]
|
||||||
|
random_sccache_port: true
|
||||||
rust: 1.47.0
|
rust: 1.47.0
|
||||||
llvm_url: 'https://github.com/wasmerio/llvm-custom-builds/releases/download/10.x/linux-aarch64.tar.gz'
|
llvm_url: 'https://github.com/wasmerio/llvm-custom-builds/releases/download/10.x/linux-aarch64.tar.gz'
|
||||||
artifact_name: 'wasmer-linux-aarch64'
|
artifact_name: 'wasmer-linux-aarch64'
|
||||||
run_integration_tests: false
|
run_integration_tests: false
|
||||||
env:
|
env:
|
||||||
CARGO_SCCACHE_VERSION: 0.2.13
|
CARGO_SCCACHE_VERSION: 0.2.14-alpha.0-parity
|
||||||
SCCACHE_AZURE_BLOB_CONTAINER: wasmerstoragesccacheblob
|
SCCACHE_AZURE_BLOB_CONTAINER: wasmerstoragesccacheblob
|
||||||
SCCACHE_AZURE_CONNECTION_STRING: ${{ secrets.SCCACHE_AZURE_CONNECTION_STRING }}
|
SCCACHE_AZURE_CONNECTION_STRING: ${{ secrets.SCCACHE_AZURE_CONNECTION_STRING }}
|
||||||
steps:
|
steps:
|
||||||
@@ -90,14 +91,6 @@ jobs:
|
|||||||
toolchain: ${{ matrix.rust }}
|
toolchain: ${{ matrix.rust }}
|
||||||
target: ${{ matrix.target }}
|
target: ${{ matrix.target }}
|
||||||
override: true
|
override: true
|
||||||
- name: Setup Rust target
|
|
||||||
run: |
|
|
||||||
cat << EOF > .cargo/config.toml
|
|
||||||
[build]
|
|
||||||
target = "${{ matrix.target }}"
|
|
||||||
EOF
|
|
||||||
if: matrix.target
|
|
||||||
- uses: Swatinem/rust-cache@v1
|
|
||||||
- name: Install LLVM (Windows)
|
- name: Install LLVM (Windows)
|
||||||
if: matrix.os == 'windows-latest'
|
if: matrix.os == 'windows-latest'
|
||||||
shell: cmd
|
shell: cmd
|
||||||
@@ -117,7 +110,60 @@ jobs:
|
|||||||
- name: Set up dependencies for Mac OS
|
- name: Set up dependencies for Mac OS
|
||||||
run: |
|
run: |
|
||||||
brew install automake
|
brew install automake
|
||||||
|
# using gnu-tar is a workaround for https://github.com/actions/cache/issues/403
|
||||||
|
brew install gnu-tar
|
||||||
|
echo PATH="/usr/local/opt/gnu-tar/libexec/gnubin:$PATH" >> $GITHUB_ENV
|
||||||
if: matrix.os == 'macos-latest' || matrix.os == 'macos-11.0'
|
if: matrix.os == 'macos-latest' || matrix.os == 'macos-11.0'
|
||||||
|
- uses: actions/cache@v2
|
||||||
|
with:
|
||||||
|
path: |
|
||||||
|
~/.cargo/registry
|
||||||
|
~/.cargo/git
|
||||||
|
key: ${{ matrix.build }}-${{ matrix.target }}-cargo-${{ hashFiles('Cargo.lock') }}-v1
|
||||||
|
# Install sccache
|
||||||
|
- uses: actions/cache@v2
|
||||||
|
with:
|
||||||
|
path: ${{ runner.tool_cache }}/cargo-sccache
|
||||||
|
key: ${{ matrix.build }}-${{ matrix.target }}-sccache-bin-${{ env.CARGO_SCCACHE_VERSION }}-v1
|
||||||
|
- name: Install sccache
|
||||||
|
run: |
|
||||||
|
if [ ! -f ${{ runner.tool_cache }}/cargo-sccache/bin/sccache ]; then
|
||||||
|
cargo install sccache --git https://github.com/paritytech/sccache.git --no-default-features --features=dist-client,azure --root ${{ runner.tool_cache }}/cargo-sccache
|
||||||
|
fi
|
||||||
|
shell: bash
|
||||||
|
- name: Setup Rust target
|
||||||
|
run: |
|
||||||
|
cat << EOF > .cargo/config.toml
|
||||||
|
[build]
|
||||||
|
target = "${{ matrix.target }}"
|
||||||
|
EOF
|
||||||
|
if: matrix.target
|
||||||
|
- name: Set sccache port
|
||||||
|
run: |
|
||||||
|
netstat -aln | awk '
|
||||||
|
$6 == "LISTEN" {
|
||||||
|
if ($4 ~ "[.:][0-9]+$") {
|
||||||
|
n = split($4, a, /[:.]/);
|
||||||
|
port = a[n];
|
||||||
|
p[port] = 1
|
||||||
|
}
|
||||||
|
}
|
||||||
|
END {
|
||||||
|
for (i = 3000; i < 65000 && p[i]; i++){};
|
||||||
|
if (i == 65000) {exit 1};
|
||||||
|
print "SCCACHE_SERVER_PORT=" i
|
||||||
|
}
|
||||||
|
' >> $GITHUB_ENV
|
||||||
|
# echo "SCCACHE_SERVER_PORT=9000"
|
||||||
|
echo "Setting random sccache port to: $SCCACHE_SERVER_PORT"
|
||||||
|
if: matrix.random_sccache_port
|
||||||
|
shell: bash
|
||||||
|
- name: Start sccache
|
||||||
|
run: |
|
||||||
|
chmod +x ${{ runner.tool_cache }}/cargo-sccache/bin/sccache
|
||||||
|
${{ runner.tool_cache }}/cargo-sccache/bin/sccache --start-server
|
||||||
|
${{ runner.tool_cache }}/cargo-sccache/bin/sccache -s
|
||||||
|
echo "RUSTC_WRAPPER=${{ runner.tool_cache }}/cargo-sccache/bin/sccache" >> $GITHUB_ENV
|
||||||
- name: Test
|
- name: Test
|
||||||
run: |
|
run: |
|
||||||
make test
|
make test
|
||||||
@@ -129,14 +175,11 @@ jobs:
|
|||||||
- name: Build C API
|
- name: Build C API
|
||||||
run: |
|
run: |
|
||||||
make build-capi
|
make build-capi
|
||||||
if: matrix.os != 'windows-latest' && matrix.target != 'aarch64-apple-darwin'
|
if: matrix.target != 'aarch64-apple-darwin'
|
||||||
- name: Build C API
|
- name: Build C API (system libffi)
|
||||||
run: |
|
run: |
|
||||||
make build-capi-cranelift-system-libffi
|
make build-capi-cranelift-system-libffi
|
||||||
if: matrix.target == 'aarch64-apple-darwin'
|
if: matrix.target == 'aarch64-apple-darwin'
|
||||||
- name: Build C API on Windows
|
|
||||||
run: make build-capi
|
|
||||||
if: matrix.os == 'windows-latest'
|
|
||||||
- name: Build Wasmer binary
|
- name: Build Wasmer binary
|
||||||
run: |
|
run: |
|
||||||
make build-wasmer
|
make build-wasmer
|
||||||
@@ -175,8 +218,8 @@ jobs:
|
|||||||
run: |
|
run: |
|
||||||
ls target/release
|
ls target/release
|
||||||
alias wasmer=target/release/wasmer
|
alias wasmer=target/release/wasmer
|
||||||
./target/release/wasmer compile --target=x86_64-apple-darwin tests/integration/cli/assets/qjs.wasm -o qjs_mac_from_linux.wjit
|
./target/release/wasmer compile --target=x86_64-apple-darwin lib/c-api/tests/assets/qjs.wasm -o qjs_mac_from_linux.wjit
|
||||||
#./target/release/wasmer compile --target=x86_64-pc-windows-msvc tests/integration/cli/assets/qjs.wasm -o qjs_win_from_linux.wjit
|
#./target/release/wasmer compile --target=x86_64-pc-windows-msvc lib/c-api/tests/assets/qjs.wasm -o qjs_win_from_linux.wjit
|
||||||
mkdir cross
|
mkdir cross
|
||||||
cp qjs_mac_from_linux.wjit cross
|
cp qjs_mac_from_linux.wjit cross
|
||||||
#cp qjs_win_from_linux.wjit cross
|
#cp qjs_win_from_linux.wjit cross
|
||||||
@@ -187,8 +230,8 @@ jobs:
|
|||||||
run: |
|
run: |
|
||||||
ls target/release
|
ls target/release
|
||||||
alias wasmer=target/release/wasmer
|
alias wasmer=target/release/wasmer
|
||||||
./target/release/wasmer compile --target=x86_64-unknown-linux-gnu tests/integration/cli/assets/qjs.wasm -o qjs_linux_from_mac.wjit
|
./target/release/wasmer compile --target=x86_64-unknown-linux-gnu lib/c-api/tests/assets/qjs.wasm -o qjs_linux_from_mac.wjit
|
||||||
#./target/release/wasmer compile --target=x86_64-pc-windows-msvc tests/integration/cli/assets/qjs.wasm -o qjs_win_from_mac.wjit
|
#./target/release/wasmer compile --target=x86_64-pc-windows-msvc lib/c-api/tests/assets/qjs.wasm -o qjs_win_from_mac.wjit
|
||||||
mkdir cross
|
mkdir cross
|
||||||
cp qjs_linux_from_mac.wjit cross
|
cp qjs_linux_from_mac.wjit cross
|
||||||
#cp qjs_win_from_mac.wjit cross
|
#cp qjs_win_from_mac.wjit cross
|
||||||
@@ -320,7 +363,7 @@ jobs:
|
|||||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||||
with:
|
with:
|
||||||
upload_url: ${{ steps.create_release.outputs.upload_url }}
|
upload_url: ${{ steps.create_release.outputs.upload_url }}
|
||||||
asset_path: artifacts/wasmer-darwin-amd64/wasmer.tar.gz
|
asset_path: artifacts/wasmer-darwin-arm64/wasmer.tar.gz
|
||||||
asset_name: wasmer-darwin-arm64.tar.gz
|
asset_name: wasmer-darwin-arm64.tar.gz
|
||||||
asset_content_type: application/gzip
|
asset_content_type: application/gzip
|
||||||
- name: Upload Release Asset Linux aarch64
|
- name: Upload Release Asset Linux aarch64
|
||||||
|
|||||||
21
CHANGELOG.md
21
CHANGELOG.md
@@ -8,9 +8,28 @@
|
|||||||
## **[Unreleased]**
|
## **[Unreleased]**
|
||||||
|
|
||||||
### Added
|
### Added
|
||||||
|
|
||||||
|
* [#1867](https://github.com/wasmerio/wasmer/pull/1867) Added `Metering::get_remaining_points` and `Metering::set_remaining_points`
|
||||||
|
* [#1881](https://github.com/wasmerio/wasmer/pull/1881) Added `UnsupportedTarget` error to `CompileError`
|
||||||
|
* [#1908](https://github.com/wasmerio/wasmer/pull/1908) Implemented `TryFrom<Value<T>>` for `i32`/`u32`/`i64`/`u64`/`f32`/`f64`
|
||||||
|
|
||||||
|
### Changed
|
||||||
|
|
||||||
|
- [#1874](https://github.com/wasmerio/wasmer/pull/1874) Set `CompilerConfig` to be owned (following wasm-c-api)
|
||||||
|
- [#1880](https://github.com/wasmerio/wasmer/pull/1880) Remove cmake dependency for tests
|
||||||
|
|
||||||
|
### Fixed
|
||||||
|
|
||||||
|
- [#1870](https://github.com/wasmerio/wasmer/pull/1870) Fixed Trap instruction address maps in Singlepass
|
||||||
|
|
||||||
|
## 1.0.0-beta1 - 2020-12-01
|
||||||
|
|
||||||
|
### Added
|
||||||
|
|
||||||
|
- [#1839](https://github.com/wasmerio/wasmer/pull/1839) Added support for Metering Middleware
|
||||||
- [#1837](https://github.com/wasmerio/wasmer/pull/1837) It is now possible to use exports of an `Intance` even after the `Instance` has been freed
|
- [#1837](https://github.com/wasmerio/wasmer/pull/1837) It is now possible to use exports of an `Intance` even after the `Instance` has been freed
|
||||||
- [#1831](https://github.com/wasmerio/wasmer/pull/1831) Added support for Apple Silicon chips (`arm64-apple-darwin`)
|
- [#1831](https://github.com/wasmerio/wasmer/pull/1831) Added support for Apple Silicon chips (`arm64-apple-darwin`)
|
||||||
|
- [#1739](https://github.com/wasmerio/wasmer/pull/1739) Improved function environment setup via `WasmerEnv` proc macro.
|
||||||
- [#1649](https://github.com/wasmerio/wasmer/pull/1649) Add outline of migration to 1.0.0 docs.
|
- [#1649](https://github.com/wasmerio/wasmer/pull/1649) Add outline of migration to 1.0.0 docs.
|
||||||
|
|
||||||
### Changed
|
### Changed
|
||||||
@@ -23,6 +42,8 @@
|
|||||||
|
|
||||||
### Fixed
|
### Fixed
|
||||||
|
|
||||||
|
- [#1857](https://github.com/wasmerio/wasmer/pull/1857) Fix dynamic function with new Environment API
|
||||||
|
- [#1855](https://github.com/wasmerio/wasmer/pull/1855) Fix memory leak when using `wat2wasm` in the C API, the function now takes its output parameter by pointer rather than returning an allocated `wasm_byte_vec_t`.
|
||||||
- [#1841](https://github.com/wasmerio/wasmer/pull/1841) We will now panic when attempting to use a native function with a captured env as a host function. Previously this would silently do the wrong thing. See [#1840](https://github.com/wasmerio/wasmer/pull/1840) for info about Wasmer's support of closures as host functions.
|
- [#1841](https://github.com/wasmerio/wasmer/pull/1841) We will now panic when attempting to use a native function with a captured env as a host function. Previously this would silently do the wrong thing. See [#1840](https://github.com/wasmerio/wasmer/pull/1840) for info about Wasmer's support of closures as host functions.
|
||||||
- [#1764](https://github.com/wasmerio/wasmer/pull/1764) Fix bug in WASI `path_rename` allowing renamed files to be 1 directory below a preopened directory.
|
- [#1764](https://github.com/wasmerio/wasmer/pull/1764) Fix bug in WASI `path_rename` allowing renamed files to be 1 directory below a preopened directory.
|
||||||
|
|
||||||
|
|||||||
236
Cargo.lock
generated
236
Cargo.lock
generated
@@ -53,9 +53,9 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "anyhow"
|
name = "anyhow"
|
||||||
version = "1.0.34"
|
version = "1.0.35"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "bf8dcb5b4bbaa28653b647d8c77bd4ed40183b48882e130c1f1ffb73de069fd7"
|
checksum = "2c0df63cb2955042487fad3aefd2c6e3ae7389ac5dc1beb28921de0b69f779d4"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "arrayref"
|
name = "arrayref"
|
||||||
@@ -121,9 +121,9 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "base64"
|
name = "base64"
|
||||||
version = "0.12.3"
|
version = "0.13.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "3441f0f7b02788e948e47f457ca01f1d7e6d92c693bc132c22b087d3141c03ff"
|
checksum = "904dfeac50f3cdaba28fc6f57fdcddb75f49ed61346676a78c4ffe55877802fd"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "bincode"
|
name = "bincode"
|
||||||
@@ -143,9 +143,9 @@ checksum = "cf1de2fe8c75bc145a2f577add951f8134889b4795d47466a54a5c846d691693"
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "blake2b_simd"
|
name = "blake2b_simd"
|
||||||
version = "0.5.10"
|
version = "0.5.11"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "d8fb2d74254a3a0b5cac33ac9f8ed0e44aa50378d9dbb2e5d83bd21ed1dc2c8a"
|
checksum = "afa748e348ad3be8263be728124b24a24f268266f6f5d58af9d75f6a40b5c587"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"arrayref",
|
"arrayref",
|
||||||
"arrayvec",
|
"arrayvec",
|
||||||
@@ -236,9 +236,9 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "cc"
|
name = "cc"
|
||||||
version = "1.0.65"
|
version = "1.0.66"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "95752358c8f7552394baf48cd82695b345628ad3f170d607de3ca03b8dacca15"
|
checksum = "4c0496836a84f8d0495758516b8621a622beb77c0fed418570e50764093ced48"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "cfg-if"
|
name = "cfg-if"
|
||||||
@@ -276,15 +276,6 @@ dependencies = [
|
|||||||
"bitflags",
|
"bitflags",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "cloudabi"
|
|
||||||
version = "0.1.0"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "4344512281c643ae7638bbabc3af17a11307803ec8f0fcad9fae512a8bf36467"
|
|
||||||
dependencies = [
|
|
||||||
"bitflags",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "colored"
|
name = "colored"
|
||||||
version = "1.9.3"
|
version = "1.9.3"
|
||||||
@@ -511,7 +502,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
|||||||
checksum = "dca26ee1f8d361640700bde38b2c37d8c22b3ce2d360e1fc1c74ea4b0aa7d775"
|
checksum = "dca26ee1f8d361640700bde38b2c37d8c22b3ce2d360e1fc1c74ea4b0aa7d775"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"cfg-if 1.0.0",
|
"cfg-if 1.0.0",
|
||||||
"crossbeam-utils 0.8.1",
|
"crossbeam-utils",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@@ -522,7 +513,7 @@ checksum = "94af6efb46fef72616855b036a624cf27ba656ffc9be1b9a3c931cfc7749a9a9"
|
|||||||
dependencies = [
|
dependencies = [
|
||||||
"cfg-if 1.0.0",
|
"cfg-if 1.0.0",
|
||||||
"crossbeam-epoch",
|
"crossbeam-epoch",
|
||||||
"crossbeam-utils 0.8.1",
|
"crossbeam-utils",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@@ -533,23 +524,12 @@ checksum = "a1aaa739f95311c2c7887a76863f500026092fb1dce0161dab577e559ef3569d"
|
|||||||
dependencies = [
|
dependencies = [
|
||||||
"cfg-if 1.0.0",
|
"cfg-if 1.0.0",
|
||||||
"const_fn",
|
"const_fn",
|
||||||
"crossbeam-utils 0.8.1",
|
"crossbeam-utils",
|
||||||
"lazy_static",
|
"lazy_static",
|
||||||
"memoffset 0.6.1",
|
"memoffset",
|
||||||
"scopeguard",
|
"scopeguard",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "crossbeam-utils"
|
|
||||||
version = "0.7.2"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "c3c7c73a2d1e9fc0886a08b93e98eb643461230d5f1925e4036204d5f2e261a8"
|
|
||||||
dependencies = [
|
|
||||||
"autocfg 1.0.1",
|
|
||||||
"cfg-if 0.1.10",
|
|
||||||
"lazy_static",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "crossbeam-utils"
|
name = "crossbeam-utils"
|
||||||
version = "0.8.1"
|
version = "0.8.1"
|
||||||
@@ -573,9 +553,9 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "csv"
|
name = "csv"
|
||||||
version = "1.1.4"
|
version = "1.1.5"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "fc4666154fd004af3fd6f1da2e81a96fd5a81927fe8ddb6ecc79e2aa6e138b54"
|
checksum = "f9d58633299b24b515ac72a3f869f8b91306a3cec616a602843a383acd6f9e97"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"bstr",
|
"bstr",
|
||||||
"csv-core",
|
"csv-core",
|
||||||
@@ -779,11 +759,11 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "filetime"
|
name = "filetime"
|
||||||
version = "0.2.12"
|
version = "0.2.13"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "3ed85775dcc68644b5c950ac06a2b23768d3bc9390464151aaf27136998dcf9e"
|
checksum = "0c122a393ea57648015bf06fbd3d372378992e86b9ff5a7a497b076a28c79efe"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"cfg-if 0.1.10",
|
"cfg-if 1.0.0",
|
||||||
"libc",
|
"libc",
|
||||||
"redox_syscall",
|
"redox_syscall",
|
||||||
"winapi",
|
"winapi",
|
||||||
@@ -1009,9 +989,9 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "inline-c"
|
name = "inline-c"
|
||||||
version = "0.1.3"
|
version = "0.1.4"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "f3f35c2ef14070ed26ac0c6ff16e22d12b35bf1a6a97dcbd1a693b56aa87a61c"
|
checksum = "5db7d6323d3b700eec996bc5d60ffed2249f6bc63d88dec0681d2158115e5ed7"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"assert_cmd",
|
"assert_cmd",
|
||||||
"cc",
|
"cc",
|
||||||
@@ -1019,6 +999,7 @@ dependencies = [
|
|||||||
"lazy_static",
|
"lazy_static",
|
||||||
"predicates",
|
"predicates",
|
||||||
"regex",
|
"regex",
|
||||||
|
"rustc_version 0.3.0",
|
||||||
"target-lexicon",
|
"target-lexicon",
|
||||||
"tempfile",
|
"tempfile",
|
||||||
]
|
]
|
||||||
@@ -1081,9 +1062,9 @@ checksum = "dc6f3ad7b9d11a0c00842ff8de1b60ee58661048eb8049ed33c73594f359d7e6"
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "js-sys"
|
name = "js-sys"
|
||||||
version = "0.3.45"
|
version = "0.3.46"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "ca059e81d9486668f12d455a4ea6daa600bd408134cd17e3d3fb5a32d1f016f8"
|
checksum = "cf3d7383929f7c9c7c2d0fa596f325832df98c3704f2c60553080f7127a58175"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"wasm-bindgen",
|
"wasm-bindgen",
|
||||||
]
|
]
|
||||||
@@ -1102,9 +1083,9 @@ checksum = "3576a87f2ba00f6f106fdfcd16db1d698d648a26ad8e0573cad8537c3c362d2a"
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "libc"
|
name = "libc"
|
||||||
version = "0.2.80"
|
version = "0.2.81"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "4d58d1b70b004888f764dfbf6a26a3b0342a1632d33968e4a179d8011c760614"
|
checksum = "1482821306169ec4d07f6aca392a4681f66c75c9918aa49641a2595db64053cb"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "libffi"
|
name = "libffi"
|
||||||
@@ -1129,9 +1110,9 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "libloading"
|
name = "libloading"
|
||||||
version = "0.6.5"
|
version = "0.6.6"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "1090080fe06ec2648d0da3881d9453d97e71a45f00eb179af7fdd7e3f686fdb0"
|
checksum = "e9367bdfa836b7e3cf895867f7a570283444da90562980ec2263d6e1569b16bc"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"cfg-if 1.0.0",
|
"cfg-if 1.0.0",
|
||||||
"winapi",
|
"winapi",
|
||||||
@@ -1205,15 +1186,6 @@ dependencies = [
|
|||||||
"winapi",
|
"winapi",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "memoffset"
|
|
||||||
version = "0.5.6"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "043175f069eda7b85febe4a74abbaeff828d9f8b448515d3151a14a3542811aa"
|
|
||||||
dependencies = [
|
|
||||||
"autocfg 1.0.1",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "memoffset"
|
name = "memoffset"
|
||||||
version = "0.6.1"
|
version = "0.6.1"
|
||||||
@@ -1254,9 +1226,9 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "miow"
|
name = "miow"
|
||||||
version = "0.3.5"
|
version = "0.3.6"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "07b88fb9795d4d36d62a012dfbf49a8f5cf12751f36d31a9dbe66d528e58979e"
|
checksum = "5a33c1b55807fbed163481b5ba66db4b2fa6cde694a5027be10fb724206c5897"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"socket2",
|
"socket2",
|
||||||
"winapi",
|
"winapi",
|
||||||
@@ -1393,12 +1365,11 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "parking_lot_core"
|
name = "parking_lot_core"
|
||||||
version = "0.8.0"
|
version = "0.8.1"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "c361aa727dd08437f2f1447be8b59a33b0edd15e0fcee698f935613d9efbca9b"
|
checksum = "d7c6d9b8427445284a09c55be860a15855ab580a417ccad9da88f5a06787ced0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"cfg-if 0.1.10",
|
"cfg-if 1.0.0",
|
||||||
"cloudabi 0.1.0",
|
|
||||||
"instant",
|
"instant",
|
||||||
"libc",
|
"libc",
|
||||||
"redox_syscall",
|
"redox_syscall",
|
||||||
@@ -1667,7 +1638,7 @@ version = "0.1.3"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "7b75f676a1e053fc562eafbb47838d67c84801e38fc1ba459e8f180deabd5071"
|
checksum = "7b75f676a1e053fc562eafbb47838d67c84801e38fc1ba459e8f180deabd5071"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"cloudabi 0.0.3",
|
"cloudabi",
|
||||||
"fuchsia-cprng",
|
"fuchsia-cprng",
|
||||||
"libc",
|
"libc",
|
||||||
"rand_core 0.4.2",
|
"rand_core 0.4.2",
|
||||||
@@ -1734,7 +1705,7 @@ checksum = "9ab346ac5921dc62ffa9f89b7a773907511cdfa5490c572ae9be1be33e8afa4a"
|
|||||||
dependencies = [
|
dependencies = [
|
||||||
"crossbeam-channel",
|
"crossbeam-channel",
|
||||||
"crossbeam-deque",
|
"crossbeam-deque",
|
||||||
"crossbeam-utils 0.8.1",
|
"crossbeam-utils",
|
||||||
"lazy_static",
|
"lazy_static",
|
||||||
"num_cpus",
|
"num_cpus",
|
||||||
]
|
]
|
||||||
@@ -1843,14 +1814,14 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "rust-argon2"
|
name = "rust-argon2"
|
||||||
version = "0.8.2"
|
version = "0.8.3"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "9dab61250775933275e84053ac235621dfb739556d5c54a2f2e9313b7cf43a19"
|
checksum = "4b18820d944b33caa75a71378964ac46f58517c92b6ae5f762636247c09e78fb"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"base64",
|
"base64",
|
||||||
"blake2b_simd",
|
"blake2b_simd",
|
||||||
"constant_time_eq",
|
"constant_time_eq",
|
||||||
"crossbeam-utils 0.7.2",
|
"crossbeam-utils",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@@ -1995,9 +1966,9 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "serde"
|
name = "serde"
|
||||||
version = "1.0.117"
|
version = "1.0.118"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "b88fa983de7720629c9387e9f517353ed404164b1e482c970a90c1a4aaf7dc1a"
|
checksum = "06c64263859d87aa2eb554587e2d23183398d617427327cf2b3d0ed8c69e4800"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"serde_derive",
|
"serde_derive",
|
||||||
]
|
]
|
||||||
@@ -2023,9 +1994,9 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "serde_derive"
|
name = "serde_derive"
|
||||||
version = "1.0.117"
|
version = "1.0.118"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "cbd1ae72adb44aab48f325a02444a5fc079349a8d804c1fc922aed3f7454c74e"
|
checksum = "c84d3526699cd55261af4b941e4e725444df67aa4f9e6a3564f18030d12672df"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"proc-macro2",
|
"proc-macro2",
|
||||||
"quote",
|
"quote",
|
||||||
@@ -2034,9 +2005,9 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "serde_json"
|
name = "serde_json"
|
||||||
version = "1.0.59"
|
version = "1.0.60"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "dcac07dbffa1c65e7f816ab9eba78eb142c6d44410f4eeba1e26e4f5dfa56b95"
|
checksum = "1500e84d27fe482ed1dc791a56eddc2f230046a040fa908c08bda1d9fb615779"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"itoa",
|
"itoa",
|
||||||
"ryu",
|
"ryu",
|
||||||
@@ -2045,17 +2016,17 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "smallvec"
|
name = "smallvec"
|
||||||
version = "1.5.0"
|
version = "1.5.1"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "7acad6f34eb9e8a259d3283d1e8c1d34d7415943d4895f65cc73813c7396fc85"
|
checksum = "ae524f056d7d770e174287294f562e95044c68e88dec909a00d2094805db9d75"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "socket2"
|
name = "socket2"
|
||||||
version = "0.3.15"
|
version = "0.3.17"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "b1fa70dc5c8104ec096f4fe7ede7a221d35ae13dcd19ba1ad9a81d2cab9a1c44"
|
checksum = "2c29947abdee2a218277abeca306f25789c938e500ea5a9d4b12a5a504466902"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"cfg-if 0.1.10",
|
"cfg-if 1.0.0",
|
||||||
"libc",
|
"libc",
|
||||||
"redox_syscall",
|
"redox_syscall",
|
||||||
"winapi",
|
"winapi",
|
||||||
@@ -2081,9 +2052,9 @@ checksum = "6446ced80d6c486436db5c078dde11a9f73d42b57fb273121e160b84f63d894c"
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "structopt"
|
name = "structopt"
|
||||||
version = "0.3.20"
|
version = "0.3.21"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "126d630294ec449fae0b16f964e35bf3c74f940da9dca17ee9b905f7b3112eb8"
|
checksum = "5277acd7ee46e63e5168a80734c9f6ee81b1367a7d8772a2d765df2a3705d28c"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"clap",
|
"clap",
|
||||||
"lazy_static",
|
"lazy_static",
|
||||||
@@ -2092,9 +2063,9 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "structopt-derive"
|
name = "structopt-derive"
|
||||||
version = "0.4.13"
|
version = "0.4.14"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "65e51c492f9e23a220534971ff5afc14037289de430e3c83f9daf6a1b6ae91e8"
|
checksum = "5ba9cdfda491b814720b6b06e0cac513d922fc407582032e8706e9f137976f90"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"heck",
|
"heck",
|
||||||
"proc-macro-error",
|
"proc-macro-error",
|
||||||
@@ -2111,9 +2082,9 @@ checksum = "343f3f510c2915908f155e94f17220b19ccfacf2a64a2a5d8004f2c3e311e7fd"
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "syn"
|
name = "syn"
|
||||||
version = "1.0.51"
|
version = "1.0.54"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "3b4f34193997d92804d359ed09953e25d5138df6bcc055a71bf68ee89fdf9223"
|
checksum = "9a2af957a63d6bd42255c359c93d9bfdb97076bd3b820897ce55ffbfbf107f44"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"proc-macro2",
|
"proc-macro2",
|
||||||
"quote",
|
"quote",
|
||||||
@@ -2382,19 +2353,19 @@ checksum = "1a143597ca7c7793eff794def352d41792a93c481eb1042423ff7ff72ba2c31f"
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "wasm-bindgen"
|
name = "wasm-bindgen"
|
||||||
version = "0.2.68"
|
version = "0.2.69"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "1ac64ead5ea5f05873d7c12b545865ca2b8d28adfc50a49b84770a3a97265d42"
|
checksum = "3cd364751395ca0f68cafb17666eee36b63077fb5ecd972bbcd74c90c4bf736e"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"cfg-if 0.1.10",
|
"cfg-if 1.0.0",
|
||||||
"wasm-bindgen-macro",
|
"wasm-bindgen-macro",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "wasm-bindgen-backend"
|
name = "wasm-bindgen-backend"
|
||||||
version = "0.2.68"
|
version = "0.2.69"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "f22b422e2a757c35a73774860af8e112bff612ce6cb604224e8e47641a9e4f68"
|
checksum = "1114f89ab1f4106e5b55e688b828c0ab0ea593a1ea7c094b141b14cbaaec2d62"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"bumpalo",
|
"bumpalo",
|
||||||
"lazy_static",
|
"lazy_static",
|
||||||
@@ -2407,9 +2378,9 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "wasm-bindgen-macro"
|
name = "wasm-bindgen-macro"
|
||||||
version = "0.2.68"
|
version = "0.2.69"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "6b13312a745c08c469f0b292dd2fcd6411dba5f7160f593da6ef69b64e407038"
|
checksum = "7a6ac8995ead1f084a8dea1e65f194d0973800c7f571f6edd70adf06ecf77084"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"quote",
|
"quote",
|
||||||
"wasm-bindgen-macro-support",
|
"wasm-bindgen-macro-support",
|
||||||
@@ -2417,9 +2388,9 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "wasm-bindgen-macro-support"
|
name = "wasm-bindgen-macro-support"
|
||||||
version = "0.2.68"
|
version = "0.2.69"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "f249f06ef7ee334cc3b8ff031bfc11ec99d00f34d86da7498396dc1e3b1498fe"
|
checksum = "b5a48c72f299d80557c7c62e37e7225369ecc0c963964059509fbafe917c7549"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"proc-macro2",
|
"proc-macro2",
|
||||||
"quote",
|
"quote",
|
||||||
@@ -2430,13 +2401,13 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "wasm-bindgen-shared"
|
name = "wasm-bindgen-shared"
|
||||||
version = "0.2.68"
|
version = "0.2.69"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "1d649a3145108d7d3fbcde896a468d1bd636791823c9921135218ad89be08307"
|
checksum = "7e7811dd7f9398f14cc76efd356f98f03aa30419dea46aa810d71e819fc97158"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "wasmer"
|
name = "wasmer"
|
||||||
version = "1.0.0-alpha5"
|
version = "1.0.0-beta1"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"anyhow",
|
"anyhow",
|
||||||
"cfg-if 0.1.10",
|
"cfg-if 0.1.10",
|
||||||
@@ -2462,7 +2433,7 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "wasmer-c-api"
|
name = "wasmer-c-api"
|
||||||
version = "1.0.0-alpha5"
|
version = "1.0.0-beta1"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"cbindgen",
|
"cbindgen",
|
||||||
"cfg-if 1.0.0",
|
"cfg-if 1.0.0",
|
||||||
@@ -2490,7 +2461,7 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "wasmer-cache"
|
name = "wasmer-cache"
|
||||||
version = "1.0.0-alpha5"
|
version = "1.0.0-beta1"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"blake3",
|
"blake3",
|
||||||
"hex",
|
"hex",
|
||||||
@@ -2501,7 +2472,7 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "wasmer-cli"
|
name = "wasmer-cli"
|
||||||
version = "1.0.0-alpha5"
|
version = "1.0.0-beta1"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"anyhow",
|
"anyhow",
|
||||||
"atty",
|
"atty",
|
||||||
@@ -2533,7 +2504,7 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "wasmer-compiler"
|
name = "wasmer-compiler"
|
||||||
version = "1.0.0-alpha5"
|
version = "1.0.0-beta1"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"enumset",
|
"enumset",
|
||||||
"hashbrown 0.9.1",
|
"hashbrown 0.9.1",
|
||||||
@@ -2550,7 +2521,7 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "wasmer-compiler-cranelift"
|
name = "wasmer-compiler-cranelift"
|
||||||
version = "1.0.0-alpha5"
|
version = "1.0.0-beta1"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"cranelift-codegen 0.67.0",
|
"cranelift-codegen 0.67.0",
|
||||||
"cranelift-codegen 0.68.0",
|
"cranelift-codegen 0.68.0",
|
||||||
@@ -2571,7 +2542,7 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "wasmer-compiler-llvm"
|
name = "wasmer-compiler-llvm"
|
||||||
version = "1.0.0-alpha5"
|
version = "1.0.0-beta1"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"byteorder",
|
"byteorder",
|
||||||
"cc",
|
"cc",
|
||||||
@@ -2593,7 +2564,7 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "wasmer-compiler-singlepass"
|
name = "wasmer-compiler-singlepass"
|
||||||
version = "1.0.0-alpha5"
|
version = "1.0.0-beta1"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"byteorder",
|
"byteorder",
|
||||||
"dynasm",
|
"dynasm",
|
||||||
@@ -2604,6 +2575,7 @@ dependencies = [
|
|||||||
"rayon",
|
"rayon",
|
||||||
"serde",
|
"serde",
|
||||||
"smallvec",
|
"smallvec",
|
||||||
|
"target-lexicon",
|
||||||
"wasmer-compiler",
|
"wasmer-compiler",
|
||||||
"wasmer-types",
|
"wasmer-types",
|
||||||
"wasmer-vm",
|
"wasmer-vm",
|
||||||
@@ -2611,7 +2583,7 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "wasmer-derive"
|
name = "wasmer-derive"
|
||||||
version = "1.0.0-alpha5"
|
version = "1.0.0-beta1"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"compiletest_rs",
|
"compiletest_rs",
|
||||||
"proc-macro-error",
|
"proc-macro-error",
|
||||||
@@ -2623,7 +2595,7 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "wasmer-emscripten"
|
name = "wasmer-emscripten"
|
||||||
version = "1.0.0-alpha5"
|
version = "1.0.0-beta1"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"byteorder",
|
"byteorder",
|
||||||
"getrandom 0.2.0",
|
"getrandom 0.2.0",
|
||||||
@@ -2636,7 +2608,7 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "wasmer-engine"
|
name = "wasmer-engine"
|
||||||
version = "1.0.0-alpha5"
|
version = "1.0.0-beta1"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"backtrace",
|
"backtrace",
|
||||||
"bincode",
|
"bincode",
|
||||||
@@ -2654,7 +2626,7 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "wasmer-engine-dummy"
|
name = "wasmer-engine-dummy"
|
||||||
version = "1.0.0-alpha5"
|
version = "1.0.0-beta1"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"bincode",
|
"bincode",
|
||||||
"serde",
|
"serde",
|
||||||
@@ -2667,7 +2639,7 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "wasmer-engine-jit"
|
name = "wasmer-engine-jit"
|
||||||
version = "1.0.0-alpha5"
|
version = "1.0.0-beta1"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"bincode",
|
"bincode",
|
||||||
"cfg-if 0.1.10",
|
"cfg-if 0.1.10",
|
||||||
@@ -2683,7 +2655,7 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "wasmer-engine-native"
|
name = "wasmer-engine-native"
|
||||||
version = "1.0.0-alpha5"
|
version = "1.0.0-beta1"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"bincode",
|
"bincode",
|
||||||
"cfg-if 0.1.10",
|
"cfg-if 0.1.10",
|
||||||
@@ -2702,7 +2674,7 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "wasmer-engine-object-file"
|
name = "wasmer-engine-object-file"
|
||||||
version = "1.0.0-alpha5"
|
version = "1.0.0-beta1"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"bincode",
|
"bincode",
|
||||||
"cfg-if 0.1.10",
|
"cfg-if 0.1.10",
|
||||||
@@ -2720,15 +2692,24 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "wasmer-integration-tests-cli"
|
name = "wasmer-integration-tests-cli"
|
||||||
version = "1.0.0-alpha5"
|
version = "1.0.0-beta1"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"anyhow",
|
"anyhow",
|
||||||
"tempfile",
|
"tempfile",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "wasmer-middlewares"
|
||||||
|
version = "1.0.0-beta1"
|
||||||
|
dependencies = [
|
||||||
|
"wasmer",
|
||||||
|
"wasmer-types",
|
||||||
|
"wasmer-vm",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "wasmer-object"
|
name = "wasmer-object"
|
||||||
version = "1.0.0-alpha5"
|
version = "1.0.0-beta1"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"object",
|
"object",
|
||||||
"thiserror",
|
"thiserror",
|
||||||
@@ -2738,7 +2719,7 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "wasmer-types"
|
name = "wasmer-types"
|
||||||
version = "1.0.0-alpha5"
|
version = "1.0.0-beta1"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"cranelift-entity 0.68.0",
|
"cranelift-entity 0.68.0",
|
||||||
"serde",
|
"serde",
|
||||||
@@ -2746,14 +2727,14 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "wasmer-vm"
|
name = "wasmer-vm"
|
||||||
version = "1.0.0-alpha5"
|
version = "1.0.0-beta1"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"backtrace",
|
"backtrace",
|
||||||
"cc",
|
"cc",
|
||||||
"cfg-if 0.1.10",
|
"cfg-if 0.1.10",
|
||||||
"indexmap",
|
"indexmap",
|
||||||
"libc",
|
"libc",
|
||||||
"memoffset 0.5.6",
|
"memoffset",
|
||||||
"more-asserts",
|
"more-asserts",
|
||||||
"region",
|
"region",
|
||||||
"serde",
|
"serde",
|
||||||
@@ -2764,7 +2745,7 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "wasmer-wasi"
|
name = "wasmer-wasi"
|
||||||
version = "1.0.0-alpha5"
|
version = "1.0.0-beta1"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"bincode",
|
"bincode",
|
||||||
"byteorder",
|
"byteorder",
|
||||||
@@ -2782,7 +2763,7 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "wasmer-wasi-experimental-io-devices"
|
name = "wasmer-wasi-experimental-io-devices"
|
||||||
version = "1.0.0-alpha5"
|
version = "1.0.0-beta1"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"minifb",
|
"minifb",
|
||||||
"ref_thread_local",
|
"ref_thread_local",
|
||||||
@@ -2794,7 +2775,7 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "wasmer-wast"
|
name = "wasmer-wast"
|
||||||
version = "1.0.0-alpha5"
|
version = "1.0.0-beta1"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"anyhow",
|
"anyhow",
|
||||||
"serde",
|
"serde",
|
||||||
@@ -2803,12 +2784,12 @@ dependencies = [
|
|||||||
"typetag",
|
"typetag",
|
||||||
"wasmer",
|
"wasmer",
|
||||||
"wasmer-wasi",
|
"wasmer-wasi",
|
||||||
"wast 17.0.0",
|
"wast 24.0.0",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "wasmer-workspace"
|
name = "wasmer-workspace"
|
||||||
version = "1.0.0-alpha5"
|
version = "1.0.0-beta1"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"anyhow",
|
"anyhow",
|
||||||
"blake3",
|
"blake3",
|
||||||
@@ -2832,6 +2813,7 @@ dependencies = [
|
|||||||
"wasmer-engine-jit",
|
"wasmer-engine-jit",
|
||||||
"wasmer-engine-native",
|
"wasmer-engine-native",
|
||||||
"wasmer-engine-object-file",
|
"wasmer-engine-object-file",
|
||||||
|
"wasmer-middlewares",
|
||||||
"wasmer-types",
|
"wasmer-types",
|
||||||
"wasmer-wasi",
|
"wasmer-wasi",
|
||||||
"wasmer-wast",
|
"wasmer-wast",
|
||||||
@@ -2845,29 +2827,29 @@ checksum = "87cc2fe6350834b4e528ba0901e7aa405d78b89dc1fa3145359eb4de0e323fcf"
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "wast"
|
name = "wast"
|
||||||
version = "17.0.0"
|
version = "24.0.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "5a0e1c36b928fca33dbaf96235188f5fad22ee87100e26cc606bd0fbabdf1932"
|
checksum = "6ff1e3bd3ad0b2ee7784add89c30dc96b89a54b43e5d6d95d774eda1863b3500"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"leb128",
|
"leb128",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "wast"
|
name = "wast"
|
||||||
version = "27.0.0"
|
version = "28.0.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "c2c3ef5f6a72dffa44c24d5811123f704e18a1dbc83637d347b1852b41d3835c"
|
checksum = "9c0586061bfacc035034672c8d760802b428ab4c80a92e2a392425c516df9be1"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"leb128",
|
"leb128",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "wat"
|
name = "wat"
|
||||||
version = "1.0.28"
|
version = "1.0.29"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "835cf59c907f67e2bbc20f50157e08f35006fe2a8444d8ec9f5683e22f937045"
|
checksum = "c06d55b5ec4f9d9396fa99abaafa0688597395e57827dffd89731412ae90c9bf"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"wast 27.0.0",
|
"wast 28.0.0",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@@ -2942,9 +2924,9 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "web-sys"
|
name = "web-sys"
|
||||||
version = "0.3.45"
|
version = "0.3.46"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "4bf6ef87ad7ae8008e15a355ce696bed26012b7caa21605188cfd8214ab51e2d"
|
checksum = "222b1ef9334f92a21d3fb53dc3fd80f30836959a90f9274a626d7e06315ba3c3"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"js-sys",
|
"js-sys",
|
||||||
"wasm-bindgen",
|
"wasm-bindgen",
|
||||||
|
|||||||
43
Cargo.toml
43
Cargo.toml
@@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "wasmer-workspace"
|
name = "wasmer-workspace"
|
||||||
version = "1.0.0-alpha5"
|
version = "1.0.0-beta1"
|
||||||
description = "Wasmer workspace"
|
description = "Wasmer workspace"
|
||||||
authors = ["Wasmer Engineering Team <engineering@wasmer.io>"]
|
authors = ["Wasmer Engineering Team <engineering@wasmer.io>"]
|
||||||
repository = "https://github.com/wasmerio/wasmer"
|
repository = "https://github.com/wasmerio/wasmer"
|
||||||
@@ -10,20 +10,21 @@ publish = false
|
|||||||
autoexamples = false
|
autoexamples = false
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
wasmer = { version = "1.0.0-alpha5", path = "lib/api", default-features = false }
|
wasmer = { version = "1.0.0-beta1", path = "lib/api", default-features = false }
|
||||||
wasmer-compiler = { version = "1.0.0-alpha5", path = "lib/compiler" }
|
wasmer-compiler = { version = "1.0.0-beta1", path = "lib/compiler" }
|
||||||
wasmer-compiler-cranelift = { version = "1.0.0-alpha5", path = "lib/compiler-cranelift", optional = true }
|
wasmer-compiler-cranelift = { version = "1.0.0-beta1", path = "lib/compiler-cranelift", optional = true }
|
||||||
wasmer-compiler-singlepass = { version = "1.0.0-alpha5", path = "lib/compiler-singlepass", optional = true }
|
wasmer-compiler-singlepass = { version = "1.0.0-beta1", path = "lib/compiler-singlepass", optional = true }
|
||||||
wasmer-compiler-llvm = { version = "1.0.0-alpha5", path = "lib/compiler-llvm", optional = true }
|
wasmer-compiler-llvm = { version = "1.0.0-beta1", path = "lib/compiler-llvm", optional = true }
|
||||||
wasmer-emscripten = { version = "1.0.0-alpha5", path = "lib/emscripten", optional = true }
|
wasmer-emscripten = { version = "1.0.0-beta1", path = "lib/emscripten", optional = true }
|
||||||
wasmer-engine = { version = "1.0.0-alpha5", path = "lib/engine" }
|
wasmer-engine = { version = "1.0.0-beta1", path = "lib/engine" }
|
||||||
wasmer-engine-jit = { version = "1.0.0-alpha5", path = "lib/engine-jit", optional = true }
|
wasmer-engine-jit = { version = "1.0.0-beta1", path = "lib/engine-jit", optional = true }
|
||||||
wasmer-engine-native = { version = "1.0.0-alpha5", path = "lib/engine-native", optional = true }
|
wasmer-engine-native = { version = "1.0.0-beta1", path = "lib/engine-native", optional = true }
|
||||||
wasmer-engine-object-file = { version = "1.0.0-alpha5", path = "lib/engine-object-file", optional = true }
|
wasmer-engine-object-file = { version = "1.0.0-beta1", path = "lib/engine-object-file", optional = true }
|
||||||
wasmer-wasi = { version = "1.0.0-alpha5", path = "lib/wasi", optional = true }
|
wasmer-wasi = { version = "1.0.0-beta1", path = "lib/wasi", optional = true }
|
||||||
wasmer-wast = { version = "1.0.0-alpha5", path = "tests/lib/wast", optional = true }
|
wasmer-wast = { version = "1.0.0-beta1", path = "tests/lib/wast", optional = true }
|
||||||
wasmer-cache = { version = "1.0.0-alpha5", path = "lib/cache", optional = true }
|
wasmer-cache = { version = "1.0.0-beta1", path = "lib/cache", optional = true }
|
||||||
wasmer-types = { version = "1.0.0-alpha5", path = "lib/wasmer-types" }
|
wasmer-types = { version = "1.0.0-beta1", path = "lib/wasmer-types" }
|
||||||
|
wasmer-middlewares = { version = "1.0.0-beta1", path = "lib/middlewares", optional = true }
|
||||||
cfg-if = "1.0"
|
cfg-if = "1.0"
|
||||||
|
|
||||||
[workspace]
|
[workspace]
|
||||||
@@ -81,6 +82,7 @@ default = [
|
|||||||
"cache",
|
"cache",
|
||||||
"wasi",
|
"wasi",
|
||||||
"emscripten",
|
"emscripten",
|
||||||
|
"middlewares",
|
||||||
]
|
]
|
||||||
engine = []
|
engine = []
|
||||||
jit = [
|
jit = [
|
||||||
@@ -119,6 +121,7 @@ llvm = [
|
|||||||
"wasmer-compiler-llvm",
|
"wasmer-compiler-llvm",
|
||||||
"compiler",
|
"compiler",
|
||||||
]
|
]
|
||||||
|
middlewares = ["wasmer-middlewares"]
|
||||||
|
|
||||||
# Testing features
|
# Testing features
|
||||||
test-singlepass = [
|
test-singlepass = [
|
||||||
@@ -252,3 +255,13 @@ required-features = ["cranelift"]
|
|||||||
name = "hello-world"
|
name = "hello-world"
|
||||||
path = "examples/hello_world.rs"
|
path = "examples/hello_world.rs"
|
||||||
required-features = ["cranelift"]
|
required-features = ["cranelift"]
|
||||||
|
|
||||||
|
[[example]]
|
||||||
|
name = "metering"
|
||||||
|
path = "examples/metering.rs"
|
||||||
|
required-features = ["cranelift"]
|
||||||
|
|
||||||
|
[[example]]
|
||||||
|
name = "imports-exports"
|
||||||
|
path = "examples/imports_exports.rs"
|
||||||
|
required-features = ["cranelift"]
|
||||||
|
|||||||
100
Makefile
100
Makefile
@@ -44,15 +44,29 @@ ifeq ($(ARCH), x86_64)
|
|||||||
endif
|
endif
|
||||||
endif
|
endif
|
||||||
|
|
||||||
ifeq ($(ARCH), aarch64)
|
# If it's an aarch64/arm64 chip
|
||||||
|
# Using filter as a logical OR
|
||||||
|
# https://stackoverflow.com/questions/7656425/makefile-ifeq-logical-or
|
||||||
|
use_system_ffi =
|
||||||
|
ifneq (,$(filter $(ARCH),aarch64 arm64))
|
||||||
test_compilers_engines += cranelift-jit
|
test_compilers_engines += cranelift-jit
|
||||||
ifneq (, $(findstring llvm,$(compilers)))
|
ifneq (, $(findstring llvm,$(compilers)))
|
||||||
test_compilers_engines += llvm-native
|
test_compilers_engines += llvm-native
|
||||||
endif
|
endif
|
||||||
|
# if we are in macos arm64, we use the system libffi for the capi
|
||||||
|
ifeq ($(UNAME_S), Darwin)
|
||||||
|
use_system_ffi = yes
|
||||||
|
endif
|
||||||
endif
|
endif
|
||||||
|
|
||||||
ifeq ($(ARCH), arm64)
|
# if the user has set the `WASMER_CAPI_USE_SYSTEM_LIBFFI` var to 1 also
|
||||||
test_compilers_engines += cranelift-jit
|
# use the system libffi.
|
||||||
|
ifeq ($(WASMER_CAPI_USE_SYSTEM_LIBFFI), 1)
|
||||||
|
use_system_ffi = yes
|
||||||
|
endif
|
||||||
|
|
||||||
|
ifdef use_system_ffi
|
||||||
|
capi_default_features := --features system-libffi
|
||||||
endif
|
endif
|
||||||
|
|
||||||
compilers := $(filter-out ,$(compilers))
|
compilers := $(filter-out ,$(compilers))
|
||||||
@@ -110,55 +124,55 @@ build-capi: build-capi-cranelift
|
|||||||
|
|
||||||
build-capi-singlepass:
|
build-capi-singlepass:
|
||||||
cargo build --manifest-path lib/c-api/Cargo.toml --release \
|
cargo build --manifest-path lib/c-api/Cargo.toml --release \
|
||||||
--no-default-features --features deprecated,wat,jit,native,object-file,singlepass,wasi
|
--no-default-features --features deprecated,wat,jit,native,object-file,singlepass,wasi $(capi_default_features)
|
||||||
|
|
||||||
build-capi-singlepass-jit:
|
build-capi-singlepass-jit:
|
||||||
cargo build --manifest-path lib/c-api/Cargo.toml --release \
|
cargo build --manifest-path lib/c-api/Cargo.toml --release \
|
||||||
--no-default-features --features deprecated,wat,jit,singlepass,wasi
|
--no-default-features --features deprecated,wat,jit,singlepass,wasi $(capi_default_features)
|
||||||
|
|
||||||
build-capi-singlepass-native:
|
build-capi-singlepass-native:
|
||||||
cargo build --manifest-path lib/c-api/Cargo.toml --release \
|
cargo build --manifest-path lib/c-api/Cargo.toml --release \
|
||||||
--no-default-features --features deprecated,wat,native,singlepass,wasi
|
--no-default-features --features deprecated,wat,native,singlepass,wasi $(capi_default_features)
|
||||||
|
|
||||||
build-capi-singlepass-object-file:
|
build-capi-singlepass-object-file:
|
||||||
cargo build --manifest-path lib/c-api/Cargo.toml --release \
|
cargo build --manifest-path lib/c-api/Cargo.toml --release \
|
||||||
--no-default-features --features deprecated,wat,object-file,singlepass,wasi
|
--no-default-features --features deprecated,wat,object-file,singlepass,wasi $(capi_default_features)
|
||||||
|
|
||||||
build-capi-cranelift:
|
build-capi-cranelift:
|
||||||
cargo build --manifest-path lib/c-api/Cargo.toml --release \
|
cargo build --manifest-path lib/c-api/Cargo.toml --release \
|
||||||
--no-default-features --features deprecated,wat,jit,native,object-file,cranelift,wasi
|
--no-default-features --features deprecated,wat,jit,native,object-file,cranelift,wasi $(capi_default_features)
|
||||||
|
|
||||||
build-capi-cranelift-jit:
|
|
||||||
cargo build --manifest-path lib/c-api/Cargo.toml --release \
|
|
||||||
--no-default-features --features deprecated,wat,jit,cranelift,wasi
|
|
||||||
|
|
||||||
build-capi-cranelift-native:
|
|
||||||
cargo build --manifest-path lib/c-api/Cargo.toml --release \
|
|
||||||
--no-default-features --features deprecated,wat,native,cranelift,wasi
|
|
||||||
|
|
||||||
build-capi-cranelift-object-file:
|
|
||||||
cargo build --manifest-path lib/c-api/Cargo.toml --release \
|
|
||||||
--no-default-features --features deprecated,wat,native,object-file,cranelift,wasi
|
|
||||||
|
|
||||||
build-capi-cranelift-system-libffi:
|
build-capi-cranelift-system-libffi:
|
||||||
cargo build --manifest-path lib/c-api/Cargo.toml --release \
|
cargo build --manifest-path lib/c-api/Cargo.toml --release \
|
||||||
--no-default-features --features deprecated,wat,jit,native,object-file,cranelift,wasi,system-libffi
|
--no-default-features --features deprecated,wat,jit,native,object-file,cranelift,wasi,system-libffi $(capi_default_features)
|
||||||
|
|
||||||
|
build-capi-cranelift-jit:
|
||||||
|
cargo build --manifest-path lib/c-api/Cargo.toml --release \
|
||||||
|
--no-default-features --features deprecated,wat,jit,cranelift,wasi $(capi_default_features)
|
||||||
|
|
||||||
|
build-capi-cranelift-native:
|
||||||
|
cargo build --manifest-path lib/c-api/Cargo.toml --release \
|
||||||
|
--no-default-features --features deprecated,wat,native,cranelift,wasi $(capi_default_features)
|
||||||
|
|
||||||
|
build-capi-cranelift-object-file:
|
||||||
|
cargo build --manifest-path lib/c-api/Cargo.toml --release \
|
||||||
|
--no-default-features --features deprecated,wat,native,object-file,cranelift,wasi $(capi_default_features)
|
||||||
|
|
||||||
build-capi-llvm:
|
build-capi-llvm:
|
||||||
cargo build --manifest-path lib/c-api/Cargo.toml --release \
|
cargo build --manifest-path lib/c-api/Cargo.toml --release \
|
||||||
--no-default-features --features deprecated,wat,jit,native,object-file,llvm,wasi
|
--no-default-features --features deprecated,wat,jit,native,object-file,llvm,wasi $(capi_default_features)
|
||||||
|
|
||||||
build-capi-llvm-jit:
|
build-capi-llvm-jit:
|
||||||
cargo build --manifest-path lib/c-api/Cargo.toml --release \
|
cargo build --manifest-path lib/c-api/Cargo.toml --release \
|
||||||
--no-default-features --features deprecated,wat,jit,llvm,wasi
|
--no-default-features --features deprecated,wat,jit,llvm,wasi $(capi_default_features)
|
||||||
|
|
||||||
build-capi-llvm-native:
|
build-capi-llvm-native:
|
||||||
cargo build --manifest-path lib/c-api/Cargo.toml --release \
|
cargo build --manifest-path lib/c-api/Cargo.toml --release \
|
||||||
--no-default-features --features deprecated,wat,native,llvm,wasi
|
--no-default-features --features deprecated,wat,native,llvm,wasi $(capi_default_features)
|
||||||
|
|
||||||
build-capi-llvm-object-file:
|
build-capi-llvm-object-file:
|
||||||
cargo build --manifest-path lib/c-api/Cargo.toml --release \
|
cargo build --manifest-path lib/c-api/Cargo.toml --release \
|
||||||
--no-default-features --features deprecated,wat,object-file,llvm,wasi
|
--no-default-features --features deprecated,wat,object-file,llvm,wasi $(capi_default_features)
|
||||||
|
|
||||||
# Headless (we include the minimal to be able to run)
|
# Headless (we include the minimal to be able to run)
|
||||||
|
|
||||||
@@ -221,33 +235,33 @@ test-packages:
|
|||||||
|
|
||||||
# The test-capi rules depend on the build-capi rules to build the .a files to
|
# The test-capi rules depend on the build-capi rules to build the .a files to
|
||||||
# link the tests against. cargo test doesn't know that the tests will be running
|
# link the tests against. cargo test doesn't know that the tests will be running
|
||||||
# cmake + make to build programs whose dependencies cargo isn't aware of.
|
test-capi: $(foreach compiler_engine,$(test_compilers_engines),test-capi-$(compiler_engine))
|
||||||
|
|
||||||
test-capi: $(foreach compiler_engine,$(test_compilers_engines),test-capi-$(compiler_engine)) #$(if $(findstring cranelift-jit,$(test_compilers_engines)),test-capi-cranelift-jit-system-libffi)
|
test-capi-singlepass-jit: build-capi-singlepass-jit test-capi-tests
|
||||||
|
|
||||||
test-capi-singlepass-jit: build-capi-singlepass-jit
|
|
||||||
cargo test --manifest-path lib/c-api/Cargo.toml --release \
|
cargo test --manifest-path lib/c-api/Cargo.toml --release \
|
||||||
--no-default-features --features deprecated,wat,jit,singlepass,wasi -- --nocapture
|
--no-default-features --features deprecated,wat,jit,singlepass,wasi $(capi_default_features) -- --nocapture
|
||||||
|
|
||||||
test-capi-cranelift-jit: build-capi-cranelift-jit
|
test-capi-cranelift-jit: build-capi-cranelift-jit test-capi-tests
|
||||||
cargo test --manifest-path lib/c-api/Cargo.toml --release \
|
cargo test --manifest-path lib/c-api/Cargo.toml --release \
|
||||||
--no-default-features --features deprecated,wat,jit,cranelift,wasi -- --nocapture
|
--no-default-features --features deprecated,wat,jit,cranelift,wasi $(capi_default_features) -- --nocapture
|
||||||
|
|
||||||
test-capi-cranelift-native: build-capi-cranelift-native
|
test-capi-cranelift-native: build-capi-cranelift-native test-capi-tests
|
||||||
cargo test --manifest-path lib/c-api/Cargo.toml --release \
|
cargo test --manifest-path lib/c-api/Cargo.toml --release \
|
||||||
--no-default-features --features deprecated,wat,native,cranelift,wasi -- --nocapture
|
--no-default-features --features deprecated,wat,native,cranelift,wasi $(capi_default_features) -- --nocapture
|
||||||
|
|
||||||
test-capi-cranelift-jit-system-libffi:
|
|
||||||
cargo test --manifest-path lib/c-api/Cargo.toml --release \
|
|
||||||
--no-default-features --features deprecated,wat,jit,cranelift,wasi,system-libffi -- --nocapture
|
|
||||||
|
|
||||||
test-capi-llvm-jit:
|
test-capi-llvm-jit:
|
||||||
cargo test --manifest-path lib/c-api/Cargo.toml --release \
|
cargo test --manifest-path lib/c-api/Cargo.toml --release \
|
||||||
--no-default-features --features deprecated,wat,jit,llvm,wasi -- --nocapture
|
--no-default-features --features deprecated,wat,jit,llvm,wasi $(capi_default_features) -- --nocapture
|
||||||
|
|
||||||
test-capi-llvm-native:
|
test-capi-llvm-native:
|
||||||
cargo test --manifest-path lib/c-api/Cargo.toml --release \
|
cargo test --manifest-path lib/c-api/Cargo.toml --release \
|
||||||
--no-default-features --features deprecated,wat,native,llvm,wasi -- --nocapture
|
--no-default-features --features deprecated,wat,native,llvm,wasi $(capi_default_features) -- --nocapture
|
||||||
|
|
||||||
|
test-capi-tests: package-capi
|
||||||
|
# Test the Wasmer C API tests for C
|
||||||
|
cd lib/c-api/tests; WASMER_DIR=`pwd`/../../../package make test
|
||||||
|
# Test the Wasmer C API examples
|
||||||
|
cd lib/c-api/examples; WASMER_DIR=`pwd`/../../../package make run
|
||||||
|
|
||||||
test-wasi-unit:
|
test-wasi-unit:
|
||||||
cargo test --manifest-path lib/wasi/Cargo.toml --release
|
cargo test --manifest-path lib/wasi/Cargo.toml --release
|
||||||
@@ -285,8 +299,6 @@ else
|
|||||||
cp target/release/wasmer package/bin/
|
cp target/release/wasmer package/bin/
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
package-capi:
|
package-capi:
|
||||||
mkdir -p "package/include"
|
mkdir -p "package/include"
|
||||||
mkdir -p "package/lib"
|
mkdir -p "package/lib"
|
||||||
@@ -299,6 +311,8 @@ ifeq ($(OS), Windows_NT)
|
|||||||
cp target/release/wasmer_c_api.lib package/lib
|
cp target/release/wasmer_c_api.lib package/lib
|
||||||
else
|
else
|
||||||
ifeq ($(UNAME_S), Darwin)
|
ifeq ($(UNAME_S), Darwin)
|
||||||
|
# For some reason in macOS arm64 there are issues if we copy constantly in the install_name_tool util
|
||||||
|
rm -f package/lib/libwasmer.dylib
|
||||||
cp target/release/libwasmer_c_api.dylib package/lib/libwasmer.dylib
|
cp target/release/libwasmer_c_api.dylib package/lib/libwasmer.dylib
|
||||||
cp target/release/libwasmer_c_api.a package/lib/libwasmer.a
|
cp target/release/libwasmer_c_api.a package/lib/libwasmer.a
|
||||||
# Fix the rpath for the dylib
|
# Fix the rpath for the dylib
|
||||||
@@ -341,7 +355,7 @@ endif
|
|||||||
update-testsuite:
|
update-testsuite:
|
||||||
git subtree pull --prefix tests/wast/spec https://github.com/WebAssembly/testsuite.git master --squash
|
git subtree pull --prefix tests/wast/spec https://github.com/WebAssembly/testsuite.git master --squash
|
||||||
|
|
||||||
RUSTFLAGS := "-D dead-code -D nonstandard-style -D unused-imports -D unused-mut -D unused-variables -D unused-unsafe -D unreachable-patterns -D bad-style -D improper-ctypes -D unused-allocation -D unused-comparisons -D while-true -D unconditional-recursion -D bare-trait-objects" # TODO: add `-D missing-docs`
|
RUSTFLAGS := "-D dead-code -D nonstandard-style -D unused-imports -D unused-mut -D unused-variables -D unused-unsafe -D unreachable-patterns -D bad-style -D improper-ctypes -D unused-allocation -D unused-comparisons -D while-true -D unconditional-recursion -D bare-trait-objects -D function_item_references" # TODO: add `-D missing-docs`
|
||||||
lint:
|
lint:
|
||||||
cargo fmt --all -- --check
|
cargo fmt --all -- --check
|
||||||
RUSTFLAGS=${RUSTFLAGS} cargo clippy $(compiler_features)
|
RUSTFLAGS=${RUSTFLAGS} cargo clippy $(compiler_features)
|
||||||
|
|||||||
@@ -150,19 +150,19 @@ pub fn run_basic_dynamic_function(store: &Store, compiler_name: &str, c: &mut Cr
|
|||||||
fn run_static_benchmarks(c: &mut Criterion) {
|
fn run_static_benchmarks(c: &mut Criterion) {
|
||||||
#[cfg(feature = "llvm")]
|
#[cfg(feature = "llvm")]
|
||||||
{
|
{
|
||||||
let store = Store::new(&JIT::new(&wasmer_compiler_llvm::LLVM::new()).engine());
|
let store = Store::new(&JIT::new(wasmer_compiler_llvm::LLVM::new()).engine());
|
||||||
run_basic_static_function(&store, "llvm", c);
|
run_basic_static_function(&store, "llvm", c);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(feature = "cranelift")]
|
#[cfg(feature = "cranelift")]
|
||||||
{
|
{
|
||||||
let store = Store::new(&JIT::new(&wasmer_compiler_cranelift::Cranelift::new()).engine());
|
let store = Store::new(&JIT::new(wasmer_compiler_cranelift::Cranelift::new()).engine());
|
||||||
run_basic_static_function(&store, "cranelift", c);
|
run_basic_static_function(&store, "cranelift", c);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(feature = "singlepass")]
|
#[cfg(feature = "singlepass")]
|
||||||
{
|
{
|
||||||
let store = Store::new(&JIT::new(&wasmer_compiler_singlepass::Singlepass::new()).engine());
|
let store = Store::new(&JIT::new(wasmer_compiler_singlepass::Singlepass::new()).engine());
|
||||||
run_basic_static_function(&store, "singlepass", c);
|
run_basic_static_function(&store, "singlepass", c);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -170,19 +170,19 @@ fn run_static_benchmarks(c: &mut Criterion) {
|
|||||||
fn run_dynamic_benchmarks(c: &mut Criterion) {
|
fn run_dynamic_benchmarks(c: &mut Criterion) {
|
||||||
#[cfg(feature = "llvm")]
|
#[cfg(feature = "llvm")]
|
||||||
{
|
{
|
||||||
let store = Store::new(&JIT::new(&wasmer_compiler_llvm::LLVM::new()).engine());
|
let store = Store::new(&JIT::new(wasmer_compiler_llvm::LLVM::new()).engine());
|
||||||
run_basic_dynamic_function(&store, "llvm", c);
|
run_basic_dynamic_function(&store, "llvm", c);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(feature = "cranelift")]
|
#[cfg(feature = "cranelift")]
|
||||||
{
|
{
|
||||||
let store = Store::new(&JIT::new(&wasmer_compiler_cranelift::Cranelift::new()).engine());
|
let store = Store::new(&JIT::new(wasmer_compiler_cranelift::Cranelift::new()).engine());
|
||||||
run_basic_dynamic_function(&store, "cranelift", c);
|
run_basic_dynamic_function(&store, "cranelift", c);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(feature = "singlepass")]
|
#[cfg(feature = "singlepass")]
|
||||||
{
|
{
|
||||||
let store = Store::new(&JIT::new(&wasmer_compiler_singlepass::Singlepass::new()).engine());
|
let store = Store::new(&JIT::new(wasmer_compiler_singlepass::Singlepass::new()).engine());
|
||||||
run_basic_dynamic_function(&store, "singlepass", c);
|
run_basic_dynamic_function(&store, "singlepass", c);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,10 +1,10 @@
|
|||||||
status = [
|
status = [
|
||||||
"Audit",
|
"Audit",
|
||||||
"Code lint",
|
"Code lint",
|
||||||
"Test on linux",
|
"Test on linux-x64",
|
||||||
"Test on linux-aarch64",
|
"Test on linux-aarch64",
|
||||||
"Test on macos",
|
"Test on macos-x64",
|
||||||
"Test on windows",
|
"Test on windows-x64",
|
||||||
"Test cross-compile on linux",
|
"Test cross-compile on linux",
|
||||||
"Test cross-compile on macos",
|
"Test cross-compile on macos",
|
||||||
]
|
]
|
||||||
|
|||||||
@@ -1,10 +1,10 @@
|
|||||||
# Migrating from Wasmer 0.x to Wasmer 1.0.0
|
# Migrating from Wasmer 0.x to Wasmer 1.0.0
|
||||||
|
|
||||||
Wasmer 1.0.0 is currently in alpha and is our primary focus. This document will
|
Wasmer 1.0.0 is currently in beta and is our primary focus. This document will
|
||||||
describe the differences between Wasmer 0.x and Wasmer 1.0.0 and provide examples
|
describe the differences between Wasmer 0.x and Wasmer 1.0.0 and provide examples
|
||||||
to make migrating to the new API as simple as possible.
|
to make migrating to the new API as simple as possible.
|
||||||
|
|
||||||
Some features are still under development during the alpha of Wasmer 1.0.0. This document
|
Some features are still under development during the beta of Wasmer 1.0.0. This document
|
||||||
will aim to make clear what these features are.
|
will aim to make clear what these features are.
|
||||||
|
|
||||||
## Table of Contents
|
## Table of Contents
|
||||||
@@ -101,7 +101,7 @@ control:
|
|||||||
|
|
||||||
```diff
|
```diff
|
||||||
- let module = compile(&wasm_bytes[..])?;
|
- let module = compile(&wasm_bytes[..])?;
|
||||||
+ let engine = JIT::new(&Cranelift::default()).engine();
|
+ let engine = JIT::new(Cranelift::default()).engine();
|
||||||
+ let store = Store::new(&engine);
|
+ let store = Store::new(&engine);
|
||||||
+ let module = Module::new(&store, wasm_bytes)?;
|
+ let module = Module::new(&store, wasm_bytes)?;
|
||||||
- let instance = module.instantiate(&imports)?;
|
- let instance = module.instantiate(&imports)?;
|
||||||
@@ -328,11 +328,11 @@ you'll be able to delegate most of the work to Wasmer:
|
|||||||
```
|
```
|
||||||
|
|
||||||
[examples]: https://docs.wasmer.io/integrations/examples
|
[examples]: https://docs.wasmer.io/integrations/examples
|
||||||
[wasmer]: https://crates.io/crates/wasmer/1.0.0-alpha3
|
[wasmer]: https://crates.io/crates/wasmer/1.0.0-beta1
|
||||||
[wasmer-wasi]: https://crates.io/crates/wasmer-wasi/1.0.0-alpha3
|
[wasmer-wasi]: https://crates.io/crates/wasmer-wasi/1.0.0-beta1
|
||||||
[wasmer-emscripten]: https://crates.io/crates/wasmer-emscripten/1.0.0-alpha3
|
[wasmer-emscripten]: https://crates.io/crates/wasmer-emscripten/1.0.0-beta1
|
||||||
[wasmer-engine]: https://crates.io/crates/wasmer-engine/1.0.0-alpha3
|
[wasmer-engine]: https://crates.io/crates/wasmer-engine/1.0.0-beta1
|
||||||
[wasmer-compiler]: https://crates.io/crates/wasmer-compiler/1.0.0-alpha3
|
[wasmer-compiler]: https://crates.io/crates/wasmer-compiler/1.0.0-beta1
|
||||||
[wasmer.io]: https://wasmer.io
|
[wasmer.io]: https://wasmer.io
|
||||||
[wasmer-nightly]: https://github.com/wasmerio/wasmer-nightly/
|
[wasmer-nightly]: https://github.com/wasmerio/wasmer-nightly/
|
||||||
[getting-started]: https://docs.wasmer.io/ecosystem/wasmer/getting-started
|
[getting-started]: https://docs.wasmer.io/ecosystem/wasmer/getting-started
|
||||||
|
|||||||
@@ -33,7 +33,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|||||||
let compiler = Cranelift::default();
|
let compiler = Cranelift::default();
|
||||||
|
|
||||||
// Create the store
|
// Create the store
|
||||||
let store = Store::new(&JIT::new(&compiler).engine());
|
let store = Store::new(&JIT::new(compiler).engine());
|
||||||
|
|
||||||
println!("Compiling module...");
|
println!("Compiling module...");
|
||||||
// Let's compile the Wasm module.
|
// Let's compile the Wasm module.
|
||||||
|
|||||||
@@ -33,7 +33,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|||||||
let compiler = LLVM::default();
|
let compiler = LLVM::default();
|
||||||
|
|
||||||
// Create the store
|
// Create the store
|
||||||
let store = Store::new(&JIT::new(&compiler).engine());
|
let store = Store::new(&JIT::new(compiler).engine());
|
||||||
|
|
||||||
println!("Compiling module...");
|
println!("Compiling module...");
|
||||||
// Let's compile the Wasm module.
|
// Let's compile the Wasm module.
|
||||||
|
|||||||
@@ -33,7 +33,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|||||||
let compiler = Singlepass::default();
|
let compiler = Singlepass::default();
|
||||||
|
|
||||||
// Create the store
|
// Create the store
|
||||||
let store = Store::new(&JIT::new(&compiler).engine());
|
let store = Store::new(&JIT::new(compiler).engine());
|
||||||
|
|
||||||
println!("Compiling module...");
|
println!("Compiling module...");
|
||||||
// Let's compile the Wasm module.
|
// Let's compile the Wasm module.
|
||||||
|
|||||||
@@ -55,7 +55,7 @@ fn main() -> anyhow::Result<()> {
|
|||||||
// Note that we don't need to specify the engine/compiler if we want to use
|
// Note that we don't need to specify the engine/compiler if we want to use
|
||||||
// the default provided by Wasmer.
|
// the default provided by Wasmer.
|
||||||
// You can use `Store::default()` for that.
|
// You can use `Store::default()` for that.
|
||||||
let store = Store::new(&JIT::new(&Cranelift::default()).engine());
|
let store = Store::new(&JIT::new(Cranelift::default()).engine());
|
||||||
|
|
||||||
println!("Compiling module...");
|
println!("Compiling module...");
|
||||||
// Let's compile the Wasm module.
|
// Let's compile the Wasm module.
|
||||||
|
|||||||
@@ -43,7 +43,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|||||||
// In this situation, the compiler is
|
// In this situation, the compiler is
|
||||||
// `wasmer_compiler_cranelift`. The compiler is responsible to
|
// `wasmer_compiler_cranelift`. The compiler is responsible to
|
||||||
// compile the Wasm module into executable code.
|
// compile the Wasm module into executable code.
|
||||||
let mut compiler_config = Cranelift::default();
|
let compiler_config = Cranelift::default();
|
||||||
|
|
||||||
// Here we go.
|
// Here we go.
|
||||||
//
|
//
|
||||||
@@ -72,7 +72,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|||||||
//
|
//
|
||||||
// That's where we specify the target for the compiler.
|
// That's where we specify the target for the compiler.
|
||||||
// Use the native engine.
|
// Use the native engine.
|
||||||
let engine = Native::new(&mut compiler_config)
|
let engine = Native::new(compiler_config)
|
||||||
// Here we go.
|
// Here we go.
|
||||||
// Pass the target to the engine! The engine will share
|
// Pass the target to the engine! The engine will share
|
||||||
// this information with the compiler.
|
// this information with the compiler.
|
||||||
|
|||||||
@@ -77,7 +77,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|||||||
// In this situation, the compiler is
|
// In this situation, the compiler is
|
||||||
// `wasmer_compiler_cranelift`. The compiler is responsible to
|
// `wasmer_compiler_cranelift`. The compiler is responsible to
|
||||||
// compile the Wasm module into executable code.
|
// compile the Wasm module into executable code.
|
||||||
let mut compiler_config = Cranelift::default();
|
let compiler_config = Cranelift::default();
|
||||||
|
|
||||||
println!("Creating Native engine...");
|
println!("Creating Native engine...");
|
||||||
// Define the engine that will drive everything.
|
// Define the engine that will drive everything.
|
||||||
@@ -88,7 +88,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|||||||
// are going to store it in a file with the `.so` extension
|
// are going to store it in a file with the `.so` extension
|
||||||
// for example (or `.dylib`, or `.dll` depending of the
|
// for example (or `.dylib`, or `.dll` depending of the
|
||||||
// platform).
|
// platform).
|
||||||
let engine = Native::new(&mut compiler_config).engine();
|
let engine = Native::new(compiler_config).engine();
|
||||||
|
|
||||||
// Create a store, that holds the engine.
|
// Create a store, that holds the engine.
|
||||||
let store = Store::new(&engine);
|
let store = Store::new(&engine);
|
||||||
|
|||||||
@@ -42,14 +42,14 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|||||||
// In this situation, the compiler is
|
// In this situation, the compiler is
|
||||||
// `wasmer_compiler_cranelift`. The compiler is responsible to
|
// `wasmer_compiler_cranelift`. The compiler is responsible to
|
||||||
// compile the Wasm module into executable code.
|
// compile the Wasm module into executable code.
|
||||||
let mut compiler_config = Cranelift::default();
|
let compiler_config = Cranelift::default();
|
||||||
|
|
||||||
println!("Creating JIT engine...");
|
println!("Creating JIT engine...");
|
||||||
// Define the engine that will drive everything.
|
// Define the engine that will drive everything.
|
||||||
//
|
//
|
||||||
// In this case, the engine is `wasmer_engine_jit` which roughly
|
// In this case, the engine is `wasmer_engine_jit` which roughly
|
||||||
// means that the executable code will live in memory.
|
// means that the executable code will live in memory.
|
||||||
let engine = JIT::new(&mut compiler_config).engine();
|
let engine = JIT::new(compiler_config).engine();
|
||||||
|
|
||||||
// Create a store, that holds the engine.
|
// Create a store, that holds the engine.
|
||||||
let store = Store::new(&engine);
|
let store = Store::new(&engine);
|
||||||
|
|||||||
@@ -43,14 +43,14 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|||||||
// In this situation, the compiler is
|
// In this situation, the compiler is
|
||||||
// `wasmer_compiler_cranelift`. The compiler is responsible to
|
// `wasmer_compiler_cranelift`. The compiler is responsible to
|
||||||
// compile the Wasm module into executable code.
|
// compile the Wasm module into executable code.
|
||||||
let mut compiler_config = Cranelift::default();
|
let compiler_config = Cranelift::default();
|
||||||
|
|
||||||
println!("Creating Native engine...");
|
println!("Creating Native engine...");
|
||||||
// Define the engine that will drive everything.
|
// Define the engine that will drive everything.
|
||||||
//
|
//
|
||||||
// In this case, the engine is `wasmer_engine_native` which means
|
// In this case, the engine is `wasmer_engine_native` which means
|
||||||
// that a native object is going to be generated.
|
// that a native object is going to be generated.
|
||||||
let engine = Native::new(&mut compiler_config).engine();
|
let engine = Native::new(compiler_config).engine();
|
||||||
|
|
||||||
// Create a store, that holds the engine.
|
// Create a store, that holds the engine.
|
||||||
let store = Store::new(&engine);
|
let store = Store::new(&engine);
|
||||||
|
|||||||
@@ -39,7 +39,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|||||||
// Note that we don't need to specify the engine/compiler if we want to use
|
// Note that we don't need to specify the engine/compiler if we want to use
|
||||||
// the default provided by Wasmer.
|
// the default provided by Wasmer.
|
||||||
// You can use `Store::default()` for that.
|
// You can use `Store::default()` for that.
|
||||||
let store = Store::new(&JIT::new(&Cranelift::default()).engine());
|
let store = Store::new(&JIT::new(Cranelift::default()).engine());
|
||||||
|
|
||||||
println!("Compiling module...");
|
println!("Compiling module...");
|
||||||
// Let's compile the Wasm module.
|
// Let's compile the Wasm module.
|
||||||
|
|||||||
@@ -40,7 +40,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|||||||
// Note that we don't need to specify the engine/compiler if we want to use
|
// Note that we don't need to specify the engine/compiler if we want to use
|
||||||
// the default provided by Wasmer.
|
// the default provided by Wasmer.
|
||||||
// You can use `Store::default()` for that.
|
// You can use `Store::default()` for that.
|
||||||
let store = Store::new(&JIT::new(&Cranelift::default()).engine());
|
let store = Store::new(&JIT::new(Cranelift::default()).engine());
|
||||||
|
|
||||||
println!("Compiling module...");
|
println!("Compiling module...");
|
||||||
// Let's compile the Wasm module.
|
// Let's compile the Wasm module.
|
||||||
|
|||||||
@@ -38,7 +38,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|||||||
// Note that we don't need to specify the engine/compiler if we want to use
|
// Note that we don't need to specify the engine/compiler if we want to use
|
||||||
// the default provided by Wasmer.
|
// the default provided by Wasmer.
|
||||||
// You can use `Store::default()` for that.
|
// You can use `Store::default()` for that.
|
||||||
let store = Store::new(&JIT::new(&Cranelift::default()).engine());
|
let store = Store::new(&JIT::new(Cranelift::default()).engine());
|
||||||
|
|
||||||
println!("Compiling module...");
|
println!("Compiling module...");
|
||||||
// Let's compile the Wasm module.
|
// Let's compile the Wasm module.
|
||||||
|
|||||||
@@ -37,7 +37,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|||||||
// Note that we don't need to specify the engine/compiler if we want to use
|
// Note that we don't need to specify the engine/compiler if we want to use
|
||||||
// the default provided by Wasmer.
|
// the default provided by Wasmer.
|
||||||
// You can use `Store::default()` for that.
|
// You can use `Store::default()` for that.
|
||||||
let store = Store::new(&JIT::new(&Cranelift::default()).engine());
|
let store = Store::new(&JIT::new(Cranelift::default()).engine());
|
||||||
|
|
||||||
println!("Compiling module...");
|
println!("Compiling module...");
|
||||||
// Let's compile the Wasm module.
|
// Let's compile the Wasm module.
|
||||||
|
|||||||
@@ -44,7 +44,7 @@ fn main() -> anyhow::Result<()> {
|
|||||||
// However for the purposes of showing what's happening, we create a compiler
|
// However for the purposes of showing what's happening, we create a compiler
|
||||||
// (`Cranelift`) and pass it to an engine (`JIT`). We then pass the engine to
|
// (`Cranelift`) and pass it to an engine (`JIT`). We then pass the engine to
|
||||||
// the store and are now ready to compile and run WebAssembly!
|
// the store and are now ready to compile and run WebAssembly!
|
||||||
let store = Store::new(&JIT::new(&Cranelift::default()).engine());
|
let store = Store::new(&JIT::new(Cranelift::default()).engine());
|
||||||
// We then use our store and Wasm bytes to compile a `Module`.
|
// We then use our store and Wasm bytes to compile a `Module`.
|
||||||
// A `Module` is a compiled WebAssembly module that isn't ready to execute yet.
|
// A `Module` is a compiled WebAssembly module that isn't ready to execute yet.
|
||||||
let module = Module::new(&store, wasm_bytes)?;
|
let module = Module::new(&store, wasm_bytes)?;
|
||||||
|
|||||||
125
examples/imports_exports.rs
Normal file
125
examples/imports_exports.rs
Normal file
@@ -0,0 +1,125 @@
|
|||||||
|
//! A Wasm module can import and export entities, like functions, memories, globals and tables.
|
||||||
|
//! This example illustrates the basics of using these entities.
|
||||||
|
//!
|
||||||
|
//! In this example we'll be using a sample Wasm module which exports some entities and requires us
|
||||||
|
//! to also import some of them.
|
||||||
|
//!
|
||||||
|
//! The goal here is to give you an idea of how to work with imports and exports. We won't go into
|
||||||
|
//! the details of each entities, they'll be covered in more details in the other examples.
|
||||||
|
//!
|
||||||
|
//! You can run the example directly by executing in Wasmer root:
|
||||||
|
//!
|
||||||
|
//! ```shell
|
||||||
|
//! cargo run --example imports-exports --release --features "cranelift"
|
||||||
|
//! ```
|
||||||
|
//!
|
||||||
|
//! Ready?
|
||||||
|
|
||||||
|
use wasmer::{
|
||||||
|
imports, wat2wasm, Function, FunctionType, Global, Instance, Memory, Module, Store, Table,
|
||||||
|
Type, Value,
|
||||||
|
};
|
||||||
|
use wasmer_compiler_cranelift::Cranelift;
|
||||||
|
use wasmer_engine_jit::JIT;
|
||||||
|
|
||||||
|
fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||||
|
// Let's declare the Wasm module.
|
||||||
|
//
|
||||||
|
// We are using the text representation of the module here but you can also load `.wasm`
|
||||||
|
// files using the `include_bytes!` macro.
|
||||||
|
let wasm_bytes = wat2wasm(
|
||||||
|
br#"
|
||||||
|
(module
|
||||||
|
(func $host_function (import "" "host_function") (result i32))
|
||||||
|
(global $host_global (import "env" "host_global") i32)
|
||||||
|
|
||||||
|
(func $function (export "guest_function") (result i32) (global.get $global))
|
||||||
|
(global $global (export "guest_global") i32 (i32.const 42))
|
||||||
|
(table $table (export "guest_table") 1 1 funcref)
|
||||||
|
(memory $memory (export "guest_memory") 1))
|
||||||
|
"#,
|
||||||
|
)?;
|
||||||
|
|
||||||
|
// Create a Store.
|
||||||
|
// Note that we don't need to specify the engine/compiler if we want to use
|
||||||
|
// the default provided by Wasmer.
|
||||||
|
// You can use `Store::default()` for that.
|
||||||
|
let store = Store::new(&JIT::new(Cranelift::default()).engine());
|
||||||
|
|
||||||
|
println!("Compiling module...");
|
||||||
|
// Let's compile the Wasm module.
|
||||||
|
let module = Module::new(&store, wasm_bytes)?;
|
||||||
|
|
||||||
|
// Here we go.
|
||||||
|
//
|
||||||
|
// Before we can instantiate our module, we need to define
|
||||||
|
// the entities we will import.
|
||||||
|
//
|
||||||
|
// We won't go into details here as creating entities will be
|
||||||
|
// covered in more detail in other examples.
|
||||||
|
println!("Creating the imported function...");
|
||||||
|
let host_function_signature = FunctionType::new(vec![], vec![Type::I32]);
|
||||||
|
let host_function = Function::new(&store, &host_function_signature, |_args| {
|
||||||
|
Ok(vec![Value::I32(42)])
|
||||||
|
});
|
||||||
|
|
||||||
|
println!("Creating the imported global...");
|
||||||
|
let host_global = Global::new(&store, Value::I32(42));
|
||||||
|
|
||||||
|
// Create an import object.
|
||||||
|
//
|
||||||
|
// Imports are stored in namespaces. We'll need to register each of the
|
||||||
|
// namespaces with a name and add the imported entities there.
|
||||||
|
//
|
||||||
|
// Note that the namespace can also have an empty name.
|
||||||
|
//
|
||||||
|
// Our module requires us to import:
|
||||||
|
// * A function `host_function` in a namespace with an empty name;
|
||||||
|
// * A global `host_global` in the `env` namespace.
|
||||||
|
//
|
||||||
|
// Let's do this!
|
||||||
|
let import_object = imports! {
|
||||||
|
"" => {
|
||||||
|
"host_function" => host_function,
|
||||||
|
},
|
||||||
|
"env" => {
|
||||||
|
"host_global" => host_global,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
println!("Instantiating module...");
|
||||||
|
// Let's instantiate the Wasm module.
|
||||||
|
let instance = Instance::new(&module, &import_object)?;
|
||||||
|
|
||||||
|
// Here we go.
|
||||||
|
//
|
||||||
|
// The WASM module exports some entities:
|
||||||
|
// * A function: `guest_function`
|
||||||
|
// * A global: `guest_global`
|
||||||
|
// * A memory: `guest_memory`
|
||||||
|
// * A table: `guest_table`
|
||||||
|
//
|
||||||
|
// Let's get them.
|
||||||
|
println!("Getting the exported function...");
|
||||||
|
let function = instance.exports.get::<Function>("guest_function")?;
|
||||||
|
println!("Got exported function of type: {:?}", function.ty());
|
||||||
|
|
||||||
|
println!("Getting the exported global...");
|
||||||
|
let global = instance.exports.get::<Global>("guest_global")?;
|
||||||
|
println!("Got exported global of type: {:?}", global.ty());
|
||||||
|
|
||||||
|
println!("Getting the exported memory...");
|
||||||
|
let memory = instance.exports.get::<Memory>("guest_memory")?;
|
||||||
|
println!("Got exported memory of type: {:?}", memory.ty());
|
||||||
|
|
||||||
|
println!("Getting the exported table...");
|
||||||
|
let table = instance.exports.get::<Table>("guest_table")?;
|
||||||
|
println!("Got exported table of type: {:?}", table.ty());
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_imports_exports() -> Result<(), Box<dyn std::error::Error>> {
|
||||||
|
main()
|
||||||
|
}
|
||||||
@@ -42,7 +42,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|||||||
// Note that we don't need to specify the engine/compiler if we want to use
|
// Note that we don't need to specify the engine/compiler if we want to use
|
||||||
// the default provided by Wasmer.
|
// the default provided by Wasmer.
|
||||||
// You can use `Store::default()` for that.
|
// You can use `Store::default()` for that.
|
||||||
let store = Store::new(&JIT::new(&Cranelift::default()).engine());
|
let store = Store::new(&JIT::new(Cranelift::default()).engine());
|
||||||
|
|
||||||
println!("Compiling module...");
|
println!("Compiling module...");
|
||||||
// Let's compile the Wasm module.
|
// Let's compile the Wasm module.
|
||||||
|
|||||||
@@ -50,7 +50,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|||||||
// Note that we don't need to specify the engine/compiler if we want to use
|
// Note that we don't need to specify the engine/compiler if we want to use
|
||||||
// the default provided by Wasmer.
|
// the default provided by Wasmer.
|
||||||
// You can use `Store::default()` for that.
|
// You can use `Store::default()` for that.
|
||||||
let store = Store::new(&JIT::new(&Cranelift::default()).engine());
|
let store = Store::new(&JIT::new(Cranelift::default()).engine());
|
||||||
|
|
||||||
println!("Compiling module...");
|
println!("Compiling module...");
|
||||||
// Let's compile the Wasm module.
|
// Let's compile the Wasm module.
|
||||||
|
|||||||
@@ -38,7 +38,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|||||||
// Note that we don't need to specify the engine/compiler if we want to use
|
// Note that we don't need to specify the engine/compiler if we want to use
|
||||||
// the default provided by Wasmer.
|
// the default provided by Wasmer.
|
||||||
// You can use `Store::default()` for that.
|
// You can use `Store::default()` for that.
|
||||||
let store = Store::new(&JIT::new(&Cranelift::default()).engine());
|
let store = Store::new(&JIT::new(Cranelift::default()).engine());
|
||||||
|
|
||||||
println!("Compiling module...");
|
println!("Compiling module...");
|
||||||
// Let's compile the Wasm module.
|
// Let's compile the Wasm module.
|
||||||
|
|||||||
@@ -39,7 +39,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|||||||
// Note that we don't need to specify the engine/compiler if we want to use
|
// Note that we don't need to specify the engine/compiler if we want to use
|
||||||
// the default provided by Wasmer.
|
// the default provided by Wasmer.
|
||||||
// You can use `Store::default()` for that.
|
// You can use `Store::default()` for that.
|
||||||
let store = Store::new(&JIT::new(&Cranelift::default()).engine());
|
let store = Store::new(&JIT::new(Cranelift::default()).engine());
|
||||||
|
|
||||||
println!("Compiling module...");
|
println!("Compiling module...");
|
||||||
// Let's compile the Wasm module.
|
// Let's compile the Wasm module.
|
||||||
|
|||||||
@@ -57,7 +57,7 @@ fn main() -> anyhow::Result<()> {
|
|||||||
// Note that we don't need to specify the engine/compiler if we want to use
|
// Note that we don't need to specify the engine/compiler if we want to use
|
||||||
// the default provided by Wasmer.
|
// the default provided by Wasmer.
|
||||||
// You can use `Store::default()` for that.
|
// You can use `Store::default()` for that.
|
||||||
let store = Store::new(&JIT::new(&Cranelift::default()).engine());
|
let store = Store::new(&JIT::new(Cranelift::default()).engine());
|
||||||
|
|
||||||
println!("Compiling module...");
|
println!("Compiling module...");
|
||||||
// Let's compile the Wasm module.
|
// Let's compile the Wasm module.
|
||||||
|
|||||||
165
examples/metering.rs
Normal file
165
examples/metering.rs
Normal file
@@ -0,0 +1,165 @@
|
|||||||
|
//! Wasmer will let you easily run Wasm module in a Rust host.
|
||||||
|
//!
|
||||||
|
//! This example illustrates the basics of using Wasmer metering features:
|
||||||
|
//!
|
||||||
|
//! 1. How to enable metering in a module
|
||||||
|
//! 2. How to meter a specific function call
|
||||||
|
//! 3. How to make execution fails if cost exceeds a given limit
|
||||||
|
//!
|
||||||
|
//! You can run the example directly by executing in Wasmer root:
|
||||||
|
//!
|
||||||
|
//! ```shell
|
||||||
|
//! cargo run --example metering --release --features "cranelift"
|
||||||
|
//! ```
|
||||||
|
//!
|
||||||
|
//! Ready?
|
||||||
|
|
||||||
|
use anyhow::bail;
|
||||||
|
use std::sync::Arc;
|
||||||
|
use wasmer::wasmparser::Operator;
|
||||||
|
use wasmer::CompilerConfig;
|
||||||
|
use wasmer::{imports, wat2wasm, Instance, Module, Store};
|
||||||
|
use wasmer_compiler_cranelift::Cranelift;
|
||||||
|
use wasmer_engine_jit::JIT;
|
||||||
|
use wasmer_middlewares::Metering;
|
||||||
|
|
||||||
|
fn main() -> anyhow::Result<()> {
|
||||||
|
// Let's declare the Wasm module.
|
||||||
|
//
|
||||||
|
// We are using the text representation of the module here but you can also load `.wasm`
|
||||||
|
// files using the `include_bytes!` macro.
|
||||||
|
let wasm_bytes = wat2wasm(
|
||||||
|
br#"
|
||||||
|
(module
|
||||||
|
(type $add_t (func (param i32) (result i32)))
|
||||||
|
(func $add_one_f (type $add_t) (param $value i32) (result i32)
|
||||||
|
local.get $value
|
||||||
|
i32.const 1
|
||||||
|
i32.add)
|
||||||
|
(export "add_one" (func $add_one_f)))
|
||||||
|
"#,
|
||||||
|
)?;
|
||||||
|
|
||||||
|
// Let's define our cost function.
|
||||||
|
//
|
||||||
|
// This function will be called for each `Operator` encountered during
|
||||||
|
// the Wasm module execution. It should return the cost of the operator
|
||||||
|
// that it received as it first argument.
|
||||||
|
let cost_function = |operator: &Operator| -> u64 {
|
||||||
|
match operator {
|
||||||
|
Operator::LocalGet { .. } | Operator::I32Const { .. } => 1,
|
||||||
|
Operator::I32Add { .. } => 2,
|
||||||
|
_ => 0,
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
// Now let's create our metering middleware.
|
||||||
|
//
|
||||||
|
// `Metering` needs to be configured with a limit (the gas limit) and
|
||||||
|
// a cost function.
|
||||||
|
//
|
||||||
|
// For each `Operator`, the metering middleware will call the cost
|
||||||
|
// function and subtract the cost from the gas.
|
||||||
|
let metering = Arc::new(Metering::new(10, cost_function));
|
||||||
|
let mut compiler_config = Cranelift::default();
|
||||||
|
compiler_config.push_middleware(metering.clone());
|
||||||
|
|
||||||
|
// Create a Store.
|
||||||
|
//
|
||||||
|
// We use our previously create compiler configuration
|
||||||
|
// with the JIT engine.
|
||||||
|
let store = Store::new(&JIT::new(compiler_config).engine());
|
||||||
|
|
||||||
|
println!("Compiling module...");
|
||||||
|
// Let's compile the Wasm module.
|
||||||
|
let module = Module::new(&store, wasm_bytes)?;
|
||||||
|
|
||||||
|
// Create an empty import object.
|
||||||
|
let import_object = imports! {};
|
||||||
|
|
||||||
|
println!("Instantiating module...");
|
||||||
|
// Let's instantiate the Wasm module.
|
||||||
|
let instance = Instance::new(&module, &import_object)?;
|
||||||
|
|
||||||
|
// We now have an instance ready to be used.
|
||||||
|
//
|
||||||
|
// Our module exports a single `add_one` function. We want to
|
||||||
|
// measure the cost of executing this function.
|
||||||
|
let add_one = instance
|
||||||
|
.exports
|
||||||
|
.get_function("add_one")?
|
||||||
|
.native::<i32, i32>()?;
|
||||||
|
|
||||||
|
println!("Calling `add_one` function once...");
|
||||||
|
add_one.call(1)?;
|
||||||
|
|
||||||
|
// As you can see here, after the first call we have 6 remaining gas points.
|
||||||
|
//
|
||||||
|
// This is correct, here are the details of how it has been computed:
|
||||||
|
// * `local.get $value` is a `Operator::LocalGet` which costs 1 point;
|
||||||
|
// * `i32.const` is a `Operator::I32Const` which costs 1 point;
|
||||||
|
// * `i32.add` is a `Operator::I32Add` which costs 2 points.
|
||||||
|
let remaining_points_after_first_call = metering.get_remaining_points(&instance);
|
||||||
|
assert_eq!(remaining_points_after_first_call, 6);
|
||||||
|
|
||||||
|
println!(
|
||||||
|
"Remaining points after the first call: {:?}",
|
||||||
|
remaining_points_after_first_call
|
||||||
|
);
|
||||||
|
|
||||||
|
println!("Calling `add_one` function twice...");
|
||||||
|
add_one.call(1)?;
|
||||||
|
|
||||||
|
// We spent 4 more gas points with the second call.
|
||||||
|
// We have 2 remaining points.
|
||||||
|
let remaining_points_after_second_call = metering.get_remaining_points(&instance);
|
||||||
|
assert_eq!(remaining_points_after_second_call, 2);
|
||||||
|
|
||||||
|
println!(
|
||||||
|
"Remaining points after the second call: {:?}",
|
||||||
|
remaining_points_after_second_call
|
||||||
|
);
|
||||||
|
|
||||||
|
// Because calling our `add_one` function consumes 4 gas points,
|
||||||
|
// calling it a third time will fail: we already consume 8 gas
|
||||||
|
// points, there are only two remaining.
|
||||||
|
println!("Calling `add_one` function a third time...");
|
||||||
|
match add_one.call(1) {
|
||||||
|
Ok(result) => {
|
||||||
|
bail!(
|
||||||
|
"Expected failure while calling `add_one`, found: {}",
|
||||||
|
result
|
||||||
|
);
|
||||||
|
}
|
||||||
|
Err(_) => {
|
||||||
|
println!("Calling `add_one` failed: not enough gas points remaining.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Becasue the previous call failed, it did not consume any gas point.
|
||||||
|
// We still have 2 remaining points.
|
||||||
|
let remaining_points_after_third_call = metering.get_remaining_points(&instance);
|
||||||
|
assert_eq!(remaining_points_after_third_call, 2);
|
||||||
|
|
||||||
|
println!(
|
||||||
|
"Remaining points after third call: {:?}",
|
||||||
|
remaining_points_after_third_call
|
||||||
|
);
|
||||||
|
|
||||||
|
// Now let's see how we can set a new limit...
|
||||||
|
println!("Set new remaining points points to 10");
|
||||||
|
let new_limit = 10;
|
||||||
|
metering.set_remaining_points(&instance, new_limit);
|
||||||
|
|
||||||
|
let remaining_points = metering.get_remaining_points(&instance);
|
||||||
|
assert_eq!(remaining_points, new_limit);
|
||||||
|
|
||||||
|
println!("Remaining points: {:?}", remaining_points);
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_metering() -> anyhow::Result<()> {
|
||||||
|
main()
|
||||||
|
}
|
||||||
@@ -51,7 +51,7 @@ fn main() -> anyhow::Result<()> {
|
|||||||
)?;
|
)?;
|
||||||
|
|
||||||
// We set up our store with an engine and a compiler.
|
// We set up our store with an engine and a compiler.
|
||||||
let store = Store::new(&JIT::new(&Cranelift::default()).engine());
|
let store = Store::new(&JIT::new(Cranelift::default()).engine());
|
||||||
// Then compile our Wasm.
|
// Then compile our Wasm.
|
||||||
let module = Module::new(&store, wasm_bytes)?;
|
let module = Module::new(&store, wasm_bytes)?;
|
||||||
let import_object = imports! {};
|
let import_object = imports! {};
|
||||||
|
|||||||
@@ -143,7 +143,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|||||||
|
|
||||||
// Any compiler and any engine do the job here
|
// Any compiler and any engine do the job here
|
||||||
let compiler = Cranelift::default();
|
let compiler = Cranelift::default();
|
||||||
let engine = JIT::new(&compiler).engine();
|
let engine = JIT::new(compiler).engine();
|
||||||
|
|
||||||
// Here is where the fun begins
|
// Here is where the fun begins
|
||||||
|
|
||||||
|
|||||||
@@ -32,7 +32,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|||||||
// Note that we don't need to specify the engine/compiler if we want to use
|
// Note that we don't need to specify the engine/compiler if we want to use
|
||||||
// the default provided by Wasmer.
|
// the default provided by Wasmer.
|
||||||
// You can use `Store::default()` for that.
|
// You can use `Store::default()` for that.
|
||||||
let store = Store::new(&JIT::new(&Cranelift::default()).engine());
|
let store = Store::new(&JIT::new(Cranelift::default()).engine());
|
||||||
|
|
||||||
println!("Compiling module...");
|
println!("Compiling module...");
|
||||||
// Let's compile the Wasm module.
|
// Let's compile the Wasm module.
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ use wasmer_engine_native::Native;
|
|||||||
fuzz_target!(|wasm_bytes: &[u8]| {
|
fuzz_target!(|wasm_bytes: &[u8]| {
|
||||||
let serialized = {
|
let serialized = {
|
||||||
let mut compiler = Cranelift::default();
|
let mut compiler = Cranelift::default();
|
||||||
let store = Store::new(&Native::new(&mut compiler).engine());
|
let store = Store::new(&Native::new(compiler).engine());
|
||||||
match Module::validate(&store, wasm_bytes) {
|
match Module::validate(&store, wasm_bytes) {
|
||||||
Err(_) => return,
|
Err(_) => return,
|
||||||
Ok(_) => {}
|
Ok(_) => {}
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ fuzz_target!(|wasm_bytes: &[u8]| {
|
|||||||
let mut compiler = Cranelift::default();
|
let mut compiler = Cranelift::default();
|
||||||
compiler.canonicalize_nans(true);
|
compiler.canonicalize_nans(true);
|
||||||
compiler.enable_verifier();
|
compiler.enable_verifier();
|
||||||
let store = Store::new(&JIT::new(&compiler).engine());
|
let store = Store::new(&JIT::new(compiler).engine());
|
||||||
match Module::validate(&store, wasm_bytes) {
|
match Module::validate(&store, wasm_bytes) {
|
||||||
Ok(_) => {
|
Ok(_) => {
|
||||||
let module = Module::new(&store, wasm_bytes).unwrap();
|
let module = Module::new(&store, wasm_bytes).unwrap();
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ fuzz_target!(|wasm_bytes: &[u8]| {
|
|||||||
let mut compiler = LLVM::default();
|
let mut compiler = LLVM::default();
|
||||||
compiler.canonicalize_nans(true);
|
compiler.canonicalize_nans(true);
|
||||||
compiler.enable_verifier();
|
compiler.enable_verifier();
|
||||||
let store = Store::new(&JIT::new(&compiler).engine());
|
let store = Store::new(&JIT::new(compiler).engine());
|
||||||
match Module::validate(&store, wasm_bytes) {
|
match Module::validate(&store, wasm_bytes) {
|
||||||
Ok(_) => {
|
Ok(_) => {
|
||||||
let module = Module::new(&store, wasm_bytes).unwrap();
|
let module = Module::new(&store, wasm_bytes).unwrap();
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ use wasmer_engine_jit::JIT;
|
|||||||
|
|
||||||
fuzz_target!(|wasm_bytes: &[u8]| {
|
fuzz_target!(|wasm_bytes: &[u8]| {
|
||||||
let compiler = Singlepass::default();
|
let compiler = Singlepass::default();
|
||||||
let store = Store::new(&JIT::new(&compiler).engine());
|
let store = Store::new(&JIT::new(compiler).engine());
|
||||||
match Module::validate(&store, wasm_bytes) {
|
match Module::validate(&store, wasm_bytes) {
|
||||||
Ok(_) => {
|
Ok(_) => {
|
||||||
let module = Module::new(&store, wasm_bytes).unwrap();
|
let module = Module::new(&store, wasm_bytes).unwrap();
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ use wasmer_engine_native::Native;
|
|||||||
fuzz_target!(|wasm_bytes: &[u8]| {
|
fuzz_target!(|wasm_bytes: &[u8]| {
|
||||||
let serialized = {
|
let serialized = {
|
||||||
let mut compiler = Cranelift::default();
|
let mut compiler = Cranelift::default();
|
||||||
let store = Store::new(&Native::new(&mut compiler).engine());
|
let store = Store::new(&Native::new(compiler).engine());
|
||||||
match Module::validate(&store, wasm_bytes) {
|
match Module::validate(&store, wasm_bytes) {
|
||||||
Err(_) => return,
|
Err(_) => return,
|
||||||
Ok(_) => {}
|
Ok(_) => {}
|
||||||
|
|||||||
@@ -8,6 +8,6 @@ use wasmer_engine_jit::JIT;
|
|||||||
|
|
||||||
fuzz_target!(|wasm_bytes: &[u8]| {
|
fuzz_target!(|wasm_bytes: &[u8]| {
|
||||||
let compiler = Cranelift::default();
|
let compiler = Cranelift::default();
|
||||||
let store = Store::new(&JIT::new(&compiler).engine());
|
let store = Store::new(&JIT::new(compiler).engine());
|
||||||
Module::validate(&store, wasm_bytes);
|
Module::validate(&store, wasm_bytes);
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "wasmer"
|
name = "wasmer"
|
||||||
version = "1.0.0-alpha5"
|
version = "1.0.0-beta1"
|
||||||
description = "High-performant WebAssembly runtime"
|
description = "High-performant WebAssembly runtime"
|
||||||
categories = ["wasm"]
|
categories = ["wasm"]
|
||||||
keywords = ["wasm", "webassembly", "runtime", "vm"]
|
keywords = ["wasm", "webassembly", "runtime", "vm"]
|
||||||
@@ -11,16 +11,16 @@ readme = "README.md"
|
|||||||
edition = "2018"
|
edition = "2018"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
wasmer-vm = { path = "../vm", version = "1.0.0-alpha5" }
|
wasmer-vm = { path = "../vm", version = "1.0.0-beta1" }
|
||||||
wasmer-compiler-singlepass = { path = "../compiler-singlepass", version = "1.0.0-alpha5", optional = true }
|
wasmer-compiler-singlepass = { path = "../compiler-singlepass", version = "1.0.0-beta1", optional = true }
|
||||||
wasmer-compiler-cranelift = { path = "../compiler-cranelift", version = "1.0.0-alpha5", optional = true }
|
wasmer-compiler-cranelift = { path = "../compiler-cranelift", version = "1.0.0-beta1", optional = true }
|
||||||
wasmer-compiler-llvm = { path = "../compiler-llvm", version = "1.0.0-alpha5", optional = true }
|
wasmer-compiler-llvm = { path = "../compiler-llvm", version = "1.0.0-beta1", optional = true }
|
||||||
wasmer-compiler = { path = "../compiler", version = "1.0.0-alpha5" }
|
wasmer-compiler = { path = "../compiler", version = "1.0.0-beta1" }
|
||||||
wasmer-derive = { path = "../derive", version = "1.0.0-alpha5" }
|
wasmer-derive = { path = "../derive", version = "1.0.0-beta1" }
|
||||||
wasmer-engine = { path = "../engine", version = "1.0.0-alpha5" }
|
wasmer-engine = { path = "../engine", version = "1.0.0-beta1" }
|
||||||
wasmer-engine-jit = { path = "../engine-jit", version = "1.0.0-alpha5", optional = true }
|
wasmer-engine-jit = { path = "../engine-jit", version = "1.0.0-beta1", optional = true }
|
||||||
wasmer-engine-native = { path = "../engine-native", version = "1.0.0-alpha5", optional = true }
|
wasmer-engine-native = { path = "../engine-native", version = "1.0.0-beta1", optional = true }
|
||||||
wasmer-types = { path = "../wasmer-types", version = "1.0.0-alpha5" }
|
wasmer-types = { path = "../wasmer-types", version = "1.0.0-beta1" }
|
||||||
indexmap = { version = "1.4", features = ["serde-1"] }
|
indexmap = { version = "1.4", features = ["serde-1"] }
|
||||||
cfg-if = "0.1"
|
cfg-if = "0.1"
|
||||||
wat = { version = "1.0", optional = true }
|
wat = { version = "1.0", optional = true }
|
||||||
@@ -64,6 +64,11 @@ cranelift = [
|
|||||||
"wasmer-compiler-cranelift",
|
"wasmer-compiler-cranelift",
|
||||||
"compiler",
|
"compiler",
|
||||||
]
|
]
|
||||||
|
# Enable Cranelift experimental x64 backend
|
||||||
|
cranelift-experimental-x64 = [
|
||||||
|
"cranelift",
|
||||||
|
"wasmer-compiler-cranelift/experimental-x64",
|
||||||
|
]
|
||||||
llvm = [
|
llvm = [
|
||||||
"wasmer-compiler-llvm",
|
"wasmer-compiler-llvm",
|
||||||
"compiler",
|
"compiler",
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ Add to your `Cargo.toml`
|
|||||||
|
|
||||||
```toml
|
```toml
|
||||||
[dependencies]
|
[dependencies]
|
||||||
wasmer = "1.0.0-alpha"
|
wasmer = "1.0.0-beta"
|
||||||
```
|
```
|
||||||
|
|
||||||
```rust
|
```rust
|
||||||
|
|||||||
9
lib/api/src/externals/function.rs
vendored
9
lib/api/src/externals/function.rs
vendored
@@ -673,13 +673,12 @@ impl Function {
|
|||||||
|
|
||||||
Ok(NativeFunc::new(
|
Ok(NativeFunc::new(
|
||||||
self.store.clone(),
|
self.store.clone(),
|
||||||
self.exported.vm_function.address,
|
self.exported.clone(),
|
||||||
self.exported.vm_function.vmctx,
|
|
||||||
self.exported.vm_function.kind,
|
|
||||||
self.definition.clone(),
|
self.definition.clone(),
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[track_caller]
|
||||||
fn closures_unsupported_panic() -> ! {
|
fn closures_unsupported_panic() -> ! {
|
||||||
unimplemented!("Closures (functions with captured environments) are currently unsupported with native functions. See: https://github.com/wasmerio/wasmer/issues/1840")
|
unimplemented!("Closures (functions with captured environments) are currently unsupported with native functions. See: https://github.com/wasmerio/wasmer/issues/1840")
|
||||||
}
|
}
|
||||||
@@ -728,14 +727,16 @@ impl VMDynamicFunction for VMDynamicFunctionWithoutEnv {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[repr(C)]
|
||||||
pub(crate) struct VMDynamicFunctionWithEnv<Env>
|
pub(crate) struct VMDynamicFunctionWithEnv<Env>
|
||||||
where
|
where
|
||||||
Env: Sized + 'static,
|
Env: Sized + 'static,
|
||||||
{
|
{
|
||||||
|
// This field _must_ come first in this struct.
|
||||||
|
env: Box<Env>,
|
||||||
function_type: FunctionType,
|
function_type: FunctionType,
|
||||||
#[allow(clippy::type_complexity)]
|
#[allow(clippy::type_complexity)]
|
||||||
func: Box<dyn Fn(&Env, &[Val]) -> Result<Vec<Val>, RuntimeError> + 'static>,
|
func: Box<dyn Fn(&Env, &[Val]) -> Result<Vec<Val>, RuntimeError> + 'static>,
|
||||||
env: Box<Env>,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<Env> VMDynamicFunction for VMDynamicFunctionWithEnv<Env>
|
impl<Env> VMDynamicFunction for VMDynamicFunctionWithEnv<Env>
|
||||||
|
|||||||
@@ -75,16 +75,17 @@ pub use crate::utils::is_wasm;
|
|||||||
pub use target_lexicon::{Architecture, CallingConvention, OperatingSystem, Triple, HOST};
|
pub use target_lexicon::{Architecture, CallingConvention, OperatingSystem, Triple, HOST};
|
||||||
#[cfg(feature = "compiler")]
|
#[cfg(feature = "compiler")]
|
||||||
pub use wasmer_compiler::{
|
pub use wasmer_compiler::{
|
||||||
wasmparser, CompilerConfig, FunctionMiddleware, FunctionMiddlewareGenerator,
|
wasmparser, CompilerConfig, FunctionMiddleware, MiddlewareReaderState, ModuleMiddleware,
|
||||||
MiddlewareReaderState,
|
};
|
||||||
|
pub use wasmer_compiler::{
|
||||||
|
CompileError, CpuFeature, Features, ParseCpuFeatureError, Target, WasmError,
|
||||||
};
|
};
|
||||||
pub use wasmer_compiler::{CpuFeature, Features, Target};
|
|
||||||
pub use wasmer_engine::{
|
pub use wasmer_engine::{
|
||||||
ChainableNamedResolver, DeserializeError, Engine, Export, FrameInfo, LinkError, NamedResolver,
|
ChainableNamedResolver, DeserializeError, Engine, Export, FrameInfo, LinkError, NamedResolver,
|
||||||
NamedResolverChain, Resolver, RuntimeError, SerializeError,
|
NamedResolverChain, Resolver, RuntimeError, SerializeError,
|
||||||
};
|
};
|
||||||
pub use wasmer_types::{
|
pub use wasmer_types::{
|
||||||
Atomically, Bytes, GlobalInit, LocalFunctionIndex, MemoryView, Pages, ValueType,
|
Atomically, Bytes, ExportIndex, GlobalInit, LocalFunctionIndex, MemoryView, Pages, ValueType,
|
||||||
WASM_MAX_PAGES, WASM_MIN_PAGES, WASM_PAGE_SIZE,
|
WASM_MAX_PAGES, WASM_MIN_PAGES, WASM_PAGE_SIZE,
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -116,7 +117,7 @@ If you wish to use more than one compiler, you can simply create the own store.
|
|||||||
```
|
```
|
||||||
use wasmer::{Store, JIT, Singlepass};
|
use wasmer::{Store, JIT, Singlepass};
|
||||||
|
|
||||||
let engine = JIT::new(&Singlepass::default()).engine();
|
let engine = JIT::new(Singlepass::default()).engine();
|
||||||
let store = Store::new(&engine);
|
let store = Store::new(&engine);
|
||||||
```"#
|
```"#
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -27,10 +27,7 @@ use wasmer_vm::{
|
|||||||
pub struct NativeFunc<Args = (), Rets = ()> {
|
pub struct NativeFunc<Args = (), Rets = ()> {
|
||||||
definition: FunctionDefinition,
|
definition: FunctionDefinition,
|
||||||
store: Store,
|
store: Store,
|
||||||
address: *const VMFunctionBody,
|
exported: ExportFunction,
|
||||||
vmctx: VMFunctionEnvironment,
|
|
||||||
arg_kind: VMFunctionKind,
|
|
||||||
// exported: ExportFunction,
|
|
||||||
_phantom: PhantomData<(Args, Rets)>,
|
_phantom: PhantomData<(Args, Rets)>,
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -43,20 +40,28 @@ where
|
|||||||
{
|
{
|
||||||
pub(crate) fn new(
|
pub(crate) fn new(
|
||||||
store: Store,
|
store: Store,
|
||||||
address: *const VMFunctionBody,
|
exported: ExportFunction,
|
||||||
vmctx: VMFunctionEnvironment,
|
|
||||||
arg_kind: VMFunctionKind,
|
|
||||||
definition: FunctionDefinition,
|
definition: FunctionDefinition,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
Self {
|
Self {
|
||||||
definition,
|
definition,
|
||||||
store,
|
store,
|
||||||
address,
|
exported,
|
||||||
vmctx,
|
|
||||||
arg_kind,
|
|
||||||
_phantom: PhantomData,
|
_phantom: PhantomData,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub(crate) fn vmctx(&self) -> VMFunctionEnvironment {
|
||||||
|
self.exported.vm_function.vmctx
|
||||||
|
}
|
||||||
|
|
||||||
|
pub(crate) fn address(&self) -> *const VMFunctionBody {
|
||||||
|
self.exported.vm_function.address
|
||||||
|
}
|
||||||
|
|
||||||
|
pub(crate) fn arg_kind(&self) -> VMFunctionKind {
|
||||||
|
self.exported.vm_function.kind
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -84,19 +89,7 @@ where
|
|||||||
Rets: WasmTypeList,
|
Rets: WasmTypeList,
|
||||||
{
|
{
|
||||||
fn from(other: &NativeFunc<Args, Rets>) -> Self {
|
fn from(other: &NativeFunc<Args, Rets>) -> Self {
|
||||||
let signature = FunctionType::new(Args::wasm_types(), Rets::wasm_types());
|
other.exported.clone()
|
||||||
Self {
|
|
||||||
// TODO:
|
|
||||||
import_init_function_ptr: None,
|
|
||||||
vm_function: VMExportFunction {
|
|
||||||
address: other.address,
|
|
||||||
vmctx: other.vmctx,
|
|
||||||
signature,
|
|
||||||
kind: other.arg_kind,
|
|
||||||
call_trampoline: None,
|
|
||||||
instance_allocator: None,
|
|
||||||
},
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -106,22 +99,10 @@ where
|
|||||||
Rets: WasmTypeList,
|
Rets: WasmTypeList,
|
||||||
{
|
{
|
||||||
fn from(other: NativeFunc<Args, Rets>) -> Self {
|
fn from(other: NativeFunc<Args, Rets>) -> Self {
|
||||||
let signature = FunctionType::new(Args::wasm_types(), Rets::wasm_types());
|
|
||||||
Self {
|
Self {
|
||||||
store: other.store,
|
store: other.store,
|
||||||
definition: other.definition,
|
definition: other.definition,
|
||||||
exported: ExportFunction {
|
exported: other.exported.clone(),
|
||||||
// TODO:
|
|
||||||
import_init_function_ptr: None,
|
|
||||||
vm_function: VMExportFunction {
|
|
||||||
address: other.address,
|
|
||||||
vmctx: other.vmctx,
|
|
||||||
signature,
|
|
||||||
kind: other.arg_kind,
|
|
||||||
call_trampoline: None,
|
|
||||||
instance_allocator: None,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -158,9 +139,9 @@ macro_rules! impl_native_traits {
|
|||||||
};
|
};
|
||||||
unsafe {
|
unsafe {
|
||||||
wasmer_vm::wasmer_call_trampoline(
|
wasmer_vm::wasmer_call_trampoline(
|
||||||
self.vmctx,
|
self.vmctx(),
|
||||||
trampoline,
|
trampoline,
|
||||||
self.address,
|
self.address(),
|
||||||
args_rets.as_mut_ptr() as *mut u8,
|
args_rets.as_mut_ptr() as *mut u8,
|
||||||
)
|
)
|
||||||
}?;
|
}?;
|
||||||
@@ -182,7 +163,7 @@ macro_rules! impl_native_traits {
|
|||||||
//
|
//
|
||||||
// let results = unsafe {
|
// let results = unsafe {
|
||||||
// wasmer_vm::catch_traps_with_result(self.vmctx, || {
|
// wasmer_vm::catch_traps_with_result(self.vmctx, || {
|
||||||
// let f = std::mem::transmute::<_, unsafe extern "C" fn( *mut VMContext, $( $x, )*) -> Rets::CStruct>(self.address);
|
// let f = std::mem::transmute::<_, unsafe extern "C" fn( *mut VMContext, $( $x, )*) -> Rets::CStruct>(self.address());
|
||||||
// // We always pass the vmctx
|
// // We always pass the vmctx
|
||||||
// f( self.vmctx, $( $x, )* )
|
// f( self.vmctx, $( $x, )* )
|
||||||
// }).map_err(RuntimeError::from_trap)?
|
// }).map_err(RuntimeError::from_trap)?
|
||||||
@@ -193,12 +174,12 @@ macro_rules! impl_native_traits {
|
|||||||
FunctionDefinition::Host(HostFunctionDefinition {
|
FunctionDefinition::Host(HostFunctionDefinition {
|
||||||
has_env
|
has_env
|
||||||
}) => {
|
}) => {
|
||||||
match self.arg_kind {
|
match self.arg_kind() {
|
||||||
VMFunctionKind::Static => {
|
VMFunctionKind::Static => {
|
||||||
let results = catch_unwind(AssertUnwindSafe(|| unsafe {
|
let results = catch_unwind(AssertUnwindSafe(|| unsafe {
|
||||||
let f = std::mem::transmute::<_, unsafe extern "C" fn( VMFunctionEnvironment, $( $x, )*) -> Rets::CStruct>(self.address);
|
let f = std::mem::transmute::<_, unsafe extern "C" fn( VMFunctionEnvironment, $( $x, )*) -> Rets::CStruct>(self.address());
|
||||||
// We always pass the vmctx
|
// We always pass the vmctx
|
||||||
f( self.vmctx, $( $x, )* )
|
f( self.vmctx(), $( $x, )* )
|
||||||
})).map_err(|e| RuntimeError::new(format!("{:?}", e)))?;
|
})).map_err(|e| RuntimeError::new(format!("{:?}", e)))?;
|
||||||
Ok(Rets::from_c_struct(results))
|
Ok(Rets::from_c_struct(results))
|
||||||
},
|
},
|
||||||
@@ -207,13 +188,13 @@ macro_rules! impl_native_traits {
|
|||||||
let results = if !has_env {
|
let results = if !has_env {
|
||||||
type VMContextWithoutEnv = VMDynamicFunctionContext<VMDynamicFunctionWithoutEnv>;
|
type VMContextWithoutEnv = VMDynamicFunctionContext<VMDynamicFunctionWithoutEnv>;
|
||||||
unsafe {
|
unsafe {
|
||||||
let ctx = self.vmctx.host_env as *mut VMContextWithoutEnv;
|
let ctx = self.vmctx().host_env as *mut VMContextWithoutEnv;
|
||||||
(*ctx).ctx.call(¶ms_list)?
|
(*ctx).ctx.call(¶ms_list)?
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
type VMContextWithEnv = VMDynamicFunctionContext<VMDynamicFunctionWithEnv<std::ffi::c_void>>;
|
type VMContextWithEnv = VMDynamicFunctionContext<VMDynamicFunctionWithEnv<std::ffi::c_void>>;
|
||||||
unsafe {
|
unsafe {
|
||||||
let ctx = self.vmctx.host_env as *mut VMContextWithEnv;
|
let ctx = self.vmctx().host_env as *mut VMContextWithEnv;
|
||||||
(*ctx).ctx.call(¶ms_list)?
|
(*ctx).ctx.call(¶ms_list)?
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -80,7 +80,7 @@ impl Default for Store {
|
|||||||
// sure this function doesn't emit a compile error even if
|
// sure this function doesn't emit a compile error even if
|
||||||
// more than one compiler is enabled.
|
// more than one compiler is enabled.
|
||||||
#[allow(unreachable_code)]
|
#[allow(unreachable_code)]
|
||||||
fn get_config() -> impl CompilerConfig + Send + Sync {
|
fn get_config() -> impl CompilerConfig + 'static {
|
||||||
cfg_if::cfg_if! {
|
cfg_if::cfg_if! {
|
||||||
if #[cfg(feature = "default-cranelift")] {
|
if #[cfg(feature = "default-cranelift")] {
|
||||||
wasmer_compiler_cranelift::Cranelift::default()
|
wasmer_compiler_cranelift::Cranelift::default()
|
||||||
@@ -95,13 +95,13 @@ impl Default for Store {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[allow(unreachable_code, unused_mut)]
|
#[allow(unreachable_code, unused_mut)]
|
||||||
fn get_engine(mut config: impl CompilerConfig + Send + Sync) -> impl Engine + Send + Sync {
|
fn get_engine(mut config: impl CompilerConfig + 'static) -> impl Engine + Send + Sync {
|
||||||
cfg_if::cfg_if! {
|
cfg_if::cfg_if! {
|
||||||
if #[cfg(feature = "default-jit")] {
|
if #[cfg(feature = "default-jit")] {
|
||||||
wasmer_engine_jit::JIT::new(&config)
|
wasmer_engine_jit::JIT::new(config)
|
||||||
.engine()
|
.engine()
|
||||||
} else if #[cfg(feature = "default-native")] {
|
} else if #[cfg(feature = "default-native")] {
|
||||||
wasmer_engine_native::Native::new(&mut config)
|
wasmer_engine_native::Native::new(config)
|
||||||
.engine()
|
.engine()
|
||||||
} else {
|
} else {
|
||||||
compile_error!("No default engine chosen")
|
compile_error!("No default engine chosen")
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "wasmer-c-api"
|
name = "wasmer-c-api"
|
||||||
version = "1.0.0-alpha5"
|
version = "1.0.0-beta1"
|
||||||
description = "Wasmer C API library"
|
description = "Wasmer C API library"
|
||||||
categories = ["wasm", "api-bindings"]
|
categories = ["wasm", "api-bindings"]
|
||||||
keywords = ["wasm", "webassembly", "runtime"]
|
keywords = ["wasm", "webassembly", "runtime"]
|
||||||
@@ -15,18 +15,18 @@ edition = "2018"
|
|||||||
crate-type = ["cdylib", "rlib", "staticlib"]
|
crate-type = ["cdylib", "rlib", "staticlib"]
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
wasmer = { version = "1.0.0-alpha5", path = "../api", default-features = false }
|
wasmer = { version = "1.0.0-beta1", path = "../api", default-features = false }
|
||||||
wasmer-compiler = { version = "1.0.0-alpha5", path = "../compiler" }
|
wasmer-compiler = { version = "1.0.0-beta1", path = "../compiler" }
|
||||||
wasmer-compiler-cranelift = { version = "1.0.0-alpha5", path = "../compiler-cranelift", optional = true }
|
wasmer-compiler-cranelift = { version = "1.0.0-beta1", path = "../compiler-cranelift", optional = true }
|
||||||
wasmer-compiler-singlepass = { version = "1.0.0-alpha5", path = "../compiler-singlepass", optional = true }
|
wasmer-compiler-singlepass = { version = "1.0.0-beta1", path = "../compiler-singlepass", optional = true }
|
||||||
wasmer-compiler-llvm = { version = "1.0.0-alpha5", path = "../compiler-llvm", optional = true }
|
wasmer-compiler-llvm = { version = "1.0.0-beta1", path = "../compiler-llvm", optional = true }
|
||||||
wasmer-emscripten = { version = "1.0.0-alpha5", path = "../emscripten", optional = true }
|
wasmer-emscripten = { version = "1.0.0-beta1", path = "../emscripten", optional = true }
|
||||||
wasmer-engine = { version = "1.0.0-alpha5", path = "../engine" }
|
wasmer-engine = { version = "1.0.0-beta1", path = "../engine" }
|
||||||
wasmer-engine-jit = { version = "1.0.0-alpha5", path = "../engine-jit", optional = true }
|
wasmer-engine-jit = { version = "1.0.0-beta1", path = "../engine-jit", optional = true }
|
||||||
wasmer-engine-native = { version = "1.0.0-alpha5", path = "../engine-native", optional = true }
|
wasmer-engine-native = { version = "1.0.0-beta1", path = "../engine-native", optional = true }
|
||||||
wasmer-engine-object-file = { version = "1.0.0-alpha5", path = "../engine-object-file", optional = true }
|
wasmer-engine-object-file = { version = "1.0.0-beta1", path = "../engine-object-file", optional = true }
|
||||||
wasmer-wasi = { version = "1.0.0-alpha5", path = "../wasi", optional = true }
|
wasmer-wasi = { version = "1.0.0-beta1", path = "../wasi", optional = true }
|
||||||
wasmer-types = { version = "1.0.0-alpha5", path = "../wasmer-types" }
|
wasmer-types = { version = "1.0.0-beta1", path = "../wasmer-types" }
|
||||||
cfg-if = "1.0"
|
cfg-if = "1.0"
|
||||||
lazy_static = "1"
|
lazy_static = "1"
|
||||||
libc = { version = "^0.2", default-features = false }
|
libc = { version = "^0.2", default-features = false }
|
||||||
@@ -37,7 +37,7 @@ typetag = { version = "0.1", optional = true }
|
|||||||
paste = "0.1"
|
paste = "0.1"
|
||||||
# for generating code in the same way thot the wasm-c-api does
|
# for generating code in the same way thot the wasm-c-api does
|
||||||
# Commented out for now until we can find a solution to the exported function problem
|
# Commented out for now until we can find a solution to the exported function problem
|
||||||
# wasmer-wasm-c-api = { version = "1.0.0-alpha5", path = "crates/wasm-c-api" }
|
# wasmer-wasm-c-api = { version = "1.0.0-beta1", path = "crates/wasm-c-api" }
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
inline-c = "0.1.2"
|
inline-c = "0.1.2"
|
||||||
@@ -94,4 +94,4 @@ cranelift-backend = ["cranelift"]
|
|||||||
llvm-backend = ["llvm"]
|
llvm-backend = ["llvm"]
|
||||||
|
|
||||||
[build-dependencies]
|
[build-dependencies]
|
||||||
cbindgen = "0.15"
|
cbindgen = "0.15"
|
||||||
|
|||||||
@@ -4,24 +4,21 @@ This crate exposes a C and a C++ API for the Wasmer runtime. It also fully suppo
|
|||||||
|
|
||||||
## Usage
|
## Usage
|
||||||
|
|
||||||
Once you [install Wasmer in your system](https://github.com/wasmerio/wasmer-install), the *shared object files* and the *headers* will be automatically available **inside the Wasmer installed path**.
|
Once you [install Wasmer in your system](https://github.com/wasmerio/wasmer-install), the *shared object files* and the *headers* are available **inside the Wasmer installed path**.
|
||||||
|
|
||||||
The C ([`wasmer.h`][wasmer_h]) and C++ ([`wasmer.hh`][wasmer_hh]) header
|
```
|
||||||
files can be found in the Wasmer `include` directory:
|
$WASMER_DIR/
|
||||||
|
lib/
|
||||||
```bash
|
libwasmer.{so,dylib,dll}
|
||||||
wasmer config --includedir
|
include/
|
||||||
|
wasm.h
|
||||||
|
wasmer.h
|
||||||
|
wasmer.hh
|
||||||
|
wasmer_wasm.h
|
||||||
```
|
```
|
||||||
|
|
||||||
The runtime shared libraries (`.so`, `.dylib`, `.dll`) can be found in the Wasmer
|
Wasmer binary also ships with [`wasmer-config`](#wasmer-config)
|
||||||
`lib` directory:
|
an utility tool that outputs config information needed to compile programs which use Wasmer.
|
||||||
|
|
||||||
```bash
|
|
||||||
wasmer config --libdir
|
|
||||||
```
|
|
||||||
|
|
||||||
> Note: You can also download the libraries or header files directly
|
|
||||||
from [Wasmer release page].
|
|
||||||
|
|
||||||
The full C API documentation can be found here:
|
The full C API documentation can be found here:
|
||||||
https://wasmerio.github.io/wasmer/c-api/
|
https://wasmerio.github.io/wasmer/c-api/
|
||||||
@@ -30,86 +27,173 @@ Here is a simple example to use the C API:
|
|||||||
|
|
||||||
```c
|
```c
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include "../wasmer.h"
|
#include "wasmer_wasm.h"
|
||||||
#include <assert.h>
|
|
||||||
#include <stdint.h>
|
int main(int argc, const char* argv[]) {
|
||||||
int main()
|
const char *wat_string =
|
||||||
{
|
"(module\n"
|
||||||
// Read the Wasm file bytes.
|
" (type $sum_t (func (param i32 i32) (result i32)))\n"
|
||||||
FILE *file = fopen("sum.wasm", "r");
|
" (func $sum_f (type $sum_t) (param $x i32) (param $y i32) (result i32)\n"
|
||||||
fseek(file, 0, SEEK_END);
|
" local.get $x\n"
|
||||||
long len = ftell(file);
|
" local.get $y\n"
|
||||||
uint8_t *bytes = malloc(len);
|
" i32.add)\n"
|
||||||
fseek(file, 0, SEEK_SET);
|
" (export \"sum\" (func $sum_f)))";
|
||||||
fread(bytes, 1, len, file);
|
|
||||||
fclose(file);
|
wasm_byte_vec_t wat;
|
||||||
// Prepare the imports.
|
wasm_byte_vec_new(&wat, strlen(wat_string), wat_string);
|
||||||
wasmer_import_t imports[] = {};
|
wasm_byte_vec_t wasm_bytes;
|
||||||
// Instantiate!
|
wat2wasm(&wat, &wasm_bytes);
|
||||||
wasmer_instance_t *instance = NULL;
|
|
||||||
wasmer_result_t instantiation_result = wasmer_instantiate(&instance, bytes, len, imports, 0);
|
printf("Creating the store...\n");
|
||||||
assert(instantiation_result == WASMER_OK);
|
wasm_engine_t* engine = wasm_engine_new();
|
||||||
// Let's call a function.
|
wasm_store_t* store = wasm_store_new(engine);
|
||||||
// Start by preparing the arguments.
|
|
||||||
// Value of argument #1 is `7i32`.
|
printf("Compiling module...\n");
|
||||||
wasmer_value_t argument_one;
|
wasm_module_t* module = wasm_module_new(store, &wasm_bytes);
|
||||||
argument_one.tag = WASM_I32;
|
|
||||||
argument_one.value.I32 = 7;
|
if (!module) {
|
||||||
// Value of argument #2 is `8i32`.
|
printf("> Error compiling module!\n");
|
||||||
wasmer_value_t argument_two;
|
return 1;
|
||||||
argument_two.tag = WASM_I32;
|
}
|
||||||
argument_two.value.I32 = 8;
|
|
||||||
// Prepare the arguments.
|
wasm_byte_vec_delete(&wasm_bytes);
|
||||||
wasmer_value_t arguments[] = {argument_one, argument_two};
|
|
||||||
// Prepare the return value.
|
printf("Creating imports...\n");
|
||||||
wasmer_value_t result_one;
|
wasm_extern_vec_t import_object = WASM_EMPTY_VEC;
|
||||||
wasmer_value_t results[] = {result_one};
|
|
||||||
// Call the `sum` function with the prepared arguments and the return value.
|
printf("Instantiating module...\n");
|
||||||
wasmer_result_t call_result = wasmer_instance_call(instance, "sum", arguments, 2, results, 1);
|
wasm_instance_t* instance = wasm_instance_new(store, module, &import_object, NULL);
|
||||||
// Let's display the result.
|
|
||||||
printf("Call result: %d\n", call_result);
|
if (!instance) {
|
||||||
printf("Result: %d\n", results[0].value.I32);
|
printf("> Error instantiating module!\n");
|
||||||
// `sum(7, 8) == 15`.
|
return 1;
|
||||||
assert(results[0].value.I32 == 15);
|
}
|
||||||
assert(call_result == WASMER_OK);
|
|
||||||
wasmer_instance_destroy(instance);
|
printf("Retrieving exports...\n");
|
||||||
return 0;
|
wasm_extern_vec_t exports;
|
||||||
|
wasm_instance_exports(instance, &exports);
|
||||||
|
|
||||||
|
if (exports.size == 0) {
|
||||||
|
printf("> Error accessing exports!\n");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
printf("Retrieving the `sum` function...\n");
|
||||||
|
wasm_func_t* sum_func = wasm_extern_as_func(exports.data[0]);
|
||||||
|
|
||||||
|
if (sum_func == NULL) {
|
||||||
|
printf("> Failed to get the `sum` function!\n");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
printf("Calling `sum` function...\n");
|
||||||
|
wasm_val_t args_val[2] = { WASM_I32_VAL(3), WASM_I32_VAL(4) };
|
||||||
|
wasm_val_t results_val[1] = { WASM_INIT_VAL };
|
||||||
|
wasm_val_vec_t args = WASM_ARRAY_VEC(args_val);
|
||||||
|
wasm_val_vec_t results = WASM_ARRAY_VEC(results_val);
|
||||||
|
|
||||||
|
if (wasm_func_call(sum_func, &args, &results)) {
|
||||||
|
printf("> Error calling the `sum` function!\n");
|
||||||
|
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
printf("Results of `sum`: %d\n", results_val[0].of.i32);
|
||||||
|
|
||||||
|
wasm_func_delete(sum_func);
|
||||||
|
wasm_module_delete(module);
|
||||||
|
wasm_instance_delete(instance);
|
||||||
|
wasm_store_delete(store);
|
||||||
|
wasm_engine_delete(engine);
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
# Testing
|
## Building
|
||||||
|
|
||||||
|
You can compile Wasmer shared library from source:
|
||||||
|
|
||||||
|
```text
|
||||||
|
make build-capi
|
||||||
|
```
|
||||||
|
|
||||||
|
This will generate the shared library \(depending on your system\):
|
||||||
|
|
||||||
|
* Windows: `target/release/libwasmer_c_api.dll`
|
||||||
|
* macOS: `target/release/libwasmer_runtime_c_api.dylib`
|
||||||
|
* Linux: `target/release/libwasmer_runtime_c_api.so`
|
||||||
|
|
||||||
|
If you want to generate the library and headers in a friendly format as shown in [Usage](#usage), you can execute the following in Wasmer root:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
make package-capi
|
||||||
|
```
|
||||||
|
|
||||||
|
This command will generate a `package` directory, that you can then use easily in the [Wasmer C API examples](https://docs.wasmer.io/integrations/examples).
|
||||||
|
|
||||||
|
|
||||||
|
## Testing
|
||||||
|
|
||||||
Tests are run using the release build of the library. If you make
|
Tests are run using the release build of the library. If you make
|
||||||
changes or compile with non-default features, please ensure you
|
changes or compile with non-default features, please ensure you
|
||||||
rebuild in release mode for the tests to see the changes.
|
rebuild in release mode for the tests to see the changes.
|
||||||
|
|
||||||
The tests can be run via `cargo test`, such as:
|
To run all the full suite of tests, enter Wasmer root directory
|
||||||
|
|
||||||
```sh
|
|
||||||
$ cargo test --release -- --nocapture
|
|
||||||
```
|
|
||||||
|
|
||||||
To run tests manually, enter the `lib/c-api/tests` directory
|
|
||||||
and run the following commands:
|
and run the following commands:
|
||||||
|
|
||||||
```sh
|
```sh
|
||||||
$ cmake .
|
$ make test-capi
|
||||||
$ make
|
|
||||||
$ make test
|
|
||||||
```
|
```
|
||||||
|
|
||||||
## pkg-config
|
## `wasmer config`
|
||||||
|
|
||||||
The Wasmer binary ships with an utility tool that outputs config
|
`wasmer config` output various configuration information needed to compile programs which use Wasmer.
|
||||||
in the `pkg-config` format.
|
|
||||||
|
|
||||||
You can use it like:
|
### `wasmer config --pkg-config`
|
||||||
|
|
||||||
|
It outputs the necessary details for compiling and linking a program to Wasmer,
|
||||||
|
using the `pkg-config` format:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
wasmer config --pkg-config > $PKG_CONFIG_PATH/wasmer.pc
|
$ wasmer config --pkg-config > $PKG_CONFIG_PATH/wasmer.pc
|
||||||
```
|
```
|
||||||
|
|
||||||
# License
|
### `wasmer config --includedir`
|
||||||
|
|
||||||
|
Directory containing Wasmer headers:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
$ wasmer config --includedir
|
||||||
|
/users/myuser/.wasmer/include
|
||||||
|
```
|
||||||
|
|
||||||
|
### `wasmer config --libdir`
|
||||||
|
|
||||||
|
Directory containing Wasmer libraries:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
$ wasmer config --libdir
|
||||||
|
/users/myuser/.wasmer/lib
|
||||||
|
```
|
||||||
|
|
||||||
|
### `wasmer config --libs`
|
||||||
|
|
||||||
|
Libraries needed to link against Wasmer components:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
$ wasmer config --libs
|
||||||
|
-L/Users/myuser/.wasmer/lib -lwasmer
|
||||||
|
```
|
||||||
|
|
||||||
|
### `wasmer config --libs`
|
||||||
|
|
||||||
|
Libraries needed to link against Wasmer components:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
$ wasmer config --cflags
|
||||||
|
-I/Users/myuser/.wasmer/include/wasmer
|
||||||
|
```
|
||||||
|
|
||||||
|
## License
|
||||||
|
|
||||||
Wasmer is primarily distributed under the terms of the [MIT
|
Wasmer is primarily distributed under the terms of the [MIT
|
||||||
license][mit-license] ([LICENSE][license]).
|
license][mit-license] ([LICENSE][license]).
|
||||||
|
|||||||
9
lib/c-api/examples/.gitignore
vendored
Normal file
9
lib/c-api/examples/.gitignore
vendored
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
|
||||||
|
*
|
||||||
|
*.o
|
||||||
|
|
||||||
|
|
||||||
|
# Unignore files ending with `.c` (i.e. `wasm-c-api-wasi.c`)
|
||||||
|
!*.c
|
||||||
|
# Unignore Makefile
|
||||||
|
!Makefile
|
||||||
46
lib/c-api/examples/Makefile
Normal file
46
lib/c-api/examples/Makefile
Normal file
@@ -0,0 +1,46 @@
|
|||||||
|
$(info Using provided WASMER_DIR=$(WASMER_DIR))
|
||||||
|
|
||||||
|
ifeq (,$(wildcard $(WASMER_DIR)/bin/wasmer))
|
||||||
|
CFLAGS = -g -I$(WASMER_DIR)/include
|
||||||
|
LDFLAGS = -Wl,-rpath,$(WASMER_DIR)/lib
|
||||||
|
LDLIBS = -L$(WASMER_DIR)/lib -lwasmer
|
||||||
|
else
|
||||||
|
CFLAGS = -g -I$(shell $(WASMER_DIR)/bin/wasmer config --includedir)
|
||||||
|
LDFLAGS = -Wl,-rpath,$(shell $(WASMER_DIR)/bin/wasmer config --libdir)
|
||||||
|
LDLIBS = $(shell $(WASMER_DIR)/bin/wasmer config --libs)
|
||||||
|
endif
|
||||||
|
|
||||||
|
$(info * CFLAGS: $(CFLAGS))
|
||||||
|
$(info * LDFLAGS: $(LDFLAGS))
|
||||||
|
$(info * LDLIBS: $(LDLIBS))
|
||||||
|
|
||||||
|
ALL = instance imports-exports exports-function exports-global memory
|
||||||
|
|
||||||
|
.SILENT: instance instance.o
|
||||||
|
instance: instance.o
|
||||||
|
|
||||||
|
.SILENT: imports-exports imports-exports.o
|
||||||
|
imports-exports: imports-exports.o
|
||||||
|
|
||||||
|
.SILENT: exports-function exports-function.o
|
||||||
|
exports-function: exports-function.o
|
||||||
|
|
||||||
|
.SILENT: exports-global exports-global.o
|
||||||
|
exports-global: exports-global.o
|
||||||
|
|
||||||
|
.SILENT: memory memory.o
|
||||||
|
memory: memory.o
|
||||||
|
|
||||||
|
.PHONY: all
|
||||||
|
all: $(ALL)
|
||||||
|
|
||||||
|
.PHONY: run
|
||||||
|
.SILENT: run
|
||||||
|
run: $(ALL)
|
||||||
|
set -o errexit; \
|
||||||
|
$(foreach example,$?,echo Running \"$(example)\" example; ./$(example); echo;)
|
||||||
|
|
||||||
|
.SILENT: clean
|
||||||
|
.PHONY: clean
|
||||||
|
clean:
|
||||||
|
$(foreach file,$(ALL),rm -f $(file).o $(file))
|
||||||
84
lib/c-api/examples/exports-function.c
Normal file
84
lib/c-api/examples/exports-function.c
Normal file
@@ -0,0 +1,84 @@
|
|||||||
|
#include <stdio.h>
|
||||||
|
#include "wasmer_wasm.h"
|
||||||
|
|
||||||
|
int main(int argc, const char* argv[]) {
|
||||||
|
const char *wat_string =
|
||||||
|
"(module\n"
|
||||||
|
" (type $sum_t (func (param i32 i32) (result i32)))\n"
|
||||||
|
" (func $sum_f (type $sum_t) (param $x i32) (param $y i32) (result i32)\n"
|
||||||
|
" local.get $x\n"
|
||||||
|
" local.get $y\n"
|
||||||
|
" i32.add)\n"
|
||||||
|
" (export \"sum\" (func $sum_f)))";
|
||||||
|
|
||||||
|
wasm_byte_vec_t wat;
|
||||||
|
wasm_byte_vec_new(&wat, strlen(wat_string), wat_string);
|
||||||
|
wasm_byte_vec_t wasm_bytes;
|
||||||
|
wat2wasm(&wat, &wasm_bytes);
|
||||||
|
|
||||||
|
printf("Creating the store...\n");
|
||||||
|
wasm_engine_t* engine = wasm_engine_new();
|
||||||
|
wasm_store_t* store = wasm_store_new(engine);
|
||||||
|
|
||||||
|
printf("Compiling module...\n");
|
||||||
|
wasm_module_t* module = wasm_module_new(store, &wasm_bytes);
|
||||||
|
|
||||||
|
if (!module) {
|
||||||
|
printf("> Error compiling module!\n");
|
||||||
|
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
wasm_byte_vec_delete(&wasm_bytes);
|
||||||
|
|
||||||
|
printf("Creating imports...\n");
|
||||||
|
wasm_extern_vec_t import_object = WASM_EMPTY_VEC;
|
||||||
|
|
||||||
|
printf("Instantiating module...\n");
|
||||||
|
wasm_instance_t* instance = wasm_instance_new(store, module, &import_object, NULL);
|
||||||
|
|
||||||
|
if (!instance) {
|
||||||
|
printf("> Error instantiating module!\n");
|
||||||
|
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
printf("Retrieving exports...\n");
|
||||||
|
wasm_extern_vec_t exports;
|
||||||
|
wasm_instance_exports(instance, &exports);
|
||||||
|
|
||||||
|
if (exports.size == 0) {
|
||||||
|
printf("> Error accessing exports!\n");
|
||||||
|
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
printf("Retrieving the `sum` function...\n");
|
||||||
|
wasm_func_t* sum_func = wasm_extern_as_func(exports.data[0]);
|
||||||
|
|
||||||
|
if (sum_func == NULL) {
|
||||||
|
printf("> Failed to get the `sum` function!\n");
|
||||||
|
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
printf("Calling `sum` function...\n");
|
||||||
|
wasm_val_t args_val[2] = { WASM_I32_VAL(3), WASM_I32_VAL(4) };
|
||||||
|
wasm_val_t results_val[1] = { WASM_INIT_VAL };
|
||||||
|
wasm_val_vec_t args = WASM_ARRAY_VEC(args_val);
|
||||||
|
wasm_val_vec_t results = WASM_ARRAY_VEC(results_val);
|
||||||
|
|
||||||
|
if (wasm_func_call(sum_func, &args, &results)) {
|
||||||
|
printf("> Error calling the `sum` function!\n");
|
||||||
|
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
printf("Results of `sum`: %d\n", results_val[0].of.i32);
|
||||||
|
|
||||||
|
wasm_func_delete(sum_func);
|
||||||
|
wasm_module_delete(module);
|
||||||
|
wasm_instance_delete(instance);
|
||||||
|
wasm_store_delete(store);
|
||||||
|
wasm_engine_delete(engine);
|
||||||
|
}
|
||||||
117
lib/c-api/examples/exports-global.c
Normal file
117
lib/c-api/examples/exports-global.c
Normal file
@@ -0,0 +1,117 @@
|
|||||||
|
#include <stdio.h>
|
||||||
|
#include "wasmer_wasm.h"
|
||||||
|
|
||||||
|
int main(int argc, const char* argv[]) {
|
||||||
|
const char *wat_string =
|
||||||
|
"(module\n"
|
||||||
|
" (global $one (export \"one\") f32 (f32.const 1))\n"
|
||||||
|
" (global $some (export \"some\") (mut f32) (f32.const 0))\n"
|
||||||
|
" (func (export \"get_one\") (result f32) (global.get $one))\n"
|
||||||
|
" (func (export \"get_some\") (result f32) (global.get $some))\n"
|
||||||
|
" (func (export \"set_some\") (param f32) (global.set $some (local.get 0))))";
|
||||||
|
|
||||||
|
wasm_byte_vec_t wat;
|
||||||
|
wasm_byte_vec_new(&wat, strlen(wat_string), wat_string);
|
||||||
|
wasm_byte_vec_t wasm_bytes;
|
||||||
|
wat2wasm(&wat, &wasm_bytes);
|
||||||
|
|
||||||
|
printf("Creating the store...\n");
|
||||||
|
wasm_engine_t* engine = wasm_engine_new();
|
||||||
|
wasm_store_t* store = wasm_store_new(engine);
|
||||||
|
|
||||||
|
printf("Compiling module...\n");
|
||||||
|
wasm_module_t* module = wasm_module_new(store, &wasm_bytes);
|
||||||
|
|
||||||
|
if (!module) {
|
||||||
|
printf("> Error compiling module!\n");
|
||||||
|
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
wasm_byte_vec_delete(&wasm_bytes);
|
||||||
|
|
||||||
|
printf("Creating imports...\n");
|
||||||
|
wasm_extern_vec_t import_object = WASM_EMPTY_VEC;
|
||||||
|
|
||||||
|
printf("Instantiating module...\n");
|
||||||
|
wasm_instance_t* instance = wasm_instance_new(store, module, &import_object, NULL);
|
||||||
|
|
||||||
|
if (!instance) {
|
||||||
|
printf("> Error instantiating module!\n");
|
||||||
|
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
printf("Retrieving exports...\n");
|
||||||
|
wasm_extern_vec_t exports;
|
||||||
|
wasm_instance_exports(instance, &exports);
|
||||||
|
|
||||||
|
if (exports.size == 0) {
|
||||||
|
printf("> Error accessing exports!\n");
|
||||||
|
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
wasm_global_t* one = wasm_extern_as_global(exports.data[0]);
|
||||||
|
|
||||||
|
if (one == NULL) {
|
||||||
|
printf("> Failed to get the `one` global!\n");
|
||||||
|
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
wasm_global_t* some = wasm_extern_as_global(exports.data[1]);
|
||||||
|
|
||||||
|
if (some == NULL) {
|
||||||
|
printf("> Failed to get the `some` global!\n");
|
||||||
|
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
printf("Getting globals types information...\n");
|
||||||
|
wasm_globaltype_t* one_type = wasm_global_type(one);
|
||||||
|
wasm_globaltype_t* some_type = wasm_global_type(some);
|
||||||
|
|
||||||
|
wasm_mutability_t one_mutability = wasm_globaltype_mutability(one_type);
|
||||||
|
const wasm_valtype_t* one_content = wasm_globaltype_content(one_type);
|
||||||
|
wasm_valkind_t one_kind = wasm_valtype_kind(one_content);
|
||||||
|
|
||||||
|
wasm_mutability_t some_mutability = wasm_globaltype_mutability(some_type);
|
||||||
|
const wasm_valtype_t* some_content = wasm_globaltype_content(some_type);
|
||||||
|
wasm_valkind_t some_kind = wasm_valtype_kind(some_content);
|
||||||
|
|
||||||
|
printf("`one` type: %s %hhu\n", one_mutability == WASM_CONST ? "const" : "", one_kind);
|
||||||
|
printf("`some` type: %s %hhu\n", some_mutability == WASM_CONST ? "const" : "", some_kind);
|
||||||
|
|
||||||
|
printf("Getting global values...");
|
||||||
|
wasm_val_t one_value;
|
||||||
|
wasm_global_get(one, &one_value);
|
||||||
|
printf("`one` value: %.1f\n", one_value.of.f32);
|
||||||
|
|
||||||
|
wasm_val_t some_value;
|
||||||
|
wasm_global_get(some, &some_value);
|
||||||
|
printf("`some` value: %.1f\n", some_value.of.f32);
|
||||||
|
|
||||||
|
printf("Setting global values...\n");
|
||||||
|
wasm_val_t one_set_value = WASM_F32_VAL(42);
|
||||||
|
wasm_global_set(one, &one_set_value);
|
||||||
|
|
||||||
|
int error_length = wasmer_last_error_length();
|
||||||
|
if (error_length > 0) {
|
||||||
|
char *error_message = malloc(error_length);
|
||||||
|
wasmer_last_error_message(error_message, error_length);
|
||||||
|
|
||||||
|
printf("Attempted to set an immutable global: `%s`\n", error_message);
|
||||||
|
}
|
||||||
|
|
||||||
|
wasm_val_t some_set_value = WASM_F32_VAL(21);
|
||||||
|
wasm_global_set(some, &some_set_value);
|
||||||
|
printf("`some` value: %.1f\n", some_value.of.f32);
|
||||||
|
|
||||||
|
wasm_global_delete(some);
|
||||||
|
wasm_global_delete(one);
|
||||||
|
wasm_module_delete(module);
|
||||||
|
wasm_instance_delete(instance);
|
||||||
|
wasm_store_delete(store);
|
||||||
|
wasm_engine_delete(engine);
|
||||||
|
}
|
||||||
134
lib/c-api/examples/imports-exports.c
Normal file
134
lib/c-api/examples/imports-exports.c
Normal file
@@ -0,0 +1,134 @@
|
|||||||
|
#include <stdio.h>
|
||||||
|
#include "wasmer_wasm.h"
|
||||||
|
|
||||||
|
wasm_trap_t* host_func_callback(const wasm_val_vec_t* args, wasm_val_vec_t* results) {
|
||||||
|
printf("Calling back...\n> ");
|
||||||
|
|
||||||
|
wasm_val_t val = WASM_I32_VAL(42);
|
||||||
|
wasm_val_copy(&results->data[0], &val);
|
||||||
|
|
||||||
|
wasm_val_delete(&val);
|
||||||
|
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
int main(int argc, const char* argv[]) {
|
||||||
|
const char *wat_string =
|
||||||
|
"(module\n"
|
||||||
|
" (func $host_function (import \"\" \"host_function\") (result i32))\n"
|
||||||
|
" (global $host_global (import \"env\" \"host_global\") i32)\n"
|
||||||
|
" (func $function (export \"guest_function\") (result i32) (global.get $global))\n"
|
||||||
|
" (global $global (export \"guest_global\") i32 (i32.const 42))\n"
|
||||||
|
" (table $table (export \"guest_table\") 1 1 funcref)\n"
|
||||||
|
" (memory $memory (export \"guest_memory\") 1))";
|
||||||
|
|
||||||
|
wasm_byte_vec_t wat;
|
||||||
|
wasm_byte_vec_new(&wat, strlen(wat_string), wat_string);
|
||||||
|
wasm_byte_vec_t wasm_bytes;
|
||||||
|
wat2wasm(&wat, &wasm_bytes);
|
||||||
|
|
||||||
|
printf("Creating the store...\n");
|
||||||
|
wasm_engine_t* engine = wasm_engine_new();
|
||||||
|
wasm_store_t* store = wasm_store_new(engine);
|
||||||
|
|
||||||
|
printf("Compiling module...\n");
|
||||||
|
wasm_module_t* module = wasm_module_new(store, &wasm_bytes);
|
||||||
|
|
||||||
|
if (!module) {
|
||||||
|
printf("> Error compiling module!\n");
|
||||||
|
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
wasm_byte_vec_delete(&wasm_bytes);
|
||||||
|
|
||||||
|
printf("Creating the imported function...\n");
|
||||||
|
wasm_functype_t* host_func_type = wasm_functype_new_0_1(wasm_valtype_new_i32());
|
||||||
|
wasm_func_t* host_func = wasm_func_new(store, host_func_type, host_func_callback);
|
||||||
|
wasm_functype_delete(host_func_type);
|
||||||
|
|
||||||
|
printf("Creating the imported global...\n");
|
||||||
|
wasm_globaltype_t* host_global_type = wasm_globaltype_new(wasm_valtype_new(WASM_F32), WASM_CONST);
|
||||||
|
wasm_val_t host_global_val = WASM_I32_VAL(42);
|
||||||
|
wasm_global_t* host_global = wasm_global_new(store, host_global_type, &host_global_val);
|
||||||
|
wasm_globaltype_delete(host_global_type);
|
||||||
|
|
||||||
|
wasm_extern_t* externs[] = {
|
||||||
|
wasm_func_as_extern(host_func),
|
||||||
|
wasm_global_as_extern(host_global)
|
||||||
|
};
|
||||||
|
|
||||||
|
wasm_extern_vec_t import_object = WASM_ARRAY_VEC(externs);
|
||||||
|
|
||||||
|
printf("Instantiating module...\n");
|
||||||
|
wasm_instance_t* instance = wasm_instance_new(store, module, &import_object, NULL);
|
||||||
|
|
||||||
|
if (!instance) {
|
||||||
|
printf("> Error instantiating module!\n");
|
||||||
|
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
printf("Retrieving exports...\n");
|
||||||
|
wasm_extern_vec_t exports;
|
||||||
|
wasm_instance_exports(instance, &exports);
|
||||||
|
|
||||||
|
if (exports.size == 0) {
|
||||||
|
printf("> Error accessing exports!\n");
|
||||||
|
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
printf("Retrieving the exported function...\n");
|
||||||
|
wasm_func_t* func = wasm_extern_as_func(exports.data[0]);
|
||||||
|
|
||||||
|
if (func == NULL) {
|
||||||
|
printf("> Failed to get the exported function!\n");
|
||||||
|
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
printf("Got the exported function: %p\n", func);
|
||||||
|
|
||||||
|
printf("Retrieving the exported global...\n");
|
||||||
|
wasm_global_t* global = wasm_extern_as_global(exports.data[1]);
|
||||||
|
|
||||||
|
if (global == NULL) {
|
||||||
|
printf("> Failed to get the exported global!\n");
|
||||||
|
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
printf("Got the exported global: %p\n", global);
|
||||||
|
|
||||||
|
printf("Retrieving the exported table...\n");
|
||||||
|
wasm_table_t* table = wasm_extern_as_table(exports.data[2]);
|
||||||
|
|
||||||
|
if (table == NULL) {
|
||||||
|
printf("> Failed to get the exported table!\n");
|
||||||
|
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
printf("Got the exported table: %p\n", table);
|
||||||
|
|
||||||
|
printf("Retrieving the exported memory...\n");
|
||||||
|
wasm_memory_t* memory = wasm_extern_as_memory(exports.data[3]);
|
||||||
|
|
||||||
|
if (memory == NULL) {
|
||||||
|
printf("> Failed to get the exported memory!\n");
|
||||||
|
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
printf("Got the exported memory: %p\n", memory);
|
||||||
|
|
||||||
|
wasm_func_delete(func);
|
||||||
|
wasm_global_delete(global);
|
||||||
|
wasm_table_delete(table);
|
||||||
|
wasm_memory_delete(memory);
|
||||||
|
wasm_module_delete(module);
|
||||||
|
wasm_instance_delete(instance);
|
||||||
|
wasm_store_delete(store);
|
||||||
|
wasm_engine_delete(engine);
|
||||||
|
}
|
||||||
82
lib/c-api/examples/instance.c
Normal file
82
lib/c-api/examples/instance.c
Normal file
@@ -0,0 +1,82 @@
|
|||||||
|
#include <stdio.h>
|
||||||
|
#include "wasmer_wasm.h"
|
||||||
|
|
||||||
|
int main(int argc, const char* argv[]) {
|
||||||
|
const char *wat_string =
|
||||||
|
"(module\n"
|
||||||
|
" (type $add_one_t (func (param i32) (result i32)))\n"
|
||||||
|
" (func $add_one_f (type $add_one_t) (param $value i32) (result i32)\n"
|
||||||
|
" local.get $value\n"
|
||||||
|
" i32.const 1\n"
|
||||||
|
" i32.add)\n"
|
||||||
|
" (export \"add_one\" (func $add_one_f)))";
|
||||||
|
|
||||||
|
wasm_byte_vec_t wat;
|
||||||
|
wasm_byte_vec_new(&wat, strlen(wat_string), wat_string);
|
||||||
|
wasm_byte_vec_t wasm_bytes;
|
||||||
|
wat2wasm(&wat, &wasm_bytes);
|
||||||
|
|
||||||
|
printf("Creating the store...\n");
|
||||||
|
wasm_engine_t* engine = wasm_engine_new();
|
||||||
|
wasm_store_t* store = wasm_store_new(engine);
|
||||||
|
|
||||||
|
printf("Compiling module...\n");
|
||||||
|
wasm_module_t* module = wasm_module_new(store, &wasm_bytes);
|
||||||
|
|
||||||
|
if (!module) {
|
||||||
|
printf("> Error compiling module!\n");
|
||||||
|
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
wasm_byte_vec_delete(&wasm_bytes);
|
||||||
|
|
||||||
|
printf("Creating imports...\n");
|
||||||
|
wasm_extern_vec_t imports = WASM_EMPTY_VEC;
|
||||||
|
|
||||||
|
printf("Instantiating module...\n");
|
||||||
|
wasm_instance_t* instance = wasm_instance_new(store, module, &imports, NULL);
|
||||||
|
|
||||||
|
if (!instance) {
|
||||||
|
printf("> Error instantiating module!\n");
|
||||||
|
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
printf("Retrieving exports...\n");
|
||||||
|
wasm_extern_vec_t exports;
|
||||||
|
wasm_instance_exports(instance, &exports);
|
||||||
|
|
||||||
|
if (exports.size == 0) {
|
||||||
|
printf("> Error accessing exports!\n");
|
||||||
|
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
const wasm_func_t* add_one_func = wasm_extern_as_func(exports.data[0]);
|
||||||
|
if (add_one_func == NULL) {
|
||||||
|
printf("> Error accessing export!\n");
|
||||||
|
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
wasm_module_delete(module);
|
||||||
|
wasm_instance_delete(instance);
|
||||||
|
|
||||||
|
printf("Calling `add_one` function...\n");
|
||||||
|
wasm_val_t args_val[1] = { WASM_I32_VAL(1) };
|
||||||
|
wasm_val_t results_val[1] = { WASM_INIT_VAL };
|
||||||
|
wasm_val_vec_t args = WASM_ARRAY_VEC(args_val);
|
||||||
|
wasm_val_vec_t results = WASM_ARRAY_VEC(results_val);
|
||||||
|
|
||||||
|
if (wasm_func_call(add_one_func, &args, &results)) {
|
||||||
|
printf("> Error calling function!\n");
|
||||||
|
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
printf("Results of `add_one`: %d\n", results_val[0].of.i32);
|
||||||
|
|
||||||
|
wasm_store_delete(store);
|
||||||
|
wasm_engine_delete(engine);
|
||||||
|
}
|
||||||
109
lib/c-api/examples/memory.c
Normal file
109
lib/c-api/examples/memory.c
Normal file
@@ -0,0 +1,109 @@
|
|||||||
|
#include <stdio.h>
|
||||||
|
#include "wasmer_wasm.h"
|
||||||
|
|
||||||
|
int main(int argc, const char* argv[]) {
|
||||||
|
const char *wat_string =
|
||||||
|
"(module\n"
|
||||||
|
" (type $mem_size_t (func (result i32)))\n"
|
||||||
|
" (type $get_at_t (func (param i32) (result i32)))\n"
|
||||||
|
" (type $set_at_t (func (param i32) (param i32)))\n"
|
||||||
|
" (memory $mem 1)\n"
|
||||||
|
" (func $get_at (type $get_at_t) (param $idx i32) (result i32)\n"
|
||||||
|
" (i32.load (local.get $idx)))\n"
|
||||||
|
" (func $set_at (type $set_at_t) (param $idx i32) (param $val i32)\n"
|
||||||
|
" (i32.store (local.get $idx) (local.get $val)))\n"
|
||||||
|
" (func $mem_size (type $mem_size_t) (result i32)\n"
|
||||||
|
" (memory.size))\n"
|
||||||
|
" (export \"get_at\" (func $get_at))\n"
|
||||||
|
" (export \"set_at\" (func $set_at))\n"
|
||||||
|
" (export \"mem_size\" (func $mem_size))\n"
|
||||||
|
" (export \"memory\" (memory $mem)))";
|
||||||
|
|
||||||
|
wasm_byte_vec_t wat;
|
||||||
|
wasm_byte_vec_new(&wat, strlen(wat_string), wat_string);
|
||||||
|
wasm_byte_vec_t wasm_bytes;
|
||||||
|
wat2wasm(&wat, &wasm_bytes);
|
||||||
|
|
||||||
|
printf("Creating the store...\n");
|
||||||
|
wasm_engine_t* engine = wasm_engine_new();
|
||||||
|
wasm_store_t* store = wasm_store_new(engine);
|
||||||
|
|
||||||
|
printf("Compiling module...\n");
|
||||||
|
wasm_module_t* module = wasm_module_new(store, &wasm_bytes);
|
||||||
|
|
||||||
|
if (!module) {
|
||||||
|
printf("> Error compiling module!\n");
|
||||||
|
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
wasm_byte_vec_delete(&wasm_bytes);
|
||||||
|
|
||||||
|
printf("Creating imports...\n");
|
||||||
|
wasm_extern_vec_t import_object = WASM_EMPTY_VEC;
|
||||||
|
|
||||||
|
printf("Instantiating module...\n");
|
||||||
|
wasm_instance_t* instance = wasm_instance_new(store, module, &import_object, NULL);
|
||||||
|
|
||||||
|
if (!instance) {
|
||||||
|
printf("> Error instantiating module!\n");
|
||||||
|
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
printf("Retrieving exports...\n");
|
||||||
|
wasm_extern_vec_t exports;
|
||||||
|
wasm_instance_exports(instance, &exports);
|
||||||
|
|
||||||
|
if (exports.size == 0) {
|
||||||
|
printf("> Error accessing exports!\n");
|
||||||
|
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
wasm_func_t* get_at = wasm_extern_as_func(exports.data[0]);
|
||||||
|
wasm_func_t* set_at = wasm_extern_as_func(exports.data[1]);
|
||||||
|
wasm_func_t* mem_size = wasm_extern_as_func(exports.data[2]);
|
||||||
|
wasm_memory_t* memory = wasm_extern_as_memory(exports.data[3]);
|
||||||
|
|
||||||
|
printf("Querying memory size...\n");
|
||||||
|
wasm_memory_pages_t pages = wasm_memory_size(memory);
|
||||||
|
size_t data_size = wasm_memory_data_size(memory);
|
||||||
|
printf("Memory size (pages): %d\n", pages);
|
||||||
|
printf("Memory size (bytes): %d\n", (int) data_size);
|
||||||
|
|
||||||
|
printf("Growing memory...\n");
|
||||||
|
if (!wasm_memory_grow(memory, 2)) {
|
||||||
|
printf("> Error growing memory!\n");
|
||||||
|
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
wasm_memory_pages_t new_pages = wasm_memory_size(memory);
|
||||||
|
printf("New memory size (pages): %d\n", new_pages);
|
||||||
|
|
||||||
|
int mem_addr = 0x2220;
|
||||||
|
int val = 0xFEFEFFE;
|
||||||
|
|
||||||
|
wasm_val_t set_at_args_val[2] = { WASM_I32_VAL(mem_addr), WASM_I32_VAL(val) };
|
||||||
|
wasm_val_vec_t set_at_args = WASM_ARRAY_VEC(set_at_args_val);
|
||||||
|
wasm_val_vec_t set_at_results = WASM_EMPTY_VEC;
|
||||||
|
wasm_func_call(set_at, &set_at_args, &set_at_results);
|
||||||
|
|
||||||
|
wasm_val_t get_at_args_val[1] = { WASM_I32_VAL(mem_addr) };
|
||||||
|
wasm_val_vec_t get_at_args = WASM_ARRAY_VEC(get_at_args_val);
|
||||||
|
wasm_val_t get_at_results_val[1] = { WASM_INIT_VAL };
|
||||||
|
wasm_val_vec_t get_at_results = WASM_ARRAY_VEC(get_at_results_val);
|
||||||
|
wasm_func_call(get_at, &get_at_args, &get_at_results);
|
||||||
|
|
||||||
|
printf("Value at 0x%04x: %d\n", mem_addr, get_at_results_val[0].of.i32);
|
||||||
|
|
||||||
|
wasm_memory_delete(memory);
|
||||||
|
wasm_func_delete(mem_size);
|
||||||
|
wasm_func_delete(set_at);
|
||||||
|
wasm_func_delete(get_at);
|
||||||
|
wasm_module_delete(module);
|
||||||
|
wasm_instance_delete(instance);
|
||||||
|
wasm_store_delete(store);
|
||||||
|
wasm_engine_delete(engine);
|
||||||
|
}
|
||||||
@@ -212,7 +212,7 @@ pub unsafe extern "C" fn wasmer_wasi_generate_default_import_object() -> *mut wa
|
|||||||
let store = get_global_store();
|
let store = get_global_store();
|
||||||
let mut wasi_state_builder = wasi::WasiState::new("wasmer-wasi-default-program-name");
|
let mut wasi_state_builder = wasi::WasiState::new("wasmer-wasi-default-program-name");
|
||||||
let wasi_state = wasi_state_builder.build().unwrap();
|
let wasi_state = wasi_state_builder.build().unwrap();
|
||||||
let mut wasi_env = wasi::WasiEnv::new(wasi_state);
|
let wasi_env = wasi::WasiEnv::new(wasi_state);
|
||||||
let import_object_inner: Box<dyn NamedResolver> = Box::new(
|
let import_object_inner: Box<dyn NamedResolver> = Box::new(
|
||||||
wasi::generate_import_object_from_env(store, wasi_env, wasi::WasiVersion::Latest),
|
wasi::generate_import_object_from_env(store, wasi_env, wasi::WasiVersion::Latest),
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ use wasmer::{Export, Exportable, Extern, Resolver};
|
|||||||
/// in a Vec, so we can retrieve them later based on index.
|
/// in a Vec, so we can retrieve them later based on index.
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
pub struct OrderedResolver {
|
pub struct OrderedResolver {
|
||||||
/// The externs to be resolved by inddex
|
/// The externs to be resolved by index
|
||||||
externs: Vec<Extern>,
|
externs: Vec<Extern>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -232,7 +232,7 @@ cfg_if! {
|
|||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub extern "C" fn wasm_engine_new() -> Box<wasm_engine_t> {
|
pub extern "C" fn wasm_engine_new() -> Box<wasm_engine_t> {
|
||||||
let compiler_config: Box<dyn CompilerConfig> = get_default_compiler_config();
|
let compiler_config: Box<dyn CompilerConfig> = get_default_compiler_config();
|
||||||
let engine: Arc<dyn Engine + Send + Sync> = Arc::new(JIT::new(&*compiler_config).engine());
|
let engine: Arc<dyn Engine + Send + Sync> = Arc::new(JIT::new(compiler_config).engine());
|
||||||
Box::new(wasm_engine_t { inner: engine })
|
Box::new(wasm_engine_t { inner: engine })
|
||||||
}
|
}
|
||||||
} else if #[cfg(feature = "jit")] {
|
} else if #[cfg(feature = "jit")] {
|
||||||
@@ -259,7 +259,7 @@ cfg_if! {
|
|||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub extern "C" fn wasm_engine_new() -> Box<wasm_engine_t> {
|
pub extern "C" fn wasm_engine_new() -> Box<wasm_engine_t> {
|
||||||
let mut compiler_config: Box<dyn CompilerConfig> = get_default_compiler_config();
|
let mut compiler_config: Box<dyn CompilerConfig> = get_default_compiler_config();
|
||||||
let engine: Arc<dyn Engine + Send + Sync> = Arc::new(Native::new(&mut *compiler_config).engine());
|
let engine: Arc<dyn Engine + Send + Sync> = Arc::new(Native::new(compiler_config).engine());
|
||||||
Box::new(wasm_engine_t { inner: engine })
|
Box::new(wasm_engine_t { inner: engine })
|
||||||
}
|
}
|
||||||
} else if #[cfg(feature = "native")] {
|
} else if #[cfg(feature = "native")] {
|
||||||
@@ -397,7 +397,7 @@ pub extern "C" fn wasm_engine_new_with_config(
|
|||||||
wasmer_engine_t::JIT => {
|
wasmer_engine_t::JIT => {
|
||||||
cfg_if! {
|
cfg_if! {
|
||||||
if #[cfg(feature = "jit")] {
|
if #[cfg(feature = "jit")] {
|
||||||
Arc::new(JIT::new(&*compiler_config).engine())
|
Arc::new(JIT::new(compiler_config).engine())
|
||||||
} else {
|
} else {
|
||||||
return return_with_error("Wasmer has not been compiled with the `jit` feature.");
|
return return_with_error("Wasmer has not been compiled with the `jit` feature.");
|
||||||
}
|
}
|
||||||
@@ -406,7 +406,7 @@ pub extern "C" fn wasm_engine_new_with_config(
|
|||||||
wasmer_engine_t::NATIVE => {
|
wasmer_engine_t::NATIVE => {
|
||||||
cfg_if! {
|
cfg_if! {
|
||||||
if #[cfg(feature = "native")] {
|
if #[cfg(feature = "native")] {
|
||||||
Arc::new(Native::new(&mut *compiler_config).engine())
|
Arc::new(Native::new(compiler_config).engine())
|
||||||
} else {
|
} else {
|
||||||
return return_with_error("Wasmer has not been compiled with the `native` feature.");
|
return return_with_error("Wasmer has not been compiled with the `native` feature.");
|
||||||
}
|
}
|
||||||
|
|||||||
75
lib/c-api/src/wasm_c_api/externals/global.rs
vendored
75
lib/c-api/src/wasm_c_api/externals/global.rs
vendored
@@ -78,3 +78,78 @@ pub unsafe extern "C" fn wasm_global_same(
|
|||||||
pub extern "C" fn wasm_global_type(global: &wasm_global_t) -> Box<wasm_globaltype_t> {
|
pub extern "C" fn wasm_global_type(global: &wasm_global_t) -> Box<wasm_globaltype_t> {
|
||||||
Box::new(wasm_globaltype_t::new(global.inner.ty().clone()))
|
Box::new(wasm_globaltype_t::new(global.inner.ty().clone()))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod tests {
|
||||||
|
use inline_c::assert_c;
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_set_host_global_immutable() {
|
||||||
|
(assert_c! {
|
||||||
|
#include "tests/wasmer_wasm.h"
|
||||||
|
|
||||||
|
int main() {
|
||||||
|
wasm_engine_t* engine = wasm_engine_new();
|
||||||
|
wasm_store_t* store = wasm_store_new(engine);
|
||||||
|
|
||||||
|
wasm_val_t forty_two = WASM_F32_VAL(42);
|
||||||
|
wasm_val_t forty_three = WASM_F32_VAL(43);
|
||||||
|
|
||||||
|
wasm_valtype_t* type = wasm_valtype_new_i32();
|
||||||
|
wasm_globaltype_t* global_type = wasm_globaltype_new(type, WASM_CONST);
|
||||||
|
wasm_global_t* global = wasm_global_new(store, global_type, &forty_two);
|
||||||
|
|
||||||
|
wasm_global_set(global, &forty_three);
|
||||||
|
|
||||||
|
assert(wasmer_last_error_length() > 0);
|
||||||
|
|
||||||
|
wasm_globaltype_delete(global_type);
|
||||||
|
wasm_valtype_delete(type);
|
||||||
|
wasm_store_delete(store);
|
||||||
|
wasm_engine_delete(engine);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.success();
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_set_guest_global_immutable() {
|
||||||
|
(assert_c! {
|
||||||
|
#include "tests/wasmer_wasm.h"
|
||||||
|
|
||||||
|
int main() {
|
||||||
|
wasm_engine_t* engine = wasm_engine_new();
|
||||||
|
wasm_store_t* store = wasm_store_new(engine);
|
||||||
|
|
||||||
|
wasm_byte_vec_t wat;
|
||||||
|
wasmer_byte_vec_new_from_string(&wat, "(module (global $global (export \"global\") f32 (f32.const 1)))");
|
||||||
|
wasm_byte_vec_t wasm_bytes;
|
||||||
|
wat2wasm(&wat, &wasm_bytes);
|
||||||
|
wasm_module_t* module = wasm_module_new(store, &wasm_bytes);
|
||||||
|
wasm_extern_vec_t import_object = WASM_EMPTY_VEC;
|
||||||
|
wasm_instance_t* instance = wasm_instance_new(store, module, &import_object, NULL);
|
||||||
|
|
||||||
|
wasm_extern_vec_t exports;
|
||||||
|
wasm_instance_exports(instance, &exports);
|
||||||
|
wasm_global_t* global = wasm_extern_as_global(exports.data[0]);
|
||||||
|
|
||||||
|
wasm_val_t forty_two = WASM_F32_VAL(42);
|
||||||
|
wasm_global_set(global, &forty_two);
|
||||||
|
|
||||||
|
printf("%d", wasmer_last_error_length());
|
||||||
|
assert(wasmer_last_error_length() > 0);
|
||||||
|
|
||||||
|
wasm_instance_delete(instance);
|
||||||
|
wasm_byte_vec_delete(&wasm_bytes);
|
||||||
|
wasm_byte_vec_delete(&wat);
|
||||||
|
wasm_store_delete(store);
|
||||||
|
wasm_engine_delete(engine);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.success();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -104,18 +104,14 @@ macro_rules! wasm_declare_vec {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub unsafe extern "C" fn [<wasm_ $name _vec_delete>](subject: Option<Box<[<wasm_ $name _vec_t>]>>) {
|
pub unsafe extern "C" fn [<wasm_ $name _vec_delete>](ptr: Option<&mut [<wasm_ $name _vec_t>]>) {
|
||||||
if subject.is_none() {
|
if let Some(vec) = ptr {
|
||||||
return;
|
if !vec.data.is_null() {
|
||||||
|
Vec::from_raw_parts(vec.data, vec.size, vec.size);
|
||||||
|
vec.data = ::std::ptr::null_mut();
|
||||||
|
vec.size = 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let subject: Box<[<wasm_ $name _vec_t>]> = subject.unwrap();
|
|
||||||
|
|
||||||
if !subject.data.is_null() {
|
|
||||||
let _ = Vec::from_raw_parts(subject.data, subject.size, subject.size);
|
|
||||||
}
|
|
||||||
|
|
||||||
::std::ptr::drop_in_place(Box::into_raw(subject));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -41,16 +41,17 @@ pub struct wasm_module_t {
|
|||||||
/// // Create a WebAssembly module from a WAT definition.
|
/// // Create a WebAssembly module from a WAT definition.
|
||||||
/// wasm_byte_vec_t wat;
|
/// wasm_byte_vec_t wat;
|
||||||
/// wasmer_byte_vec_new_from_string(&wat, "(module)");
|
/// wasmer_byte_vec_new_from_string(&wat, "(module)");
|
||||||
/// wasm_byte_vec_t* wasm = wat2wasm(&wat);
|
/// wasm_byte_vec_t wasm;
|
||||||
///
|
/// wat2wasm(&wat, &wasm);
|
||||||
|
///
|
||||||
/// // Create the module.
|
/// // Create the module.
|
||||||
/// wasm_module_t* module = wasm_module_new(store, wasm);
|
/// wasm_module_t* module = wasm_module_new(store, &wasm);
|
||||||
///
|
|
||||||
/// // It works!
|
/// // It works!
|
||||||
/// assert(module);
|
/// assert(module);
|
||||||
///
|
///
|
||||||
/// // Free everything.
|
/// // Free everything.
|
||||||
/// wasm_byte_vec_delete(wasm);
|
/// wasm_byte_vec_delete(&wasm);
|
||||||
/// wasm_byte_vec_delete(&wat);
|
/// wasm_byte_vec_delete(&wat);
|
||||||
/// wasm_module_delete(module);
|
/// wasm_module_delete(module);
|
||||||
/// wasm_store_delete(store);
|
/// wasm_store_delete(store);
|
||||||
@@ -109,13 +110,14 @@ pub unsafe extern "C" fn wasm_module_delete(_module: Option<Box<wasm_module_t>>)
|
|||||||
/// // Create a WebAssembly module from a WAT definition.
|
/// // Create a WebAssembly module from a WAT definition.
|
||||||
/// wasm_byte_vec_t wat;
|
/// wasm_byte_vec_t wat;
|
||||||
/// wasmer_byte_vec_new_from_string(&wat, "(module)");
|
/// wasmer_byte_vec_new_from_string(&wat, "(module)");
|
||||||
/// wasm_byte_vec_t* wasm = wat2wasm(&wat);
|
/// wasm_byte_vec_t wasm;
|
||||||
|
/// wat2wasm(&wat, &wasm);
|
||||||
///
|
///
|
||||||
/// // Validate that the WebAssembly module is correct.
|
/// // Validate that the WebAssembly module is correct.
|
||||||
/// assert(wasm_module_validate(store, wasm));
|
/// assert(wasm_module_validate(store, wasm));
|
||||||
///
|
///
|
||||||
/// // Free everything.
|
/// // Free everything.
|
||||||
/// wasm_byte_vec_delete(wasm);
|
/// wasm_byte_vec_delete(&wasm);
|
||||||
/// wasm_byte_vec_delete(&wat);
|
/// wasm_byte_vec_delete(&wat);
|
||||||
/// wasm_store_delete(store);
|
/// wasm_store_delete(store);
|
||||||
/// wasm_engine_delete(engine);
|
/// wasm_engine_delete(engine);
|
||||||
@@ -182,7 +184,8 @@ pub unsafe extern "C" fn wasm_module_validate(
|
|||||||
/// " (table (export \"table\") 0 funcref)\n"
|
/// " (table (export \"table\") 0 funcref)\n"
|
||||||
/// " (memory (export \"memory\") 1))"
|
/// " (memory (export \"memory\") 1))"
|
||||||
/// );
|
/// );
|
||||||
/// wasm_byte_vec_t* wasm = wat2wasm(&wat);
|
/// wasm_byte_vec_t wasm;
|
||||||
|
/// wat2wasm(&wat, &wasm);
|
||||||
///
|
///
|
||||||
/// // Create the module.
|
/// // Create the module.
|
||||||
/// wasm_module_t* module = wasm_module_new(store, wasm);
|
/// wasm_module_t* module = wasm_module_new(store, wasm);
|
||||||
@@ -249,7 +252,7 @@ pub unsafe extern "C" fn wasm_module_validate(
|
|||||||
///
|
///
|
||||||
/// // Free everything.
|
/// // Free everything.
|
||||||
/// wasm_exporttype_vec_delete(&export_types);
|
/// wasm_exporttype_vec_delete(&export_types);
|
||||||
/// wasm_byte_vec_delete(wasm);
|
/// wasm_byte_vec_delete(&wasm);
|
||||||
/// wasm_byte_vec_delete(&wat);
|
/// wasm_byte_vec_delete(&wat);
|
||||||
/// wasm_module_delete(module);
|
/// wasm_module_delete(module);
|
||||||
/// wasm_store_delete(store);
|
/// wasm_store_delete(store);
|
||||||
@@ -305,7 +308,8 @@ pub unsafe extern "C" fn wasm_module_exports(
|
|||||||
/// " (import \"ns\" \"table\" (table 1 2 anyfunc))\n"
|
/// " (import \"ns\" \"table\" (table 1 2 anyfunc))\n"
|
||||||
/// " (import \"ns\" \"memory\" (memory 3 4)))"
|
/// " (import \"ns\" \"memory\" (memory 3 4)))"
|
||||||
/// );
|
/// );
|
||||||
/// wasm_byte_vec_t* wasm = wat2wasm(&wat);
|
/// wasm_byte_vec_t wasm;
|
||||||
|
/// wat2wasm(&wat, &wasm);
|
||||||
///
|
///
|
||||||
/// // Create the module.
|
/// // Create the module.
|
||||||
/// wasm_module_t* module = wasm_module_new(store, wasm);
|
/// wasm_module_t* module = wasm_module_new(store, wasm);
|
||||||
@@ -390,7 +394,7 @@ pub unsafe extern "C" fn wasm_module_exports(
|
|||||||
/// // Free everything.
|
/// // Free everything.
|
||||||
/// wasm_importtype_vec_delete(&import_types);
|
/// wasm_importtype_vec_delete(&import_types);
|
||||||
/// wasm_module_delete(module);
|
/// wasm_module_delete(module);
|
||||||
/// wasm_byte_vec_delete(wasm);
|
/// wasm_byte_vec_delete(&wasm);
|
||||||
/// wasm_byte_vec_delete(&wat);
|
/// wasm_byte_vec_delete(&wat);
|
||||||
/// wasm_store_delete(store);
|
/// wasm_store_delete(store);
|
||||||
/// wasm_engine_delete(engine);
|
/// wasm_engine_delete(engine);
|
||||||
@@ -456,7 +460,8 @@ pub unsafe extern "C" fn wasm_module_imports(
|
|||||||
/// " (table (export \"table\") 0 funcref)\n"
|
/// " (table (export \"table\") 0 funcref)\n"
|
||||||
/// " (memory (export \"memory\") 1))"
|
/// " (memory (export \"memory\") 1))"
|
||||||
/// );
|
/// );
|
||||||
/// wasm_byte_vec_t* wasm = wat2wasm(&wat);
|
/// wasm_byte_vec_t wasm;
|
||||||
|
/// wat2wasm(&wat, &wasm);
|
||||||
///
|
///
|
||||||
/// // Create the module.
|
/// // Create the module.
|
||||||
/// wasm_module_t* module = wasm_module_new(store, wasm);
|
/// wasm_module_t* module = wasm_module_new(store, wasm);
|
||||||
@@ -488,7 +493,7 @@ pub unsafe extern "C" fn wasm_module_imports(
|
|||||||
/// // Free everything.
|
/// // Free everything.
|
||||||
/// wasm_exporttype_vec_delete(&export_types);
|
/// wasm_exporttype_vec_delete(&export_types);
|
||||||
/// wasm_module_delete(deserialized_module);
|
/// wasm_module_delete(deserialized_module);
|
||||||
/// wasm_byte_vec_delete(wasm);
|
/// wasm_byte_vec_delete(&wasm);
|
||||||
/// wasm_byte_vec_delete(&wat);
|
/// wasm_byte_vec_delete(&wat);
|
||||||
/// wasm_store_delete(store);
|
/// wasm_store_delete(store);
|
||||||
/// wasm_engine_delete(engine);
|
/// wasm_engine_delete(engine);
|
||||||
@@ -561,11 +566,12 @@ mod tests {
|
|||||||
|
|
||||||
wasm_byte_vec_t wat;
|
wasm_byte_vec_t wat;
|
||||||
wasmer_byte_vec_new_from_string(&wat, "(module)");
|
wasmer_byte_vec_new_from_string(&wat, "(module)");
|
||||||
wasm_byte_vec_t* wasm = wat2wasm(&wat);
|
wasm_byte_vec_t wasm;
|
||||||
|
wat2wasm(&wat, &wasm);
|
||||||
|
|
||||||
assert(wasm_module_validate(store, wasm));
|
assert(wasm_module_validate(store, &wasm));
|
||||||
|
|
||||||
wasm_byte_vec_delete(wasm);
|
wasm_byte_vec_delete(&wasm);
|
||||||
wasm_byte_vec_delete(&wat);
|
wasm_byte_vec_delete(&wat);
|
||||||
wasm_store_delete(store);
|
wasm_store_delete(store);
|
||||||
wasm_engine_delete(engine);
|
wasm_engine_delete(engine);
|
||||||
@@ -587,12 +593,13 @@ mod tests {
|
|||||||
|
|
||||||
wasm_byte_vec_t wat;
|
wasm_byte_vec_t wat;
|
||||||
wasmer_byte_vec_new_from_string(&wat, "(module)");
|
wasmer_byte_vec_new_from_string(&wat, "(module)");
|
||||||
wasm_byte_vec_t* wasm = wat2wasm(&wat);
|
wasm_byte_vec_t wasm;
|
||||||
|
wat2wasm(&wat, &wasm);
|
||||||
|
|
||||||
wasm_module_t* module = wasm_module_new(store, wasm);
|
wasm_module_t* module = wasm_module_new(store, &wasm);
|
||||||
assert(module);
|
assert(module);
|
||||||
|
|
||||||
wasm_byte_vec_delete(wasm);
|
wasm_byte_vec_delete(&wasm);
|
||||||
wasm_byte_vec_delete(&wat);
|
wasm_byte_vec_delete(&wat);
|
||||||
wasm_module_delete(module);
|
wasm_module_delete(module);
|
||||||
wasm_store_delete(store);
|
wasm_store_delete(store);
|
||||||
@@ -622,9 +629,10 @@ mod tests {
|
|||||||
" (table (export \"table\") 0 funcref)\n"
|
" (table (export \"table\") 0 funcref)\n"
|
||||||
" (memory (export \"memory\") 1))"
|
" (memory (export \"memory\") 1))"
|
||||||
);
|
);
|
||||||
wasm_byte_vec_t* wasm = wat2wasm(&wat);
|
wasm_byte_vec_t wasm;
|
||||||
|
wat2wasm(&wat, &wasm);
|
||||||
|
|
||||||
wasm_module_t* module = wasm_module_new(store, wasm);
|
wasm_module_t* module = wasm_module_new(store, &wasm);
|
||||||
assert(module);
|
assert(module);
|
||||||
|
|
||||||
wasm_exporttype_vec_t export_types;
|
wasm_exporttype_vec_t export_types;
|
||||||
@@ -699,7 +707,7 @@ mod tests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
wasm_exporttype_vec_delete(&export_types);
|
wasm_exporttype_vec_delete(&export_types);
|
||||||
wasm_byte_vec_delete(wasm);
|
wasm_byte_vec_delete(&wasm);
|
||||||
wasm_byte_vec_delete(&wat);
|
wasm_byte_vec_delete(&wat);
|
||||||
wasm_module_delete(module);
|
wasm_module_delete(module);
|
||||||
wasm_store_delete(store);
|
wasm_store_delete(store);
|
||||||
@@ -729,9 +737,10 @@ mod tests {
|
|||||||
" (import \"ns\" \"table\" (table 1 2 anyfunc))\n"
|
" (import \"ns\" \"table\" (table 1 2 anyfunc))\n"
|
||||||
" (import \"ns\" \"memory\" (memory 3 4)))"
|
" (import \"ns\" \"memory\" (memory 3 4)))"
|
||||||
);
|
);
|
||||||
wasm_byte_vec_t* wasm = wat2wasm(&wat);
|
wasm_byte_vec_t wasm;
|
||||||
|
wat2wasm(&wat, &wasm);
|
||||||
|
|
||||||
wasm_module_t* module = wasm_module_new(store, wasm);
|
wasm_module_t* module = wasm_module_new(store, &wasm);
|
||||||
assert(module);
|
assert(module);
|
||||||
|
|
||||||
wasm_importtype_vec_t import_types;
|
wasm_importtype_vec_t import_types;
|
||||||
@@ -817,7 +826,7 @@ mod tests {
|
|||||||
|
|
||||||
wasm_importtype_vec_delete(&import_types);
|
wasm_importtype_vec_delete(&import_types);
|
||||||
wasm_module_delete(module);
|
wasm_module_delete(module);
|
||||||
wasm_byte_vec_delete(wasm);
|
wasm_byte_vec_delete(&wasm);
|
||||||
wasm_byte_vec_delete(&wat);
|
wasm_byte_vec_delete(&wat);
|
||||||
wasm_store_delete(store);
|
wasm_store_delete(store);
|
||||||
wasm_engine_delete(engine);
|
wasm_engine_delete(engine);
|
||||||
@@ -839,9 +848,10 @@ mod tests {
|
|||||||
|
|
||||||
wasm_byte_vec_t wat;
|
wasm_byte_vec_t wat;
|
||||||
wasmer_byte_vec_new_from_string(&wat, "(module)");
|
wasmer_byte_vec_new_from_string(&wat, "(module)");
|
||||||
wasm_byte_vec_t* wasm = wat2wasm(&wat);
|
wasm_byte_vec_t wasm;
|
||||||
|
wat2wasm(&wat, &wasm);
|
||||||
|
|
||||||
wasm_module_t* module = wasm_module_new(store, wasm);
|
wasm_module_t* module = wasm_module_new(store, &wasm);
|
||||||
assert(module);
|
assert(module);
|
||||||
|
|
||||||
wasm_byte_vec_t serialized_module;
|
wasm_byte_vec_t serialized_module;
|
||||||
@@ -850,7 +860,7 @@ mod tests {
|
|||||||
|
|
||||||
wasm_module_delete(module);
|
wasm_module_delete(module);
|
||||||
wasm_byte_vec_delete(&serialized_module);
|
wasm_byte_vec_delete(&serialized_module);
|
||||||
wasm_byte_vec_delete(wasm);
|
wasm_byte_vec_delete(&wasm);
|
||||||
wasm_byte_vec_delete(&wat);
|
wasm_byte_vec_delete(&wat);
|
||||||
wasm_store_delete(store);
|
wasm_store_delete(store);
|
||||||
wasm_engine_delete(engine);
|
wasm_engine_delete(engine);
|
||||||
@@ -879,9 +889,10 @@ mod tests {
|
|||||||
" (table (export \"table\") 0 funcref)\n"
|
" (table (export \"table\") 0 funcref)\n"
|
||||||
" (memory (export \"memory\") 1))"
|
" (memory (export \"memory\") 1))"
|
||||||
);
|
);
|
||||||
wasm_byte_vec_t* wasm = wat2wasm(&wat);
|
wasm_byte_vec_t wasm;
|
||||||
|
wat2wasm(&wat, &wasm);
|
||||||
|
|
||||||
wasm_module_t* module = wasm_module_new(store, wasm);
|
wasm_module_t* module = wasm_module_new(store, &wasm);
|
||||||
assert(module);
|
assert(module);
|
||||||
|
|
||||||
wasm_byte_vec_t serialized_module;
|
wasm_byte_vec_t serialized_module;
|
||||||
@@ -903,7 +914,7 @@ mod tests {
|
|||||||
|
|
||||||
wasm_exporttype_vec_delete(&export_types);
|
wasm_exporttype_vec_delete(&export_types);
|
||||||
wasm_module_delete(deserialized_module);
|
wasm_module_delete(deserialized_module);
|
||||||
wasm_byte_vec_delete(wasm);
|
wasm_byte_vec_delete(&wasm);
|
||||||
wasm_byte_vec_delete(&wat);
|
wasm_byte_vec_delete(&wat);
|
||||||
wasm_store_delete(store);
|
wasm_store_delete(store);
|
||||||
wasm_engine_delete(engine);
|
wasm_engine_delete(engine);
|
||||||
|
|||||||
@@ -208,7 +208,7 @@ pub unsafe extern "C" fn wasi_env_read_stdout(
|
|||||||
buffer_len: usize,
|
buffer_len: usize,
|
||||||
) -> isize {
|
) -> isize {
|
||||||
let inner_buffer = slice::from_raw_parts_mut(buffer as *mut _, buffer_len as usize);
|
let inner_buffer = slice::from_raw_parts_mut(buffer as *mut _, buffer_len as usize);
|
||||||
let mut state = env.inner.state_mut();
|
let mut state = env.inner.state();
|
||||||
|
|
||||||
let stdout = if let Ok(stdout) = state.fs.stdout_mut() {
|
let stdout = if let Ok(stdout) = state.fs.stdout_mut() {
|
||||||
if let Some(stdout) = stdout.as_mut() {
|
if let Some(stdout) = stdout.as_mut() {
|
||||||
@@ -232,7 +232,7 @@ pub unsafe extern "C" fn wasi_env_read_stderr(
|
|||||||
buffer_len: usize,
|
buffer_len: usize,
|
||||||
) -> isize {
|
) -> isize {
|
||||||
let inner_buffer = slice::from_raw_parts_mut(buffer as *mut _, buffer_len as usize);
|
let inner_buffer = slice::from_raw_parts_mut(buffer as *mut _, buffer_len as usize);
|
||||||
let mut state = env.inner.state_mut();
|
let mut state = env.inner.state();
|
||||||
let stderr = if let Ok(stderr) = state.fs.stderr_mut() {
|
let stderr = if let Ok(stderr) = state.fs.stderr_mut() {
|
||||||
if let Some(stderr) = stderr.as_mut() {
|
if let Some(stderr) = stderr.as_mut() {
|
||||||
stderr
|
stderr
|
||||||
|
|||||||
@@ -3,14 +3,29 @@ use super::types::wasm_byte_vec_t;
|
|||||||
/// Parses in-memory bytes as either the WAT format, or a binary Wasm
|
/// Parses in-memory bytes as either the WAT format, or a binary Wasm
|
||||||
/// module. This is wasmer-specific.
|
/// module. This is wasmer-specific.
|
||||||
///
|
///
|
||||||
/// In case of failure, `wat2wasm` returns `NULL`.
|
/// In case of failure, `wat2wasm` sets the `out->data = NULL` and `out->size = 0`.
|
||||||
#[cfg(feature = "wat")]
|
#[cfg(feature = "wat")]
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub unsafe extern "C" fn wat2wasm(wat: &wasm_byte_vec_t) -> Option<Box<wasm_byte_vec_t>> {
|
pub unsafe extern "C" fn wat2wasm(wat: &wasm_byte_vec_t, out: &mut wasm_byte_vec_t) {
|
||||||
let wat: &[u8] = wat.into_slice()?;
|
let wat: &[u8] = match wat.into_slice() {
|
||||||
let result: wasm_byte_vec_t = c_try!(wasmer::wat2wasm(wat)).into_owned().into();
|
Some(v) => v,
|
||||||
|
_ => {
|
||||||
|
out.data = std::ptr::null_mut();
|
||||||
|
out.size = 0;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
let result: wasm_byte_vec_t = match wasmer::wat2wasm(wat) {
|
||||||
|
Ok(val) => val.into_owned().into(),
|
||||||
|
Err(err) => {
|
||||||
|
crate::error::update_last_error(err);
|
||||||
|
out.data = std::ptr::null_mut();
|
||||||
|
out.size = 0;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
Some(Box::new(result))
|
*out = result;
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
@@ -28,22 +43,23 @@ mod tests {
|
|||||||
|
|
||||||
wasm_byte_vec_t wat;
|
wasm_byte_vec_t wat;
|
||||||
wasmer_byte_vec_new_from_string(&wat, "(module)");
|
wasmer_byte_vec_new_from_string(&wat, "(module)");
|
||||||
wasm_byte_vec_t* wasm = wat2wasm(&wat);
|
wasm_byte_vec_t wasm;
|
||||||
|
wat2wasm(&wat, &wasm);
|
||||||
|
|
||||||
assert(wasm);
|
assert(wasm.data);
|
||||||
assert(wasm->size == 8);
|
assert(wasm.size == 8);
|
||||||
assert(
|
assert(
|
||||||
wasm->data[0] == 0 &&
|
wasm.data[0] == 0 &&
|
||||||
wasm->data[1] == 'a' &&
|
wasm.data[1] == 'a' &&
|
||||||
wasm->data[2] == 's' &&
|
wasm.data[2] == 's' &&
|
||||||
wasm->data[3] == 'm' &&
|
wasm.data[3] == 'm' &&
|
||||||
wasm->data[4] == 1 &&
|
wasm.data[4] == 1 &&
|
||||||
wasm->data[5] == 0 &&
|
wasm.data[5] == 0 &&
|
||||||
wasm->data[6] == 0 &&
|
wasm.data[6] == 0 &&
|
||||||
wasm->data[7] == 0
|
wasm.data[7] == 0
|
||||||
);
|
);
|
||||||
|
|
||||||
wasm_byte_vec_delete(wasm);
|
wasm_byte_vec_delete(&wasm);
|
||||||
wasm_byte_vec_delete(&wat);
|
wasm_byte_vec_delete(&wat);
|
||||||
wasm_store_delete(store);
|
wasm_store_delete(store);
|
||||||
wasm_engine_delete(engine);
|
wasm_engine_delete(engine);
|
||||||
@@ -65,9 +81,10 @@ mod tests {
|
|||||||
|
|
||||||
wasm_byte_vec_t wat;
|
wasm_byte_vec_t wat;
|
||||||
wasmer_byte_vec_new_from_string(&wat, "(module");
|
wasmer_byte_vec_new_from_string(&wat, "(module");
|
||||||
wasm_byte_vec_t* wasm = wat2wasm(&wat);
|
wasm_byte_vec_t wasm;
|
||||||
|
wat2wasm(&wat, &wasm);
|
||||||
|
|
||||||
assert(!wasm);
|
assert(!wasm.data);
|
||||||
assert(wasmer_last_error_length() > 0);
|
assert(wasmer_last_error_length() > 0);
|
||||||
|
|
||||||
wasm_byte_vec_delete(&wat);
|
wasm_byte_vec_delete(&wat);
|
||||||
|
|||||||
6
lib/c-api/tests/.gitignore
vendored
Normal file
6
lib/c-api/tests/.gitignore
vendored
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
# ignore wasm-c-api binaries
|
||||||
|
wasm-c-api-*
|
||||||
|
test-*
|
||||||
|
|
||||||
|
# Unignore files ending with `.c` (i.e. `wasm-c-api-wasi.c`)
|
||||||
|
!*.c
|
||||||
75
lib/c-api/tests/Makefile
Normal file
75
lib/c-api/tests/Makefile
Normal file
@@ -0,0 +1,75 @@
|
|||||||
|
$(info Using provided WASMER_DIR=$(WASMER_DIR))
|
||||||
|
|
||||||
|
ifeq (,$(wildcard $(WASMER_DIR)/bin/wasmer))
|
||||||
|
CFLAGS = -g -I$(WASMER_DIR)/include
|
||||||
|
LDFLAGS = -Wl,-rpath,$(WASMER_DIR)/lib
|
||||||
|
LDLIBS = -L$(WASMER_DIR)/lib -lwasmer
|
||||||
|
else
|
||||||
|
CFLAGS = -g -I$(shell $(WASMER_DIR)/bin/wasmer config --includedir)
|
||||||
|
LDFLAGS = -Wl,-rpath,$(shell $(WASMER_DIR)/bin/wasmer config --libdir)
|
||||||
|
LDLIBS = $(shell $(WASMER_DIR)/bin/wasmer config --libs)
|
||||||
|
endif
|
||||||
|
|
||||||
|
$(info * CFLAGS: $(CFLAGS))
|
||||||
|
$(info * LDFLAGS: $(LDFLAGS))
|
||||||
|
$(info * LDLIBS: $(LDLIBS))
|
||||||
|
|
||||||
|
CAPI_WASMER_TESTS = \
|
||||||
|
test-early-exit test-memory test-wasi \
|
||||||
|
test-wat2wasm
|
||||||
|
|
||||||
|
CAPI_BASE_TESTS = \
|
||||||
|
wasm-c-api/example/callback wasm-c-api/example/global wasm-c-api/example/hello \
|
||||||
|
wasm-c-api/example/memory wasm-c-api/example/reflect wasm-c-api/example/serialize \
|
||||||
|
wasm-c-api/example/start wasm-c-api/example/trap
|
||||||
|
|
||||||
|
CAPI_BASE_TESTS_NOT_WORKING = \
|
||||||
|
wasm-c-api/example/finalize wasm-c-api/example/hostref wasm-c-api/example/multi \
|
||||||
|
wasm-c-api/example/table wasm-c-api/example/threads
|
||||||
|
|
||||||
|
DEPRECATED_TESTS = \
|
||||||
|
deprecated/test-context deprecated/test-import-object deprecated/test-module-imports \
|
||||||
|
deprecated/test-import-trap deprecated/test-module-serialize \
|
||||||
|
deprecated/test-exported-memory deprecated/test-imports deprecated/test-module \
|
||||||
|
deprecated/test-exports deprecated/test-instantiate deprecated/test-tables \
|
||||||
|
deprecated/test-globals deprecated/test-memory deprecated/test-validate \
|
||||||
|
deprecated/test-module-exports deprecated/test-module-import-instantiate
|
||||||
|
|
||||||
|
DEPRECATED_NOT_WORKING = test-import-function test-import-function-callinfo test-wasi-import-object test-emscripten-import-object
|
||||||
|
|
||||||
|
ALL = $(CAPI_BASE_TESTS) $(CAPI_WASMER_TESTS) $(DEPRECATED_TESTS)
|
||||||
|
|
||||||
|
test-%: %.o
|
||||||
|
deprecated/test-%: deprecated/%.o
|
||||||
|
|
||||||
|
.PHONY: all
|
||||||
|
all: $(ALL)
|
||||||
|
|
||||||
|
.PHONY: test-capi-wasmer
|
||||||
|
.SILENT: test-capi-wasmer
|
||||||
|
test-capi-wasmer: $(CAPI_WASMER_TESTS)
|
||||||
|
set -o errexit; \
|
||||||
|
$(foreach example,$?,echo Running \"$(example)\" example; cd $(shell dirname $(realpath $(example))) && ./$(shell basename $(example)); echo;)
|
||||||
|
|
||||||
|
.PHONY: test-capi-base
|
||||||
|
.SILENT: test-capi-base
|
||||||
|
test-capi-base: $(CAPI_BASE_TESTS)
|
||||||
|
set -o errexit; \
|
||||||
|
$(foreach example,$?,echo Running \"$(example)\" example; cd $(shell dirname $(realpath $(example))) && ./$(shell basename $(example)); echo;)
|
||||||
|
|
||||||
|
.PHONY: test-capi-base
|
||||||
|
.SILENT: test-capi-base
|
||||||
|
test-capi: test-capi-base test-capi-wasmer
|
||||||
|
|
||||||
|
.PHONY: test-deprecated
|
||||||
|
.SILENT: test-deprecated
|
||||||
|
test-deprecated: $(DEPRECATED_TESTS)
|
||||||
|
set -o errexit; \
|
||||||
|
$(foreach example,$?,echo Running \"$(example)\" example; cd $(shell dirname $(realpath $(example))) && ./$(shell basename $(example)); echo;)
|
||||||
|
|
||||||
|
test: test-capi test-deprecated
|
||||||
|
|
||||||
|
.SILENT: clean
|
||||||
|
.PHONY: clean
|
||||||
|
clean:
|
||||||
|
$(foreach file,$(ALL),rm -f $(file).o $(file))
|
||||||
32
lib/c-api/tests/deprecated/.gitignore
vendored
32
lib/c-api/tests/deprecated/.gitignore
vendored
@@ -1,35 +1,3 @@
|
|||||||
CMakeLists.txt.user
|
|
||||||
CMakeCache.txt
|
|
||||||
CMakeFiles
|
|
||||||
CMakeScripts
|
|
||||||
Testing
|
|
||||||
Makefile
|
|
||||||
cmake_install.cmake
|
|
||||||
install_manifest.txt
|
|
||||||
compile_commands.json
|
|
||||||
CTestTestfile.cmake
|
|
||||||
_deps
|
|
||||||
rust-build
|
|
||||||
test-context
|
|
||||||
test-exported-memory
|
|
||||||
test-exports
|
|
||||||
test-globals
|
|
||||||
test-import-function
|
|
||||||
test-import-trap
|
|
||||||
test-import-object
|
|
||||||
test-imports
|
|
||||||
test-instantiate
|
|
||||||
test-memory
|
|
||||||
test-module
|
|
||||||
test-module-exports
|
|
||||||
test-module-import-instantiate
|
|
||||||
test-module-imports
|
|
||||||
test-module-serialize
|
|
||||||
test-tables
|
|
||||||
test-validate
|
|
||||||
test-wasi-import-object
|
|
||||||
test-emscripten-import-object
|
|
||||||
|
|
||||||
# ignore wasm-c-api binaries
|
# ignore wasm-c-api binaries
|
||||||
wasm-c-api-*
|
wasm-c-api-*
|
||||||
test-*
|
test-*
|
||||||
|
|||||||
@@ -1,130 +0,0 @@
|
|||||||
cmake_minimum_required (VERSION 2.6)
|
|
||||||
project (WasmerDeprecatedCApiTests)
|
|
||||||
|
|
||||||
add_executable(test-context test-context.c)
|
|
||||||
add_executable(test-exported-memory test-exported-memory.c)
|
|
||||||
add_executable(test-exports test-exports.c)
|
|
||||||
add_executable(test-globals test-globals.c)
|
|
||||||
add_executable(test-import-object test-import-object.c)
|
|
||||||
add_executable(test-import-trap test-import-trap.c)
|
|
||||||
add_executable(test-imports test-imports.c)
|
|
||||||
add_executable(test-instantiate test-instantiate.c)
|
|
||||||
add_executable(test-memory test-memory.c)
|
|
||||||
add_executable(test-module test-module.c)
|
|
||||||
add_executable(test-module-exports test-module-exports.c)
|
|
||||||
add_executable(test-module-import-instantiate test-module-import-instantiate.c)
|
|
||||||
add_executable(test-module-imports test-module-imports.c)
|
|
||||||
add_executable(test-module-serialize test-module-serialize.c)
|
|
||||||
add_executable(test-tables test-tables.c)
|
|
||||||
add_executable(test-validate test-validate.c)
|
|
||||||
|
|
||||||
if (DEFINED WASI_TESTS)
|
|
||||||
add_executable(test-wasi-import-object test-wasi-import-object.c)
|
|
||||||
endif()
|
|
||||||
|
|
||||||
if (DEFINED EMSCRIPTEN_TESTS)
|
|
||||||
add_executable(test-emscripten-import-object test-emscripten-import-object.c)
|
|
||||||
endif()
|
|
||||||
|
|
||||||
include_directories(../../)
|
|
||||||
|
|
||||||
find_library(
|
|
||||||
WASMER_LIB NAMES libwasmer_c_api.dylib libwasmer_c_api.so wasmer_c_api.dll
|
|
||||||
PATHS ${CMAKE_SOURCE_DIR}/../../../../target/release/
|
|
||||||
REQUIRED
|
|
||||||
)
|
|
||||||
|
|
||||||
enable_testing()
|
|
||||||
|
|
||||||
set(
|
|
||||||
COMPILER_OPTIONS
|
|
||||||
# Clang or gcc
|
|
||||||
$<$<OR:$<CXX_COMPILER_ID:Clang>,$<CXX_COMPILER_ID:GNU>>:
|
|
||||||
"-Werror" >
|
|
||||||
# MSVC
|
|
||||||
$<$<CXX_COMPILER_ID:MSVC>:
|
|
||||||
"/WX" >
|
|
||||||
)
|
|
||||||
|
|
||||||
target_link_libraries(test-context general ${WASMER_LIB})
|
|
||||||
target_compile_options(test-context PRIVATE ${COMPILER_OPTIONS})
|
|
||||||
add_test(test-context test-context)
|
|
||||||
|
|
||||||
target_link_libraries(test-exported-memory general ${WASMER_LIB})
|
|
||||||
target_compile_options(test-exported-memory PRIVATE ${COMPILER_OPTIONS})
|
|
||||||
add_test(test-exported-memory test-exported-memory)
|
|
||||||
|
|
||||||
target_link_libraries(test-exports general ${WASMER_LIB})
|
|
||||||
target_compile_options(test-exports PRIVATE ${COMPILER_OPTIONS})
|
|
||||||
add_test(test-exports test-exports)
|
|
||||||
|
|
||||||
target_link_libraries(test-globals general ${WASMER_LIB})
|
|
||||||
target_compile_options(test-globals PRIVATE ${COMPILER_OPTIONS})
|
|
||||||
add_test(test-globals test-globals)
|
|
||||||
|
|
||||||
target_link_libraries(test-import-object general ${WASMER_LIB})
|
|
||||||
target_compile_options(test-import-object PRIVATE ${COMPILER_OPTIONS})
|
|
||||||
add_test(test-import-object test-import-object)
|
|
||||||
|
|
||||||
# trampoline functionality not yet implemented
|
|
||||||
#target_link_libraries(test-import-function general ${WASMER_LIB})
|
|
||||||
#target_compile_options(test-import-function PRIVATE ${COMPILER_OPTIONS})
|
|
||||||
#add_test(test-import-function test-import-function)
|
|
||||||
|
|
||||||
target_link_libraries(test-import-trap general ${WASMER_LIB})
|
|
||||||
target_compile_options(test-import-trap PRIVATE ${COMPILER_OPTIONS})
|
|
||||||
add_test(test-import-trap test-import-trap)
|
|
||||||
|
|
||||||
target_link_libraries(test-imports general ${WASMER_LIB})
|
|
||||||
target_compile_options(test-imports PRIVATE ${COMPILER_OPTIONS})
|
|
||||||
add_test(test-imports test-imports)
|
|
||||||
|
|
||||||
target_link_libraries(test-instantiate general ${WASMER_LIB})
|
|
||||||
target_compile_options(test-instantiate PRIVATE ${COMPILER_OPTIONS})
|
|
||||||
add_test(test-instantiate test-instantiate)
|
|
||||||
|
|
||||||
target_link_libraries(test-memory general ${WASMER_LIB})
|
|
||||||
target_compile_options(test-memory PRIVATE ${COMPILER_OPTIONS})
|
|
||||||
add_test(test-memory test-memory)
|
|
||||||
|
|
||||||
target_link_libraries(test-module general ${WASMER_LIB})
|
|
||||||
target_compile_options(test-module PRIVATE ${COMPILER_OPTIONS})
|
|
||||||
add_test(test-module test-module)
|
|
||||||
|
|
||||||
target_link_libraries(test-module-exports general ${WASMER_LIB})
|
|
||||||
target_compile_options(test-module-exports PRIVATE ${COMPILER_OPTIONS})
|
|
||||||
add_test(test-module-exports test-module-exports)
|
|
||||||
|
|
||||||
target_link_libraries(test-module-import-instantiate general ${WASMER_LIB})
|
|
||||||
target_compile_options(test-module-import-instantiate PRIVATE ${COMPILER_OPTIONS})
|
|
||||||
add_test(test-module-import-instantiate test-module-import-instantiate)
|
|
||||||
|
|
||||||
target_link_libraries(test-module-imports general ${WASMER_LIB})
|
|
||||||
target_compile_options(test-module-imports PRIVATE ${COMPILER_OPTIONS})
|
|
||||||
add_test(test-module-imports test-module-imports)
|
|
||||||
|
|
||||||
target_link_libraries(test-module-serialize general ${WASMER_LIB})
|
|
||||||
target_compile_options(test-module-serialize PRIVATE ${COMPILER_OPTIONS})
|
|
||||||
add_test(test-module-serialize test-module-serialize)
|
|
||||||
|
|
||||||
target_link_libraries(test-tables general ${WASMER_LIB})
|
|
||||||
target_compile_options(test-tables PRIVATE ${COMPILER_OPTIONS})
|
|
||||||
add_test(test-tables test-tables)
|
|
||||||
|
|
||||||
target_link_libraries(test-validate general ${WASMER_LIB})
|
|
||||||
target_compile_options(test-validate PRIVATE ${COMPILER_OPTIONS})
|
|
||||||
add_test(test-validate test-validate)
|
|
||||||
|
|
||||||
if (DEFINED WASI_TESTS)
|
|
||||||
target_link_libraries(test-wasi-import-object general ${WASMER_LIB})
|
|
||||||
target_compile_options(test-wasi-import-object PRIVATE ${COMPILER_OPTIONS})
|
|
||||||
# TODO: reenable this test
|
|
||||||
#add_test(test-wasi-import-object test-wasi-import-object)
|
|
||||||
endif()
|
|
||||||
|
|
||||||
# TODO: reenable this test
|
|
||||||
#if (DEFINED EMSCRIPTEN_TESTS)
|
|
||||||
# target_link_libraries(test-emscripten-import-object general ${WASMER_LIB})
|
|
||||||
# target_compile_options(test-emscripten-import-object PRIVATE ${COMPILER_OPTIONS})
|
|
||||||
# add_test(test-emscripten-import-object test-emscripten-import-object)
|
|
||||||
#endif()
|
|
||||||
@@ -1,23 +0,0 @@
|
|||||||
mod test_c_helpers;
|
|
||||||
|
|
||||||
use test_c_helpers::compile_with_cmake_and_run_test;
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
#[cfg(feature = "deprecated")]
|
|
||||||
fn test_deprecated_c_api() {
|
|
||||||
let project_tests_dir = concat!(env!("CARGO_MANIFEST_DIR"), "/tests/deprecated/");
|
|
||||||
|
|
||||||
let cmake_args = vec![
|
|
||||||
".",
|
|
||||||
#[cfg(feature = "wasi")]
|
|
||||||
"-DWASI_TESTS=ON",
|
|
||||||
#[cfg(feature = "emscripten")]
|
|
||||||
"-DEMSCRIPTEN_TESTS=ON",
|
|
||||||
// We need something like this to get this working on Windows, but this doesn't seem
|
|
||||||
// quite right -- perhaps it's double escaping the quotes?
|
|
||||||
#[cfg(target_os = "windows")]
|
|
||||||
r#"-G "MinGW Makefiles""#,
|
|
||||||
];
|
|
||||||
|
|
||||||
compile_with_cmake_and_run_test(project_tests_dir, cmake_args);
|
|
||||||
}
|
|
||||||
@@ -20,31 +20,32 @@ int main(int argc, const char* argv[]) {
|
|||||||
.data = "(module)",
|
.data = "(module)",
|
||||||
.size = 8,
|
.size = 8,
|
||||||
};
|
};
|
||||||
wasm_byte_vec_t *wasm = wat2wasm(&wat);
|
wasm_byte_vec_t wasm;
|
||||||
|
wat2wasm(&wat, &wasm);
|
||||||
|
|
||||||
if (!wasm) {
|
if (!wasm.data) {
|
||||||
printf("> Error compiler WAT to Wasm!\n");
|
printf("> Error compiling WAT to Wasm!\n");
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (wasm->size != 8) {
|
if (wasm.size != 8) {
|
||||||
printf("The Wasm size is incorrect!\n");
|
printf("The Wasm size is incorrect!\n");
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!(wasm->data[0] == 0 &&
|
if (!(wasm.data[0] == 0 &&
|
||||||
wasm->data[1] == 'a' &&
|
wasm.data[1] == 'a' &&
|
||||||
wasm->data[2] == 's' &&
|
wasm.data[2] == 's' &&
|
||||||
wasm->data[3] == 'm' &&
|
wasm.data[3] == 'm' &&
|
||||||
wasm->data[4] == 1 &&
|
wasm.data[4] == 1 &&
|
||||||
wasm->data[5] == 0 &&
|
wasm.data[5] == 0 &&
|
||||||
wasm->data[6] == 0 &&
|
wasm.data[6] == 0 &&
|
||||||
wasm->data[7] == 0)) {
|
wasm.data[7] == 0)) {
|
||||||
printf("The Wasm data is incorrect!\n");
|
printf("The Wasm data is incorrect!\n");
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
wasm_byte_vec_delete(wasm);
|
wasm_byte_vec_delete(&wasm);
|
||||||
|
|
||||||
// All done.
|
// All done.
|
||||||
printf("Done.\n");
|
printf("Done.\n");
|
||||||
@@ -1,47 +0,0 @@
|
|||||||
use std::process::Command;
|
|
||||||
|
|
||||||
pub fn compile_with_cmake_and_run_test(project_tests_dir: &str, cmake_args: Vec<&str>) {
|
|
||||||
run_command(
|
|
||||||
"rm",
|
|
||||||
project_tests_dir,
|
|
||||||
vec![
|
|
||||||
"-f", // we use -f so it doesn't fail if the file doesn't exist
|
|
||||||
"CMakeCache.txt",
|
|
||||||
],
|
|
||||||
);
|
|
||||||
run_command("cmake", project_tests_dir, cmake_args);
|
|
||||||
run_command("make", project_tests_dir, vec!["clean"]);
|
|
||||||
run_command("make", project_tests_dir, vec!["-Wdev", "-Werror=dev"]);
|
|
||||||
run_command("make", project_tests_dir, vec!["test", "ARGS=\"-V\""]);
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn run_command(command_str: &str, dir: &str, args: Vec<&str>) {
|
|
||||||
println!(
|
|
||||||
"Running command: `{}` with arguments: {:?}",
|
|
||||||
command_str, args
|
|
||||||
);
|
|
||||||
|
|
||||||
let mut command = Command::new(command_str);
|
|
||||||
command.args(&args);
|
|
||||||
command.current_dir(dir);
|
|
||||||
|
|
||||||
match command.output() {
|
|
||||||
Ok(result) => {
|
|
||||||
println!(
|
|
||||||
"> Status: `{:?}`\n> Stdout: `{}`\n> Stderr: `{}`",
|
|
||||||
result.status.code(),
|
|
||||||
String::from_utf8_lossy(&result.stdout[..]),
|
|
||||||
String::from_utf8_lossy(&result.stderr[..]),
|
|
||||||
);
|
|
||||||
|
|
||||||
if result.status.success() {
|
|
||||||
assert!(true)
|
|
||||||
} else {
|
|
||||||
panic!("Command failed with exit status: `{:?}`", result.status);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Err(error) => panic!("Command failed: `{}`", error),
|
|
||||||
}
|
|
||||||
|
|
||||||
println!("\n");
|
|
||||||
}
|
|
||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user