Merge branch 'master' into fix-c-api-trampoline

This commit is contained in:
Ivan Enderlin
2020-10-19 09:22:13 +02:00
287 changed files with 8940 additions and 4040 deletions

View File

@@ -1,4 +1,4 @@
[target.x86_64-unknown-linux-gnu] [target.'cfg(target_os = "linux")']
rustflags = [ rustflags = [
"-C", "link-arg=-Wl,-E" "-C", "link-arg=-Wl,-E"
] ]

View File

@@ -16,7 +16,7 @@ jobs:
include: include:
- build: linux - build: linux
os: ubuntu-latest os: ubuntu-latest
rust: 1.45.0 rust: 1.46.0
env: env:
CARGO_SCCACHE_VERSION: 0.2.13 CARGO_SCCACHE_VERSION: 0.2.13
SCCACHE_AZURE_BLOB_CONTAINER: wasmerstoragesccacheblob SCCACHE_AZURE_BLOB_CONTAINER: wasmerstoragesccacheblob
@@ -35,7 +35,7 @@ jobs:
# that are needed during the build process. Additionally, this works # that are needed during the build process. Additionally, this works
# around a bug in the 'cache' action that causes directories outside of # around a bug in the 'cache' action that causes directories outside of
# the workspace dir to be saved/restored incorrectly. # the workspace dir to be saved/restored incorrectly.
run: echo "::set-env name=CARGO_HOME::$(pwd)/.cargo_home" run: echo "CARGO_HOME=$(pwd)/.cargo_home" >> $GITHUB_ENV
- name: Cache - name: Cache
uses: actions/cache@master uses: actions/cache@master
with: with:
@@ -56,8 +56,8 @@ jobs:
curl --proto '=https' --tlsv1.2 -sSf https://github.com/llvm/llvm-project/releases/download/llvmorg-10.0.0/clang+llvm-10.0.0-x86_64-linux-gnu-ubuntu-18.04.tar.xz -L -o llvm.tar.xz curl --proto '=https' --tlsv1.2 -sSf https://github.com/llvm/llvm-project/releases/download/llvmorg-10.0.0/clang+llvm-10.0.0-x86_64-linux-gnu-ubuntu-18.04.tar.xz -L -o llvm.tar.xz
mkdir -p /opt/llvm-10 mkdir -p /opt/llvm-10
tar xf llvm.tar.xz --strip-components=1 -C /opt/llvm-10 tar xf llvm.tar.xz --strip-components=1 -C /opt/llvm-10
echo ::add-path::/opt/llvm-10/bin echo '/opt/llvm-10/bin' >> $GITHUB_PATH
echo ::set-env name=LLVM_SYS_100_PREFIX::/opt/llvm-10 echo 'name=LLVM_SYS_100_PREFIX=/opt/llvm-10' >> $GITHUB_ENV
- name: Install Python - name: Install Python
uses: actions/setup-python@v2 uses: actions/setup-python@v2
with: with:

View File

@@ -1,4 +1,10 @@
on: [push] on:
push:
branches:
- '!trying'
- '!trying.tmp'
- '!staging'
- '!staging.tmp'
name: build name: build
@@ -16,15 +22,15 @@ jobs:
uses: actions-rs/toolchain@v1 uses: actions-rs/toolchain@v1
with: with:
profile: minimal profile: minimal
toolchain: 1.45.0 toolchain: 1.46.0
override: true override: true
- name: Install LLVM (Linux) - name: Install LLVM (Linux)
run: | run: |
curl --proto '=https' --tlsv1.2 -sSf https://github.com/llvm/llvm-project/releases/download/llvmorg-10.0.0/clang+llvm-10.0.0-x86_64-linux-gnu-ubuntu-18.04.tar.xz -L -o llvm.tar.xz curl --proto '=https' --tlsv1.2 -sSf https://github.com/llvm/llvm-project/releases/download/llvmorg-10.0.0/clang+llvm-10.0.0-x86_64-linux-gnu-ubuntu-18.04.tar.xz -L -o llvm.tar.xz
mkdir -p /opt/llvm-10 mkdir -p /opt/llvm-10
tar xf llvm.tar.xz --strip-components=1 -C /opt/llvm-10 tar xf llvm.tar.xz --strip-components=1 -C /opt/llvm-10
echo ::add-path::/opt/llvm-10/bin echo '/opt/llvm-10/bin' >> $GITHUB_PATH
echo ::set-env name=LLVM_SYS_100_PREFIX::/opt/llvm-10 echo 'LLVM_SYS_100_PREFIX=/opt/llvm-10' >> $GITHUB_ENV
- name: Generate Coverage Report - name: Generate Coverage Report
run: | run: |
cargo install cargo-tarpaulin cargo install cargo-tarpaulin

View File

@@ -19,7 +19,7 @@ jobs:
uses: actions-rs/toolchain@v1 uses: actions-rs/toolchain@v1
with: with:
profile: minimal profile: minimal
toolchain: 1.45.0 toolchain: 1.46.0
override: true override: true
components: rustfmt, clippy components: rustfmt, clippy
- run: make lint - run: make lint

View File

@@ -38,17 +38,32 @@ jobs:
strategy: strategy:
fail-fast: false fail-fast: false
matrix: matrix:
build: [linux, macos, windows] build: [linux, macos, windows, linux-aarch64]
include: include:
- build: linux - build: linux
os: ubuntu-latest os: ubuntu-latest
rust: 1.45.2 rust: 1.46.0
llvm_url: 'https://github.com/wasmerio/llvm-build/releases/download/10.x/Ubuntu1910_Release.tar.xz'
# llvm_url: 'https://github.com/llvm/llvm-project/releases/download/llvmorg-10.0.0/clang+llvm-10.0.0-x86_64-linux-gnu-ubuntu-18.04.tar.xz'
artifact_name: 'wasmer-linux-amd64'
run_integration_tests: true
- build: macos - build: macos
os: macos-latest os: macos-latest
rust: 1.45.2 rust: 1.46.0
llvm_url: 'https://github.com/llvm/llvm-project/releases/download/llvmorg-10.0.0/clang+llvm-10.0.0-x86_64-apple-darwin.tar.xz'
artifact_name: 'wasmer-macos-amd64'
run_integration_tests: true
- build: windows - build: windows
os: windows-latest os: windows-latest
rust: 1.45.2 rust: 1.46.0
artifact_name: 'wasmer-windows-amd64'
run_integration_tests: true
- build: linux-aarch64
os: [self-hosted, linux, ARM64]
rust: 1.46.0
llvm_url: 'https://github.com/llvm/llvm-project/releases/download/llvmorg-10.0.0/clang+llvm-10.0.0-aarch64-linux-gnu.tar.xz'
artifact_name: 'wasmer-linux-aarch64'
run_integration_tests: false
env: env:
CARGO_SCCACHE_VERSION: 0.2.13 CARGO_SCCACHE_VERSION: 0.2.13
SCCACHE_AZURE_BLOB_CONTAINER: wasmerstoragesccacheblob SCCACHE_AZURE_BLOB_CONTAINER: wasmerstoragesccacheblob
@@ -66,7 +81,7 @@ jobs:
# that are needed during the build process. Additionally, this works # that are needed during the build process. Additionally, this works
# around a bug in the 'cache' action that causes directories outside of # around a bug in the 'cache' action that causes directories outside of
# the workspace dir to be saved/restored incorrectly. # the workspace dir to be saved/restored incorrectly.
run: echo "::set-env name=CARGO_HOME::$(pwd)/.cargo_home" run: echo "CARGO_HOME=$(pwd)/.cargo_home" >> $GITHUB_ENV
- name: Cache - name: Cache
uses: actions/cache@master uses: actions/cache@master
with: with:
@@ -88,40 +103,34 @@ jobs:
# key: cargo-sccache-bin-${{ env.CARGO_SCCACHE_VERSION }} # key: cargo-sccache-bin-${{ env.CARGO_SCCACHE_VERSION }}
# - name: Install sccache # - name: Install sccache
# run: | # run: |
# echo "::add-path::${{ runner.tool_cache }}/cargo-sccache/bin" # echo "${{ runner.tool_cache }}/cargo-sccache/bin" >> $GITHUB_PATH
# cargo install sccache --version ${{ env.CARGO_SCCACHE_VERSION }} --root ${{ runner.tool_cache }}/cargo-sccache # cargo install sccache --version ${{ env.CARGO_SCCACHE_VERSION }} --root ${{ runner.tool_cache }}/cargo-sccache
# - name: Start sccache # - name: Start sccache
# run: | # run: |
# ${{ runner.tool_cache }}/cargo-sccache/bin/sccache --start-server # ${{ runner.tool_cache }}/cargo-sccache/bin/sccache --start-server
# ${{ runner.tool_cache }}/cargo-sccache/bin/sscache -s # ${{ runner.tool_cache }}/cargo-sccache/bin/sscache -s
# echo "::set-env name=RUSTC_WRAPPER::${{ runner.tool_cache }}/cargo-sccache/bin/sccache" # echo "RUSTC_WRAPPER=${{ runner.tool_cache }}/cargo-sccache/bin/sccache" >> $GITHUB_ENV
- name: Install LLVM (Windows) - name: Install LLVM (Windows)
if: matrix.os == 'windows-latest' if: matrix.os == 'windows-latest'
run: choco install llvm shell: cmd
run: |
choco install llvm
# run: | # run: |
# curl --proto '=https' --tlsv1.2 -sSf https://github.com/llvm/llvm-project/releases/download/llvmorg-10.0.0/LLVM-10.0.0-win64.exe -L -o llvm-installer.exe # curl --proto '=https' --tlsv1.2 -sSf https://github.com/llvm/llvm-project/releases/download/llvmorg-10.0.0/LLVM-10.0.0-win64.exe -L -o llvm-installer.exe
# 7z x llvm-installer.exe -oC:/llvm-10 # 7z x llvm-installer.exe -oC:/llvm-10
# echo ::add-path::C:/llvm-10/bin # echo C:/llvm-10/bin >> $GITHUB_PATH
# echo ::set-env name=LLVM_SYS_100_PREFIX::C:/llvm-10 # echo "LLVM_SYS_100_PREFIX=C:/llvm-10" >> $GITHUB_ENV
# echo ::set-env name=LIBCLANG_PATH::C:/llvm-10/bin/libclang.dll # echo "LIBCLANG_PATH=C:/llvm-10/bin/libclang.dll" >> $GITHUB_ENV
- name: Install LLVM (macOS) - name: Install LLVM (Unix)
if: matrix.os == 'macos-latest' if: matrix.os != 'windows-latest'
run: | run: |
curl --proto '=https' --tlsv1.2 -sSf https://github.com/llvm/llvm-project/releases/download/llvmorg-10.0.0/clang+llvm-10.0.0-x86_64-apple-darwin.tar.xz -L -o llvm.tar.xz curl --proto '=https' --tlsv1.2 -sSf ${{ matrix.llvm_url }} -L -o llvm.tar.xz
mkdir -p ${{ env.LLVM_DIR }} mkdir -p ${{ env.LLVM_DIR }}
tar xf llvm.tar.xz --strip-components=1 -C ${{ env.LLVM_DIR }} tar xf llvm.tar.xz --strip-components=1 -C ${{ env.LLVM_DIR }}
echo "::add-path::${{ env.LLVM_DIR }}/bin" echo "${{ env.LLVM_DIR }}/bin" >> $GITHUB_PATH
echo "::set-env name=LLVM_SYS_100_PREFIX::${{ env.LLVM_DIR }}" echo "LLVM_SYS_100_PREFIX=${{ env.LLVM_DIR }}" >> $GITHUB_ENV
env: env:
LLVM_DIR: ${{ github.workspace }}/llvm-10 LLVM_DIR: ${{ github.workspace }}/llvm-10
- name: Install LLVM (Linux)
if: matrix.os == 'ubuntu-latest'
run: |
curl --proto '=https' --tlsv1.2 -sSf https://github.com/llvm/llvm-project/releases/download/llvmorg-10.0.0/clang+llvm-10.0.0-x86_64-linux-gnu-ubuntu-18.04.tar.xz -L -o llvm.tar.xz
mkdir -p /opt/llvm-10
tar xf llvm.tar.xz --strip-components=1 -C /opt/llvm-10
echo ::add-path::/opt/llvm-10/bin
echo ::set-env name=LLVM_SYS_100_PREFIX::/opt/llvm-10
- name: Set up dependencies for Mac OS - name: Set up dependencies for Mac OS
run: brew install automake run: brew install automake
if: matrix.os == 'macos-latest' if: matrix.os == 'macos-latest'
@@ -141,15 +150,30 @@ jobs:
run: | run: |
make build-wapm make build-wapm
if: needs.setup.outputs.DOING_RELEASE == '1' if: needs.setup.outputs.DOING_RELEASE == '1'
- name: Package Wasmer for integration tests
run: make package-without-wapm-for-integration-tests
if: needs.setup.outputs.DOING_RELEASE != '1'
- name: Package Wasmer - name: Package Wasmer
run: | run: |
make package make package
if: needs.setup.outputs.DOING_RELEASE == '1' if: needs.setup.outputs.DOING_RELEASE == '1'
- name: Run integration tests (Windows)
shell: cmd
run: |
call refreshenv
set WASMER_DIR=%CD%\package
make test-integration
if: matrix.run_integration_tests && matrix.os == 'windows-latest'
- name: Run integration tests (Unix)
run: |
export WASMER_DIR=`pwd`/package
make test-integration
if: matrix.run_integration_tests && matrix.os != 'windows-latest'
- name: Upload Artifacts - name: Upload Artifacts
uses: actions/upload-artifact@v2 uses: actions/upload-artifact@v2
if: needs.setup.outputs.DOING_RELEASE == '1' if: needs.setup.outputs.DOING_RELEASE == '1'
with: with:
name: wasmer-${{ matrix.os }} name: ${{ matrix.artifact_name }}
path: dist path: dist
release: release:
@@ -178,17 +202,17 @@ jobs:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with: with:
upload_url: ${{ steps.create_release.outputs.upload_url }} # This pulls from the CREATE RELEASE step above, referencing it's ID to get its outputs object, which include a `upload_url`. See this blog post for more info: https://jasonet.co/posts/new-features-of-github-actions/#passing-data-to-future-steps upload_url: ${{ steps.create_release.outputs.upload_url }} # This pulls from the CREATE RELEASE step above, referencing it's ID to get its outputs object, which include a `upload_url`. See this blog post for more info: https://jasonet.co/posts/new-features-of-github-actions/#passing-data-to-future-steps
asset_path: artifacts/wasmer-windows-latest/wasmer-windows.exe asset_path: artifacts/wasmer-windows-amd64/wasmer-windows.exe
asset_name: wasmer-windows.exe asset_name: wasmer-windows.exe
asset_content_type: application/vnd.microsoft.portable-executable asset_content_type: application/vnd.microsoft.portable-executable
- name: Upload Release Asset Linux - name: Upload Release Asset Linux amd64
id: upload-release-asset-linux id: upload-release-asset-linux-amd64
uses: actions/upload-release-asset@v1 uses: actions/upload-release-asset@v1
env: env:
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-ubuntu-latest/wasmer-linux-amd64.tar.gz asset_path: artifacts/wasmer-linux-amd64/wasmer-linux-amd64.tar.gz
asset_name: wasmer-linux-amd64.tar.gz asset_name: wasmer-linux-amd64.tar.gz
asset_content_type: application/gzip asset_content_type: application/gzip
- name: Upload Release Asset Mac - name: Upload Release Asset Mac
@@ -198,9 +222,19 @@ 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-macos-latest/wasmer-darwin-amd64.tar.gz asset_path: artifacts/wasmer-macos-amd64/wasmer-darwin-amd64.tar.gz
asset_name: wasmer-darwin-amd64.tar.gz asset_name: wasmer-darwin-amd64.tar.gz
asset_content_type: application/gzip asset_content_type: application/gzip
- name: Upload Release Asset Linux aarch64
id: upload-release-asset-linux-aarch64
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: artifacts/wasmer-linux-aarch64/wasmer-linux-aarch64.tar.gz
asset_name: wasmer-linux-aarch64.tar.gz
asset_content_type: application/gzip
audit: audit:
name: Audit name: Audit
@@ -214,7 +248,7 @@ jobs:
path: ${{ runner.tool_cache }}/cargo-audit path: ${{ runner.tool_cache }}/cargo-audit
key: cargo-audit-bin-${{ env.CARGO_AUDIT_VERSION }} key: cargo-audit-bin-${{ env.CARGO_AUDIT_VERSION }}
- run: | - run: |
echo "::add-path::${{ runner.tool_cache }}/cargo-audit/bin" echo "${{ runner.tool_cache }}/cargo-audit/bin" >> $GITHUB_PATH
- run: | - run: |
cargo install cargo-audit --version ${{ env.CARGO_AUDIT_VERSION }} --root ${{ runner.tool_cache }}/cargo-audit cargo install cargo-audit --version ${{ env.CARGO_AUDIT_VERSION }} --root ${{ runner.tool_cache }}/cargo-audit
cargo audit cargo audit

View File

@@ -1,17 +1,16 @@
[cranelift_coverage] [cranelift_coverage]
features = "cranelift,singlepass,llvm,test-no-traps,test-cranelift" features = "cranelift,singlepass,llvm,coverage,test-cranelift,test-jit"
examples = ["early-exit", "engine-jit", "engine-native", "engine-headless", "cross-compilation", "compiler-cranelift", "exported-function", "wasi"]
release = true release = true
[llvm_coverage] [llvm_coverage]
features = "cranelift,singlepass,llvm,test-no-traps,test-llvm" features = "cranelift,singlepass,llvm,coverage,test-llvm,test-jit"
examples = ["compiler-llvm"]
release = true release = true
[singlepass_coverage] [singlepass_coverage]
features = "cranelift,singlepass,llvm,test-no-traps,test-singlepass" features = "cranelift,singlepass,llvm,coverage,test-singlepass,test-jit"
release = true examples = ["compiler-singlepass"]
[feature_a_and_b_coverage]
features = "feature_a feature_b"
release = true release = true
[report] [report]

View File

@@ -1,66 +1,124 @@
# Changelog # Changelog
*The format is based on [Keep a Changelog].*
[Keep a Changelog]: http://keepachangelog.com/en/1.0.0/
## **[Unreleased]** ## **[Unreleased]**
### Added
- [#1699](https://github.com/wasmerio/wasmer/pull/1699) Update `wasm.h` to its latest version.
- [#1685](https://github.com/wasmerio/wasmer/pull/1685) Implement `wasm_exporttype_delete` in the Wasm C API.
- [#1725](https://github.com/wasmerio/wasmer/pull/1725) Implement `wasm_func_type` in the Wasm C API.
- [#1715](https://github.com/wasmerio/wasmer/pull/1715) Register errors from `wasm_module_serialize` in the Wasm C API.
- [#1709](https://github.com/wasmerio/wasmer/pull/1709) Implement `wasm_module_name` and `wasm_module_set_name` in the Wasm(er) C API.
- [#1700](https://github.com/wasmerio/wasmer/pull/1700) Implement `wasm_externtype_copy` in the Wasm C API.
### Fixed
- [#1718](https://github.com/wasmerio/wasmer/pull/1718) Fix panic in the API in some situations when the memory's min bound was greater than the memory's max bound.
## 1.0.0-alpha4 - 2020-10-08
### Added
- [#1635](https://github.com/wasmerio/wasmer/pull/1635) Implement `wat2wasm` in the Wasm C API.
- [#1636](https://github.com/wasmerio/wasmer/pull/1636) Implement `wasm_module_validate` in the Wasm C API.
- [#1657](https://github.com/wasmerio/wasmer/pull/1657) Implement `wasm_trap_t` and `wasm_frame_t` for Wasm C API; add examples in Rust and C of exiting early with a host function.
### Fixed
- [#1690](https://github.com/wasmerio/wasmer/pull/1690) Fix `wasm_memorytype_limits` where `min` and `max` represents pages, not bytes. Additionally, fixes the max limit sentinel value.
- [#1671](https://github.com/wasmerio/wasmer/pull/1671) Fix probestack firing inappropriately, and sometimes over/under allocating stack.
- [#1660](https://github.com/wasmerio/wasmer/pull/1660) Fix issue preventing map-dir aliases starting with `/` from working properly.
### Changed
- [#1682](https://github.com/wasmerio/wasmer/pull/1682) Improve error reporting when making a memory with invalid settings.
- [#1691](https://github.com/wasmerio/wasmer/pull/1691) Bump minimum supported Rust version to 1.46.0
- [#1645](https://github.com/wasmerio/wasmer/pull/1645) Move the install script to https://github.com/wasmerio/wasmer-install
## 1.0.0-alpha3 - 2020-09-14 ## 1.0.0-alpha3 - 2020-09-14
### Fixed
- [#1620](https://github.com/wasmerio/wasmer/pull/1620) Fix bug causing the Wapm binary to not be packaged with the release - [#1620](https://github.com/wasmerio/wasmer/pull/1620) Fix bug causing the Wapm binary to not be packaged with the release
- [#1619](https://github.com/wasmerio/wasmer/pull/1619) Improve error message in engine-native when C compiler is missing - [#1619](https://github.com/wasmerio/wasmer/pull/1619) Improve error message in engine-native when C compiler is missing
## 1.0.0-alpha02.0 - 2020-09-11 ## 1.0.0-alpha02.0 - 2020-09-11
- [#1602](https://github.com/wasmerio/wasmer/pull/1602) Fix panic when calling host functions with negative numbers in certain situations
- [#1590](https://github.com/wasmerio/wasmer/pull/1590) Fix soundness issue in API of vm::Global ### Added
- [#1566](https://github.com/wasmerio/wasmer/pull/1566) Add support for opening special Unix files to the WASI FS - [#1566](https://github.com/wasmerio/wasmer/pull/1566) Add support for opening special Unix files to the WASI FS
### Fixed
- [#1602](https://github.com/wasmerio/wasmer/pull/1602) Fix panic when calling host functions with negative numbers in certain situations
- [#1590](https://github.com/wasmerio/wasmer/pull/1590) Fix soundness issue in API of vm::Global
## TODO: 1.0.0-alpha01.0 ## TODO: 1.0.0-alpha01.0
- Wasmer refactor lands - Wasmer refactor lands
## TODO: 17... ## 0.17.1 - 2020-06-24
### Changed
- [#1439](https://github.com/wasmerio/wasmer/pull/1439) Move `wasmer-interface-types` into its own repository
### Fixed
- [#1554](https://github.com/wasmerio/wasmer/pull/1554) Update supported stable Rust version to 1.45.2. - [#1554](https://github.com/wasmerio/wasmer/pull/1554) Update supported stable Rust version to 1.45.2.
- [#1552](https://github.com/wasmerio/wasmer/pull/1552) Disable `sigint` handler by default. - [#1552](https://github.com/wasmerio/wasmer/pull/1552) Disable `sigint` handler by default.
## 0.17.1 - 2020-06-24
- [#1439](https://github.com/wasmerio/wasmer/pull/1439) Move `wasmer-interface-types` into its own repository
## 0.17.0 - 2020-05-11 ## 0.17.0 - 2020-05-11
- [#1401](https://github.com/wasmerio/wasmer/pull/1401) Make breaking change to `RuntimeError`: `RuntimeError` is now more explicit about its possible error values allowing for better insight into why a call into Wasm failed. ### Added
- [#1382](https://github.com/wasmerio/wasmer/pull/1382) Refactored test infranstructure (part 2)
- [#1380](https://github.com/wasmerio/wasmer/pull/1380) Refactored test infranstructure (part 1)
- [#1357](https://github.com/wasmerio/wasmer/pull/1357) Refactored bin commands into separate files
- [#1331](https://github.com/wasmerio/wasmer/pull/1331) Implement the `record` type and instrutions for WIT - [#1331](https://github.com/wasmerio/wasmer/pull/1331) Implement the `record` type and instrutions for WIT
- [#1345](https://github.com/wasmerio/wasmer/pull/1345) Adding ARM testing in Azure Pipelines - [#1345](https://github.com/wasmerio/wasmer/pull/1345) Adding ARM testing in Azure Pipelines
- [#1335](https://github.com/wasmerio/wasmer/pull/1335) Change mutability of `memory` to `const` in `wasmer_memory_data_length` in the C API
- [#1329](https://github.com/wasmerio/wasmer/pull/1329) New numbers and strings instructions for WIT - [#1329](https://github.com/wasmerio/wasmer/pull/1329) New numbers and strings instructions for WIT
- [#1332](https://github.com/wasmerio/wasmer/pull/1332) Add option to `CompilerConfig` to force compiler IR verification off even when `debug_assertions` are enabled. This can be used to make debug builds faster, which may be important if you're creating a library that wraps Wasmer and depend on the speed of debug builds. - [#1285](https://github.com/wasmerio/wasmer/pull/1285) Greatly improve errors in `wasmer-interface-types`
- [#1320](https://github.com/wasmerio/wasmer/pull/1320) Change `custom_sections` field in `ModuleInfo` to be more standards compliant by allowing multiple custom sections with the same name. To get the old behavior with the new API, you can add `.last().unwrap()` to accesses. For example, `module_info.custom_sections["custom_section_name"].last().unwrap()`. - [#1303](https://github.com/wasmerio/wasmer/pull/1303) NaN canonicalization for singlepass backend.
- [#1313](https://github.com/wasmerio/wasmer/pull/1313) Add new high-level public API through `wasmer` crate. Includes many updates including: - [#1313](https://github.com/wasmerio/wasmer/pull/1313) Add new high-level public API through `wasmer` crate. Includes many updates including:
- Minor improvement: `imports!` macro now handles no trailing comma as well as a trailing comma in namespaces and between namespaces. - Minor improvement: `imports!` macro now handles no trailing comma as well as a trailing comma in namespaces and between namespaces.
- New methods on `Module`: `exports`, `imports`, and `custom_sections`. - New methods on `Module`: `exports`, `imports`, and `custom_sections`.
- New way to get exports from an instance with `let func_name: Func<i32, i64> = instance.exports.get("func_name");`. - New way to get exports from an instance with `let func_name: Func<i32, i64> = instance.exports.get("func_name");`.
- Improved `Table` APIs including `set` which now allows setting functions directly. TODO: update this more if `Table::get` gets made public in this PR - Improved `Table` APIs including `set` which now allows setting functions directly. TODO: update this more if `Table::get` gets made public in this PR
- TODO: finish the list of changes here - TODO: finish the list of changes here
- [#1303](https://github.com/wasmerio/wasmer/pull/1303) NaN canonicalization for singlepass backend.
- [#1292](https://github.com/wasmerio/wasmer/pull/1292) Experimental Support for Android (x86_64 and AArch64)
- [#1305](https://github.com/wasmerio/wasmer/pull/1305) Handle panics from DynamicFunc. - [#1305](https://github.com/wasmerio/wasmer/pull/1305) Handle panics from DynamicFunc.
- [#1301](https://github.com/wasmerio/wasmer/pull/1301) Update supported stable Rust version to 1.41.1.
- [#1300](https://github.com/wasmerio/wasmer/pull/1300) Add support for multiple versions of WASI tests: wasitests now test all versions of WASI. - [#1300](https://github.com/wasmerio/wasmer/pull/1300) Add support for multiple versions of WASI tests: wasitests now test all versions of WASI.
- [#1285](https://github.com/wasmerio/wasmer/pull/1285) Greatly improve errors in `wasmer-interface-types` - [#1292](https://github.com/wasmerio/wasmer/pull/1292) Experimental Support for Android (x86_64 and AArch64)
### Fixed
- [#1283](https://github.com/wasmerio/wasmer/pull/1283) Workaround for floating point arguments and return values in `DynamicFunc`s. - [#1283](https://github.com/wasmerio/wasmer/pull/1283) Workaround for floating point arguments and return values in `DynamicFunc`s.
### Changed
- [#1401](https://github.com/wasmerio/wasmer/pull/1401) Make breaking change to `RuntimeError`: `RuntimeError` is now more explicit about its possible error values allowing for better insight into why a call into Wasm failed.
- [#1382](https://github.com/wasmerio/wasmer/pull/1382) Refactored test infranstructure (part 2)
- [#1380](https://github.com/wasmerio/wasmer/pull/1380) Refactored test infranstructure (part 1)
- [#1357](https://github.com/wasmerio/wasmer/pull/1357) Refactored bin commands into separate files
- [#1335](https://github.com/wasmerio/wasmer/pull/1335) Change mutability of `memory` to `const` in `wasmer_memory_data_length` in the C API
- [#1332](https://github.com/wasmerio/wasmer/pull/1332) Add option to `CompilerConfig` to force compiler IR verification off even when `debug_assertions` are enabled. This can be used to make debug builds faster, which may be important if you're creating a library that wraps Wasmer and depend on the speed of debug builds.
- [#1320](https://github.com/wasmerio/wasmer/pull/1320) Change `custom_sections` field in `ModuleInfo` to be more standards compliant by allowing multiple custom sections with the same name. To get the old behavior with the new API, you can add `.last().unwrap()` to accesses. For example, `module_info.custom_sections["custom_section_name"].last().unwrap()`.
- [#1301](https://github.com/wasmerio/wasmer/pull/1301) Update supported stable Rust version to 1.41.1.
## 0.16.2 - 2020-03-11 ## 0.16.2 - 2020-03-11
### Fixed
- [#1294](https://github.com/wasmerio/wasmer/pull/1294) Fix bug related to system calls in WASI that rely on reading from WasmPtrs as arrays of length 0. `WasmPtr` will now succeed on length 0 arrays again. - [#1294](https://github.com/wasmerio/wasmer/pull/1294) Fix bug related to system calls in WASI that rely on reading from WasmPtrs as arrays of length 0. `WasmPtr` will now succeed on length 0 arrays again.
## 0.16.1 - 2020-03-11 ## 0.16.1 - 2020-03-11
### Fixed
- [#1291](https://github.com/wasmerio/wasmer/pull/1291) Fix installation packaging script to package the `wax` command. - [#1291](https://github.com/wasmerio/wasmer/pull/1291) Fix installation packaging script to package the `wax` command.
## 0.16.0 - 2020-03-11 ## 0.16.0 - 2020-03-11
### Added
- [#1286](https://github.com/wasmerio/wasmer/pull/1286) Updated Windows Wasmer icons. Add wax - [#1286](https://github.com/wasmerio/wasmer/pull/1286) Updated Windows Wasmer icons. Add wax
- [#1284](https://github.com/wasmerio/wasmer/pull/1284) Implement string and memory instructions in `wasmer-interface-types` - [#1284](https://github.com/wasmerio/wasmer/pull/1284) Implement string and memory instructions in `wasmer-interface-types`
### Fixed
- [#1272](https://github.com/wasmerio/wasmer/pull/1272) Fix off-by-one error bug when accessing memory with a `WasmPtr` that contains the last valid byte of memory. Also changes the behavior of `WasmPtr<T, Array>` with a length of 0 and `WasmPtr<T>` where `std::mem::size_of::<T>()` is 0 to always return `None` - [#1272](https://github.com/wasmerio/wasmer/pull/1272) Fix off-by-one error bug when accessing memory with a `WasmPtr` that contains the last valid byte of memory. Also changes the behavior of `WasmPtr<T, Array>` with a length of 0 and `WasmPtr<T>` where `std::mem::size_of::<T>()` is 0 to always return `None`
## 0.15.0 - 2020-03-04 ## 0.15.0 - 2020-03-04

309
Cargo.lock generated
View File

@@ -47,9 +47,9 @@ dependencies = [
[[package]] [[package]]
name = "anyhow" name = "anyhow"
version = "1.0.31" version = "1.0.32"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "85bb70cc08ec97ca5450e6eba421deeea5f172c0fc61f78b5357b2a8e8be195f" checksum = "6b602bfe940d21c130f3895acd65221e8a61270debe89d628b9cb4e3ccb8569b"
[[package]] [[package]]
name = "arrayref" name = "arrayref"
@@ -82,9 +82,9 @@ checksum = "1d49d90015b3c36167a20fe2810c5cd875ad504b39cff3d4eae7977e6b7c1cb2"
[[package]] [[package]]
name = "autocfg" name = "autocfg"
version = "1.0.0" version = "1.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f8aac770f1885fd7e387acedd76065302551364496e46b3dd00860b2f8359b9d" checksum = "cdb031dd78e28731d87d56cc8ffef4a8f36ca26c38fe2de700543e627f8a464a"
[[package]] [[package]]
name = "backtrace" name = "backtrace"
@@ -142,9 +142,9 @@ checksum = "cf1de2fe8c75bc145a2f577add951f8134889b4795d47466a54a5c846d691693"
[[package]] [[package]]
name = "blake3" name = "blake3"
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 = "59f88a20f7dc23e3896bcbd85add056543c87215de721468b90e0c85d5a9f365" checksum = "ce4f9586c9a3151c4b49b19e82ba163dd073614dd057e53c969e1a4db5b52720"
dependencies = [ dependencies = [
"arrayref", "arrayref",
"arrayvec", "arrayvec",
@@ -205,12 +205,13 @@ dependencies = [
[[package]] [[package]]
name = "cbindgen" name = "cbindgen"
version = "0.14.4" version = "0.15.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e783d38a7700989e0209d0b0ed224c34ade92d3603da0cf15dc502ebada685a6" checksum = "1df6a11bba1d7cab86c166cecf4cf8acd7d02b7b65924d81b33d27197f22ee35"
dependencies = [ dependencies = [
"clap", "clap",
"heck", "heck",
"indexmap",
"log", "log",
"proc-macro2", "proc-macro2",
"quote", "quote",
@@ -223,9 +224,9 @@ dependencies = [
[[package]] [[package]]
name = "cc" name = "cc"
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 = "66120af515773fb005778dc07c261bd201ec8ce50bd6e7144c927753fe013381" checksum = "ef611cc68ff783f18535d77ddd080185275713d852c4f5cbb6122c462a7a825c"
[[package]] [[package]]
name = "cexpr" name = "cexpr"
@@ -255,9 +256,9 @@ dependencies = [
[[package]] [[package]]
name = "clap" name = "clap"
version = "2.33.1" version = "2.33.3"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bdfa80d47f954d53a35a64987ca1422f495b8d6483c0fe9f7117b36c2a792129" checksum = "37e58ac78573c40708d45522f0d80fa2f01cc4f9b4e2bf749807255454312002"
dependencies = [ dependencies = [
"ansi_term", "ansi_term",
"atty", "atty",
@@ -429,12 +430,12 @@ dependencies = [
[[package]] [[package]]
name = "crossbeam-channel" name = "crossbeam-channel"
version = "0.4.3" version = "0.4.4"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "09ee0cc8804d5393478d743b035099520087a5186f3b93fa58cec08fa62407b6" checksum = "b153fe7cbef478c567df0f972e02e6d736db11affe43dfc9c56a9374d1adfb87"
dependencies = [ dependencies = [
"cfg-if",
"crossbeam-utils", "crossbeam-utils",
"maybe-uninit",
] ]
[[package]] [[package]]
@@ -454,7 +455,7 @@ version = "0.8.2"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "058ed274caafc1f60c4997b5fc07bf7dc7cca454af7c6e81edffe5f33f70dace" checksum = "058ed274caafc1f60c4997b5fc07bf7dc7cca454af7c6e81edffe5f33f70dace"
dependencies = [ dependencies = [
"autocfg 1.0.0", "autocfg 1.0.1",
"cfg-if", "cfg-if",
"crossbeam-utils", "crossbeam-utils",
"lazy_static", "lazy_static",
@@ -469,7 +470,7 @@ version = "0.7.2"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c3c7c73a2d1e9fc0886a08b93e98eb643461230d5f1925e4036204d5f2e261a8" checksum = "c3c7c73a2d1e9fc0886a08b93e98eb643461230d5f1925e4036204d5f2e261a8"
dependencies = [ dependencies = [
"autocfg 1.0.0", "autocfg 1.0.1",
"cfg-if", "cfg-if",
"lazy_static", "lazy_static",
] ]
@@ -508,9 +509,9 @@ dependencies = [
[[package]] [[package]]
name = "ctor" name = "ctor"
version = "0.1.15" version = "0.1.16"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "39858aa5bac06462d4dd4b9164848eb81ffc4aa5c479746393598fd193afa227" checksum = "7fbaabec2c953050352311293be5c6aba8e141ba19d6811862b232d6fd020484"
dependencies = [ dependencies = [
"quote", "quote",
"syn", "syn",
@@ -609,9 +610,9 @@ dependencies = [
[[package]] [[package]]
name = "either" name = "either"
version = "1.5.3" version = "1.6.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bb1f6b1ce1c140482ea30ddd3335fc0024ac7ee112895426e0a629a6c20adfe3" checksum = "e78d4f1cc4ae33bbfc157ed5d5a5ef3bc29227303d595861deb238fcec4e9457"
[[package]] [[package]]
name = "enumset" name = "enumset"
@@ -697,9 +698,9 @@ dependencies = [
[[package]] [[package]]
name = "generic-array" name = "generic-array"
version = "0.14.3" version = "0.14.4"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "60fb4bb6bba52f78a471264d9a3b7d026cc0af47b22cd2cffbc0b787ca003e63" checksum = "501466ecc8a30d1d3b7fc9229b122b2ce8ed6e9d9223f1138d4babb253e51817"
dependencies = [ dependencies = [
"typenum", "typenum",
"version_check 0.9.2", "version_check 0.9.2",
@@ -707,9 +708,9 @@ dependencies = [
[[package]] [[package]]
name = "getrandom" name = "getrandom"
version = "0.1.14" version = "0.1.15"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7abc8dd8451921606d809ba32e95b6111925cd2906060d2dcc29c070220503eb" checksum = "fc587bc0ec293155d5bfa6b9891ec18a1e330c234f896ea47fbada4cadbe47e6"
dependencies = [ dependencies = [
"cfg-if", "cfg-if",
"libc", "libc",
@@ -774,7 +775,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "96282e96bfcd3da0d3aa9938bedf1e50df3269b6db08b4876d2da0bb1a0841cf" checksum = "96282e96bfcd3da0d3aa9938bedf1e50df3269b6db08b4876d2da0bb1a0841cf"
dependencies = [ dependencies = [
"ahash", "ahash",
"autocfg 1.0.0", "autocfg 1.0.1",
] ]
[[package]] [[package]]
@@ -784,9 +785,15 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e91b62f79061a0bc2e046024cb7ba44b08419ed238ecbd9adbd787434b9e8c25" checksum = "e91b62f79061a0bc2e046024cb7ba44b08419ed238ecbd9adbd787434b9e8c25"
dependencies = [ dependencies = [
"ahash", "ahash",
"autocfg 1.0.0", "autocfg 1.0.1",
] ]
[[package]]
name = "hashbrown"
version = "0.9.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "00d63df3d41950fb462ed38308eea019113ad1508da725bbedcd0fa5a85ef5f7"
[[package]] [[package]]
name = "heck" name = "heck"
version = "0.3.1" version = "0.3.1"
@@ -798,9 +805,9 @@ dependencies = [
[[package]] [[package]]
name = "hermit-abi" name = "hermit-abi"
version = "0.1.15" version = "0.1.16"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3deed196b6e7f9e44a2ae8d94225d80302d81208b1bb673fd21fe634645c85a9" checksum = "4c30f6d0bc6b00693347368a67d41b58f2fb851215ff1da49e90fe2c5c667151"
dependencies = [ dependencies = [
"libc", "libc",
] ]
@@ -828,12 +835,12 @@ checksum = "b9e0384b61958566e926dc50660321d12159025e767c18e043daf26b70104c39"
[[package]] [[package]]
name = "indexmap" name = "indexmap"
version = "1.5.0" version = "1.6.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5b88cd59ee5f71fea89a62248fc8f387d44400cefe05ef548466d61ced9029a7" checksum = "55e2e4c765aa53a0424761bf9f41aa7a6ac1efa87238f59560640e27fca028f2"
dependencies = [ dependencies = [
"autocfg 1.0.0", "autocfg 1.0.1",
"hashbrown 0.8.2", "hashbrown 0.9.0",
"serde", "serde",
] ]
@@ -865,15 +872,18 @@ dependencies = [
[[package]] [[package]]
name = "instant" name = "instant"
version = "0.1.6" version = "0.1.7"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5b141fdc7836c525d4d594027d318c84161ca17aaf8113ab1f81ab93ae897485" checksum = "63312a18f7ea8760cdd0a7c5aac1a619752a246b833545e3e36d1f81f7cd9e66"
dependencies = [
"cfg-if",
]
[[package]] [[package]]
name = "inventory" name = "inventory"
version = "0.1.7" version = "0.1.9"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "621b50c176968fd3b0bd71f821a28a0ea98db2b5aea966b2fbb8bd1b7d310328" checksum = "fedd49de24d8c263613701406611410687148ae8c37cd6452650b250f753a0dd"
dependencies = [ dependencies = [
"ctor", "ctor",
"ghost", "ghost",
@@ -882,9 +892,9 @@ dependencies = [
[[package]] [[package]]
name = "inventory-impl" name = "inventory-impl"
version = "0.1.7" version = "0.1.9"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f99a4111304bade76468d05beab3487c226e4fe4c4de1c4e8f006e815762db73" checksum = "ddead8880bc50f57fcd3b5869a7f6ff92570bb4e8f6870c22e2483272f2256da"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2",
"quote", "quote",
@@ -908,9 +918,9 @@ checksum = "dc6f3ad7b9d11a0c00842ff8de1b60ee58661048eb8049ed33c73594f359d7e6"
[[package]] [[package]]
name = "js-sys" name = "js-sys"
version = "0.3.42" version = "0.3.45"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "52732a3d3ad72c58ad2dc70624f9c17b46ecd0943b9a4f1ee37c4c18c5d983e2" checksum = "ca059e81d9486668f12d455a4ea6daa600bd408134cd17e3d3fb5a32d1f016f8"
dependencies = [ dependencies = [
"wasm-bindgen", "wasm-bindgen",
] ]
@@ -923,9 +933,9 @@ checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646"
[[package]] [[package]]
name = "lazycell" name = "lazycell"
version = "1.2.1" version = "1.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b294d6fa9ee409a054354afc4352b0b9ef7ca222c69b8812cbea9e7d2bf3783f" checksum = "830d08ce1d1d941e6b30645f1a0eb5643013d835ce3779a5fc208261dbe10f55"
[[package]] [[package]]
name = "leb128" name = "leb128"
@@ -935,9 +945,9 @@ checksum = "3576a87f2ba00f6f106fdfcd16db1d698d648a26ad8e0573cad8537c3c362d2a"
[[package]] [[package]]
name = "libc" name = "libc"
version = "0.2.76" version = "0.2.77"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "755456fae044e6fa1ebbbd1b3e902ae19e73097ed4ed87bb79934a867c007bc3" checksum = "f2f96b10ec2560088a8e76961b00d47107b3a625fecb76dedb29ee7ccbf98235"
[[package]] [[package]]
name = "libffi" name = "libffi"
@@ -984,9 +994,9 @@ dependencies = [
[[package]] [[package]]
name = "llvm-sys" name = "llvm-sys"
version = "100.1.0" version = "100.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5545bf9a09267c644e4d0ac68f37ac200af6579ae2e82aebce382654eb4abab1" checksum = "9109e19fbfac3458f2970189719fa19f1007c6fd4e08c44fdebf4be0ddbe261d"
dependencies = [ dependencies = [
"cc", "cc",
"lazy_static", "lazy_static",
@@ -1052,11 +1062,11 @@ dependencies = [
[[package]] [[package]]
name = "memoffset" name = "memoffset"
version = "0.5.5" version = "0.5.6"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c198b026e1bbf08a937e94c6c60f9ec4a2267f5b0d2eec9c1b21b061ce2be55f" checksum = "043175f069eda7b85febe4a74abbaeff828d9f8b448515d3151a14a3542811aa"
dependencies = [ dependencies = [
"autocfg 1.0.0", "autocfg 1.0.1",
] ]
[[package]] [[package]]
@@ -1082,11 +1092,12 @@ dependencies = [
[[package]] [[package]]
name = "miniz_oxide" name = "miniz_oxide"
version = "0.4.0" version = "0.4.2"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "be0f75932c1f6cfae3c04000e40114adf955636e19040f9c0a2c380702aa1c7f" checksum = "c60c0dfe32c10b43a144bad8fc83538c52f58302c92300ea7ec7bf7b38d5a7b9"
dependencies = [ dependencies = [
"adler", "adler",
"autocfg 1.0.1",
] ]
[[package]] [[package]]
@@ -1135,7 +1146,7 @@ version = "0.1.43"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8d59457e662d541ba17869cf51cf177c0b5f0cbf476c66bdc90bf1edac4f875b" checksum = "8d59457e662d541ba17869cf51cf177c0b5f0cbf476c66bdc90bf1edac4f875b"
dependencies = [ dependencies = [
"autocfg 1.0.0", "autocfg 1.0.1",
"num-traits", "num-traits",
] ]
@@ -1145,7 +1156,7 @@ version = "0.1.41"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7a6e6b7c748f995c4c29c5f5ae0248536e04a5739927c74ec0fa564805094b9f" checksum = "7a6e6b7c748f995c4c29c5f5ae0248536e04a5739927c74ec0fa564805094b9f"
dependencies = [ dependencies = [
"autocfg 1.0.0", "autocfg 1.0.1",
"num-integer", "num-integer",
"num-traits", "num-traits",
] ]
@@ -1156,7 +1167,7 @@ version = "0.2.12"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ac267bcc07f48ee5f8935ab0d24f316fb722d7a1292e2913f0cc196b29ffd611" checksum = "ac267bcc07f48ee5f8935ab0d24f316fb722d7a1292e2913f0cc196b29ffd611"
dependencies = [ dependencies = [
"autocfg 1.0.0", "autocfg 1.0.1",
] ]
[[package]] [[package]]
@@ -1187,9 +1198,9 @@ checksum = "1ab52be62400ca80aa00285d25253d7f7c437b7375c4de678f5405d3afe82ca5"
[[package]] [[package]]
name = "once_cell" name = "once_cell"
version = "1.4.0" version = "1.4.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0b631f7e854af39a1739f401cf34a8a013dfe09eac4fa4dba91e9768bd28168d" checksum = "260e51e7efe62b592207e9e13a68e43692a7a279171d6ba57abd208bf23645ad"
[[package]] [[package]]
name = "oorandom" name = "oorandom"
@@ -1284,15 +1295,15 @@ dependencies = [
[[package]] [[package]]
name = "ppv-lite86" name = "ppv-lite86"
version = "0.2.8" version = "0.2.9"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "237a5ed80e274dbc66f86bd59c1e25edc039660be53194b5fe0a482e0f2612ea" checksum = "c36fa947111f5c62a733b652544dd0016a43ce89619538a8ef92724a6f501a20"
[[package]] [[package]]
name = "proc-macro-error" name = "proc-macro-error"
version = "1.0.3" version = "1.0.4"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fc175e9777c3116627248584e8f8b3e2987405cabe1c0adf7d1dd28f09dc7880" checksum = "da25490ff9892aab3fcf7c36f08cfb902dd3e71ca0f9f9517bea02a73a5ce38c"
dependencies = [ dependencies = [
"proc-macro-error-attr", "proc-macro-error-attr",
"proc-macro2", "proc-macro2",
@@ -1303,28 +1314,26 @@ dependencies = [
[[package]] [[package]]
name = "proc-macro-error-attr" name = "proc-macro-error-attr"
version = "1.0.3" version = "1.0.4"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3cc9795ca17eb581285ec44936da7fc2335a3f34f2ddd13118b6f4d515435c50" checksum = "a1be40180e52ecc98ad80b184934baf3d0d29f979574e439af5a55274b35f869"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2",
"quote", "quote",
"syn",
"syn-mid",
"version_check 0.9.2", "version_check 0.9.2",
] ]
[[package]] [[package]]
name = "proc-macro-hack" name = "proc-macro-hack"
version = "0.5.16" version = "0.5.18"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7e0456befd48169b9f13ef0f0ad46d492cf9d2dbb918bcf38e01eed4ce3ec5e4" checksum = "99c605b9a0adc77b7211c6b1f722dcb613d68d66859a44f3d485a6da332b0598"
[[package]] [[package]]
name = "proc-macro2" name = "proc-macro2"
version = "1.0.19" version = "1.0.21"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "04f5f085b5d71e2188cb8271e5da0161ad52c3f227a661a3c135fdf28e258b12" checksum = "36e28516df94f3dd551a587da5357459d9b36d945a7c37c3557928c1c2ff2a2c"
dependencies = [ dependencies = [
"unicode-xid", "unicode-xid",
] ]
@@ -1517,7 +1526,7 @@ version = "1.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cfd016f0c045ad38b5251be2c9c0ab806917f82da4d36b2a327e5166adad9270" checksum = "cfd016f0c045ad38b5251be2c9c0ab806917f82da4d36b2a327e5166adad9270"
dependencies = [ dependencies = [
"autocfg 1.0.0", "autocfg 1.0.1",
"crossbeam-deque", "crossbeam-deque",
"either", "either",
"rayon-core", "rayon-core",
@@ -1525,9 +1534,9 @@ dependencies = [
[[package]] [[package]]
name = "rayon-core" name = "rayon-core"
version = "1.8.0" version = "1.8.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "91739a34c4355b5434ce54c9086c5895604a9c278586d1f1aa95e04f66b525a0" checksum = "e8c4fec834fb6e6d2dd5eece3c7b432a52f0ba887cf40e595190c4107edc08bf"
dependencies = [ dependencies = [
"crossbeam-channel", "crossbeam-channel",
"crossbeam-deque", "crossbeam-deque",
@@ -1725,9 +1734,9 @@ checksum = "388a1df253eca08550bef6c72392cfe7c30914bf41df5269b68cbd6ff8f570a3"
[[package]] [[package]]
name = "serde" name = "serde"
version = "1.0.115" version = "1.0.116"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e54c9a88f2da7238af84b5101443f0c0d0a3bbdc455e34a5c9497b1903ed55d5" checksum = "96fe57af81d28386a513cbc6858332abc6117cfdb5999647c6444b8f43a370a5"
dependencies = [ dependencies = [
"serde_derive", "serde_derive",
] ]
@@ -1753,9 +1762,9 @@ dependencies = [
[[package]] [[package]]
name = "serde_derive" name = "serde_derive"
version = "1.0.115" version = "1.0.116"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "609feed1d0a73cc36a0182a840a9b37b4a82f0b1150369f0536a9e3f2a31dc48" checksum = "f630a6370fd8e457873b4bd2ffdae75408bc291ba72be773772a4c2a065d9ae8"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2",
"quote", "quote",
@@ -1764,9 +1773,9 @@ dependencies = [
[[package]] [[package]]
name = "serde_json" name = "serde_json"
version = "1.0.56" version = "1.0.57"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3433e879a558dde8b5e8feb2a04899cf34fdde1fafb894687e52105fc1162ac3" checksum = "164eacbdb13512ec2745fb09d51fd5b22b0d65ed294a1dcf7285a360c80a675c"
dependencies = [ dependencies = [
"itoa", "itoa",
"ryu", "ryu",
@@ -1829,32 +1838,21 @@ dependencies = [
[[package]] [[package]]
name = "subtle" name = "subtle"
version = "2.2.3" version = "2.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "502d53007c02d7605a05df1c1a73ee436952781653da5d0bf57ad608f66932c1" checksum = "343f3f510c2915908f155e94f17220b19ccfacf2a64a2a5d8004f2c3e311e7fd"
[[package]] [[package]]
name = "syn" name = "syn"
version = "1.0.35" version = "1.0.41"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fb7f4c519df8c117855e19dd8cc851e89eb746fe7a73f0157e0d95fdec5369b0" checksum = "6690e3e9f692504b941dc6c3b188fd28df054f7fb8469ab40680df52fdcc842b"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2",
"quote", "quote",
"unicode-xid", "unicode-xid",
] ]
[[package]]
name = "syn-mid"
version = "0.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7be3539f6c128a931cf19dcee741c1af532c7fd387baa739c03dd2e96479338a"
dependencies = [
"proc-macro2",
"quote",
"syn",
]
[[package]] [[package]]
name = "target-lexicon" name = "target-lexicon"
version = "0.10.0" version = "0.10.0"
@@ -1962,9 +1960,9 @@ dependencies = [
[[package]] [[package]]
name = "tracing" name = "tracing"
version = "0.1.16" version = "0.1.19"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c2e2a2de6b0d5cbb13fc21193a2296888eaab62b6044479aafb3c54c01c29fcd" checksum = "6d79ca061b032d6ce30c660fded31189ca0b9922bf483cd70759f13a2d86786c"
dependencies = [ dependencies = [
"cfg-if", "cfg-if",
"log", "log",
@@ -1974,9 +1972,9 @@ dependencies = [
[[package]] [[package]]
name = "tracing-attributes" name = "tracing-attributes"
version = "0.1.9" version = "0.1.11"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f0693bf8d6f2bf22c690fc61a9d21ac69efdbb894a17ed596b9af0f01e64b84b" checksum = "80e0ccfc3378da0cce270c946b676a376943f5cd16aeba64568e7939806f4ada"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2",
"quote", "quote",
@@ -1985,9 +1983,9 @@ dependencies = [
[[package]] [[package]]
name = "tracing-core" name = "tracing-core"
version = "0.1.11" version = "0.1.16"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "94ae75f0d28ae10786f3b1895c55fe72e79928fd5ccdebb5438c75e93fec178f" checksum = "5bcf46c1f1f06aeea2d6b81f3c863d0930a596c86ad1920d4e5bad6dd1d7119a"
dependencies = [ dependencies = [
"lazy_static", "lazy_static",
] ]
@@ -2000,9 +1998,9 @@ checksum = "373c8a200f9e67a0c95e62a4f52fbf80c23b4381c05a17845531982fa99e6b33"
[[package]] [[package]]
name = "typetag" name = "typetag"
version = "0.1.5" version = "0.1.6"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9275125decb5d75fe57ebfe92debd119b15757aae27c56d7cb61ecab871960bc" checksum = "83b97b107d25d29de6879ac4f676ac5bfea92bdd01f206e995794493f1fc2e32"
dependencies = [ dependencies = [
"erased-serde", "erased-serde",
"inventory", "inventory",
@@ -2013,9 +2011,9 @@ dependencies = [
[[package]] [[package]]
name = "typetag-impl" name = "typetag-impl"
version = "0.1.5" version = "0.1.6"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "dc232cda3b1d82664153e6c95d1071809aa0f1011f306c3d6989f33d8c6ede17" checksum = "3f2466fc87b07b800a5060f89ba579d6882f7a03ac21363e4737764aaf9f99f9"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2",
"quote", "quote",
@@ -2089,9 +2087,9 @@ checksum = "1a143597ca7c7793eff794def352d41792a93c481eb1042423ff7ff72ba2c31f"
[[package]] [[package]]
name = "wasm-bindgen" name = "wasm-bindgen"
version = "0.2.65" version = "0.2.68"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f3edbcc9536ab7eababcc6d2374a0b7bfe13a2b6d562c5e07f370456b1a8f33d" checksum = "1ac64ead5ea5f05873d7c12b545865ca2b8d28adfc50a49b84770a3a97265d42"
dependencies = [ dependencies = [
"cfg-if", "cfg-if",
"wasm-bindgen-macro", "wasm-bindgen-macro",
@@ -2099,9 +2097,9 @@ dependencies = [
[[package]] [[package]]
name = "wasm-bindgen-backend" name = "wasm-bindgen-backend"
version = "0.2.65" version = "0.2.68"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "89ed2fb8c84bfad20ea66b26a3743f3e7ba8735a69fe7d95118c33ec8fc1244d" checksum = "f22b422e2a757c35a73774860af8e112bff612ce6cb604224e8e47641a9e4f68"
dependencies = [ dependencies = [
"bumpalo", "bumpalo",
"lazy_static", "lazy_static",
@@ -2114,9 +2112,9 @@ dependencies = [
[[package]] [[package]]
name = "wasm-bindgen-macro" name = "wasm-bindgen-macro"
version = "0.2.65" version = "0.2.68"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "eb071268b031a64d92fc6cf691715ca5a40950694d8f683c5bb43db7c730929e" checksum = "6b13312a745c08c469f0b292dd2fcd6411dba5f7160f593da6ef69b64e407038"
dependencies = [ dependencies = [
"quote", "quote",
"wasm-bindgen-macro-support", "wasm-bindgen-macro-support",
@@ -2124,9 +2122,9 @@ dependencies = [
[[package]] [[package]]
name = "wasm-bindgen-macro-support" name = "wasm-bindgen-macro-support"
version = "0.2.65" version = "0.2.68"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cf592c807080719d1ff2f245a687cbadb3ed28b2077ed7084b47aba8b691f2c6" checksum = "f249f06ef7ee334cc3b8ff031bfc11ec99d00f34d86da7498396dc1e3b1498fe"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2",
"quote", "quote",
@@ -2137,13 +2135,13 @@ dependencies = [
[[package]] [[package]]
name = "wasm-bindgen-shared" name = "wasm-bindgen-shared"
version = "0.2.65" version = "0.2.68"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "72b6c0220ded549d63860c78c38f3bcc558d1ca3f4efa74942c536ddbbb55e87" checksum = "1d649a3145108d7d3fbcde896a468d1bd636791823c9921135218ad89be08307"
[[package]] [[package]]
name = "wasmer" name = "wasmer"
version = "1.0.0-alpha3" version = "1.0.0-alpha4"
dependencies = [ dependencies = [
"anyhow", "anyhow",
"cfg-if", "cfg-if",
@@ -2168,7 +2166,7 @@ dependencies = [
[[package]] [[package]]
name = "wasmer-c-api" name = "wasmer-c-api"
version = "1.0.0-alpha3" version = "1.0.0-alpha4"
dependencies = [ dependencies = [
"cbindgen", "cbindgen",
"cfg-if", "cfg-if",
@@ -2188,13 +2186,14 @@ dependencies = [
"wasmer-engine", "wasmer-engine",
"wasmer-engine-jit", "wasmer-engine-jit",
"wasmer-engine-native", "wasmer-engine-native",
"wasmer-engine-object-file",
"wasmer-types", "wasmer-types",
"wasmer-wasi", "wasmer-wasi",
] ]
[[package]] [[package]]
name = "wasmer-cache" name = "wasmer-cache"
version = "1.0.0-alpha3" version = "1.0.0-alpha4"
dependencies = [ dependencies = [
"blake3", "blake3",
"hex", "hex",
@@ -2205,7 +2204,7 @@ dependencies = [
[[package]] [[package]]
name = "wasmer-cli" name = "wasmer-cli"
version = "1.0.0-alpha3" version = "1.0.0-alpha4"
dependencies = [ dependencies = [
"anyhow", "anyhow",
"atty", "atty",
@@ -2216,6 +2215,7 @@ dependencies = [
"fern", "fern",
"log", "log",
"structopt", "structopt",
"tempfile",
"wasmer", "wasmer",
"wasmer-cache", "wasmer-cache",
"wasmer-compiler", "wasmer-compiler",
@@ -2226,7 +2226,9 @@ dependencies = [
"wasmer-engine", "wasmer-engine",
"wasmer-engine-jit", "wasmer-engine-jit",
"wasmer-engine-native", "wasmer-engine-native",
"wasmer-engine-object-file",
"wasmer-types", "wasmer-types",
"wasmer-vm",
"wasmer-wasi", "wasmer-wasi",
"wasmer-wasi-experimental-io-devices", "wasmer-wasi-experimental-io-devices",
"wasmer-wast", "wasmer-wast",
@@ -2234,7 +2236,7 @@ dependencies = [
[[package]] [[package]]
name = "wasmer-compiler" name = "wasmer-compiler"
version = "1.0.0-alpha3" version = "1.0.0-alpha4"
dependencies = [ dependencies = [
"enumset", "enumset",
"hashbrown 0.8.2", "hashbrown 0.8.2",
@@ -2251,7 +2253,7 @@ dependencies = [
[[package]] [[package]]
name = "wasmer-compiler-cranelift" name = "wasmer-compiler-cranelift"
version = "1.0.0-alpha3" version = "1.0.0-alpha4"
dependencies = [ dependencies = [
"cranelift-codegen", "cranelift-codegen",
"cranelift-frontend", "cranelift-frontend",
@@ -2270,7 +2272,7 @@ dependencies = [
[[package]] [[package]]
name = "wasmer-compiler-llvm" name = "wasmer-compiler-llvm"
version = "1.0.0-alpha3" version = "1.0.0-alpha4"
dependencies = [ dependencies = [
"byteorder", "byteorder",
"cc", "cc",
@@ -2292,7 +2294,7 @@ dependencies = [
[[package]] [[package]]
name = "wasmer-compiler-singlepass" name = "wasmer-compiler-singlepass"
version = "1.0.0-alpha3" version = "1.0.0-alpha4"
dependencies = [ dependencies = [
"byteorder", "byteorder",
"dynasm", "dynasm",
@@ -2310,7 +2312,7 @@ dependencies = [
[[package]] [[package]]
name = "wasmer-emscripten" name = "wasmer-emscripten"
version = "1.0.0-alpha3" version = "1.0.0-alpha4"
dependencies = [ dependencies = [
"byteorder", "byteorder",
"getrandom", "getrandom",
@@ -2323,7 +2325,7 @@ dependencies = [
[[package]] [[package]]
name = "wasmer-engine" name = "wasmer-engine"
version = "1.0.0-alpha3" version = "1.0.0-alpha4"
dependencies = [ dependencies = [
"backtrace", "backtrace",
"bincode", "bincode",
@@ -2341,7 +2343,7 @@ dependencies = [
[[package]] [[package]]
name = "wasmer-engine-dummy" name = "wasmer-engine-dummy"
version = "1.0.0-alpha3" version = "1.0.0-alpha4"
dependencies = [ dependencies = [
"bincode", "bincode",
"serde", "serde",
@@ -2354,7 +2356,7 @@ dependencies = [
[[package]] [[package]]
name = "wasmer-engine-jit" name = "wasmer-engine-jit"
version = "1.0.0-alpha3" version = "1.0.0-alpha4"
dependencies = [ dependencies = [
"bincode", "bincode",
"cfg-if", "cfg-if",
@@ -2370,7 +2372,7 @@ dependencies = [
[[package]] [[package]]
name = "wasmer-engine-native" name = "wasmer-engine-native"
version = "1.0.0-alpha3" version = "1.0.0-alpha4"
dependencies = [ dependencies = [
"bincode", "bincode",
"cfg-if", "cfg-if",
@@ -2387,9 +2389,35 @@ dependencies = [
"which 4.0.2", "which 4.0.2",
] ]
[[package]]
name = "wasmer-engine-object-file"
version = "1.0.0-alpha4"
dependencies = [
"bincode",
"cfg-if",
"leb128",
"libloading 0.6.3",
"serde",
"tempfile",
"tracing",
"wasmer-compiler",
"wasmer-engine",
"wasmer-object",
"wasmer-types",
"wasmer-vm",
]
[[package]]
name = "wasmer-integration-tests-cli"
version = "1.0.0-alpha4"
dependencies = [
"anyhow",
"tempfile",
]
[[package]] [[package]]
name = "wasmer-object" name = "wasmer-object"
version = "1.0.0-alpha3" version = "1.0.0-alpha4"
dependencies = [ dependencies = [
"object 0.19.0", "object 0.19.0",
"thiserror", "thiserror",
@@ -2399,7 +2427,7 @@ dependencies = [
[[package]] [[package]]
name = "wasmer-types" name = "wasmer-types"
version = "1.0.0-alpha3" version = "1.0.0-alpha4"
dependencies = [ dependencies = [
"cranelift-entity", "cranelift-entity",
"serde", "serde",
@@ -2407,7 +2435,7 @@ dependencies = [
[[package]] [[package]]
name = "wasmer-vm" name = "wasmer-vm"
version = "1.0.0-alpha3" version = "1.0.0-alpha4"
dependencies = [ dependencies = [
"backtrace", "backtrace",
"cc", "cc",
@@ -2425,7 +2453,7 @@ dependencies = [
[[package]] [[package]]
name = "wasmer-wasi" name = "wasmer-wasi"
version = "1.0.0-alpha3" version = "1.0.0-alpha4"
dependencies = [ dependencies = [
"bincode", "bincode",
"byteorder", "byteorder",
@@ -2443,7 +2471,7 @@ dependencies = [
[[package]] [[package]]
name = "wasmer-wasi-experimental-io-devices" name = "wasmer-wasi-experimental-io-devices"
version = "1.0.0-alpha3" version = "1.0.0-alpha4"
dependencies = [ dependencies = [
"minifb", "minifb",
"ref_thread_local", "ref_thread_local",
@@ -2455,7 +2483,7 @@ dependencies = [
[[package]] [[package]]
name = "wasmer-wast" name = "wasmer-wast"
version = "1.0.0-alpha3" version = "1.0.0-alpha4"
dependencies = [ dependencies = [
"anyhow", "anyhow",
"serde", "serde",
@@ -2469,7 +2497,7 @@ dependencies = [
[[package]] [[package]]
name = "wasmer-workspace" name = "wasmer-workspace"
version = "1.0.0-alpha3" version = "1.0.0-alpha4"
dependencies = [ dependencies = [
"anyhow", "anyhow",
"blake3", "blake3",
@@ -2491,6 +2519,7 @@ dependencies = [
"wasmer-engine-dummy", "wasmer-engine-dummy",
"wasmer-engine-jit", "wasmer-engine-jit",
"wasmer-engine-native", "wasmer-engine-native",
"wasmer-engine-object-file",
"wasmer-types", "wasmer-types",
"wasmer-wasi", "wasmer-wasi",
"wasmer-wast", "wasmer-wast",
@@ -2513,20 +2542,20 @@ dependencies = [
[[package]] [[package]]
name = "wast" name = "wast"
version = "23.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 = "26b080a48623c1b15193eac2e28c7b8d0e6b2e1c6c67ed46ddcd86063e78e504" checksum = "6ff1e3bd3ad0b2ee7784add89c30dc96b89a54b43e5d6d95d774eda1863b3500"
dependencies = [ dependencies = [
"leb128", "leb128",
] ]
[[package]] [[package]]
name = "wat" name = "wat"
version = "1.0.24" version = "1.0.25"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6c350d7431aa486488d28cdf75b57d59c02fab9cde20d93c52424510afe18ecc" checksum = "c7c0bb2872ae453f98cec6ff1bf1a71cde1da6041fce8b0ac39d51eb033e9ec0"
dependencies = [ dependencies = [
"wast 23.0.0", "wast 24.0.0",
] ]
[[package]] [[package]]
@@ -2601,9 +2630,9 @@ dependencies = [
[[package]] [[package]]
name = "web-sys" name = "web-sys"
version = "0.3.42" version = "0.3.45"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8be2398f326b7ba09815d0b403095f34dd708579220d099caae89be0b32137b2" checksum = "4bf6ef87ad7ae8008e15a355ce696bed26012b7caa21605188cfd8214ab51e2d"
dependencies = [ dependencies = [
"js-sys", "js-sys",
"wasm-bindgen", "wasm-bindgen",

View File

@@ -1,6 +1,6 @@
[package] [package]
name = "wasmer-workspace" name = "wasmer-workspace"
version = "1.0.0-alpha3" version = "1.0.0-alpha4"
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,18 +10,19 @@ publish = false
autoexamples = false autoexamples = false
[dependencies] [dependencies]
wasmer = { version = "1.0.0-alpha3", path = "lib/api", default-features = false } wasmer = { version = "1.0.0-alpha4", path = "lib/api", default-features = false }
wasmer-compiler = { version = "1.0.0-alpha3", path = "lib/compiler" } wasmer-compiler = { version = "1.0.0-alpha4", path = "lib/compiler" }
wasmer-compiler-cranelift = { version = "1.0.0-alpha3", path = "lib/compiler-cranelift", optional = true } wasmer-compiler-cranelift = { version = "1.0.0-alpha4", path = "lib/compiler-cranelift", optional = true }
wasmer-compiler-singlepass = { version = "1.0.0-alpha3", path = "lib/compiler-singlepass", optional = true } wasmer-compiler-singlepass = { version = "1.0.0-alpha4", path = "lib/compiler-singlepass", optional = true }
wasmer-compiler-llvm = { version = "1.0.0-alpha3", path = "lib/compiler-llvm", optional = true } wasmer-compiler-llvm = { version = "1.0.0-alpha4", path = "lib/compiler-llvm", optional = true }
wasmer-engine = { version = "1.0.0-alpha3", path = "lib/engine" } wasmer-engine = { version = "1.0.0-alpha4", path = "lib/engine" }
wasmer-engine-jit = { version = "1.0.0-alpha3", path = "lib/engine-jit", optional = true } wasmer-engine-jit = { version = "1.0.0-alpha4", path = "lib/engine-jit", optional = true }
wasmer-engine-native = { version = "1.0.0-alpha3", path = "lib/engine-native", optional = true } wasmer-engine-native = { version = "1.0.0-alpha4", path = "lib/engine-native", optional = true }
wasmer-wasi = { version = "1.0.0-alpha3", path = "lib/wasi", optional = true } wasmer-engine-object-file = { version = "1.0.0-alpha4", path = "lib/engine-object-file", optional = true }
wasmer-wast = { version = "1.0.0-alpha3", path = "tests/lib/wast", optional = true } wasmer-wasi = { version = "1.0.0-alpha4", path = "lib/wasi", optional = true }
wasmer-cache = { version = "1.0.0-alpha3", path = "lib/cache", optional = true } wasmer-wast = { version = "1.0.0-alpha4", path = "tests/lib/wast", optional = true }
wasmer-types = { version = "1.0.0-alpha3", path = "lib/wasmer-types" } wasmer-cache = { version = "1.0.0-alpha4", path = "lib/cache", optional = true }
wasmer-types = { version = "1.0.0-alpha4", path = "lib/wasmer-types" }
cfg-if = "0.1" cfg-if = "0.1"
[workspace] [workspace]
@@ -38,12 +39,14 @@ members = [
"lib/engine", "lib/engine",
"lib/engine-jit", "lib/engine-jit",
"lib/engine-native", "lib/engine-native",
"lib/engine-object-file",
"lib/object", "lib/object",
"lib/vm", "lib/vm",
"lib/wasi", "lib/wasi",
"lib/wasi-experimental-io-devices", "lib/wasi-experimental-io-devices",
"lib/wasmer-types", "lib/wasmer-types",
"tests/lib/wast", "tests/lib/wast",
"tests/integration/cli",
] ]
exclude = [ exclude = [
"lib/deprecated", "lib/deprecated",
@@ -72,6 +75,7 @@ default = [
"wast", "wast",
"jit", "jit",
"native", "native",
"object-file",
"cache", "cache",
"wasi", "wasi",
# "emscripten", # "emscripten",
@@ -85,6 +89,10 @@ native = [
"wasmer-engine-native", "wasmer-engine-native",
"engine", "engine",
] ]
object-file = [
"wasmer-engine-object-file",
"engine",
]
cache = ["wasmer-cache"] cache = ["wasmer-cache"]
wast = ["wasmer-wast"] wast = ["wasmer-wast"]
wasi = ["wasmer-wasi"] wasi = ["wasmer-wasi"]
@@ -94,7 +102,8 @@ compiler = [
"wasmer/compiler", "wasmer/compiler",
"wasmer-compiler/translator", "wasmer-compiler/translator",
"wasmer-engine-jit/compiler", "wasmer-engine-jit/compiler",
"wasmer-engine-native/compiler" "wasmer-engine-native/compiler",
"wasmer-engine-object-file/compiler",
] ]
singlepass = [ singlepass = [
"wasmer-compiler-singlepass", "wasmer-compiler-singlepass",
@@ -120,14 +129,28 @@ test-llvm = [
"llvm", "llvm",
] ]
# Disable trap asserts in the WAST tests. This is useful for running the tests in a test-native = [
# context where signal handling is a problem, such as tarpaulin for code coverage. "native",
test-no-traps = ["wasmer-wast/test-no-traps"] "test-generator/test-native",
]
test-jit = [
"jit",
"test-generator/test-jit",
]
# Specifies that we're running in coverage testing mode. This disables tests
# that raise signals because that interferes with tarpaulin.
coverage = []
[[bench]] [[bench]]
name = "static_and_dynamic_functions" name = "static_and_dynamic_functions"
harness = false harness = false
[[example]]
name = "early-exit"
path = "examples/early_exit.rs"
required-features = ["cranelift"]
[[example]] [[example]]
name = "engine-jit" name = "engine-jit"
path = "examples/engine_jit.rs" path = "examples/engine_jit.rs"

View File

@@ -8,11 +8,13 @@ else
UNAME_S := UNAME_S :=
endif endif
compilers := # Which compilers we build. These have dependencies that may not on the system.
compilers := cranelift
# Which engines we test. We always build all engines.
engines := jit
ifeq ($(ARCH), x86_64) ifeq ($(ARCH), x86_64)
# In X64, Cranelift is enabled
compilers += cranelift
# LLVM could be enabled if not in Windows # LLVM could be enabled if not in Windows
ifneq ($(OS), Windows_NT) ifneq ($(OS), Windows_NT)
# Singlepass doesn't work yet on Windows # Singlepass doesn't work yet on Windows
@@ -29,10 +31,14 @@ ifeq ($(ARCH), x86_64)
compilers += llvm compilers += llvm
endif endif
endif endif
# Native engine doesn't work yet on Windows
engines += native
endif endif
endif endif
compilers := $(filter-out ,$(compilers)) compilers := $(filter-out ,$(compilers))
engines := $(filter-out ,$(engines))
ifneq ($(OS), Windows_NT) ifneq ($(OS), Windows_NT)
bold := $(shell tput bold) bold := $(shell tput bold)
@@ -76,31 +82,44 @@ 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 jit,singlepass,wasi --no-default-features --features wat,jit,object-file,singlepass,wasi
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 jit,cranelift,wasi --no-default-features --features wat,jit,object-file,cranelift,wasi
build-capi-cranelift-system-libffi:
cargo build --manifest-path lib/c-api/Cargo.toml --release \
--no-default-features --features wat,jit,object-file,cranelift,wasi,system-libffi
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 jit,llvm,wasi --no-default-features --features wat,jit,object-file,llvm,wasi
########### ###########
# Testing # # Testing #
########### ###########
test: $(foreach compiler,$(compilers),test-$(compiler)) test-packages test-examples test-deprecated test: $(foreach engine,$(engines),$(foreach compiler,$(compilers),test-$(compiler)-$(engine))) test-packages test-examples test-deprecated
test-singlepass: # Singlepass and native engine don't work together, this rule does nothing.
cargo test --release $(compiler_features) --features "test-singlepass" test-singlepass-native:
@:
test-cranelift: test-singlepass-jit:
cargo test --release $(compiler_features) --features "test-cranelift" cargo test --release $(compiler_features) --features "test-singlepass test-jit"
test-llvm: test-cranelift-native:
cargo test --release $(compiler_features) --features "test-llvm" cargo test --release $(compiler_features) --features "test-cranelift test-native"
test-cranelift-jit:
cargo test --release $(compiler_features) --features "test-cranelift test-jit"
test-llvm-native:
cargo test --release $(compiler_features) --features "test-llvm test-native"
test-llvm-jit:
cargo test --release $(compiler_features) --features "test-llvm test-jit"
test-packages: test-packages:
cargo test -p wasmer --release cargo test -p wasmer --release
@@ -109,18 +128,23 @@ test-packages:
cargo test -p wasmer-wasi --release cargo test -p wasmer-wasi --release
cargo test -p wasmer-object --release cargo test -p wasmer-object --release
cargo test -p wasmer-engine-native --release --no-default-features cargo test -p wasmer-engine-native --release --no-default-features
cargo test -p wasmer-cli --release
test-capi-singlepass: build-capi-singlepass test-capi-singlepass: build-capi-singlepass
cargo test --manifest-path lib/c-api/Cargo.toml --release \ cargo test --manifest-path lib/c-api/Cargo.toml --release \
--no-default-features --features jit,singlepass,wasi -- --nocapture --no-default-features --features wat,jit,singlepass,wasi -- --nocapture
test-capi-cranelift: build-capi-cranelift test-capi-cranelift: build-capi-cranelift
cargo test --manifest-path lib/c-api/Cargo.toml --release \ cargo test --manifest-path lib/c-api/Cargo.toml --release \
--no-default-features --features jit,cranelift,wasi -- --nocapture --no-default-features --features wat,jit,cranelift,wasi -- --nocapture
test-capi-cranelift-system-libffi: build-capi-cranelift-system-libffi
cargo test --manifest-path lib/c-api/Cargo.toml --release \
--no-default-features --features wat,jit,cranelift,wasi,system-libffi -- --nocapture
test-capi-llvm: build-capi-llvm test-capi-llvm: build-capi-llvm
cargo test --manifest-path lib/c-api/Cargo.toml --release \ cargo test --manifest-path lib/c-api/Cargo.toml --release \
--no-default-features --features jit,llvm,wasi -- --nocapture --no-default-features --features wat,jit,llvm,wasi -- --nocapture
test-capi: test-capi-singlepass test-capi-cranelift test-capi-llvm test-capi: test-capi-singlepass test-capi-cranelift test-capi-llvm
@@ -135,6 +159,9 @@ test-deprecated:
cargo test --manifest-path lib/deprecated/runtime/Cargo.toml -p wasmer-runtime --release cargo test --manifest-path lib/deprecated/runtime/Cargo.toml -p wasmer-runtime --release
cargo test --manifest-path lib/deprecated/runtime/Cargo.toml -p wasmer-runtime --release --examples cargo test --manifest-path lib/deprecated/runtime/Cargo.toml -p wasmer-runtime --release --examples
test-integration:
cargo test -p wasmer-integration-tests-cli
############# #############
# Packaging # # Packaging #
############# #############
@@ -163,7 +190,9 @@ package-capi:
mkdir -p "package/include" mkdir -p "package/include"
mkdir -p "package/lib" mkdir -p "package/lib"
cp lib/c-api/wasmer.h* package/include cp lib/c-api/wasmer.h* package/include
cp lib/c-api/doc/index.md package/include/README.md cp lib/c-api/wasmer_wasm.h* package/include
cp lib/c-api/wasm.h* package/include
cp lib/c-api/doc/deprecated/index.md package/include/README.md
ifeq ($(OS), Windows_NT) ifeq ($(OS), Windows_NT)
cp target/release/wasmer_c_api.dll package/lib cp target/release/wasmer_c_api.dll package/lib
cp target/release/wasmer_c_api.lib package/lib cp target/release/wasmer_c_api.lib package/lib
@@ -201,6 +230,9 @@ else
cp ./wasmer.tar.gz ./dist/$(shell ./scripts/binary-name.sh) cp ./wasmer.tar.gz ./dist/$(shell ./scripts/binary-name.sh)
endif endif
# command for simulating installing Wasmer without wapm.
package-without-wapm-for-integration-tests: package-wasmer package-capi
################# #################
# Miscellaneous # # Miscellaneous #
################# #################

View File

@@ -35,7 +35,7 @@
* **Pluggable**. Wasmer supports different compilation frameworks to best suit your needs (LLVM, Cranelift...). * **Pluggable**. Wasmer supports different compilation frameworks to best suit your needs (LLVM, Cranelift...).
* **Universal**. You can run Wasmer in almost any *platform* (macOS, Linux and Windows) and *chipset*. * **Universal**. You can run Wasmer in any *platform* (macOS, Linux and Windows) and *chipset*.
* **Standards compliant**. The runtime passes [official WebAssembly test * **Standards compliant**. The runtime passes [official WebAssembly test
suite](https://github.com/WebAssembly/testsuite) supporting [WASI](https://github.com/WebAssembly/WASI) and [Emscripten](https://emscripten.org/). suite](https://github.com/WebAssembly/testsuite) supporting [WASI](https://github.com/WebAssembly/WASI) and [Emscripten](https://emscripten.org/).
@@ -171,7 +171,7 @@ Test you want? The [Wasmer docs will show you how](https://docs.wasmer.io/ecosys
## Community ## Community
Wasmer has an amazing community developers and contributors. Welcome, please join us! 👋 Wasmer has an amazing community of developers and contributors. Welcome, please join us! 👋
### Channels ### Channels

View File

@@ -2,6 +2,7 @@ status = [
"Audit", "Audit",
"Code lint", "Code lint",
"Test on linux", "Test on linux",
"Test on linux-aarch64",
"Test on macos", "Test on macos",
"Test on windows" "Test on windows"
] ]

82
examples/early_exit.rs Normal file
View File

@@ -0,0 +1,82 @@
//! This example shows how the host can terminate execution of Wasm early from
//! inside a host function called by the Wasm.
use anyhow::bail;
use std::fmt;
use wasmer::{imports, wat2wasm, Function, Instance, Module, NativeFunc, RuntimeError, Store};
use wasmer_compiler_cranelift::Cranelift;
use wasmer_engine_jit::JIT;
// First we need to create an error type that we'll use to signal the end of execution.
#[derive(Debug, Clone, Copy)]
struct ExitCode(u32);
// This type must implement `std::error::Error` so we must also implement `std::fmt::Display` for it.
impl fmt::Display for ExitCode {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "{}", self.0)
}
}
// And then we implement `std::error::Error`.
impl std::error::Error for ExitCode {}
// The host function that we'll use to terminate execution.
fn early_exit() {
// This is where it happens.
RuntimeError::raise(Box::new(ExitCode(1)));
}
fn main() -> anyhow::Result<()> {
// Let's declare the Wasm module with the text representation.
let wasm_bytes = wat2wasm(
br#"
(module
(type $run_t (func (param i32 i32) (result i32)))
(type $early_exit_t (func (param) (result)))
(import "env" "early_exit" (func $early_exit (type $early_exit_t)))
(func $run (type $run_t) (param $x i32) (param $y i32) (result i32)
(call $early_exit)
(i32.add
local.get $x
local.get $y))
(export "run" (func $run)))
"#,
)?;
let store = Store::new(&JIT::new(&Cranelift::default()).engine());
let module = Module::new(&store, wasm_bytes)?;
let import_object = imports! {
"env" => {
"early_exit" => Function::new_native(&store, early_exit),
}
};
let instance = Instance::new(&module, &import_object)?;
// Get the `run` function which we'll use as our entrypoint.
let run_func: NativeFunc<(i32, i32), i32> =
instance.exports.get_native_function("run").unwrap();
// When we call a function it can either succeed or fail.
match run_func.call(1, 7) {
Ok(result) => {
bail!(
"Expected early termination with `ExitCode`, found: {}",
result
);
}
// We're expecting it to fail.
// We attempt to downcast the error into the error type that we were expecting.
Err(e) => match e.downcast::<ExitCode>() {
// We found the exit code used to terminate execution.
Ok(exit_code) => {
println!("Exited early with exit code: {}", exit_code);
Ok(())
}
Err(e) => {
bail!("Unknown error `{}` found. expected `ErrorCode`", e);
}
},
}
}

View File

@@ -27,7 +27,7 @@ use wasmer_engine_native::Native;
fn main() -> Result<(), Box<dyn std::error::Error>> { fn main() -> Result<(), Box<dyn std::error::Error>> {
// Let's declare the Wasm module with the text representation. // Let's declare the Wasm module with the text representation.
let wasm_bytes = wat2wasm( let wasm_bytes = wat2wasm(
r#" br#"
(module (module
(type $sum_t (func (param i32 i32) (result i32))) (type $sum_t (func (param i32 i32) (result i32)))
(func $sum_f (type $sum_t) (param $x i32) (param $y i32) (result i32) (func $sum_f (type $sum_t) (param $x i32) (param $y i32) (result i32)
@@ -35,8 +35,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
local.get $y local.get $y
i32.add) i32.add)
(export "sum" (func $sum_f))) (export "sum" (func $sum_f)))
"# "#,
.as_bytes(),
)?; )?;
// Define a compiler configuration. // Define a compiler configuration.

View File

@@ -147,7 +147,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
} }
#[test] #[test]
#[cfg(not(windows))] #[cfg(not(any(windows, target_arch = "aarch64")))]
fn test_engine_headless() -> Result<(), Box<dyn std::error::Error>> { fn test_engine_headless() -> Result<(), Box<dyn std::error::Error>> {
main() main()
} }

View File

@@ -87,6 +87,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
} }
#[test] #[test]
#[cfg(not(target_arch = "aarch64"))]
fn test_engine_native() -> Result<(), Box<dyn std::error::Error>> { fn test_engine_native() -> Result<(), Box<dyn std::error::Error>> {
main() main()
} }

View File

@@ -21,9 +21,9 @@ use wasmer_engine_jit::JIT;
use wasmer_wasi::WasiState; use wasmer_wasi::WasiState;
fn main() -> Result<(), Box<dyn std::error::Error>> { fn main() -> Result<(), Box<dyn std::error::Error>> {
let wasm_path = format!( let wasm_path = concat!(
"{}/tests/wasi-wast/wasi/unstable/hello.wasm", env!("CARGO_MANIFEST_DIR"),
std::env::var("CARGO_MANIFEST_DIR").unwrap() "/tests/wasi-wast/wasi/unstable/hello.wasm"
); );
// Let's declare the Wasm module with the text representation. // Let's declare the Wasm module with the text representation.
let wasm_bytes = std::fs::read(wasm_path)?; let wasm_bytes = std::fs::read(wasm_path)?;

View File

@@ -1,6 +1,6 @@
[package] [package]
name = "wasmer" name = "wasmer"
version = "1.0.0-alpha3" version = "1.0.0-alpha4"
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,15 +11,15 @@ readme = "README.md"
edition = "2018" edition = "2018"
[dependencies] [dependencies]
wasmer-vm = { path = "../vm", version = "1.0.0-alpha3" } wasmer-vm = { path = "../vm", version = "1.0.0-alpha4" }
wasmer-compiler-singlepass = { path = "../compiler-singlepass", version = "1.0.0-alpha3", optional = true } wasmer-compiler-singlepass = { path = "../compiler-singlepass", version = "1.0.0-alpha4", optional = true }
wasmer-compiler-cranelift = { path = "../compiler-cranelift", version = "1.0.0-alpha3", optional = true } wasmer-compiler-cranelift = { path = "../compiler-cranelift", version = "1.0.0-alpha4", optional = true }
wasmer-compiler-llvm = { path = "../compiler-llvm", version = "1.0.0-alpha3", optional = true } wasmer-compiler-llvm = { path = "../compiler-llvm", version = "1.0.0-alpha4", optional = true }
wasmer-compiler = { path = "../compiler", version = "1.0.0-alpha3" } wasmer-compiler = { path = "../compiler", version = "1.0.0-alpha4" }
wasmer-engine = { path = "../engine", version = "1.0.0-alpha3" } wasmer-engine = { path = "../engine", version = "1.0.0-alpha4" }
wasmer-engine-jit = { path = "../engine-jit", version = "1.0.0-alpha3", optional = true } wasmer-engine-jit = { path = "../engine-jit", version = "1.0.0-alpha4", optional = true }
wasmer-engine-native = { path = "../engine-native", version = "1.0.0-alpha3", optional = true } wasmer-engine-native = { path = "../engine-native", version = "1.0.0-alpha4", optional = true }
wasmer-types = { path = "../wasmer-types", version = "1.0.0-alpha3" } wasmer-types = { path = "../wasmer-types", version = "1.0.0-alpha4" }
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 }

View File

@@ -51,7 +51,7 @@ impl Exports {
/// Creates a new `Exports` with capacity `n`. /// Creates a new `Exports` with capacity `n`.
pub fn with_capacity(n: usize) -> Self { pub fn with_capacity(n: usize) -> Self {
Exports { Self {
map: Arc::new(IndexMap::with_capacity(n)), map: Arc::new(IndexMap::with_capacity(n)),
} }
} }
@@ -224,7 +224,7 @@ where
impl FromIterator<(String, Extern)> for Exports { impl FromIterator<(String, Extern)> for Exports {
fn from_iter<I: IntoIterator<Item = (String, Extern)>>(iter: I) -> Self { fn from_iter<I: IntoIterator<Item = (String, Extern)>>(iter: I) -> Self {
// TODO: Move into IndexMap collect // TODO: Move into IndexMap collect
let mut exports = Exports::new(); let mut exports = Self::new();
for (name, extern_) in iter { for (name, extern_) in iter {
exports.insert(name, extern_); exports.insert(name, extern_);
} }

View File

@@ -23,17 +23,17 @@ pub struct Global {
impl Global { impl Global {
/// Create a new `Global` with the initial value [`Val`]. /// Create a new `Global` with the initial value [`Val`].
pub fn new(store: &Store, val: Val) -> Global { pub fn new(store: &Store, val: Val) -> Self {
Self::from_value(store, val, Mutability::Const).unwrap() Self::from_value(store, val, Mutability::Const).unwrap()
} }
/// Create a mutable `Global` with the initial value [`Val`]. /// Create a mutable `Global` with the initial value [`Val`].
pub fn new_mut(store: &Store, val: Val) -> Global { pub fn new_mut(store: &Store, val: Val) -> Self {
Self::from_value(store, val, Mutability::Var).unwrap() Self::from_value(store, val, Mutability::Var).unwrap()
} }
/// Create a `Global` with the initial value [`Val`] and the provided [`Mutability`]. /// Create a `Global` with the initial value [`Val`] and the provided [`Mutability`].
fn from_value(store: &Store, val: Val, mutability: Mutability) -> Result<Global, RuntimeError> { fn from_value(store: &Store, val: Val, mutability: Mutability) -> Result<Self, RuntimeError> {
if !val.comes_from_same_store(store) { if !val.comes_from_same_store(store) {
return Err(RuntimeError::new("cross-`Store` globals are not supported")); return Err(RuntimeError::new("cross-`Store` globals are not supported"));
} }
@@ -47,7 +47,7 @@ impl Global {
.map_err(|e| RuntimeError::new(format!("create global for {:?}: {}", val, e)))?; .map_err(|e| RuntimeError::new(format!("create global for {:?}: {}", val, e)))?;
}; };
Ok(Global { Ok(Self {
store: store.clone(), store: store.clone(),
global: Arc::new(global), global: Arc::new(global),
}) })
@@ -87,15 +87,15 @@ impl Global {
Ok(()) Ok(())
} }
pub(crate) fn from_export(store: &Store, wasmer_export: ExportGlobal) -> Global { pub(crate) fn from_export(store: &Store, wasmer_export: ExportGlobal) -> Self {
Global { Self {
store: store.clone(), store: store.clone(),
global: wasmer_export.from.clone(), global: wasmer_export.from,
} }
} }
/// Returns whether or not these two globals refer to the same data. /// Returns whether or not these two globals refer to the same data.
pub fn same(&self, other: &Global) -> bool { pub fn same(&self, other: &Self) -> bool {
Arc::ptr_eq(&self.global, &other.global) Arc::ptr_eq(&self.global, &other.global)
} }
} }

View File

@@ -34,12 +34,12 @@ impl Memory {
/// This function will construct the `Memory` using the store [`Tunables`]. /// This function will construct the `Memory` using the store [`Tunables`].
/// ///
/// [`Tunables`]: crate::tunables::Tunables /// [`Tunables`]: crate::tunables::Tunables
pub fn new(store: &Store, ty: MemoryType) -> Result<Memory, MemoryError> { pub fn new(store: &Store, ty: MemoryType) -> Result<Self, MemoryError> {
let tunables = store.tunables(); let tunables = store.tunables();
let style = tunables.memory_style(&ty); let style = tunables.memory_style(&ty);
let memory = tunables.create_memory(&ty, &style)?; let memory = tunables.create_memory(&ty, &style)?;
Ok(Memory { Ok(Self {
store: store.clone(), store: store.clone(),
memory, memory,
}) })
@@ -148,15 +148,15 @@ impl Memory {
unsafe { MemoryView::new(base as _, length as u32) } unsafe { MemoryView::new(base as _, length as u32) }
} }
pub(crate) fn from_export(store: &Store, wasmer_export: ExportMemory) -> Memory { pub(crate) fn from_export(store: &Store, wasmer_export: ExportMemory) -> Self {
Memory { Self {
store: store.clone(), store: store.clone(),
memory: wasmer_export.from, memory: wasmer_export.from,
} }
} }
/// Returns whether or not these two globals refer to the same data. /// Returns whether or not these two globals refer to the same data.
pub fn same(&self, other: &Memory) -> bool { pub fn same(&self, other: &Self) -> bool {
Arc::ptr_eq(&self.memory, &other.memory) Arc::ptr_eq(&self.memory, &other.memory)
} }
} }

View File

@@ -36,20 +36,20 @@ impl Extern {
/// Return the undelying type of the inner `Extern`. /// Return the undelying type of the inner `Extern`.
pub fn ty(&self) -> ExternType { pub fn ty(&self) -> ExternType {
match self { match self {
Extern::Function(ft) => ExternType::Function(ft.ty().clone()), Self::Function(ft) => ExternType::Function(ft.ty().clone()),
Extern::Memory(ft) => ExternType::Memory(*ft.ty()), Self::Memory(ft) => ExternType::Memory(*ft.ty()),
Extern::Table(tt) => ExternType::Table(*tt.ty()), Self::Table(tt) => ExternType::Table(*tt.ty()),
Extern::Global(gt) => ExternType::Global(*gt.ty()), Self::Global(gt) => ExternType::Global(*gt.ty()),
} }
} }
/// Create an `Extern` from an `Export`. /// Create an `Extern` from an `Export`.
pub fn from_export(store: &Store, export: Export) -> Extern { pub fn from_export(store: &Store, export: Export) -> Self {
match export { match export {
Export::Function(f) => Extern::Function(Function::from_export(store, f)), Export::Function(f) => Self::Function(Function::from_export(store, f)),
Export::Memory(m) => Extern::Memory(Memory::from_export(store, m)), Export::Memory(m) => Self::Memory(Memory::from_export(store, m)),
Export::Global(g) => Extern::Global(Global::from_export(store, g)), Export::Global(g) => Self::Global(Global::from_export(store, g)),
Export::Table(t) => Extern::Table(Table::from_export(store, t)), Export::Table(t) => Self::Table(Table::from_export(store, t)),
} }
} }
} }
@@ -57,14 +57,14 @@ impl Extern {
impl<'a> Exportable<'a> for Extern { impl<'a> Exportable<'a> for Extern {
fn to_export(&self) -> Export { fn to_export(&self) -> Export {
match self { match self {
Extern::Function(f) => f.to_export(), Self::Function(f) => f.to_export(),
Extern::Global(g) => g.to_export(), Self::Global(g) => g.to_export(),
Extern::Memory(m) => m.to_export(), Self::Memory(m) => m.to_export(),
Extern::Table(t) => t.to_export(), Self::Table(t) => t.to_export(),
} }
} }
fn get_self_from_extern(_extern: &'a Extern) -> Result<&'a Self, ExportError> { fn get_self_from_extern(_extern: &'a Self) -> Result<&'a Self, ExportError> {
// Since this is already an extern, we can just return it. // Since this is already an extern, we can just return it.
Ok(_extern) Ok(_extern)
} }
@@ -73,10 +73,10 @@ impl<'a> Exportable<'a> for Extern {
impl StoreObject for Extern { impl StoreObject for Extern {
fn comes_from_same_store(&self, store: &Store) -> bool { fn comes_from_same_store(&self, store: &Store) -> bool {
let my_store = match self { let my_store = match self {
Extern::Function(f) => f.store(), Self::Function(f) => f.store(),
Extern::Global(g) => g.store(), Self::Global(g) => g.store(),
Extern::Memory(m) => m.store(), Self::Memory(m) => m.store(),
Extern::Table(t) => t.store(), Self::Table(t) => t.store(),
}; };
Store::same(my_store, store) Store::same(my_store, store)
} }
@@ -99,24 +99,24 @@ impl fmt::Debug for Extern {
impl From<Function> for Extern { impl From<Function> for Extern {
fn from(r: Function) -> Self { fn from(r: Function) -> Self {
Extern::Function(r) Self::Function(r)
} }
} }
impl From<Global> for Extern { impl From<Global> for Extern {
fn from(r: Global) -> Self { fn from(r: Global) -> Self {
Extern::Global(r) Self::Global(r)
} }
} }
impl From<Memory> for Extern { impl From<Memory> for Extern {
fn from(r: Memory) -> Self { fn from(r: Memory) -> Self {
Extern::Memory(r) Self::Memory(r)
} }
} }
impl From<Table> for Extern { impl From<Table> for Extern {
fn from(r: Table) -> Self { fn from(r: Table) -> Self {
Extern::Table(r) Self::Table(r)
} }
} }

View File

@@ -38,7 +38,7 @@ impl Table {
/// This function will construct the `Table` using the store [`Tunables`]. /// This function will construct the `Table` using the store [`Tunables`].
/// ///
/// [`Tunables`]: crate::tunables::Tunables /// [`Tunables`]: crate::tunables::Tunables
pub fn new(store: &Store, ty: TableType, init: Val) -> Result<Table, RuntimeError> { pub fn new(store: &Store, ty: TableType, init: Val) -> Result<Self, RuntimeError> {
let item = init.into_checked_anyfunc(store)?; let item = init.into_checked_anyfunc(store)?;
let tunables = store.tunables(); let tunables = store.tunables();
let style = tunables.table_style(&ty); let style = tunables.table_style(&ty);
@@ -51,7 +51,7 @@ impl Table {
set_table_item(table.as_ref(), i, item.clone())?; set_table_item(table.as_ref(), i, item.clone())?;
} }
Ok(Table { Ok(Self {
store: store.clone(), store: store.clone(),
table, table,
}) })
@@ -117,9 +117,9 @@ impl Table {
/// Returns an error if the range is out of bounds of either the source or /// Returns an error if the range is out of bounds of either the source or
/// destination tables. /// destination tables.
pub fn copy( pub fn copy(
dst_table: &Table, dst_table: &Self,
dst_index: u32, dst_index: u32,
src_table: &Table, src_table: &Self,
src_index: u32, src_index: u32,
len: u32, len: u32,
) -> Result<(), RuntimeError> { ) -> Result<(), RuntimeError> {
@@ -139,8 +139,8 @@ impl Table {
Ok(()) Ok(())
} }
pub(crate) fn from_export(store: &Store, wasmer_export: ExportTable) -> Table { pub(crate) fn from_export(store: &Store, wasmer_export: ExportTable) -> Self {
Table { Self {
store: store.clone(), store: store.clone(),
table: wasmer_export.from, table: wasmer_export.from,
} }

View File

@@ -5,7 +5,7 @@ use crate::store::Store;
use crate::InstantiationError; use crate::InstantiationError;
use std::fmt; use std::fmt;
use wasmer_engine::Resolver; use wasmer_engine::Resolver;
use wasmer_vm::InstanceHandle; use wasmer_vm::{InstanceHandle, VMContext};
/// A WebAssembly Instance is a stateful, executable /// A WebAssembly Instance is a stateful, executable
/// instance of a WebAssembly [`Module`]. /// instance of a WebAssembly [`Module`].
@@ -70,7 +70,7 @@ impl Instance {
/// Those are, as defined by the spec: /// Those are, as defined by the spec:
/// * Link errors that happen when plugging the imports into the instance /// * Link errors that happen when plugging the imports into the instance
/// * Runtime errors that happen when running the module `start` function. /// * Runtime errors that happen when running the module `start` function.
pub fn new(module: &Module, resolver: &dyn Resolver) -> Result<Instance, InstantiationError> { pub fn new(module: &Module, resolver: &dyn Resolver) -> Result<Self, InstantiationError> {
let store = module.store(); let store = module.store();
let handle = module.instantiate(resolver)?; let handle = module.instantiate(resolver)?;
@@ -85,7 +85,7 @@ impl Instance {
}) })
.collect::<Exports>(); .collect::<Exports>();
Ok(Instance { Ok(Self {
handle, handle,
module: module.clone(), module: module.clone(),
exports, exports,
@@ -101,6 +101,11 @@ impl Instance {
pub fn store(&self) -> &Store { pub fn store(&self) -> &Store {
self.module.store() self.module.store()
} }
#[doc(hidden)]
pub fn vmctx_ptr(&self) -> *mut VMContext {
self.handle.vmctx_ptr()
}
} }
impl fmt::Debug for Instance { impl fmt::Debug for Instance {

View File

@@ -3,7 +3,7 @@
missing_docs, missing_docs,
trivial_numeric_casts, trivial_numeric_casts,
unused_extern_crates, unused_extern_crates,
intra_doc_link_resolution_failure broken_intra_doc_links
)] )]
#![warn(unused_import_braces)] #![warn(unused_import_braces)]
#![cfg_attr( #![cfg_attr(
@@ -70,8 +70,8 @@ pub use wasmer_compiler::{
}; };
pub use wasmer_compiler::{CpuFeature, Features, Target}; pub use wasmer_compiler::{CpuFeature, Features, Target};
pub use wasmer_engine::{ pub use wasmer_engine::{
ChainableNamedResolver, DeserializeError, Engine, InstantiationError, LinkError, NamedResolver, ChainableNamedResolver, DeserializeError, Engine, FrameInfo, InstantiationError, LinkError,
NamedResolverChain, Resolver, RuntimeError, SerializeError, NamedResolver, NamedResolverChain, Resolver, RuntimeError, SerializeError,
}; };
pub use wasmer_types::{ pub use wasmer_types::{
Atomically, Bytes, GlobalInit, LocalFunctionIndex, MemoryView, Pages, ValueType, Atomically, Bytes, GlobalInit, LocalFunctionIndex, MemoryView, Pages, ValueType,

View File

@@ -97,7 +97,7 @@ impl Module {
/// # } /// # }
/// ``` /// ```
#[allow(unreachable_code)] #[allow(unreachable_code)]
pub fn new(store: &Store, bytes: impl AsRef<[u8]>) -> Result<Module, CompileError> { pub fn new(store: &Store, bytes: impl AsRef<[u8]>) -> Result<Self, CompileError> {
#[cfg(feature = "wat")] #[cfg(feature = "wat")]
let bytes = wat::parse_bytes(bytes.as_ref()).map_err(|e| { let bytes = wat::parse_bytes(bytes.as_ref()).map_err(|e| {
CompileError::Wasm(WasmError::Generic(format!( CompileError::Wasm(WasmError::Generic(format!(
@@ -106,15 +106,15 @@ impl Module {
))) )))
})?; })?;
Module::from_binary(store, bytes.as_ref()) Self::from_binary(store, bytes.as_ref())
} }
/// Creates a new WebAssembly module from a file path. /// Creates a new WebAssembly module from a file path.
pub fn from_file(store: &Store, file: impl AsRef<Path>) -> Result<Module, IoCompileError> { pub fn from_file(store: &Store, file: impl AsRef<Path>) -> Result<Self, IoCompileError> {
let file_ref = file.as_ref(); let file_ref = file.as_ref();
let canonical = file_ref.canonicalize()?; let canonical = file_ref.canonicalize()?;
let wasm_bytes = std::fs::read(file_ref)?; let wasm_bytes = std::fs::read(file_ref)?;
let mut module = Module::new(store, &wasm_bytes)?; let mut module = Self::new(store, &wasm_bytes)?;
// Set the module name to the absolute path of the filename. // Set the module name to the absolute path of the filename.
// This is useful for debugging the stack traces. // This is useful for debugging the stack traces.
let filename = canonical.as_path().to_str().unwrap(); let filename = canonical.as_path().to_str().unwrap();
@@ -127,9 +127,9 @@ impl Module {
/// Opposed to [`Module::new`], this function is not compatible with /// Opposed to [`Module::new`], this function is not compatible with
/// the WebAssembly text format (if the "wat" feature is enabled for /// the WebAssembly text format (if the "wat" feature is enabled for
/// this crate). /// this crate).
pub fn from_binary(store: &Store, binary: &[u8]) -> Result<Module, CompileError> { pub fn from_binary(store: &Store, binary: &[u8]) -> Result<Self, CompileError> {
Module::validate(store, binary)?; Self::validate(store, binary)?;
unsafe { Module::from_binary_unchecked(store, binary) } unsafe { Self::from_binary_unchecked(store, binary) }
} }
/// Creates a new WebAssembly module skipping any kind of validation. /// Creates a new WebAssembly module skipping any kind of validation.
@@ -142,8 +142,8 @@ impl Module {
pub unsafe fn from_binary_unchecked( pub unsafe fn from_binary_unchecked(
store: &Store, store: &Store,
binary: &[u8], binary: &[u8],
) -> Result<Module, CompileError> { ) -> Result<Self, CompileError> {
let module = Module::compile(store, binary)?; let module = Self::compile(store, binary)?;
Ok(module) Ok(module)
} }
@@ -252,7 +252,7 @@ impl Module {
} }
fn from_artifact(store: &Store, artifact: Arc<dyn Artifact>) -> Self { fn from_artifact(store: &Store, artifact: Arc<dyn Artifact>) -> Self {
Module { Self {
store: store.clone(), store: store.clone(),
artifact, artifact,
} }
@@ -410,6 +410,16 @@ impl Module {
pub fn info(&self) -> &ModuleInfo { pub fn info(&self) -> &ModuleInfo {
&self.artifact.module_ref() &self.artifact.module_ref()
} }
/// Gets the [`Artifact`] used internally by the Module.
///
/// This API is hidden because it's not necessarily stable;
/// this functionality is required for some core functionality though, like
/// the object file engine.
#[doc(hidden)]
pub fn artifact(&self) -> &Arc<dyn Artifact> {
&self.artifact
}
} }
impl fmt::Debug for Module { impl fmt::Debug for Module {

View File

@@ -94,14 +94,14 @@ impl Default for Store {
} }
} }
#[allow(unreachable_code)] #[allow(unreachable_code, unused_mut)]
fn get_engine(config: impl CompilerConfig + Send + Sync) -> impl Engine + Send + Sync { fn get_engine(mut config: impl CompilerConfig + Send + Sync) -> 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(&config) wasmer_engine_native::Native::new(&mut config)
.engine() .engine()
} else { } else {
compile_error!("No default engine chosen") compile_error!("No default engine chosen")

View File

@@ -1,5 +1,4 @@
use crate::{MemoryType, Pages, TableType}; use crate::{MemoryType, Pages, TableType};
use more_asserts::assert_ge;
use std::cmp::min; use std::cmp::min;
use std::sync::Arc; use std::sync::Arc;
use target_lexicon::{OperatingSystem, PointerWidth}; use target_lexicon::{OperatingSystem, PointerWidth};
@@ -67,7 +66,6 @@ impl BaseTunables for Tunables {
// If the module doesn't declare an explicit maximum treat it as 4GiB. // If the module doesn't declare an explicit maximum treat it as 4GiB.
let maximum = memory.maximum.unwrap_or_else(Pages::max_value); let maximum = memory.maximum.unwrap_or_else(Pages::max_value);
if maximum <= self.static_memory_bound { if maximum <= self.static_memory_bound {
assert_ge!(self.static_memory_bound, memory.minimum);
MemoryStyle::Static { MemoryStyle::Static {
bound: self.static_memory_bound, bound: self.static_memory_bound,
offset_guard_size: self.static_memory_offset_guard_size, offset_guard_size: self.static_memory_offset_guard_size,

View File

@@ -19,17 +19,17 @@ pub type Val = Value<Function>;
impl StoreObject for Val { impl StoreObject for Val {
fn comes_from_same_store(&self, store: &Store) -> bool { fn comes_from_same_store(&self, store: &Store) -> bool {
match self { match self {
Val::FuncRef(f) => Store::same(store, f.store()), Self::FuncRef(f) => Store::same(store, f.store()),
Val::ExternRef(ExternRef::Ref(_)) | Val::ExternRef(ExternRef::Other(_)) => false, Self::ExternRef(ExternRef::Ref(_)) | Self::ExternRef(ExternRef::Other(_)) => false,
Val::ExternRef(ExternRef::Null) => true, Self::ExternRef(ExternRef::Null) => true,
Val::I32(_) | Val::I64(_) | Val::F32(_) | Val::F64(_) | Val::V128(_) => true, Self::I32(_) | Self::I64(_) | Self::F32(_) | Self::F64(_) | Self::V128(_) => true,
} }
} }
} }
impl From<Function> for Val { impl From<Function> for Val {
fn from(val: Function) -> Val { fn from(val: Function) -> Self {
Val::FuncRef(val) Self::FuncRef(val)
} }
} }
@@ -53,19 +53,19 @@ impl ValFuncRef for Val {
return Err(RuntimeError::new("cross-`Store` values are not supported")); return Err(RuntimeError::new("cross-`Store` values are not supported"));
} }
Ok(match self { Ok(match self {
Val::ExternRef(ExternRef::Null) => wasmer_vm::VMCallerCheckedAnyfunc { Self::ExternRef(ExternRef::Null) => wasmer_vm::VMCallerCheckedAnyfunc {
func_ptr: ptr::null(), func_ptr: ptr::null(),
type_index: wasmer_vm::VMSharedSignatureIndex::default(), type_index: wasmer_vm::VMSharedSignatureIndex::default(),
vmctx: ptr::null_mut(), vmctx: ptr::null_mut(),
}, },
Val::FuncRef(f) => f.checked_anyfunc(), Self::FuncRef(f) => f.checked_anyfunc(),
_ => return Err(RuntimeError::new("val is not funcref")), _ => return Err(RuntimeError::new("val is not funcref")),
}) })
} }
fn from_checked_anyfunc(item: wasmer_vm::VMCallerCheckedAnyfunc, store: &Store) -> Val { fn from_checked_anyfunc(item: wasmer_vm::VMCallerCheckedAnyfunc, store: &Store) -> Self {
if item.type_index == wasmer_vm::VMSharedSignatureIndex::default() { if item.type_index == wasmer_vm::VMSharedSignatureIndex::default() {
return Val::ExternRef(ExternRef::Null); return Self::ExternRef(ExternRef::Null);
} }
let signature = store let signature = store
.engine() .engine()
@@ -80,6 +80,6 @@ impl ValFuncRef for Val {
vmctx: item.vmctx, vmctx: item.vmctx,
}; };
let f = Function::from_export(store, export); let f = Function::from_export(store, export);
Val::FuncRef(f) Self::FuncRef(f)
} }
} }

View File

@@ -1 +1 @@
doc/html/ doc/deprecated/html/

View File

@@ -1,6 +1,6 @@
[package] [package]
name = "wasmer-c-api" name = "wasmer-c-api"
version = "1.0.0-alpha3" version = "1.0.0-alpha4"
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"]
@@ -12,20 +12,21 @@ readme = "README.md"
edition = "2018" edition = "2018"
[lib] [lib]
crate-type = ["cdylib", "staticlib"] crate-type = ["cdylib", "rlib", "staticlib"]
[dependencies] [dependencies]
wasmer = { version = "1.0.0-alpha3", path = "../api", default-features = false } wasmer = { version = "1.0.0-alpha4", path = "../api", default-features = false }
wasmer-compiler = { version = "1.0.0-alpha3", path = "../compiler" } wasmer-compiler = { version = "1.0.0-alpha4", path = "../compiler" }
wasmer-compiler-cranelift = { version = "1.0.0-alpha3", path = "../compiler-cranelift", optional = true } wasmer-compiler-cranelift = { version = "1.0.0-alpha4", path = "../compiler-cranelift", optional = true }
wasmer-compiler-singlepass = { version = "1.0.0-alpha3", path = "../compiler-singlepass", optional = true } wasmer-compiler-singlepass = { version = "1.0.0-alpha4", path = "../compiler-singlepass", optional = true }
wasmer-compiler-llvm = { version = "1.0.0-alpha3", path = "../compiler-llvm", optional = true } wasmer-compiler-llvm = { version = "1.0.0-alpha4", path = "../compiler-llvm", optional = true }
wasmer-emscripten = { version = "1.0.0-alpha3", path = "../emscripten", optional = true } wasmer-emscripten = { version = "1.0.0-alpha4", path = "../emscripten", optional = true }
wasmer-engine = { version = "1.0.0-alpha3", path = "../engine" } wasmer-engine = { version = "1.0.0-alpha4", path = "../engine" }
wasmer-engine-jit = { version = "1.0.0-alpha3", path = "../engine-jit", optional = true } wasmer-engine-jit = { version = "1.0.0-alpha4", path = "../engine-jit", optional = true }
wasmer-engine-native = { version = "1.0.0-alpha3", path = "../engine-native", optional = true } wasmer-engine-native = { version = "1.0.0-alpha4", path = "../engine-native", optional = true }
wasmer-wasi = { version = "1.0.0-alpha3", path = "../wasi", optional = true } wasmer-engine-object-file = { version = "1.0.0-alpha4", path = "../engine-object-file", optional = true }
wasmer-types = { version = "1.0.0-alpha3", path = "../wasmer-types" } wasmer-wasi = { version = "1.0.0-alpha4", path = "../wasi", optional = true }
wasmer-types = { version = "1.0.0-alpha4", path = "../wasmer-types" }
cfg-if = "0.1" cfg-if = "0.1"
lazy_static = "1" lazy_static = "1"
libc = { version = "^0.2.69", default-features = false } libc = { version = "^0.2.69", default-features = false }
@@ -36,13 +37,15 @@ 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-alpha3", path = "crates/wasm-c-api" } # wasmer-wasm-c-api = { version = "1.0.0-alpha4", path = "crates/wasm-c-api" }
[features] [features]
default = [ default = [
"wat",
"cranelift", "cranelift",
"wasi", "wasi",
] ]
wat = ["wasmer/wat"]
wasi = ["wasmer-wasi", "typetag", "serde"] wasi = ["wasmer-wasi", "typetag", "serde"]
engine = [] engine = []
jit = [ jit = [
@@ -53,9 +56,14 @@ native = [
"wasmer-engine-native", "wasmer-engine-native",
"engine", "engine",
] ]
object-file = [
"wasmer-engine-object-file",
"engine",
]
compiler = [ compiler = [
"wasmer-engine-jit/compiler", "wasmer-engine-jit/compiler",
"wasmer-engine-native/compiler" "wasmer-engine-native/compiler",
"wasmer-engine-object-file/compiler"
] ]
singlepass = [ singlepass = [
"wasmer-compiler-singlepass", "wasmer-compiler-singlepass",
@@ -69,10 +77,11 @@ llvm = [
"wasmer-compiler-llvm", "wasmer-compiler-llvm",
"compiler", "compiler",
] ]
system-libffi = ["libffi/system"]
# Deprecated feature.
# TODO: Port this feature.
#emscripten = ["wasmer-emscripten"] #emscripten = ["wasmer-emscripten"]
# used to avoid generating standard Wasm C API types in our header files
ignore-wasm-c-api = []
# This is for compatibility for old usage # This is for compatibility for old usage
singlepass-backend = ["singlepass"] singlepass-backend = ["singlepass"]
@@ -80,4 +89,4 @@ cranelift-backend = ["cranelift"]
llvm-backend = ["llvm"] llvm-backend = ["llvm"]
[build-dependencies] [build-dependencies]
cbindgen = { version = "0.14.3" } cbindgen = "0.15"

View File

@@ -33,7 +33,6 @@ Here is a simple example to use the C API:
#include "../wasmer.h" #include "../wasmer.h"
#include <assert.h> #include <assert.h>
#include <stdint.h> #include <stdint.h>
int main() int main()
{ {
// Read the Wasm file bytes. // Read the Wasm file bytes.
@@ -44,49 +43,36 @@ int main()
fseek(file, 0, SEEK_SET); fseek(file, 0, SEEK_SET);
fread(bytes, 1, len, file); fread(bytes, 1, len, file);
fclose(file); fclose(file);
// Prepare the imports. // Prepare the imports.
wasmer_import_t imports[] = {}; wasmer_import_t imports[] = {};
// Instantiate! // Instantiate!
wasmer_instance_t *instance = NULL; wasmer_instance_t *instance = NULL;
wasmer_result_t instantiation_result = wasmer_instantiate(&instance, bytes, len, imports, 0); wasmer_result_t instantiation_result = wasmer_instantiate(&instance, bytes, len, imports, 0);
assert(instantiation_result == WASMER_OK); assert(instantiation_result == WASMER_OK);
// Let's call a function. // Let's call a function.
// Start by preparing the arguments. // Start by preparing the arguments.
// Value of argument #1 is `7i32`. // Value of argument #1 is `7i32`.
wasmer_value_t argument_one; wasmer_value_t argument_one;
argument_one.tag = WASM_I32; argument_one.tag = WASM_I32;
argument_one.value.I32 = 7; argument_one.value.I32 = 7;
// Value of argument #2 is `8i32`. // Value of argument #2 is `8i32`.
wasmer_value_t argument_two; wasmer_value_t argument_two;
argument_two.tag = WASM_I32; argument_two.tag = WASM_I32;
argument_two.value.I32 = 8; argument_two.value.I32 = 8;
// Prepare the arguments. // Prepare the arguments.
wasmer_value_t arguments[] = {argument_one, argument_two}; wasmer_value_t arguments[] = {argument_one, argument_two};
// Prepare the return value. // Prepare the return value.
wasmer_value_t result_one; wasmer_value_t result_one;
wasmer_value_t results[] = {result_one}; wasmer_value_t results[] = {result_one};
// Call the `sum` function with the prepared arguments and the return value. // Call the `sum` function with the prepared arguments and the return value.
wasmer_result_t call_result = wasmer_instance_call(instance, "sum", arguments, 2, results, 1); wasmer_result_t call_result = wasmer_instance_call(instance, "sum", arguments, 2, results, 1);
// Let's display the result. // Let's display the result.
printf("Call result: %d\n", call_result); printf("Call result: %d\n", call_result);
printf("Result: %d\n", results[0].value.I32); printf("Result: %d\n", results[0].value.I32);
// `sum(7, 8) == 15`. // `sum(7, 8) == 15`.
assert(results[0].value.I32 == 15); assert(results[0].value.I32 == 15);
assert(call_result == WASMER_OK); assert(call_result == WASMER_OK);
wasmer_instance_destroy(instance); wasmer_instance_destroy(instance);
return 0; return 0;
} }
``` ```

View File

@@ -1,22 +1,7 @@
extern crate cbindgen;
use cbindgen::{Builder, Language}; use cbindgen::{Builder, Language};
use std::{env, fs, path::PathBuf}; use std::{env, fs, path::PathBuf};
fn main() { const PRE_HEADER: &'static str = r#"
let crate_dir = env::var("CARGO_MANIFEST_DIR").unwrap();
let mut crate_wasmer_header_file = PathBuf::from(&crate_dir);
crate_wasmer_header_file.push("wasmer");
let out_dir = env::var("OUT_DIR").unwrap();
let mut out_wasmer_header_file = PathBuf::from(&out_dir);
out_wasmer_header_file.push("wasmer");
let mut pre_header = r#"
#if !defined(WASMER_H_MACROS)
#define WASMER_H_MACROS
// Define the `ARCH_X86_X64` constant. // Define the `ARCH_X86_X64` constant.
#if defined(MSVC) && defined(_M_AMD64) #if defined(MSVC) && defined(_M_AMD64)
# define ARCH_X86_64 # define ARCH_X86_64
@@ -40,67 +25,367 @@ fn main() {
#elif defined(MSVC) || __has_declspec_attribute(deprecated) #elif defined(MSVC) || __has_declspec_attribute(deprecated)
# define DEPRECATED(message) __declspec(deprecated(message)) # define DEPRECATED(message) __declspec(deprecated(message))
#endif #endif
"#;
"# #[allow(unused)]
.to_string(); const JIT_FEATURE_AS_C_DEFINE: &'static str = "WASMER_JIT_ENABLED";
#[cfg(feature = "wasi")] #[allow(unused)]
const COMPILER_FEATURE_AS_C_DEFINE: &'static str = "WASMER_COMPILER_ENABLED";
#[allow(unused)]
const WASI_FEATURE_AS_C_DEFINE: &'static str = "WASMER_WASI_ENABLED";
#[allow(unused)]
const EMSCRIPTEN_FEATURE_AS_C_DEFINE: &'static str = "WASMER_EMSCRIPTEN_ENABLED";
macro_rules! map_feature_as_c_define {
($feature:expr, $c_define:ident, $accumulator:ident) => {
#[cfg(feature = $feature)]
{ {
pre_header += "#define WASMER_WASI_ENABLED\n"; $accumulator.push_str(&format!(
r#"
// The `{feature}` feature has been enabled for this build.
#define {define}
"#,
feature = $feature,
define = $c_define,
));
}
};
} }
#[cfg(feature = "emscripten")] fn main() {
{ let crate_dir = env::var("CARGO_MANIFEST_DIR").unwrap();
pre_header += "#define WASMER_EMSCRIPTEN_ENABLED\n"; let out_dir = env::var("OUT_DIR").unwrap();
build_wasm_c_api_headers(&crate_dir, &out_dir);
build_wasmer_headers(&crate_dir, &out_dir);
} }
/// Build the header files for the `wasm_c_api` API.
fn build_wasm_c_api_headers(crate_dir: &str, out_dir: &str) {
let mut crate_header_file = PathBuf::from(crate_dir);
crate_header_file.push("wasmer_wasm");
let mut out_header_file = PathBuf::from(out_dir);
out_header_file.push("wasmer_wasm");
let mut pre_header = format!(
r#"// The Wasmer C/C++ header file compatible with the `wasm-c-api` standard API.
#if !defined(WASMER_WASM_H_MACROS)
#define WASMER_WASM_H_MACROS
{pre_header}"#,
pre_header = PRE_HEADER
);
map_feature_as_c_define!("jit", JIT_FEATURE_AS_C_DEFINE, pre_header);
map_feature_as_c_define!("compiler", COMPILER_FEATURE_AS_C_DEFINE, pre_header);
map_feature_as_c_define!("wasi", WASI_FEATURE_AS_C_DEFINE, pre_header);
map_feature_as_c_define!("emscripten", EMSCRIPTEN_FEATURE_AS_C_DEFINE, pre_header);
// Close pre header. // Close pre header.
pre_header += "#endif // WASMER_H_MACROS\n"; pre_header.push_str(
r#"
#endif // WASMER_WASM_H_MACROS
// Generate the C bindings in the `OUT_DIR`.
out_wasmer_header_file.set_extension("h"); //
Builder::new() // OK, here we go. The code below is automatically generated.
.with_crate(crate_dir.clone()) //
.with_language(Language::C) "#,
.with_include_guard("WASMER_H") );
.with_header(&pre_header)
.with_define("target_family", "windows", "_WIN32") let guard = "WASMER_WASM_H";
.with_define("target_arch", "x86_64", "ARCH_X86_64")
.with_define("feature", "wasi", "WASMER_WASI_ENABLED") // C bindings.
.with_define("feature", "emscripten", "WASMER_EMSCRIPTEN_ENABLED") {
// Generate the bindings in the `OUT_DIR`.
out_header_file.set_extension("h");
// Build and generate the header file.
exclude_items_from_deprecated(new_builder(Language::C, crate_dir, guard, &pre_header))
.with_include("wasm.h")
.generate() .generate()
.expect("Unable to generate C bindings") .expect("Unable to generate C bindings")
.write_to_file(out_wasmer_header_file.as_path()); .write_to_file(out_header_file.as_path());
// Generate the C++ bindings in the `OUT_DIR`. // Copy the generated bindings from `OUT_DIR` to
out_wasmer_header_file.set_extension("hh"); // `CARGO_MANIFEST_DIR`.
Builder::new() crate_header_file.set_extension("h");
.with_crate(crate_dir)
.with_language(Language::Cxx) fs::copy(out_header_file.as_path(), crate_header_file.as_path())
.with_include_guard("WASMER_H") .expect("Unable to copy the generated C bindings");
.with_header(&pre_header) }
.with_define("target_family", "windows", "_WIN32") }
.with_define("target_arch", "x86_64", "ARCH_X86_64")
.with_define("feature", "wasi", "WASMER_WASI_ENABLED") /// Build the header files for the `deprecated` API.
.with_define("feature", "emscripten", "WASMER_EMSCRIPTEN_ENABLED") fn build_wasmer_headers(crate_dir: &str, out_dir: &str) {
let mut crate_header_file = PathBuf::from(crate_dir);
crate_header_file.push("wasmer");
let mut out_header_file = PathBuf::from(out_dir);
out_header_file.push("wasmer");
let mut pre_header = format!(
r#"// The Wasmer C/C++ header file.
#if !defined(WASMER_H_MACROS)
#define WASMER_H_MACROS
{pre_header}"#,
pre_header = PRE_HEADER
);
map_feature_as_c_define!("wasi", WASI_FEATURE_AS_C_DEFINE, pre_header);
map_feature_as_c_define!("emscritpen", EMSCRIPTEN_FEATURE_AS_C_DEFINE, pre_header);
// Close pre header.
pre_header.push_str(
r#"#endif // WASMER_H_MACROS
//
// OK, here we go. The code below is automatically generated.
//
"#,
);
let guard = "WASMER_H";
// C bindings.
{
// Generate the bindings in the `OUT_DIR`.
out_header_file.set_extension("h");
// Build and generate the header file.
exclude_items_from_wasm_c_api(new_builder(Language::C, crate_dir, guard, &pre_header))
.generate()
.expect("Unable to generate C bindings")
.write_to_file(out_header_file.as_path());
// Copy the generated bindings from `OUT_DIR` to
// `CARGO_MANIFEST_DIR`.
crate_header_file.set_extension("h");
fs::copy(out_header_file.as_path(), crate_header_file.as_path())
.expect("Unable to copy the generated C bindings");
}
// C++ bindings.
{
// Generate the bindings in the `OUT_DIR`.
out_header_file.set_extension("hh");
// Build and generate the header file.
exclude_items_from_wasm_c_api(new_builder(Language::Cxx, crate_dir, guard, &pre_header))
.generate() .generate()
.expect("Unable to generate C++ bindings") .expect("Unable to generate C++ bindings")
.write_to_file(out_wasmer_header_file.as_path()); .write_to_file(out_header_file.as_path());
// Copy the generated C bindings from `OUT_DIR` to // Copy the generated bindings from `OUT_DIR` to
// `CARGO_MANIFEST_DIR`. // `CARGO_MANIFEST_DIR`.
crate_wasmer_header_file.set_extension("h"); crate_header_file.set_extension("hh");
out_wasmer_header_file.set_extension("h");
fs::copy(
out_wasmer_header_file.as_path(),
crate_wasmer_header_file.as_path(),
)
.expect("Unable to copy the generated C bindings");
// Copy the generated C++ bindings from `OUT_DIR` to fs::copy(out_header_file, crate_header_file)
// `CARGO_MANIFEST_DIR`.
crate_wasmer_header_file.set_extension("hh");
out_wasmer_header_file.set_extension("hh");
fs::copy(out_wasmer_header_file, crate_wasmer_header_file)
.expect("Unable to copy the generated C++ bindings"); .expect("Unable to copy the generated C++ bindings");
} }
}
/// Create a fresh new `Builder`, already pre-configured.
fn new_builder(language: Language, crate_dir: &str, include_guard: &str, header: &str) -> Builder {
Builder::new()
.with_config(cbindgen::Config {
sort_by: cbindgen::SortKey::Name,
..cbindgen::Config::default()
})
.with_language(language)
.with_crate(crate_dir)
.with_include_guard(include_guard)
.with_header(header)
.with_documentation(true)
.with_define("target_family", "windows", "_WIN32")
.with_define("target_arch", "x86_64", "ARCH_X86_64")
.with_define("feature", "jit", JIT_FEATURE_AS_C_DEFINE)
.with_define("feature", "compiler", COMPILER_FEATURE_AS_C_DEFINE)
.with_define("feature", "wasi", WASI_FEATURE_AS_C_DEFINE)
.with_define("feature", "emscripten", EMSCRIPTEN_FEATURE_AS_C_DEFINE)
}
/// Exclude types and functions from the `deprecated` API.
fn exclude_items_from_deprecated(builder: Builder) -> Builder {
builder
// List of all functions to exclude given by:
//
// `rg 'extern "C" fn' deprecated/` builder = builder
.exclude_item("wasmer_compile")
.exclude_item("wasmer_emscripten_call_main")
.exclude_item("wasmer_emscripten_destroy_globals")
.exclude_item("wasmer_emscripten_generate_import_object")
.exclude_item("wasmer_emscripten_get_globals")
.exclude_item("wasmer_emscripten_set_up")
.exclude_item("wasmer_export_descriptor_kind")
.exclude_item("wasmer_export_descriptor_name")
.exclude_item("wasmer_export_descriptors")
.exclude_item("wasmer_export_descriptors_destroy")
.exclude_item("wasmer_export_descriptors_get")
.exclude_item("wasmer_export_descriptors_len")
.exclude_item("wasmer_export_func_call")
.exclude_item("wasmer_export_func_params")
.exclude_item("wasmer_export_func_params_arity")
.exclude_item("wasmer_export_func_returns")
.exclude_item("wasmer_export_func_returns_arity")
.exclude_item("wasmer_export_kind")
.exclude_item("wasmer_export_name")
.exclude_item("wasmer_export_to_func")
.exclude_item("wasmer_export_to_memory")
.exclude_item("wasmer_exports_destroy")
.exclude_item("wasmer_exports_get")
.exclude_item("wasmer_exports_len")
.exclude_item("wasmer_global_destroy")
.exclude_item("wasmer_global_get")
.exclude_item("wasmer_global_get_descriptor")
.exclude_item("wasmer_global_new")
.exclude_item("wasmer_global_set")
.exclude_item("wasmer_import_descriptor_kind")
.exclude_item("wasmer_import_descriptor_module_name")
.exclude_item("wasmer_import_descriptor_name")
.exclude_item("wasmer_import_descriptors")
.exclude_item("wasmer_import_descriptors_destroy")
.exclude_item("wasmer_import_descriptors_get")
.exclude_item("wasmer_import_descriptors_len")
.exclude_item("wasmer_import_func_destroy")
.exclude_item("wasmer_import_func_new")
.exclude_item("wasmer_import_func_params")
.exclude_item("wasmer_import_func_params_arity")
.exclude_item("wasmer_import_func_returns")
.exclude_item("wasmer_import_func_returns_arity")
.exclude_item("wasmer_import_object_destroy")
.exclude_item("wasmer_import_object_extend")
.exclude_item("wasmer_import_object_get_import")
.exclude_item("wasmer_import_object_imports_destroy")
.exclude_item("wasmer_import_object_iter_at_end")
.exclude_item("wasmer_import_object_iter_destroy")
.exclude_item("wasmer_import_object_iter_next")
.exclude_item("wasmer_import_object_iterate_functions")
.exclude_item("wasmer_import_object_new")
.exclude_item("wasmer_import_object_new")
.exclude_item("wasmer_instance_call")
.exclude_item("wasmer_instance_context_data_get")
.exclude_item("wasmer_instance_context_data_set")
.exclude_item("wasmer_instance_context_get")
.exclude_item("wasmer_instance_context_memory")
.exclude_item("wasmer_instance_destroy")
.exclude_item("wasmer_instance_exports")
.exclude_item("wasmer_instantiate")
.exclude_item("wasmer_memory_data")
.exclude_item("wasmer_memory_data_length")
.exclude_item("wasmer_memory_destroy")
.exclude_item("wasmer_memory_grow")
.exclude_item("wasmer_memory_length")
.exclude_item("wasmer_memory_new")
.exclude_item("wasmer_module_deserialize")
.exclude_item("wasmer_module_destroy")
.exclude_item("wasmer_module_import_instantiate")
.exclude_item("wasmer_module_instantiate")
.exclude_item("wasmer_module_serialize")
.exclude_item("wasmer_serialized_module_bytes")
.exclude_item("wasmer_serialized_module_destroy")
.exclude_item("wasmer_serialized_module_from_bytes")
.exclude_item("wasmer_table_destroy")
.exclude_item("wasmer_table_grow")
.exclude_item("wasmer_table_length")
.exclude_item("wasmer_table_new")
.exclude_item("wasmer_trampoline_buffer_builder_add_callinfo_trampoline")
.exclude_item("wasmer_trampoline_buffer_builder_add_context_trampoline")
.exclude_item("wasmer_trampoline_buffer_builder_build")
.exclude_item("wasmer_trampoline_buffer_builder_new")
.exclude_item("wasmer_trampoline_buffer_destroy")
.exclude_item("wasmer_trampoline_buffer_get_trampoline")
.exclude_item("wasmer_trampoline_get_context")
.exclude_item("wasmer_trap")
.exclude_item("wasmer_validate")
.exclude_item("wasmer_wasi_generate_default_import_object")
.exclude_item("wasmer_wasi_generate_import_object")
.exclude_item("wasmer_wasi_generate_import_object_for_version")
.exclude_item("wasmer_wasi_get_version")
// List of all structs and enums to exclude given by:
//
// `rg 'pub (enum|struct|union)' deprecated/`
.exclude_item("NamedExportDescriptors(Vec<NamedExportDescriptor>)")
.exclude_item("NamedImportDescriptors(Vec<ImportType>)")
.exclude_item("Version")
.exclude_item("WasmerImportObjectIterator")
.exclude_item("wasmer_byte_array")
.exclude_item("wasmer_emscripten_globals_t")
.exclude_item("wasmer_export_descriptor_t")
.exclude_item("wasmer_export_descriptors_t")
.exclude_item("wasmer_export_func_t")
.exclude_item("wasmer_export_t")
.exclude_item("wasmer_exports_t")
.exclude_item("wasmer_global_descriptor_t")
.exclude_item("wasmer_global_t")
.exclude_item("wasmer_import_descriptor_t")
.exclude_item("wasmer_import_descriptors_t")
.exclude_item("wasmer_import_export_kind")
.exclude_item("wasmer_import_func_t")
.exclude_item("wasmer_import_object_iter_t")
.exclude_item("wasmer_import_object_t")
.exclude_item("wasmer_import_t")
.exclude_item("wasmer_instance_context_t")
.exclude_item("wasmer_instance_t")
.exclude_item("wasmer_limit_option_t")
.exclude_item("wasmer_limits_t")
.exclude_item("wasmer_memory_t")
.exclude_item("wasmer_module_t")
.exclude_item("wasmer_result_t")
.exclude_item("wasmer_serialized_module_t")
.exclude_item("wasmer_table_t")
.exclude_item("wasmer_trampoline_buffer_builder_t")
.exclude_item("wasmer_trampoline_buffer_t")
.exclude_item("wasmer_trampoline_callable_t")
.exclude_item("wasmer_value_t")
.exclude_item("wasmer_value_tag")
.exclude_item("wasmer_wasi_map_dir_entry_t")
}
/// Excludes non-standard types and functions of the `wasm_c_api` API.
///
/// All items defined in `wasm.h` are ignored by cbindgen already
/// based on `cbindgen:ignore` instructions, because we don't want
/// duplications. We must exclude extra non-standard items, like the
/// ones from the WASI API.
fn exclude_items_from_wasm_c_api(builder: Builder) -> Builder {
builder
.exclude_item("wasi_config_arg")
.exclude_item("wasi_config_env")
.exclude_item("wasi_config_mapdir")
.exclude_item("wasi_config_preopen_dir")
.exclude_item("wasi_config_inherit_stderr")
.exclude_item("wasi_config_inherit_stdin")
.exclude_item("wasi_config_inherit_stdout")
.exclude_item("wasi_config_new")
.exclude_item("wasi_config_t")
.exclude_item("wasi_env_delete")
.exclude_item("wasi_env_new")
.exclude_item("wasi_env_read_stderr")
.exclude_item("wasi_env_read_stdout")
.exclude_item("wasi_env_set_instance")
.exclude_item("wasi_env_set_memory")
.exclude_item("wasi_env_t")
.exclude_item("wasi_get_imports")
.exclude_item("wasi_get_imports_inner")
.exclude_item("wasi_get_start_function")
.exclude_item("wasi_get_wasi_version")
.exclude_item("wasi_version_t")
.exclude_item("wasm_config_set_compiler")
.exclude_item("wasm_config_set_engine")
.exclude_item("wasm_instance_get_vmctx_ptr")
.exclude_item("wasm_module_name")
.exclude_item("wasm_module_set_name")
.exclude_item("wasmer_compiler_t")
.exclude_item("wasmer_engine_t")
.exclude_item("wat2wasm")
}

View File

@@ -0,0 +1,8 @@
# Compile the documentation
Run `doxygen` in this directory:
```sh
$ doxygen
$ open html/index.html
```

View File

@@ -7,8 +7,8 @@ DOXYFILE_ENCODING = UTF-8
PROJECT_NAME = "wasmer-c-api" PROJECT_NAME = "wasmer-c-api"
PROJECT_NUMBER = PROJECT_NUMBER =
PROJECT_BRIEF = PROJECT_BRIEF =
PROJECT_LOGO = ../../assets/logo.png PROJECT_LOGO = ../../../../assets/logo.png
OUTPUT_DIRECTORY = doc/ OUTPUT_DIRECTORY = .
CREATE_SUBDIRS = NO CREATE_SUBDIRS = NO
ALLOW_UNICODE_NAMES = NO ALLOW_UNICODE_NAMES = NO
OUTPUT_LANGUAGE = English OUTPUT_LANGUAGE = English
@@ -116,8 +116,8 @@ WARN_LOGFILE =
#--------------------------------------------------------------------------- #---------------------------------------------------------------------------
# Configuration options related to the input files # Configuration options related to the input files
#--------------------------------------------------------------------------- #---------------------------------------------------------------------------
INPUT = doc/index.md INPUT = index.md
INPUT += wasmer.h INPUT += ../../wasmer.h
INPUT_ENCODING = UTF-8 INPUT_ENCODING = UTF-8
FILE_PATTERNS = *.h \ FILE_PATTERNS = *.h \
*.hh *.hh
@@ -134,7 +134,7 @@ INPUT_FILTER =
FILTER_PATTERNS = FILTER_PATTERNS =
FILTER_SOURCE_FILES = NO FILTER_SOURCE_FILES = NO
FILTER_SOURCE_PATTERNS = FILTER_SOURCE_PATTERNS =
USE_MDFILE_AS_MAINPAGE = doc/index.md USE_MDFILE_AS_MAINPAGE = index.md
#--------------------------------------------------------------------------- #---------------------------------------------------------------------------
# Configuration options related to source browsing # Configuration options related to source browsing
#--------------------------------------------------------------------------- #---------------------------------------------------------------------------
@@ -159,10 +159,10 @@ IGNORE_PREFIX =
GENERATE_HTML = YES GENERATE_HTML = YES
HTML_OUTPUT = html HTML_OUTPUT = html
HTML_FILE_EXTENSION = .html HTML_FILE_EXTENSION = .html
HTML_HEADER = doc/theme/header.html HTML_HEADER = theme/header.html
HTML_FOOTER = doc/theme/footer.html HTML_FOOTER = theme/footer.html
HTML_STYLESHEET = HTML_STYLESHEET =
HTML_EXTRA_STYLESHEET = doc/theme/css/wasmer.css HTML_EXTRA_STYLESHEET = theme/css/wasmer.css
HTML_EXTRA_FILES = HTML_EXTRA_FILES =
HTML_COLORSTYLE_HUE = 220 HTML_COLORSTYLE_HUE = 220
HTML_COLORSTYLE_SAT = 100 HTML_COLORSTYLE_SAT = 100

View File

@@ -1,8 +1,7 @@
//! Create, read, destroy export definitions (function, global, memory //! Create, read, destroy export definitions (function, global, memory
//! and table) on an instance. //! and table) on an instance.
use crate::{ use crate::deprecated::{
error::{update_last_error, CApiError},
global::wasmer_global_t, global::wasmer_global_t,
import::wasmer_import_func_t, import::wasmer_import_func_t,
instance::CAPIInstance, instance::CAPIInstance,
@@ -12,6 +11,7 @@ use crate::{
value::{wasmer_value, wasmer_value_t, wasmer_value_tag}, value::{wasmer_value, wasmer_value_t, wasmer_value_tag},
wasmer_byte_array, wasmer_result_t, wasmer_byte_array, wasmer_result_t,
}; };
use crate::error::{update_last_error, CApiError};
use libc::{c_int, c_uint}; use libc::{c_int, c_uint};
use std::ptr::{self, NonNull}; use std::ptr::{self, NonNull};
use std::slice; use std::slice;
@@ -41,9 +41,9 @@ pub struct wasmer_export_func_t;
/// exposed to C. /// exposed to C.
pub(crate) struct NamedExports(pub Vec<NamedExport>); pub(crate) struct NamedExports(pub Vec<NamedExport>);
/// Opaque pointer to the opaque structure `crate::NamedExports`, /// Opaque pointer to the opaque structure
/// which is a wrapper around a vector of the opaque structure /// `crate::deprecated::NamedExports`, which is a wrapper around a
/// `crate::NamedExport`. /// vector of the opaque structure `crate::deprecated::NamedExport`.
/// ///
/// Check the `wasmer_instance_exports()` function to learn more. /// Check the `wasmer_instance_exports()` function to learn more.
#[repr(C)] #[repr(C)]

View File

@@ -1,7 +1,10 @@
//! Create, set, get and destroy global variables of an instance. //! Create, set, get and destroy global variables of an instance.
use crate::deprecated::{
get_global_store,
value::{wasmer_value_t, wasmer_value_tag},
};
use crate::error::update_last_error; use crate::error::update_last_error;
use crate::value::{wasmer_value_t, wasmer_value_tag};
use std::ptr::NonNull; use std::ptr::NonNull;
use wasmer::Global; use wasmer::Global;
@@ -20,7 +23,7 @@ pub struct wasmer_global_t;
/// The caller owns the object and should call `wasmer_global_destroy` to free it. /// The caller owns the object and should call `wasmer_global_destroy` to free it.
#[no_mangle] #[no_mangle]
pub extern "C" fn wasmer_global_new(value: wasmer_value_t, mutable: bool) -> *mut wasmer_global_t { pub extern "C" fn wasmer_global_new(value: wasmer_value_t, mutable: bool) -> *mut wasmer_global_t {
let store = crate::get_global_store(); let store = get_global_store();
let global = if mutable { let global = if mutable {
Global::new_mut(store, value.into()) Global::new_mut(store, value.into())
} else { } else {

View File

@@ -1,7 +1,7 @@
//! Functions and types for dealing with Emscripten imports //! Functions and types for dealing with Emscripten imports
use super::*; use super::*;
use crate::{ use crate::deprecated::{
get_slice_checked, get_slice_checked,
instance::{wasmer_instance_t, CAPIInstance}, instance::{wasmer_instance_t, CAPIInstance},
module::wasmer_module_t, module::wasmer_module_t,

View File

@@ -1,14 +1,15 @@
//! Create, read, destroy import definitions (function, global, memory //! Create, read, destroy import definitions (function, global, memory
//! and table) on an instance. //! and table) on an instance.
use crate::{ use crate::deprecated::{
error::{update_last_error, CApiError},
export::{wasmer_import_export_kind, wasmer_import_export_value}, export::{wasmer_import_export_kind, wasmer_import_export_value},
get_global_store,
instance::{wasmer_instance_context_t, CAPIInstance}, instance::{wasmer_instance_context_t, CAPIInstance},
module::wasmer_module_t, module::wasmer_module_t,
value::wasmer_value_tag, value::wasmer_value_tag,
wasmer_byte_array, wasmer_result_t, wasmer_byte_array, wasmer_result_t,
}; };
use crate::error::{update_last_error, CApiError};
use libc::c_uint; use libc::c_uint;
use std::ffi::{c_void, CStr}; use std::ffi::{c_void, CStr};
use std::os::raw::c_char; use std::os::raw::c_char;
@@ -687,7 +688,7 @@ pub unsafe extern "C" fn wasmer_import_func_new(
let returns: Vec<ValType> = returns.iter().cloned().map(|x| x.into()).collect(); let returns: Vec<ValType> = returns.iter().cloned().map(|x| x.into()).collect();
let func_type = FunctionType::new(params, &returns[..]); let func_type = FunctionType::new(params, &returns[..]);
let store = crate::get_global_store(); let store = get_global_store();
let env_ptr = Box::into_raw(Box::new(LegacyEnv::default())); let env_ptr = Box::into_raw(Box::new(LegacyEnv::default()));

View File

@@ -1,5 +1,5 @@
use super::*; use super::*;
use crate::get_slice_checked; use crate::deprecated::{get_global_store, get_slice_checked};
use libc::c_uchar; use libc::c_uchar;
use std::path::PathBuf; use std::path::PathBuf;
use std::ptr; use std::ptr;
@@ -174,7 +174,7 @@ fn wasmer_wasi_generate_import_object_inner(
_ => panic!("Version {:?} is invalid.", version), _ => panic!("Version {:?} is invalid.", version),
}; };
let store = crate::get_global_store(); let store = get_global_store();
let mut wasi_state_builder = wasi::WasiState::new( let mut wasi_state_builder = wasi::WasiState::new(
arg_vec arg_vec
@@ -209,7 +209,7 @@ fn wasmer_wasi_generate_import_object_inner(
#[no_mangle] #[no_mangle]
pub unsafe extern "C" fn wasmer_wasi_generate_default_import_object() -> *mut wasmer_import_object_t pub unsafe extern "C" fn wasmer_wasi_generate_default_import_object() -> *mut wasmer_import_object_t
{ {
let store = crate::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 mut wasi_env = wasi::WasiEnv::new(wasi_state);

View File

@@ -1,13 +1,14 @@
//! Instantiate a module, call functions, and read exports. //! Instantiate a module, call functions, and read exports.
use crate::{ use crate::deprecated::{
error::{update_last_error, CApiError},
export::{wasmer_exports_t, wasmer_import_export_kind, NamedExport, NamedExports}, export::{wasmer_exports_t, wasmer_import_export_kind, NamedExport, NamedExports},
get_global_store,
import::{wasmer_import_t, FunctionWrapper}, import::{wasmer_import_t, FunctionWrapper},
memory::wasmer_memory_t, memory::wasmer_memory_t,
value::{wasmer_value, wasmer_value_t, wasmer_value_tag}, value::{wasmer_value, wasmer_value_t, wasmer_value_tag},
wasmer_result_t, wasmer_result_t,
}; };
use crate::error::{update_last_error, CApiError};
use libc::{c_char, c_int, c_void}; use libc::{c_char, c_int, c_void};
use std::collections::HashMap; use std::collections::HashMap;
use std::ffi::CStr; use std::ffi::CStr;
@@ -191,7 +192,7 @@ pub unsafe extern "C" fn wasmer_instantiate(
} }
let bytes: &[u8] = slice::from_raw_parts_mut(wasm_bytes.as_ptr(), wasm_bytes_len as usize); let bytes: &[u8] = slice::from_raw_parts_mut(wasm_bytes.as_ptr(), wasm_bytes_len as usize);
let store = crate::get_global_store(); let store = get_global_store();
let module_result = Module::from_binary(store, bytes); let module_result = Module::from_binary(store, bytes);
let module = match module_result { let module = match module_result {

View File

@@ -1,9 +1,7 @@
//! Create, read, write, grow, destroy memory of an instance. //! Create, read, write, grow, destroy memory of an instance.
use crate::{ use crate::deprecated::{get_global_store, wasmer_limits_t, wasmer_result_t};
error::{update_last_error, CApiError}, use crate::error::{update_last_error, CApiError};
wasmer_limits_t, wasmer_result_t,
};
use std::{cell::Cell, ptr}; use std::{cell::Cell, ptr};
use wasmer::{Bytes, Memory, MemoryType, Pages}; use wasmer::{Bytes, Memory, MemoryType, Pages};
@@ -67,7 +65,7 @@ pub unsafe extern "C" fn wasmer_memory_new(
} else { } else {
None None
}; };
let store = crate::get_global_store(); let store = get_global_store();
let desc = MemoryType::new(Pages(limits.min), max, false); let desc = MemoryType::new(Pages(limits.min), max, false);
match Memory::new(store, desc) { match Memory::new(store, desc) {
Ok(new_memory) => { Ok(new_memory) => {

View File

@@ -0,0 +1,180 @@
//! # Wasmer Runtime C API
//!
//! Wasmer is a standalone JIT WebAssembly runtime, aiming to be fully
//! compatible with Emscripten, Rust and Go. [Learn
//! more](https://github.com/wasmerio/wasmer).
//!
//! This crate exposes a C and C++ API for the Wasmer runtime.
//!
//! # Usage
//!
//! The C and C++ header files can be found in the source tree of this
//! crate, respectively [`wasmer.h`][wasmer_h] and
//! [`wasmer.hh`][wasmer_hh]. They are automatically generated, and always
//! up-to-date in this repository.
//!
//! Here is a simple example to use the C API:
//!
//! ```c
//! #include <stdio.h>
//! #include "wasmer.h"
//! #include <assert.h>
//! #include <stdint.h>
//!
//! int main()
//! {
//! // Read the Wasm file bytes.
//! FILE *file = fopen("sum.wasm", "r");
//! fseek(file, 0, SEEK_END);
//! long len = ftell(file);
//! uint8_t *bytes = malloc(len);
//! fseek(file, 0, SEEK_SET);
//! fread(bytes, 1, len, file);
//! fclose(file);
//!
//! // Prepare the imports.
//! wasmer_import_t imports[] = {};
//!
//! // Instantiate!
//! wasmer_instance_t *instance = NULL;
//! wasmer_result_t instantiation_result = wasmer_instantiate(&instance, bytes, len, imports, 0);
//!
//! assert(instantiation_result == WASMER_OK);
//!
//! // Let's call a function.
//! // Start by preparing the arguments.
//!
//! // Value of argument #1 is `7i32`.
//! wasmer_value_t argument_one;
//! argument_one.tag = WASM_I32;
//! argument_one.value.I32 = 7;
//!
//! // Value of argument #2 is `8i32`.
//! wasmer_value_t argument_two;
//! argument_two.tag = WASM_I32;
//! argument_two.value.I32 = 8;
//!
//! // Prepare the arguments.
//! wasmer_value_t arguments[] = {argument_one, argument_two};
//!
//! // Prepare the return value.
//! wasmer_value_t result_one;
//! wasmer_value_t results[] = {result_one};
//!
//! // Call the `sum` function with the prepared arguments and the return value.
//! wasmer_result_t call_result = wasmer_instance_call(instance, "sum", arguments, 2, results, 1);
//!
//! // Let's display the result.
//! printf("Call result: %d\n", call_result);
//! printf("Result: %d\n", results[0].value.I32);
//!
//! // `sum(7, 8) == 15`.
//! assert(results[0].value.I32 == 15);
//! assert(call_result == WASMER_OK);
//!
//! wasmer_instance_destroy(instance);
//!
//! return 0;
//! }
//! ```
//!
//! [wasmer_h]: ./wasmer.h
//! [wasmer_hh]: ./wasmer.hh
use lazy_static::lazy_static;
pub mod export;
pub mod global;
pub mod import;
pub mod instance;
pub mod memory;
pub mod module;
pub mod table;
// `not(target_family = "windows")` is simpler than `unix`. See build.rs
// if you want to change the meaning of these `cfg`s in the header file.
/*
TODO: reenable `trampoline` module when the refactor gains feature parity with Wasmer master
#[cfg(all(not(target_family = "windows"), target_arch = "x86_64"))]
pub mod trampoline;*/
pub mod value;
/// The `wasmer_result_t` enum is a type that represents either a
/// success, or a failure.
#[allow(non_camel_case_types)]
#[repr(C)]
pub enum wasmer_result_t {
/// Represents a success.
WASMER_OK = 1,
/// Represents a failure.
WASMER_ERROR = 2,
}
/// The `wasmer_limits_t` struct is a type that describes the limits of something
/// such as a memory or a table. See the `wasmer_memory_new()` function to get
/// more information.
#[repr(C)]
pub struct wasmer_limits_t {
/// The minimum number of allowed pages.
pub min: u32,
/// The maximum number of allowed pages.
pub max: wasmer_limit_option_t,
}
/// The `wasmer_limit_option_t` struct represents an optional limit
/// for `wasmer_limits_t`.
#[repr(C)]
pub struct wasmer_limit_option_t {
/// Whether the limit is set.
pub has_some: bool,
/// The limit value.
pub some: u32,
}
#[repr(C)]
pub struct wasmer_byte_array {
pub bytes: *const u8,
pub bytes_len: u32,
}
impl wasmer_byte_array {
/// Get the data as a slice
pub unsafe fn as_slice<'a>(&self) -> &'a [u8] {
get_slice_checked(self.bytes, self.bytes_len as usize)
}
/// Copy the data into an owned Vec
pub unsafe fn as_vec(&self) -> Vec<u8> {
let mut out = Vec::with_capacity(self.bytes_len as usize);
out.extend_from_slice(self.as_slice());
out
}
/// Read the data as a &str, returns an error if the string is not valid UTF8
pub unsafe fn as_str<'a>(&self) -> Result<&'a str, std::str::Utf8Error> {
std::str::from_utf8(self.as_slice())
}
}
/// Gets a slice from a pointer and a length, returning an empty slice if the
/// pointer is null
#[inline]
pub(crate) unsafe fn get_slice_checked<'a, T>(ptr: *const T, len: usize) -> &'a [T] {
if ptr.is_null() {
&[]
} else {
std::slice::from_raw_parts(ptr, len)
}
}
lazy_static! {
pub(crate) static ref GLOBAL_STORE: wasmer::Store =
wasmer::Store::new(&*crate::wasm_c_api::engine::wasm_engine_new().inner);
}
pub(crate) fn get_global_store() -> &'static wasmer::Store {
&*GLOBAL_STORE
}

View File

@@ -1,12 +1,13 @@
//! Compile, validate, instantiate, serialize, and destroy modules. //! Compile, validate, instantiate, serialize, and destroy modules.
use crate::{ use crate::deprecated::{
error::{update_last_error, CApiError},
export::wasmer_import_export_kind, export::wasmer_import_export_kind,
get_global_store,
import::{wasmer_import_object_t, wasmer_import_t, CAPIImportObject}, import::{wasmer_import_object_t, wasmer_import_t, CAPIImportObject},
instance::{wasmer_instance_t, CAPIInstance}, instance::{wasmer_instance_t, CAPIInstance},
wasmer_byte_array, wasmer_result_t, wasmer_byte_array, wasmer_result_t,
}; };
use crate::error::{update_last_error, CApiError};
use libc::c_int; use libc::c_int;
use std::collections::HashMap; use std::collections::HashMap;
use std::ptr::NonNull; use std::ptr::NonNull;
@@ -33,7 +34,7 @@ pub unsafe extern "C" fn wasmer_compile(
wasm_bytes_len: u32, wasm_bytes_len: u32,
) -> wasmer_result_t { ) -> wasmer_result_t {
let bytes: &[u8] = slice::from_raw_parts_mut(wasm_bytes, wasm_bytes_len as usize); let bytes: &[u8] = slice::from_raw_parts_mut(wasm_bytes, wasm_bytes_len as usize);
let store = crate::get_global_store(); let store = get_global_store();
let result = Module::from_binary(store, bytes); let result = Module::from_binary(store, bytes);
let new_module = match result { let new_module = match result {
Ok(instance) => instance, Ok(instance) => instance,
@@ -68,7 +69,7 @@ pub unsafe extern "C" fn wasmer_validate(wasm_bytes: *const u8, wasm_bytes_len:
let bytes: &[u8] = slice::from_raw_parts(wasm_bytes, wasm_bytes_len as usize); let bytes: &[u8] = slice::from_raw_parts(wasm_bytes, wasm_bytes_len as usize);
let store = crate::get_global_store(); let store = get_global_store();
Module::validate(store, bytes).is_ok() Module::validate(store, bytes).is_ok()
} }
@@ -297,7 +298,7 @@ pub unsafe extern "C" fn wasmer_module_deserialize(
return wasmer_result_t::WASMER_ERROR; return wasmer_result_t::WASMER_ERROR;
}; };
let store = crate::get_global_store(); let store = get_global_store();
match Module::deserialize(store, serialized_module) { match Module::deserialize(store, serialized_module) {
Ok(deserialized_module) => { Ok(deserialized_module) => {

View File

@@ -1,6 +1,7 @@
//! Create, grow, destroy tables of an instance. //! Create, grow, destroy tables of an instance.
use crate::{error::update_last_error, wasmer_limits_t, wasmer_result_t}; use crate::deprecated::{get_global_store, wasmer_limits_t, wasmer_result_t};
use crate::error::update_last_error;
use std::ptr::NonNull; use std::ptr::NonNull;
use wasmer::{ExternRef, Table, TableType, Val, ValType}; use wasmer::{ExternRef, Table, TableType, Val, ValType};
@@ -45,7 +46,7 @@ pub unsafe extern "C" fn wasmer_table_new(
minimum: limits.min, minimum: limits.min,
maximum: max, maximum: max,
}; };
let store = crate::get_global_store(); let store = get_global_store();
let result = Table::new(store, desc, get_default_table_value(ValType::FuncRef)); let result = Table::new(store, desc, get_default_table_value(ValType::FuncRef));
let new_table = match result { let new_table = match result {
Ok(table) => table, Ok(table) => table,

View File

@@ -1,90 +1,26 @@
//! Wasmer C API.
//!
//! [Wasmer](https://github.com/wasmerio/wasmer) is the leading
//! WebAssembly runtime. This crate exposes the C and C++ bindings.
//!
//! This crate provides 2 API:
//!
//! * `deprecated`, which is the old one, and is represented by the
//! `wasmer.h` and the `wasmer.hh` C header files,
//! * `wasm_c_api`, which is the new, standard C API, and is
//! represented by the `wasmer_wasm.h` C header file.
//!
//! The `wasm_c_api` follows the [official WebAssembly C and C++
//! API](https://github.com/WebAssembly/wasm-c-api). It provides
//! however some extensions, like the `wasi_*` types and functions,
//! which aren't yet defined by the standard. The `wasmer_wasm.h`
//! header file already depends on the `wasm.h` file. A copy lands in
//! this repository for the sake of simplicity.
#![doc(html_favicon_url = "https://wasmer.io/static/icons/favicon.ico")] #![doc(html_favicon_url = "https://wasmer.io/static/icons/favicon.ico")]
#![doc(html_logo_url = "https://avatars3.githubusercontent.com/u/44205449?s=200&v=4")] #![doc(html_logo_url = "https://avatars3.githubusercontent.com/u/44205449?s=200&v=4")]
// temporary while in transition // temporary while in transition
#![allow(unused_variables)] #![allow(unused_variables)]
//! # Wasmer Runtime C API
//!
//! Wasmer is a standalone JIT WebAssembly runtime, aiming to be fully
//! compatible with Emscripten, Rust and Go. [Learn
//! more](https://github.com/wasmerio/wasmer).
//!
//! This crate exposes a C and C++ API for the Wasmer runtime.
//!
//! # Usage
//!
//! The C and C++ header files can be found in the source tree of this
//! crate, respectively [`wasmer.h`][wasmer_h] and
//! [`wasmer.hh`][wasmer_hh]. They are automatically generated, and always
//! up-to-date in this repository.
//!
//! Here is a simple example to use the C API:
//!
//! ```c
//! #include <stdio.h>
//! #include "wasmer.h"
//! #include <assert.h>
//! #include <stdint.h>
//!
//! int main()
//! {
//! // Read the Wasm file bytes.
//! FILE *file = fopen("sum.wasm", "r");
//! fseek(file, 0, SEEK_END);
//! long len = ftell(file);
//! uint8_t *bytes = malloc(len);
//! fseek(file, 0, SEEK_SET);
//! fread(bytes, 1, len, file);
//! fclose(file);
//!
//! // Prepare the imports.
//! wasmer_import_t imports[] = {};
//!
//! // Instantiate!
//! wasmer_instance_t *instance = NULL;
//! wasmer_result_t instantiation_result = wasmer_instantiate(&instance, bytes, len, imports, 0);
//!
//! assert(instantiation_result == WASMER_OK);
//!
//! // Let's call a function.
//! // Start by preparing the arguments.
//!
//! // Value of argument #1 is `7i32`.
//! wasmer_value_t argument_one;
//! argument_one.tag = WASM_I32;
//! argument_one.value.I32 = 7;
//!
//! // Value of argument #2 is `8i32`.
//! wasmer_value_t argument_two;
//! argument_two.tag = WASM_I32;
//! argument_two.value.I32 = 8;
//!
//! // Prepare the arguments.
//! wasmer_value_t arguments[] = {argument_one, argument_two};
//!
//! // Prepare the return value.
//! wasmer_value_t result_one;
//! wasmer_value_t results[] = {result_one};
//!
//! // Call the `sum` function with the prepared arguments and the return value.
//! wasmer_result_t call_result = wasmer_instance_call(instance, "sum", arguments, 2, results, 1);
//!
//! // Let's display the result.
//! printf("Call result: %d\n", call_result);
//! printf("Result: %d\n", results[0].value.I32);
//!
//! // `sum(7, 8) == 15`.
//! assert(results[0].value.I32 == 15);
//! assert(call_result == WASMER_OK);
//!
//! wasmer_instance_destroy(instance);
//!
//! return 0;
//! }
//! ```
//!
//! [wasmer_h]: ./wasmer.h
//! [wasmer_hh]: ./wasmer.hh
#![deny( #![deny(
dead_code, dead_code,
unused_imports, unused_imports,
@@ -94,105 +30,7 @@
unreachable_patterns unreachable_patterns
)] )]
#[allow(unused_imports)] pub mod deprecated;
#[macro_use]
extern crate cfg_if;
#[macro_use]
extern crate lazy_static;
#[macro_use]
extern crate thiserror;
/// cbindgen:ignore
pub mod wasm_c_api;
pub mod error; pub mod error;
pub mod export;
pub mod global;
pub mod import;
pub mod instance;
pub mod memory;
pub mod module;
mod ordered_resolver; mod ordered_resolver;
pub mod table; pub mod wasm_c_api;
pub mod value;
/// The `wasmer_result_t` enum is a type that represents either a
/// success, or a failure.
#[allow(non_camel_case_types)]
#[repr(C)]
pub enum wasmer_result_t {
/// Represents a success.
WASMER_OK = 1,
/// Represents a failure.
WASMER_ERROR = 2,
}
/// The `wasmer_limits_t` struct is a type that describes the limits of something
/// such as a memory or a table. See the `wasmer_memory_new()` function to get
/// more information.
#[repr(C)]
pub struct wasmer_limits_t {
/// The minimum number of allowed pages.
pub min: u32,
/// The maximum number of allowed pages.
pub max: wasmer_limit_option_t,
}
/// The `wasmer_limit_option_t` struct represents an optional limit
/// for `wasmer_limits_t`.
#[repr(C)]
pub struct wasmer_limit_option_t {
/// Whether the limit is set.
pub has_some: bool,
/// The limit value.
pub some: u32,
}
#[repr(C)]
pub struct wasmer_byte_array {
pub bytes: *const u8,
pub bytes_len: u32,
}
impl wasmer_byte_array {
/// Get the data as a slice
pub unsafe fn as_slice<'a>(&self) -> &'a [u8] {
get_slice_checked(self.bytes, self.bytes_len as usize)
}
/// Copy the data into an owned Vec
pub unsafe fn as_vec(&self) -> Vec<u8> {
let mut out = Vec::with_capacity(self.bytes_len as usize);
out.extend_from_slice(self.as_slice());
out
}
/// Read the data as a &str, returns an error if the string is not valid UTF8
pub unsafe fn as_str<'a>(&self) -> Result<&'a str, std::str::Utf8Error> {
std::str::from_utf8(self.as_slice())
}
}
/// Gets a slice from a pointer and a length, returning an empty slice if the
/// pointer is null
#[inline]
pub(crate) unsafe fn get_slice_checked<'a, T>(ptr: *const T, len: usize) -> &'a [T] {
if ptr.is_null() {
&[]
} else {
std::slice::from_raw_parts(ptr, len)
}
}
lazy_static! {
pub(crate) static ref GLOBAL_STORE: wasmer::Store =
wasmer::Store::new(&*crate::wasm_c_api::wasm_engine_new().inner);
}
pub(crate) fn get_global_store() -> &'static wasmer::Store {
&*GLOBAL_STORE
}

View File

@@ -0,0 +1,270 @@
use cfg_if::cfg_if;
use std::sync::Arc;
use wasmer::Engine;
#[cfg(feature = "jit")]
use wasmer_engine_jit::JIT;
#[cfg(feature = "native")]
use wasmer_engine_native::Native;
#[cfg(feature = "object-file")]
use wasmer_engine_object_file::ObjectFile;
/// this can be a wasmer-specific type with wasmer-specific functions for manipulating it
#[derive(Debug, Copy, Clone)]
#[repr(C)]
pub enum wasmer_compiler_t {
CRANELIFT = 0,
LLVM = 1,
SINGLEPASS = 2,
}
impl Default for wasmer_compiler_t {
fn default() -> Self {
cfg_if! {
if #[cfg(feature = "cranelift")] {
Self::CRANELIFT
} else if #[cfg(feature = "llvm")] {
Self::LLVM
} else if #[cfg(feature = "singlepass")] {
Self::SINGLEPASS
} else {
compile_error!("Please enable one of the compiler backends")
}
}
}
}
#[derive(Debug, Copy, Clone)]
#[repr(C)]
#[allow(non_camel_case_types)]
pub enum wasmer_engine_t {
JIT = 0,
NATIVE = 1,
OBJECT_FILE = 2,
}
impl Default for wasmer_engine_t {
fn default() -> Self {
cfg_if! {
if #[cfg(feature = "jit")] {
Self::JIT
} else if #[cfg(feature = "native")] {
Self::NATIVE
} else if #[cfg(feature = "object-file")] {
Self::OBJECT_FILE
} else {
compile_error!("Please enable one of the engines")
}
}
}
}
/// cbindgen:ignore
/// this can be a wasmer-specific type with wasmer-specific functions for manipulating it
#[derive(Debug, Default)]
#[repr(C)]
pub struct wasm_config_t {
compiler: wasmer_compiler_t,
engine: wasmer_engine_t,
}
/// cbindgen:ignore
#[no_mangle]
pub extern "C" fn wasm_config_new() -> Box<wasm_config_t> {
Box::new(wasm_config_t::default())
}
#[no_mangle]
pub extern "C" fn wasm_config_set_compiler(
config: &mut wasm_config_t,
compiler: wasmer_compiler_t,
) {
config.compiler = compiler;
}
#[no_mangle]
pub extern "C" fn wasm_config_set_engine(config: &mut wasm_config_t, engine: wasmer_engine_t) {
config.engine = engine;
}
/// cbindgen:ignore
#[allow(non_camel_case_types)]
pub struct wasm_engine_t {
pub(crate) inner: Arc<dyn Engine + Send + Sync>,
}
// Compiler JIT
#[cfg(feature = "compiler")]
use wasmer_compiler::CompilerConfig;
#[cfg(feature = "compiler")]
fn get_default_compiler_config() -> Box<dyn CompilerConfig> {
cfg_if! {
if #[cfg(feature = "cranelift")] {
Box::new(wasmer_compiler_cranelift::Cranelift::default())
} else if #[cfg(feature = "llvm")] {
Box::new(wasmer_compiler_llvm::LLVM::default())
} else if #[cfg(feature = "singlepass")] {
Box::new(wasmer_compiler_singlepass::Singlepass::default())
} else {
compile_error!("Please enable one of the compiler backends")
}
}
}
cfg_if! {
if #[cfg(all(feature = "jit", feature = "compiler"))] {
#[no_mangle]
pub extern "C" fn wasm_engine_new() -> Box<wasm_engine_t> {
let compiler_config: Box<dyn CompilerConfig> = get_default_compiler_config();
let engine: Arc<dyn Engine + Send + Sync> = Arc::new(JIT::new(&*compiler_config).engine());
Box::new(wasm_engine_t { inner: engine })
}
}
else if #[cfg(feature = "jit")] {
// Headless JIT
#[no_mangle]
pub extern "C" fn wasm_engine_new() -> Box<wasm_engine_t> {
let engine: Arc<dyn Engine + Send + Sync> = Arc::new(JIT::headless().engine());
Box::new(wasm_engine_t { inner: engine })
}
}
else if #[cfg(all(feature = "native", feature = "compiler"))] {
#[no_mangle]
pub extern "C" fn wasm_engine_new() -> Box<wasm_engine_t> {
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());
Box::new(wasm_engine_t { inner: engine })
}
}
else if #[cfg(feature = "native")] {
#[no_mangle]
pub extern "C" fn wasm_engine_new() -> Box<wasm_engine_t> {
let engine: Arc<dyn Engine + Send + Sync> = Arc::new(Native::headless().engine());
Box::new(wasm_engine_t { inner: engine })
}
}
// There are currently no uses of the object-file engine + compiler from the C API.
// So if we get here, we default to headless mode regardless of if `compiler` is enabled.
else if #[cfg(feature = "object-file")] {
#[no_mangle]
pub extern "C" fn wasm_engine_new() -> Box<wasm_engine_t> {
let engine: Arc<dyn Engine + Send + Sync> = Arc::new(ObjectFile::headless().engine());
Box::new(wasm_engine_t { inner: engine })
}
}
else {
#[no_mangle]
pub extern "C" fn wasm_engine_new() -> Box<wasm_engine_t> {
unimplemented!("The JITEngine is not attached; You might want to recompile `wasmer_c_api` with `--feature jit`");
}
}
}
/// cbindgen:ignore
#[no_mangle]
pub unsafe extern "C" fn wasm_engine_delete(_wasm_engine_address: Option<Box<wasm_engine_t>>) {}
/// cbindgen:ignore
#[no_mangle]
pub extern "C" fn wasm_engine_new_with_config(
config: Box<wasm_config_t>,
) -> Option<Box<wasm_engine_t>> {
// TODO: return useful error messages in failure branches
cfg_if! {
if #[cfg(feature = "compiler")] {
#[allow(unused_mut)]
let mut compiler_config: Box<dyn CompilerConfig> = match config.compiler {
wasmer_compiler_t::CRANELIFT => {
cfg_if! {
if #[cfg(feature = "cranelift")] {
Box::new(wasmer_compiler_cranelift::Cranelift::default())
} else {
return None;
}
}
},
wasmer_compiler_t::LLVM => {
cfg_if! {
if #[cfg(feature = "llvm")] {
Box::new(wasmer_compiler_llvm::LLVM::default())
} else {
return None;
}
}
},
wasmer_compiler_t::SINGLEPASS => {
cfg_if! {
if #[cfg(feature = "singlepass")] {
Box::new(wasmer_compiler_singlepass::Singlepass::default())
} else {
return None;
}
}
},
};
let inner: Arc<dyn Engine + Send + Sync> = match config.engine {
wasmer_engine_t::JIT => {
cfg_if! {
if #[cfg(feature = "jit")] {
Arc::new(JIT::new(&*compiler_config).engine())
} else {
return None;
}
}
},
wasmer_engine_t::NATIVE => {
cfg_if! {
if #[cfg(feature = "native")] {
Arc::new(Native::new(&mut *compiler_config).engine())
} else {
return None;
}
}
},
wasmer_engine_t::OBJECT_FILE => {
cfg_if! {
// There are currently no uses of the object-file engine + compiler from the C API.
// So we run in headless mode.
if #[cfg(feature = "object-file")] {
Arc::new(ObjectFile::headless().engine())
} else {
return None;
}
}
},
};
Some(Box::new(wasm_engine_t { inner }))
} else {
let inner: Arc<dyn Engine + Send + Sync> = match config.engine {
wasmer_engine_t::JIT => {
cfg_if! {
if #[cfg(feature = "jit")] {
Arc::new(JIT::headless().engine())
} else {
return None;
}
}
},
wasmer_engine_t::NATIVE => {
cfg_if! {
if #[cfg(feature = "native")] {
Arc::new(Native::headless().engine())
} else {
return None;
}
}
},
wasmer_engine_t::OBJECT_FILE => {
cfg_if! {
if #[cfg(feature = "object-file")] {
Arc::new(ObjectFile::headless().engine())
} else {
return None;
}
}
},
};
Some(Box::new(wasm_engine_t { inner }))
}
}
}

View File

@@ -0,0 +1,183 @@
use super::super::store::wasm_store_t;
use super::super::trap::wasm_trap_t;
use super::super::types::{wasm_functype_t, wasm_valkind_enum};
use super::super::value::{wasm_val_inner, wasm_val_t, wasm_val_vec_t};
use std::convert::TryInto;
use std::ffi::c_void;
use std::sync::Arc;
use wasmer::{Function, Instance, RuntimeError, Val};
#[allow(non_camel_case_types)]
pub struct wasm_func_t {
pub(crate) inner: Function,
// this is how we ensure the instance stays alive
pub(crate) instance: Option<Arc<Instance>>,
}
#[allow(non_camel_case_types)]
pub type wasm_func_callback_t = unsafe extern "C" fn(
args: *const wasm_val_vec_t,
results: *mut wasm_val_vec_t,
) -> *mut wasm_trap_t;
#[allow(non_camel_case_types)]
pub type wasm_func_callback_with_env_t = unsafe extern "C" fn(
*mut c_void,
args: *const wasm_val_vec_t,
results: *mut wasm_val_vec_t,
) -> *mut wasm_trap_t;
#[allow(non_camel_case_types)]
pub type wasm_env_finalizer_t = unsafe extern "C" fn(c_void);
#[no_mangle]
pub unsafe extern "C" fn wasm_func_new(
store: &wasm_store_t,
ft: &wasm_functype_t,
callback: wasm_func_callback_t,
) -> Option<Box<wasm_func_t>> {
// TODO: handle null pointers?
let func_sig = ft.sig();
let num_rets = func_sig.results().len();
let inner_callback = move |args: &[Val]| -> Result<Vec<Val>, RuntimeError> {
let processed_args: wasm_val_vec_t = args
.into_iter()
.map(TryInto::try_into)
.collect::<Result<Vec<wasm_val_t>, _>>()
.expect("Argument conversion failed")
.into();
let mut results: wasm_val_vec_t = vec![
wasm_val_t {
kind: wasm_valkind_enum::WASM_I64 as _,
of: wasm_val_inner { int64_t: 0 },
};
num_rets
]
.into();
let trap = callback(&processed_args, &mut results);
if !trap.is_null() {
let trap: Box<wasm_trap_t> = Box::from_raw(trap);
RuntimeError::raise(Box::new(trap.inner));
}
let processed_results = results
.into_slice()
.expect("Failed to convert `results` into a slice")
.into_iter()
.map(TryInto::try_into)
.collect::<Result<Vec<Val>, _>>()
.expect("Result conversion failed");
Ok(processed_results)
};
let function = Function::new(&store.inner, &func_sig, inner_callback);
Some(Box::new(wasm_func_t {
instance: None,
inner: function,
}))
}
#[no_mangle]
pub unsafe extern "C" fn wasm_func_new_with_env(
store: &wasm_store_t,
ft: &wasm_functype_t,
callback: wasm_func_callback_with_env_t,
env: *mut c_void,
finalizer: wasm_env_finalizer_t,
) -> Option<Box<wasm_func_t>> {
// TODO: handle null pointers?
let func_sig = ft.sig();
let num_rets = func_sig.results().len();
let inner_callback =
move |env: &mut *mut c_void, args: &[Val]| -> Result<Vec<Val>, RuntimeError> {
let processed_args: wasm_val_vec_t = args
.into_iter()
.map(TryInto::try_into)
.collect::<Result<Vec<wasm_val_t>, _>>()
.expect("Argument conversion failed")
.into();
let mut results: wasm_val_vec_t = vec![
wasm_val_t {
kind: wasm_valkind_enum::WASM_I64 as _,
of: wasm_val_inner { int64_t: 0 },
};
num_rets
]
.into();
let _traps = callback(*env, &processed_args, &mut results);
// TODO: do something with `traps`
let processed_results = results
.into_slice()
.expect("Failed to convert `results` into a slice")
.into_iter()
.map(TryInto::try_into)
.collect::<Result<Vec<Val>, _>>()
.expect("Result conversion failed");
Ok(processed_results)
};
let function = Function::new_with_env(&store.inner, &func_sig, env, inner_callback);
Some(Box::new(wasm_func_t {
instance: None,
inner: function,
}))
}
#[no_mangle]
pub unsafe extern "C" fn wasm_func_delete(_func: Option<Box<wasm_func_t>>) {}
#[no_mangle]
pub unsafe extern "C" fn wasm_func_call(
func: &wasm_func_t,
args: &wasm_val_vec_t,
results: &mut wasm_val_vec_t,
) -> Option<Box<wasm_trap_t>> {
let params = args
.into_slice()
.map(|slice| {
slice
.into_iter()
.map(TryInto::try_into)
.collect::<Result<Vec<Val>, _>>()
.expect("Argument conversion failed")
})
.unwrap_or_default();
match func.inner.call(&params) {
Ok(wasm_results) => {
*results = wasm_results
.into_iter()
.map(TryInto::try_into)
.collect::<Result<Vec<wasm_val_t>, _>>()
.expect("Argument conversion failed")
.into();
None
}
Err(e) => Some(Box::new(e.into())),
}
}
#[no_mangle]
pub unsafe extern "C" fn wasm_func_param_arity(func: &wasm_func_t) -> usize {
func.inner.ty().params().len()
}
#[no_mangle]
pub unsafe extern "C" fn wasm_func_result_arity(func: &wasm_func_t) -> usize {
func.inner.ty().results().len()
}
#[no_mangle]
pub extern "C" fn wasm_func_type(func: &wasm_func_t) -> Box<wasm_functype_t> {
Box::new(wasm_functype_t::new(func.inner.ty().clone()))
}

View File

@@ -0,0 +1,61 @@
use super::super::store::wasm_store_t;
use super::super::types::wasm_globaltype_t;
use super::super::value::wasm_val_t;
use std::convert::TryInto;
use wasmer::{Global, Val};
#[allow(non_camel_case_types)]
pub struct wasm_global_t {
// maybe needs to hold onto instance
pub(crate) inner: Global,
}
#[no_mangle]
pub unsafe extern "C" fn wasm_global_new(
store: &wasm_store_t,
gt: &wasm_globaltype_t,
val: &wasm_val_t,
) -> Option<Box<wasm_global_t>> {
let gt = gt.as_globaltype();
let wasm_val = val.try_into().ok()?;
let store = &store.inner;
let global = if gt.mutability.is_mutable() {
Global::new_mut(store, wasm_val)
} else {
Global::new(store, wasm_val)
};
Some(Box::new(wasm_global_t { inner: global }))
}
#[no_mangle]
pub unsafe extern "C" fn wasm_global_delete(_global: Option<Box<wasm_global_t>>) {}
// TODO: figure out if these should be deep or shallow copies
#[no_mangle]
pub unsafe extern "C" fn wasm_global_copy(wasm_global: &wasm_global_t) -> Box<wasm_global_t> {
// do shallow copy
Box::new(wasm_global_t {
inner: wasm_global.inner.clone(),
})
}
#[no_mangle]
pub unsafe extern "C" fn wasm_global_get(wasm_global: &wasm_global_t, out: &mut wasm_val_t) {
let value = wasm_global.inner.get();
*out = value.try_into().unwrap();
}
#[no_mangle]
pub unsafe extern "C" fn wasm_global_set(wasm_global: &mut wasm_global_t, val: &wasm_val_t) {
let value: Val = val.try_into().unwrap();
wasm_global.inner.set(value);
}
#[no_mangle]
pub unsafe extern "C" fn wasm_global_same(
wasm_global1: &wasm_global_t,
wasm_global2: &wasm_global_t,
) -> bool {
wasm_global1.inner.same(&wasm_global2.inner)
}

View File

@@ -0,0 +1,71 @@
use super::super::store::wasm_store_t;
use super::super::types::wasm_memorytype_t;
use std::mem;
use wasmer::{Memory, Pages};
#[allow(non_camel_case_types)]
pub struct wasm_memory_t {
// maybe needs to hold onto instance
pub(crate) inner: Memory,
}
#[no_mangle]
pub unsafe extern "C" fn wasm_memory_new(
store: &wasm_store_t,
mt: &wasm_memorytype_t,
) -> Option<Box<wasm_memory_t>> {
let md = mt.as_memorytype().clone();
let memory = c_try!(Memory::new(&store.inner, md));
Some(Box::new(wasm_memory_t { inner: memory }))
}
#[no_mangle]
pub unsafe extern "C" fn wasm_memory_delete(_memory: Option<Box<wasm_memory_t>>) {}
// TODO: figure out if these should be deep or shallow copies
#[no_mangle]
pub unsafe extern "C" fn wasm_memory_copy(wasm_memory: &wasm_memory_t) -> Box<wasm_memory_t> {
// do shallow copy
Box::new(wasm_memory_t {
inner: wasm_memory.inner.clone(),
})
}
#[no_mangle]
pub unsafe extern "C" fn wasm_memory_type(_memory_ptr: &wasm_memory_t) -> *mut wasm_memorytype_t {
todo!("wasm_memory_type")
}
// get a raw pointer into bytes
#[no_mangle]
pub unsafe extern "C" fn wasm_memory_data(memory: &mut wasm_memory_t) -> *mut u8 {
mem::transmute::<&[std::cell::Cell<u8>], &[u8]>(&memory.inner.view()[..]) as *const [u8]
as *const u8 as *mut u8
}
// size in bytes
#[no_mangle]
pub unsafe extern "C" fn wasm_memory_data_size(memory: &wasm_memory_t) -> usize {
memory.inner.size().bytes().0
}
// size in pages
#[no_mangle]
pub unsafe extern "C" fn wasm_memory_size(memory: &wasm_memory_t) -> u32 {
memory.inner.size().0 as _
}
// delta is in pages
#[no_mangle]
pub unsafe extern "C" fn wasm_memory_grow(memory: &mut wasm_memory_t, delta: u32) -> bool {
memory.inner.grow(Pages(delta)).is_ok()
}
#[no_mangle]
pub unsafe extern "C" fn wasm_memory_same(
wasm_memory1: &wasm_memory_t,
wasm_memory2: &wasm_memory_t,
) -> bool {
wasm_memory1.inner.same(&wasm_memory2.inner)
}

View File

@@ -0,0 +1,131 @@
mod function;
mod global;
mod memory;
mod table;
pub use function::*;
pub use global::*;
pub use memory::*;
use std::ptr::NonNull;
use std::sync::Arc;
pub use table::*;
use wasmer::{Extern, Instance};
#[allow(non_camel_case_types)]
pub struct wasm_extern_t {
// this is how we ensure the instance stays alive
pub(crate) instance: Option<Arc<Instance>>,
pub(crate) inner: Extern,
}
wasm_declare_boxed_vec!(extern);
#[no_mangle]
pub unsafe extern "C" fn wasm_func_as_extern(
func_ptr: Option<NonNull<wasm_func_t>>,
) -> Option<Box<wasm_extern_t>> {
let func_ptr = func_ptr?;
let func = func_ptr.as_ref();
Some(Box::new(wasm_extern_t {
instance: func.instance.clone(),
inner: Extern::Function(func.inner.clone()),
}))
}
#[no_mangle]
pub unsafe extern "C" fn wasm_global_as_extern(
global_ptr: Option<NonNull<wasm_global_t>>,
) -> Option<Box<wasm_extern_t>> {
let global_ptr = global_ptr?;
let global = global_ptr.as_ref();
Some(Box::new(wasm_extern_t {
// update this if global does hold onto an `instance`
instance: None,
inner: Extern::Global(global.inner.clone()),
}))
}
#[no_mangle]
pub unsafe extern "C" fn wasm_memory_as_extern(
memory_ptr: Option<NonNull<wasm_memory_t>>,
) -> Option<Box<wasm_extern_t>> {
let memory_ptr = memory_ptr?;
let memory = memory_ptr.as_ref();
Some(Box::new(wasm_extern_t {
// update this if global does hold onto an `instance`
instance: None,
inner: Extern::Memory(memory.inner.clone()),
}))
}
#[no_mangle]
pub unsafe extern "C" fn wasm_table_as_extern(
table_ptr: Option<NonNull<wasm_table_t>>,
) -> Option<Box<wasm_extern_t>> {
let table_ptr = table_ptr?;
let table = table_ptr.as_ref();
Some(Box::new(wasm_extern_t {
// update this if global does hold onto an `instance`
instance: None,
inner: Extern::Table(table.inner.clone()),
}))
}
#[no_mangle]
pub unsafe extern "C" fn wasm_extern_as_func(
extern_ptr: Option<NonNull<wasm_extern_t>>,
) -> Option<Box<wasm_func_t>> {
let extern_ptr = extern_ptr?;
let r#extern = extern_ptr.as_ref();
if let Extern::Function(f) = &r#extern.inner {
Some(Box::new(wasm_func_t {
inner: f.clone(),
instance: r#extern.instance.clone(),
}))
} else {
None
}
}
#[no_mangle]
pub unsafe extern "C" fn wasm_extern_as_global(
extern_ptr: Option<NonNull<wasm_extern_t>>,
) -> Option<Box<wasm_global_t>> {
let extern_ptr = extern_ptr?;
let r#extern = extern_ptr.as_ref();
if let Extern::Global(g) = &r#extern.inner {
Some(Box::new(wasm_global_t { inner: g.clone() }))
} else {
None
}
}
#[no_mangle]
pub unsafe extern "C" fn wasm_extern_as_memory(
extern_ptr: Option<NonNull<wasm_extern_t>>,
) -> Option<Box<wasm_memory_t>> {
let extern_ptr = extern_ptr?;
let r#extern = extern_ptr.as_ref();
if let Extern::Memory(m) = &r#extern.inner {
Some(Box::new(wasm_memory_t { inner: m.clone() }))
} else {
None
}
}
#[no_mangle]
pub unsafe extern "C" fn wasm_extern_as_table(
extern_ptr: Option<NonNull<wasm_extern_t>>,
) -> Option<Box<wasm_table_t>> {
let extern_ptr = extern_ptr?;
let r#extern = extern_ptr.as_ref();
if let Extern::Table(t) = &r#extern.inner {
Some(Box::new(wasm_table_t { inner: t.clone() }))
} else {
None
}
}

View File

@@ -0,0 +1,57 @@
use super::super::store::wasm_store_t;
use super::super::types::{wasm_ref_t, wasm_table_size_t, wasm_tabletype_t};
use wasmer::Table;
#[allow(non_camel_case_types)]
pub struct wasm_table_t {
// maybe needs to hold onto instance
pub(crate) inner: Table,
}
#[no_mangle]
pub unsafe extern "C" fn wasm_table_new(
store: &wasm_store_t,
tt: &wasm_tabletype_t,
init: *const wasm_ref_t,
) -> Option<Box<wasm_table_t>> {
let tt = tt.as_tabletype().clone();
let init_val = todo!("get val from init somehow");
let table = c_try!(Table::new(&store.inner, tt, init_val));
Some(Box::new(wasm_table_t { inner: table }))
}
#[no_mangle]
pub unsafe extern "C" fn wasm_table_delete(_table: Option<Box<wasm_table_t>>) {}
#[no_mangle]
pub unsafe extern "C" fn wasm_table_copy(wasm_table: &wasm_table_t) -> Box<wasm_table_t> {
// do shallow copy
Box::new(wasm_table_t {
inner: wasm_table.inner.clone(),
})
}
#[no_mangle]
pub unsafe extern "C" fn wasm_table_same(
wasm_table1: &wasm_table_t,
wasm_table2: &wasm_table_t,
) -> bool {
wasm_table1.inner.same(&wasm_table2.inner)
}
#[no_mangle]
pub unsafe extern "C" fn wasm_table_size(wasm_table: &wasm_table_t) -> usize {
wasm_table.inner.size() as _
}
#[no_mangle]
pub unsafe extern "C" fn wasm_table_grow(
_wasm_table: &mut wasm_table_t,
_delta: wasm_table_size_t,
_init: *mut wasm_ref_t,
) -> bool {
// TODO: maybe need to look at result to return `true`; also maybe report error here
//wasm_table.inner.grow(delta, init).is_ok()
todo!("Blocked on transforming ExternRef into a val type")
}

View File

@@ -0,0 +1,70 @@
use super::externals::{wasm_extern_t, wasm_extern_vec_t};
use super::module::wasm_module_t;
use super::store::wasm_store_t;
use super::trap::wasm_trap_t;
use crate::ordered_resolver::OrderedResolver;
use std::mem;
use std::sync::Arc;
use wasmer::{Extern, Instance};
#[allow(non_camel_case_types)]
pub struct wasm_instance_t {
pub(crate) inner: Arc<Instance>,
}
#[no_mangle]
pub unsafe extern "C" fn wasm_instance_new(
_store: &wasm_store_t,
module: &wasm_module_t,
imports: &wasm_extern_vec_t,
// own
_traps: *mut *mut wasm_trap_t,
) -> Option<Box<wasm_instance_t>> {
let wasm_module = &module.inner;
let module_imports = wasm_module.imports();
let module_import_count = module_imports.len();
let resolver: OrderedResolver = imports
.into_slice()
.map(|imports| imports.iter())
.unwrap_or_else(|| [].iter())
.map(|imp| &imp.inner)
.take(module_import_count)
.cloned()
.collect();
let instance = Arc::new(c_try!(Instance::new(wasm_module, &resolver)));
Some(Box::new(wasm_instance_t { inner: instance }))
}
#[no_mangle]
pub unsafe extern "C" fn wasm_instance_delete(_instance: Option<Box<wasm_instance_t>>) {}
#[no_mangle]
pub unsafe extern "C" fn wasm_instance_exports(
instance: &wasm_instance_t,
// TODO: review types on wasm_declare_vec, handle the optional pointer part properly
out: &mut wasm_extern_vec_t,
) {
let instance = &instance.inner;
let mut extern_vec = instance
.exports
.iter()
.map(|(name, r#extern)| {
let function = if let Extern::Function { .. } = r#extern {
instance.exports.get_function(&name).ok().cloned()
} else {
None
};
Box::into_raw(Box::new(wasm_extern_t {
instance: Some(Arc::clone(instance)),
inner: r#extern.clone(),
}))
})
.collect::<Vec<*mut wasm_extern_t>>();
extern_vec.shrink_to_fit();
out.size = extern_vec.len();
out.data = extern_vec.as_mut_ptr();
// TODO: double check that the destructor will work correctly here
mem::forget(extern_vec);
}

View File

@@ -0,0 +1,235 @@
#[doc(hidden)]
#[macro_export]
macro_rules! wasm_declare_vec_inner {
($name:ident) => {
paste::item! {
#[no_mangle]
pub unsafe extern "C" fn [<wasm_ $name _vec_new_empty>](out: *mut [<wasm_ $name _vec_t>]) {
// TODO: actually implement this
[<wasm_ $name _vec_new_uninitialized>](out, 0);
}
}
}
}
#[doc(hidden)]
#[macro_export]
macro_rules! wasm_declare_vec {
($name:ident) => {
paste::item! {
#[repr(C)]
pub struct [<wasm_ $name _vec_t>] {
pub size: usize,
pub data: *mut [<wasm_ $name _t>],
}
impl<'a> From<Vec<[<wasm_ $name _t>]>> for [<wasm_ $name _vec_t>] {
fn from(other: Vec<[<wasm_ $name _t>]>) -> Self {
let mut boxed_slice = other.into_boxed_slice();
let size = boxed_slice.len();
let data = boxed_slice.as_mut_ptr();
::std::mem::forget(boxed_slice);
Self {
size,
data,
}
}
}
impl<'a, T: Into<[<wasm_ $name _t>]> + Clone> From<&'a [T]> for [<wasm_ $name _vec_t>] {
fn from(other: &'a [T]) -> Self {
let size = other.len();
let mut copied_data = other
.iter()
.cloned()
.map(Into::into)
.collect::<Vec<[<wasm_ $name _t>]>>()
.into_boxed_slice();
let data = copied_data.as_mut_ptr();
::std::mem::forget(copied_data);
Self {
size,
data,
}
}
}
impl [<wasm_ $name _vec_t>] {
pub unsafe fn into_slice(&self) -> Option<&[[<wasm_ $name _t>]]>{
if self.data.is_null() {
return None;
}
Some(::std::slice::from_raw_parts(self.data, self.size))
}
}
// TODO: investigate possible memory leak on `init` (owned pointer)
#[no_mangle]
pub unsafe extern "C" fn [<wasm_ $name _vec_new>](out: *mut [<wasm_ $name _vec_t>], length: usize, init: *mut [<wasm_ $name _t>]) {
let mut bytes: Vec<[<wasm_ $name _t>]> = Vec::with_capacity(length);
for i in 0..length {
bytes.push(::std::ptr::read(init.add(i)));
}
let pointer = bytes.as_mut_ptr();
debug_assert!(bytes.len() == bytes.capacity());
(*out).data = pointer;
(*out).size = length;
::std::mem::forget(bytes);
}
#[no_mangle]
pub unsafe extern "C" fn [<wasm_ $name _vec_new_uninitialized>](out: *mut [<wasm_ $name _vec_t>], length: usize) {
let mut bytes: Vec<[<wasm_ $name _t>]> = Vec::with_capacity(length);
let pointer = bytes.as_mut_ptr();
(*out).data = pointer;
(*out).size = length;
::std::mem::forget(bytes);
}
#[no_mangle]
pub unsafe extern "C" fn [<wasm_ $name _vec_delete>](ptr: *mut [<wasm_ $name _vec_t>]) {
let vec = &mut *ptr;
if !vec.data.is_null() {
Vec::from_raw_parts(vec.data, vec.size, vec.size);
vec.data = ::std::ptr::null_mut();
vec.size = 0;
}
}
}
wasm_declare_vec_inner!($name);
};
}
#[doc(hidden)]
#[macro_export]
macro_rules! wasm_declare_boxed_vec {
($name:ident) => {
paste::item! {
#[repr(C)]
pub struct [<wasm_ $name _vec_t>] {
pub size: usize,
pub data: *mut *mut [<wasm_ $name _t>],
}
impl<'a> From<Vec<Box<[<wasm_ $name _t>]>>> for [<wasm_ $name _vec_t>] {
fn from(other: Vec<Box<[<wasm_ $name _t>]>>) -> Self {
let boxed_slice: Box<[Box<[<wasm_ $name _t>]>]> = other.into_boxed_slice();
let mut boxed_slice: Box<[*mut [<wasm_ $name _t>]]> = unsafe { ::std::mem::transmute(boxed_slice) };
let size = boxed_slice.len();
let data = boxed_slice.as_mut_ptr();
::std::mem::forget(boxed_slice);
Self {
size,
data,
}
}
}
// TODO: do this properly
impl [<wasm_ $name _vec_t>] {
pub unsafe fn into_slice(&self) -> Option<&[Box<[<wasm_ $name _t>]>]>{
if self.data.is_null() {
return None;
}
let slice: &[*mut [<wasm_ $name _t>]] = ::std::slice::from_raw_parts(self.data, self.size);
let slice: &[Box<[<wasm_ $name _t>]>] = ::std::mem::transmute(slice);
Some(slice)
}
}
// TODO: investigate possible memory leak on `init` (owned pointer)
#[no_mangle]
pub unsafe extern "C" fn [<wasm_ $name _vec_new>](out: *mut [<wasm_ $name _vec_t>], length: usize, init: *const *mut [<wasm_ $name _t>]) {
let mut bytes: Vec<*mut [<wasm_ $name _t>]> = Vec::with_capacity(length);
for i in 0..length {
bytes.push(*init.add(i));
}
let pointer = bytes.as_mut_ptr();
debug_assert!(bytes.len() == bytes.capacity());
(*out).data = pointer;
(*out).size = length;
::std::mem::forget(bytes);
}
#[no_mangle]
pub unsafe extern "C" fn [<wasm_ $name _vec_new_uninitialized>](out: *mut [<wasm_ $name _vec_t>], length: usize) {
let mut bytes: Vec<*mut [<wasm_ $name _t>]> = Vec::with_capacity(length);
let pointer = bytes.as_mut_ptr();
(*out).data = pointer;
(*out).size = length;
::std::mem::forget(bytes);
}
#[no_mangle]
pub unsafe extern "C" fn [<wasm_ $name _vec_delete>](ptr: *mut [<wasm_ $name _vec_t>]) {
let vec = &mut *ptr;
if !vec.data.is_null() {
let data: Vec<*mut [<wasm_ $name _t>]> = Vec::from_raw_parts(vec.data, vec.size, vec.size);
let data: Vec<Box<[<wasm_ $name _t>]>> = ::std::mem::transmute(data);
vec.data = ::std::ptr::null_mut();
vec.size = 0;
}
}
}
wasm_declare_vec_inner!($name);
};
}
#[doc(hidden)]
#[macro_export]
macro_rules! wasm_declare_ref_base {
($name:ident) => {
wasm_declare_own!($name);
paste::item! {
#[no_mangle]
pub extern "C" fn [<wasm_ $name _copy>](_arg: *const [<wasm_ $name _t>]) -> *mut [<wasm_ $name _t>] {
todo!("in generated declare ref base");
//ptr::null_mut()
}
// TODO: finish this...
}
};
}
#[doc(hidden)]
#[macro_export]
macro_rules! wasm_declare_own {
($name:ident) => {
paste::item! {
#[repr(C)]
pub struct [<wasm_ $name _t>] {}
#[no_mangle]
pub extern "C" fn [<wasm_ $name _delete>](_arg: *mut [<wasm_ $name _t>]) {
todo!("in generated delete")
}
}
};
}
#[macro_export]
macro_rules! c_try {
($expr:expr) => {{
let res: Result<_, _> = $expr;
match res {
Ok(val) => val,
Err(err) => {
crate::error::update_last_error(err);
return None;
}
}
}};
($expr:expr, $e:expr) => {{
let opt: Option<_> = $expr;
c_try!(opt.ok_or_else(|| $e))
}};
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,117 @@
use super::store::wasm_store_t;
use super::types::{
wasm_byte_vec_t, wasm_exporttype_t, wasm_exporttype_vec_t, wasm_importtype_t,
wasm_importtype_vec_t,
};
use crate::error::update_last_error;
use std::ptr::NonNull;
use std::slice;
use std::sync::Arc;
use wasmer::Module;
#[allow(non_camel_case_types)]
pub struct wasm_module_t {
pub(crate) inner: Arc<Module>,
}
#[no_mangle]
pub unsafe extern "C" fn wasm_module_new(
store: &wasm_store_t,
bytes: &wasm_byte_vec_t,
) -> Option<Box<wasm_module_t>> {
// TODO: review lifetime of byte slice
let wasm_byte_slice: &[u8] = slice::from_raw_parts_mut(bytes.data, bytes.size);
let module = c_try!(Module::from_binary(&store.inner, wasm_byte_slice));
Some(Box::new(wasm_module_t {
inner: Arc::new(module),
}))
}
#[no_mangle]
pub unsafe extern "C" fn wasm_module_delete(_module: Option<Box<wasm_module_t>>) {}
#[no_mangle]
pub unsafe extern "C" fn wasm_module_validate(
store: &wasm_store_t,
bytes: &wasm_byte_vec_t,
) -> bool {
// TODO: review lifetime of byte slice.
let wasm_byte_slice: &[u8] = slice::from_raw_parts(bytes.data, bytes.size);
if let Err(error) = Module::validate(&store.inner, wasm_byte_slice) {
update_last_error(error);
false
} else {
true
}
}
#[no_mangle]
pub unsafe extern "C" fn wasm_module_exports(
module: &wasm_module_t,
out: &mut wasm_exporttype_vec_t,
) {
let exports = module
.inner
.exports()
.map(Into::into)
.map(Box::new)
.collect::<Vec<Box<wasm_exporttype_t>>>();
*out = exports.into();
}
#[no_mangle]
pub unsafe extern "C" fn wasm_module_imports(
module: &wasm_module_t,
out: &mut wasm_importtype_vec_t,
) {
let imports = module
.inner
.imports()
.map(Into::into)
.map(Box::new)
.collect::<Vec<Box<wasm_importtype_t>>>();
*out = imports.into();
}
#[no_mangle]
pub unsafe extern "C" fn wasm_module_deserialize(
store: &wasm_store_t,
bytes: *const wasm_byte_vec_t,
) -> Option<NonNull<wasm_module_t>> {
// TODO: read config from store and use that to decide which compiler to use
let byte_slice = if bytes.is_null() || (&*bytes).into_slice().is_none() {
// TODO: error handling here
return None;
} else {
(&*bytes).into_slice().unwrap()
};
let module = c_try!(Module::deserialize(&store.inner, byte_slice));
Some(NonNull::new_unchecked(Box::into_raw(Box::new(
wasm_module_t {
inner: Arc::new(module),
},
))))
}
#[no_mangle]
pub unsafe extern "C" fn wasm_module_serialize(
module: &wasm_module_t,
out_ptr: &mut wasm_byte_vec_t,
) {
let byte_vec = match module.inner.serialize() {
Ok(byte_vec) => byte_vec,
Err(err) => {
crate::error::update_last_error(err);
return;
}
};
*out_ptr = byte_vec.into();
}

View File

@@ -0,0 +1,23 @@
use super::engine::wasm_engine_t;
use std::ptr::NonNull;
use wasmer::Store;
/// Opaque wrapper around `Store`
#[allow(non_camel_case_types)]
pub struct wasm_store_t {
pub(crate) inner: Store,
}
#[no_mangle]
pub unsafe extern "C" fn wasm_store_new(
wasm_engine_ptr: Option<NonNull<wasm_engine_t>>,
) -> Option<Box<wasm_store_t>> {
let wasm_engine_ptr = wasm_engine_ptr?;
let wasm_engine = wasm_engine_ptr.as_ref();
let store = Store::new(&*wasm_engine.inner);
Some(Box::new(wasm_store_t { inner: store }))
}
#[no_mangle]
pub unsafe extern "C" fn wasm_store_delete(_store: Option<Box<wasm_store_t>>) {}

View File

@@ -0,0 +1,53 @@
use super::store::wasm_store_t;
use super::types::{wasm_byte_vec_t, wasm_frame_t, wasm_frame_vec_t, wasm_message_t};
use wasmer::RuntimeError;
// opaque type which is a `RuntimeError`
#[allow(non_camel_case_types)]
pub struct wasm_trap_t {
pub(crate) inner: RuntimeError,
}
impl From<RuntimeError> for wasm_trap_t {
fn from(other: RuntimeError) -> Self {
Self { inner: other }
}
}
#[no_mangle]
pub unsafe extern "C" fn wasm_trap_new(
_store: &mut wasm_store_t,
message: &wasm_message_t,
) -> Option<Box<wasm_trap_t>> {
let message_bytes: &[u8] = message.into_slice()?;
let message_str = c_try!(std::str::from_utf8(message_bytes));
let runtime_error = RuntimeError::new(message_str);
let trap = runtime_error.into();
Some(Box::new(trap))
}
#[no_mangle]
pub unsafe extern "C" fn wasm_trap_delete(_trap: Option<Box<wasm_trap_t>>) {}
#[no_mangle]
pub unsafe extern "C" fn wasm_trap_message(trap: &wasm_trap_t, out_ptr: &mut wasm_byte_vec_t) {
let message = trap.inner.message();
let byte_vec: wasm_byte_vec_t = message.into_bytes().into();
out_ptr.size = byte_vec.size;
out_ptr.data = byte_vec.data;
}
#[no_mangle]
pub unsafe extern "C" fn wasm_trap_origin(trap: &wasm_trap_t) -> Option<Box<wasm_frame_t>> {
trap.inner.trace().first().map(Into::into).map(Box::new)
}
#[no_mangle]
pub unsafe extern "C" fn wasm_trap_trace(trap: &wasm_trap_t, out_ptr: &mut wasm_frame_vec_t) {
let frames = trap.inner.trace();
let frame_vec: wasm_frame_vec_t = frames.into();
out_ptr.size = frame_vec.size;
out_ptr.data = frame_vec.data;
}

View File

@@ -0,0 +1,90 @@
use super::{wasm_externtype_t, wasm_name_t};
use std::ptr::NonNull;
use wasmer::ExportType;
#[allow(non_camel_case_types)]
pub struct wasm_exporttype_t {
name: NonNull<wasm_name_t>,
extern_type: NonNull<wasm_externtype_t>,
/// If `true`, `name` and `extern_type` will be dropped by
/// `wasm_exporttype_t::drop`.
owns_fields: bool,
}
wasm_declare_boxed_vec!(exporttype);
#[no_mangle]
pub extern "C" fn wasm_exporttype_new(
name: NonNull<wasm_name_t>,
extern_type: NonNull<wasm_externtype_t>,
) -> Box<wasm_exporttype_t> {
Box::new(wasm_exporttype_t {
name,
extern_type,
owns_fields: false,
})
}
#[no_mangle]
pub extern "C" fn wasm_exporttype_name(et: &'static wasm_exporttype_t) -> &'static wasm_name_t {
unsafe { et.name.as_ref() }
}
#[no_mangle]
pub extern "C" fn wasm_exporttype_type(
et: &'static wasm_exporttype_t,
) -> &'static wasm_externtype_t {
unsafe { et.extern_type.as_ref() }
}
#[no_mangle]
pub extern "C" fn wasm_exporttype_delete(_exporttype: Option<Box<wasm_exporttype_t>>) {}
impl Drop for wasm_exporttype_t {
fn drop(&mut self) {
if self.owns_fields {
// SAFETY: `owns_fields` is set to `true` only in
// `wasm_exporttype_t::from(&ExportType)`, where the data
// are leaked properly and won't be freed somewhere else.
unsafe {
let _ = Box::from_raw(self.name.as_ptr());
let _ = Box::from_raw(self.extern_type.as_ptr());
}
}
}
}
impl From<ExportType> for wasm_exporttype_t {
fn from(other: ExportType) -> Self {
(&other).into()
}
}
impl From<&ExportType> for wasm_exporttype_t {
fn from(other: &ExportType) -> Self {
// TODO: double check that freeing String as `Vec<u8>` is valid
let name = {
let mut heap_str: Box<str> = other.name().to_string().into_boxed_str();
let char_ptr = heap_str.as_mut_ptr();
let str_len = heap_str.bytes().len();
let name_inner = wasm_name_t {
size: str_len,
data: char_ptr,
};
Box::leak(heap_str);
unsafe { NonNull::new_unchecked(Box::into_raw(Box::new(name_inner))) }
};
let extern_type = {
let extern_type: wasm_externtype_t = other.ty().into();
unsafe { NonNull::new_unchecked(Box::into_raw(Box::new(extern_type))) }
};
wasm_exporttype_t {
name,
extern_type,
owns_fields: true,
}
}
}

View File

@@ -0,0 +1,251 @@
use super::super::externals::wasm_extern_t;
use super::{wasm_functype_t, wasm_globaltype_t, wasm_memorytype_t, wasm_tabletype_t};
use std::convert::{TryFrom, TryInto};
use std::mem;
use thiserror::Error;
use wasmer::ExternType;
#[allow(non_camel_case_types)]
#[derive(Clone, Debug)]
pub struct wasm_externtype_t {
pub(crate) inner: ExternType,
}
#[no_mangle]
pub unsafe extern "C" fn wasm_extern_type(e: &wasm_extern_t) -> Box<wasm_externtype_t> {
Box::new(wasm_externtype_t {
inner: e.inner.ty(),
})
}
#[no_mangle]
pub unsafe extern "C" fn wasm_externtype_delete(_et: Option<Box<wasm_externtype_t>>) {}
#[no_mangle]
pub extern "C" fn wasm_externtype_copy(
wasm_externtype: &wasm_externtype_t,
) -> Box<wasm_externtype_t> {
Box::new(wasm_externtype_t {
inner: wasm_externtype.inner.clone(),
})
}
impl From<ExternType> for wasm_externtype_t {
fn from(other: ExternType) -> Self {
Self { inner: other }
}
}
impl From<&ExternType> for wasm_externtype_t {
fn from(other: &ExternType) -> Self {
other.clone().into()
}
}
#[allow(non_camel_case_types)]
type wasm_externkind_t = u8;
#[allow(non_camel_case_types)]
#[repr(u8)]
pub enum wasm_externkind_enum {
WASM_EXTERN_FUNC = 0,
WASM_EXTERN_GLOBAL = 1,
WASM_EXTERN_TABLE = 2,
WASM_EXTERN_MEMORY = 3,
}
#[no_mangle]
pub unsafe extern "C" fn wasm_extern_kind(e: &wasm_extern_t) -> wasm_externkind_t {
wasm_externkind_enum::from(e.inner.ty()) as wasm_externkind_t
}
impl From<ExternType> for wasm_externkind_enum {
fn from(other: ExternType) -> Self {
(&other).into()
}
}
impl From<&ExternType> for wasm_externkind_enum {
fn from(other: &ExternType) -> Self {
match other {
ExternType::Function(_) => Self::WASM_EXTERN_FUNC,
ExternType::Global(_) => Self::WASM_EXTERN_GLOBAL,
ExternType::Table(_) => Self::WASM_EXTERN_TABLE,
ExternType::Memory(_) => Self::WASM_EXTERN_MEMORY,
}
}
}
#[no_mangle]
pub unsafe extern "C" fn wasm_externtype_kind(et: &wasm_externtype_t) -> wasm_externkind_t {
wasm_externkind_enum::from(&et.inner) as wasm_externkind_t
}
#[derive(Debug, Clone, Error)]
#[error("failed to convert from `wasm_externtype_t`: {0}")]
pub struct ExternTypeConversionError(&'static str);
impl From<&'static str> for ExternTypeConversionError {
fn from(other: &'static str) -> Self {
Self(other)
}
}
impl TryFrom<&'static wasm_externtype_t> for &'static wasm_functype_t {
type Error = ExternTypeConversionError;
fn try_from(other: &'static wasm_externtype_t) -> Result<Self, Self::Error> {
if let ExternType::Function(_) = other.inner {
Ok(unsafe { mem::transmute::<&'static wasm_externtype_t, Self>(other) })
} else {
Err(ExternTypeConversionError("Wrong type: expected function"))
}
}
}
impl TryFrom<&'static wasm_externtype_t> for &'static wasm_globaltype_t {
type Error = ExternTypeConversionError;
fn try_from(other: &'static wasm_externtype_t) -> Result<Self, Self::Error> {
if let ExternType::Global(_) = other.inner {
Ok(unsafe { mem::transmute::<&'static wasm_externtype_t, Self>(other) })
} else {
Err(ExternTypeConversionError("Wrong type: expected global"))
}
}
}
impl TryFrom<&'static wasm_externtype_t> for &'static wasm_memorytype_t {
type Error = ExternTypeConversionError;
fn try_from(other: &'static wasm_externtype_t) -> Result<Self, Self::Error> {
if let ExternType::Memory(_) = other.inner {
Ok(unsafe { mem::transmute::<&'static wasm_externtype_t, Self>(other) })
} else {
Err(ExternTypeConversionError("Wrong type: expected memory"))
}
}
}
impl TryFrom<&'static wasm_externtype_t> for &'static wasm_tabletype_t {
type Error = ExternTypeConversionError;
fn try_from(other: &'static wasm_externtype_t) -> Result<Self, Self::Error> {
if let ExternType::Table(_) = other.inner {
Ok(unsafe { mem::transmute::<&'static wasm_externtype_t, Self>(other) })
} else {
Err(ExternTypeConversionError("Wrong type: expected table"))
}
}
}
#[no_mangle]
pub unsafe extern "C" fn wasm_externtype_as_functype_const(
et: &'static wasm_externtype_t,
) -> Option<&'static wasm_functype_t> {
Some(c_try!(et.try_into()))
}
#[no_mangle]
pub unsafe extern "C" fn wasm_externtype_as_functype(
et: &'static wasm_externtype_t,
) -> Option<&'static wasm_functype_t> {
Some(c_try!(et.try_into()))
}
#[no_mangle]
pub unsafe extern "C" fn wasm_functype_as_externtype_const(
ft: &'static wasm_functype_t,
) -> &'static wasm_externtype_t {
&ft.extern_
}
#[no_mangle]
pub unsafe extern "C" fn wasm_functype_as_externtype(
ft: &'static wasm_functype_t,
) -> &'static wasm_externtype_t {
&ft.extern_
}
#[no_mangle]
pub unsafe extern "C" fn wasm_externtype_as_memorytype_const(
et: &'static wasm_externtype_t,
) -> Option<&'static wasm_memorytype_t> {
Some(c_try!(et.try_into()))
}
#[no_mangle]
pub unsafe extern "C" fn wasm_externtype_as_memorytype(
et: &'static wasm_externtype_t,
) -> Option<&'static wasm_memorytype_t> {
Some(c_try!(et.try_into()))
}
#[no_mangle]
pub unsafe extern "C" fn wasm_memorytype_as_externtype_const(
mt: &'static wasm_memorytype_t,
) -> &'static wasm_externtype_t {
&mt.extern_
}
#[no_mangle]
pub unsafe extern "C" fn wasm_memorytype_as_externtype(
mt: &'static wasm_memorytype_t,
) -> &'static wasm_externtype_t {
&mt.extern_
}
#[no_mangle]
pub unsafe extern "C" fn wasm_externtype_as_globaltype_const(
et: &'static wasm_externtype_t,
) -> Option<&'static wasm_globaltype_t> {
Some(c_try!(et.try_into()))
}
#[no_mangle]
pub unsafe extern "C" fn wasm_externtype_as_globaltype(
et: &'static wasm_externtype_t,
) -> Option<&'static wasm_globaltype_t> {
Some(c_try!(et.try_into()))
}
#[no_mangle]
pub unsafe extern "C" fn wasm_globaltype_as_externtype_const(
gt: &'static wasm_globaltype_t,
) -> &'static wasm_externtype_t {
&gt.extern_
}
#[no_mangle]
pub unsafe extern "C" fn wasm_globaltype_as_externtype(
gt: &'static wasm_globaltype_t,
) -> &'static wasm_externtype_t {
&gt.extern_
}
#[no_mangle]
pub unsafe extern "C" fn wasm_externtype_as_tabletype_const(
et: &'static wasm_externtype_t,
) -> Option<&'static wasm_tabletype_t> {
Some(c_try!(et.try_into()))
}
#[no_mangle]
pub unsafe extern "C" fn wasm_externtype_as_tabletype(
et: &'static wasm_externtype_t,
) -> Option<&'static wasm_tabletype_t> {
Some(c_try!(et.try_into()))
}
#[no_mangle]
pub unsafe extern "C" fn wasm_tabletype_as_externtype_const(
tt: &'static wasm_tabletype_t,
) -> &'static wasm_externtype_t {
&tt.extern_
}
#[no_mangle]
pub unsafe extern "C" fn wasm_tabletype_as_externtype(
tt: &'static wasm_tabletype_t,
) -> &'static wasm_externtype_t {
&tt.extern_
}

View File

@@ -0,0 +1,51 @@
use super::super::instance::wasm_instance_t;
use wasmer::FrameInfo;
#[allow(non_camel_case_types)]
#[derive(Debug, Clone)]
pub struct wasm_frame_t {
info: FrameInfo,
}
impl<'a> From<&'a FrameInfo> for wasm_frame_t {
fn from(other: &'a FrameInfo) -> Self {
other.clone().into()
}
}
impl From<FrameInfo> for wasm_frame_t {
fn from(other: FrameInfo) -> Self {
Self { info: other }
}
}
#[no_mangle]
pub unsafe extern "C" fn wasm_frame_copy(frame: &wasm_frame_t) -> Box<wasm_frame_t> {
Box::new(frame.clone())
}
#[no_mangle]
pub unsafe extern "C" fn wasm_frame_delete(_frame: Option<Box<wasm_frame_t>>) {}
#[no_mangle]
pub unsafe extern "C" fn wasm_frame_instance(frame: &wasm_frame_t) -> *const wasm_instance_t {
//todo!("wasm_frame_instance")
std::ptr::null()
}
#[no_mangle]
pub unsafe extern "C" fn wasm_frame_func_index(frame: &wasm_frame_t) -> u32 {
frame.info.func_index()
}
#[no_mangle]
pub unsafe extern "C" fn wasm_frame_func_offset(frame: &wasm_frame_t) -> usize {
frame.info.func_offset()
}
#[no_mangle]
pub unsafe extern "C" fn wasm_frame_module_offset(frame: &wasm_frame_t) -> usize {
frame.info.module_offset()
}
wasm_declare_vec!(frame);

View File

@@ -0,0 +1,118 @@
use super::{wasm_externtype_t, wasm_valtype_t, wasm_valtype_vec_t};
use std::mem;
use std::ptr::NonNull;
use wasmer::{ExternType, FunctionType, ValType};
#[allow(non_camel_case_types)]
#[derive(Clone, Debug)]
pub struct wasm_functype_t {
pub(crate) extern_: wasm_externtype_t,
}
impl wasm_functype_t {
pub(crate) fn sig(&self) -> &FunctionType {
if let ExternType::Function(ref f) = self.extern_.inner {
f
} else {
unreachable!("data corruption: `wasm_functype_t` does not contain a function")
}
}
pub(crate) fn new(function_type: FunctionType) -> Self {
Self {
extern_: wasm_externtype_t {
inner: ExternType::Function(function_type),
},
}
}
}
wasm_declare_vec!(functype);
#[no_mangle]
pub unsafe extern "C" fn wasm_functype_new(
// own
params: Option<NonNull<wasm_valtype_vec_t>>,
// own
results: Option<NonNull<wasm_valtype_vec_t>>,
) -> Option<Box<wasm_functype_t>> {
wasm_functype_new_inner(params?, results?)
}
unsafe fn wasm_functype_new_inner(
// own
params: NonNull<wasm_valtype_vec_t>,
// own
results: NonNull<wasm_valtype_vec_t>,
) -> Option<Box<wasm_functype_t>> {
let params = params.as_ref();
let results = results.as_ref();
let params: Vec<ValType> = params
.into_slice()?
.iter()
.map(|ptr| **ptr)
.map(Into::into)
.collect::<Vec<_>>();
let results: Vec<ValType> = results
.into_slice()?
.iter()
.map(|ptr| **ptr)
.map(Into::into)
.collect::<Vec<_>>();
Some(Box::new(wasm_functype_t::new(FunctionType::new(
params, results,
))))
}
#[no_mangle]
pub unsafe extern "C" fn wasm_functype_delete(_ft: Option<Box<wasm_functype_t>>) {}
#[no_mangle]
pub unsafe extern "C" fn wasm_functype_copy(
arg: Option<NonNull<wasm_functype_t>>,
) -> Option<Box<wasm_functype_t>> {
let arg = arg?;
let funcsig = arg.as_ref();
Some(Box::new(funcsig.clone()))
}
// TODO: fix memory leak
#[no_mangle]
pub unsafe extern "C" fn wasm_functype_params(ft: &wasm_functype_t) -> *const wasm_valtype_vec_t {
let mut valtypes = ft
.sig()
.params()
.iter()
.cloned()
.map(Into::into)
.map(Box::new)
.map(Box::into_raw)
.collect::<Vec<*mut wasm_valtype_t>>();
let out = Box::into_raw(Box::new(wasm_valtype_vec_t {
size: valtypes.len(),
data: valtypes.as_mut_ptr(),
}));
mem::forget(valtypes);
out as *const _
}
// TODO: fix memory leak
#[no_mangle]
pub unsafe extern "C" fn wasm_functype_results(ft: &wasm_functype_t) -> *const wasm_valtype_vec_t {
let mut valtypes = ft
.sig()
.results()
.iter()
.cloned()
.map(Into::into)
.map(Box::new)
.map(Box::into_raw)
.collect::<Vec<*mut wasm_valtype_t>>();
let out = Box::into_raw(Box::new(wasm_valtype_vec_t {
size: valtypes.len(),
data: valtypes.as_mut_ptr(),
}));
mem::forget(valtypes);
out as *const _
}

View File

@@ -0,0 +1,71 @@
use super::{
wasm_externtype_t, wasm_mutability_enum, wasm_mutability_t, wasm_valtype_delete, wasm_valtype_t,
};
use std::convert::TryInto;
use wasmer::{ExternType, GlobalType};
#[allow(non_camel_case_types)]
#[derive(Clone, Debug)]
pub struct wasm_globaltype_t {
pub(crate) extern_: wasm_externtype_t,
}
impl wasm_globaltype_t {
pub(crate) fn as_globaltype(&self) -> &GlobalType {
if let ExternType::Global(ref g) = self.extern_.inner {
g
} else {
unreachable!(
"Data corruption detected: `wasm_globaltype_t` does not contain a `GlobalType`"
);
}
}
}
wasm_declare_vec!(globaltype);
#[no_mangle]
pub unsafe extern "C" fn wasm_globaltype_new(
// own
valtype: Option<Box<wasm_valtype_t>>,
mutability: wasm_mutability_t,
) -> Option<Box<wasm_globaltype_t>> {
wasm_globaltype_new_inner(valtype?, mutability)
}
#[no_mangle]
pub unsafe extern "C" fn wasm_globaltype_delete(_globaltype: Option<Box<wasm_globaltype_t>>) {}
unsafe fn wasm_globaltype_new_inner(
// own
valtype: Box<wasm_valtype_t>,
mutability: wasm_mutability_t,
) -> Option<Box<wasm_globaltype_t>> {
let me: wasm_mutability_enum = mutability.try_into().ok()?;
let gd = Box::new(wasm_globaltype_t {
extern_: wasm_externtype_t {
inner: ExternType::Global(GlobalType::new((*valtype).into(), me.into())),
},
});
wasm_valtype_delete(Some(valtype));
Some(gd)
}
#[no_mangle]
pub unsafe extern "C" fn wasm_globaltype_mutability(
globaltype: &wasm_globaltype_t,
) -> wasm_mutability_t {
let gt = globaltype.as_globaltype();
wasm_mutability_enum::from(gt.mutability).into()
}
// TODO: fix memory leak
// this function leaks memory because the returned limits pointer is not owned
#[no_mangle]
pub unsafe extern "C" fn wasm_globaltype_content(
globaltype: &wasm_globaltype_t,
) -> *const wasm_valtype_t {
let gt = globaltype.as_globaltype();
Box::into_raw(Box::new(gt.ty.into()))
}

View File

@@ -0,0 +1,93 @@
use super::{wasm_externtype_t, wasm_name_t};
use std::ptr::NonNull;
use wasmer::ImportType;
// TODO: improve ownership in `importtype_t` (can we safely use `Box<wasm_name_t>` here?)
#[allow(non_camel_case_types)]
pub struct wasm_importtype_t {
pub(crate) module: NonNull<wasm_name_t>,
pub(crate) name: NonNull<wasm_name_t>,
pub(crate) extern_type: NonNull<wasm_externtype_t>,
}
wasm_declare_boxed_vec!(importtype);
#[no_mangle]
pub extern "C" fn wasm_importtype_new(
module: NonNull<wasm_name_t>,
name: NonNull<wasm_name_t>,
extern_type: NonNull<wasm_externtype_t>,
) -> Box<wasm_importtype_t> {
Box::new(wasm_importtype_t {
name,
module,
extern_type,
})
}
#[no_mangle]
pub extern "C" fn wasm_importtype_module(et: &'static wasm_importtype_t) -> &'static wasm_name_t {
unsafe { et.module.as_ref() }
}
#[no_mangle]
pub extern "C" fn wasm_importtype_name(et: &'static wasm_importtype_t) -> &'static wasm_name_t {
unsafe { et.name.as_ref() }
}
#[no_mangle]
pub extern "C" fn wasm_importtype_type(
et: &'static wasm_importtype_t,
) -> &'static wasm_externtype_t {
unsafe { et.extern_type.as_ref() }
}
#[no_mangle]
pub unsafe extern "C" fn wasm_importtype_delete(_importtype: Option<Box<wasm_importtype_t>>) {}
impl From<ImportType> for wasm_importtype_t {
fn from(other: ImportType) -> Self {
(&other).into()
}
}
impl From<&ImportType> for wasm_importtype_t {
fn from(other: &ImportType) -> Self {
// TODO: double check that freeing String as `Vec<u8>` is valid
let name = {
let mut heap_str: Box<str> = other.name().to_string().into_boxed_str();
let char_ptr = heap_str.as_mut_ptr();
let str_len = heap_str.bytes().len();
let name_inner = wasm_name_t {
size: str_len,
data: char_ptr,
};
Box::leak(heap_str);
unsafe { NonNull::new_unchecked(Box::into_raw(Box::new(name_inner))) }
};
// TODO: double check that freeing String as `Vec<u8>` is valid
let module = {
let mut heap_str: Box<str> = other.module().to_string().into_boxed_str();
let char_ptr = heap_str.as_mut_ptr();
let str_len = heap_str.bytes().len();
let name_inner = wasm_name_t {
size: str_len,
data: char_ptr,
};
Box::leak(heap_str);
unsafe { NonNull::new_unchecked(Box::into_raw(Box::new(name_inner))) }
};
let extern_type = {
let extern_type: wasm_externtype_t = other.ty().into();
unsafe { NonNull::new_unchecked(Box::into_raw(Box::new(extern_type))) }
};
wasm_importtype_t {
name,
module,
extern_type,
}
}
}

View File

@@ -0,0 +1,68 @@
use super::wasm_externtype_t;
use wasmer::{ExternType, MemoryType, Pages};
// opaque type wrapping `MemoryType`
#[allow(non_camel_case_types)]
#[derive(Clone, Debug)]
pub struct wasm_memorytype_t {
pub(crate) extern_: wasm_externtype_t,
}
impl wasm_memorytype_t {
pub(crate) fn as_memorytype(&self) -> &MemoryType {
if let ExternType::Memory(ref mt) = self.extern_.inner {
mt
} else {
unreachable!(
"Data corruption detected: `wasm_memorytype_t` does not contain a `MemoryType`"
);
}
}
}
wasm_declare_vec!(memorytype);
#[allow(non_camel_case_types)]
#[derive(Copy, Clone, Debug)]
#[repr(C)]
pub struct wasm_limits_t {
pub(crate) min: u32,
pub(crate) max: u32,
}
const LIMITS_MAX_SENTINEL: u32 = u32::max_value();
#[no_mangle]
pub unsafe extern "C" fn wasm_memorytype_new(limits: &wasm_limits_t) -> Box<wasm_memorytype_t> {
let min_pages = Pages(limits.min as _);
// u32::max_value() is a sentinel value for no max specified
let max_pages = if limits.max == LIMITS_MAX_SENTINEL {
None
} else {
Some(Pages(limits.max as _))
};
Box::new(wasm_memorytype_t {
extern_: wasm_externtype_t {
inner: ExternType::Memory(MemoryType::new(min_pages, max_pages, false)),
},
})
}
#[no_mangle]
pub unsafe extern "C" fn wasm_memorytype_delete(_memorytype: Option<Box<wasm_memorytype_t>>) {}
// TODO: fix memory leak
// this function leaks memory because the returned limits pointer is not owned
#[no_mangle]
pub unsafe extern "C" fn wasm_memorytype_limits(mt: &wasm_memorytype_t) -> *const wasm_limits_t {
let md = mt.as_memorytype();
Box::into_raw(Box::new(wasm_limits_t {
min: md.minimum.0 as _,
max: md
.maximum
.map(|max| max.0 as _)
.unwrap_or(LIMITS_MAX_SENTINEL),
}))
}

View File

@@ -0,0 +1,36 @@
mod export;
mod extern_;
mod frame;
mod function;
mod global;
mod import;
mod memory;
mod mutability;
mod table;
mod value;
pub use export::*;
pub use extern_::*;
pub use frame::*;
pub use function::*;
pub use global::*;
pub use import::*;
pub use memory::*;
pub use mutability::*;
pub use table::*;
pub use value::*;
#[allow(non_camel_case_types)]
pub type wasm_byte_t = u8;
wasm_declare_vec!(byte);
#[allow(non_camel_case_types)]
pub type wasm_name_t = wasm_byte_vec_t;
// opaque type over `ExternRef`?
#[allow(non_camel_case_types)]
pub struct wasm_ref_t;
#[allow(non_camel_case_types)]
pub type wasm_message_t = wasm_byte_vec_t;

View File

@@ -0,0 +1,56 @@
use std::convert::TryFrom;
use wasmer::Mutability;
#[allow(non_camel_case_types)]
pub type wasm_mutability_t = u8;
#[allow(non_camel_case_types)]
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[repr(u8)]
pub enum wasm_mutability_enum {
WASM_CONST = 0,
WASM_VAR,
}
impl wasm_mutability_enum {
#[allow(dead_code)]
fn is_mutable(self) -> bool {
self == Self::WASM_VAR
}
}
impl TryFrom<wasm_mutability_t> for wasm_mutability_enum {
type Error = &'static str;
fn try_from(item: wasm_mutability_t) -> Result<Self, Self::Error> {
Ok(match item {
0 => wasm_mutability_enum::WASM_CONST,
1 => wasm_mutability_enum::WASM_VAR,
_ => return Err("wasm_mutability_t value out of bounds"),
})
}
}
impl From<wasm_mutability_enum> for wasm_mutability_t {
fn from(other: wasm_mutability_enum) -> Self {
other as wasm_mutability_t
}
}
impl From<wasm_mutability_enum> for Mutability {
fn from(other: wasm_mutability_enum) -> Self {
match other {
wasm_mutability_enum::WASM_CONST => Mutability::Const,
wasm_mutability_enum::WASM_VAR => Mutability::Var,
}
}
}
impl From<Mutability> for wasm_mutability_enum {
fn from(other: Mutability) -> Self {
match other {
Mutability::Const => wasm_mutability_enum::WASM_CONST,
Mutability::Var => wasm_mutability_enum::WASM_VAR,
}
}
}

View File

@@ -0,0 +1,79 @@
use super::{wasm_externtype_t, wasm_limits_t, wasm_valtype_delete, wasm_valtype_t};
use wasmer::{ExternType, TableType};
#[allow(non_camel_case_types)]
pub type wasm_table_size_t = u32;
#[allow(non_camel_case_types)]
#[derive(Clone, Debug)]
#[repr(C)]
pub struct wasm_tabletype_t {
pub(crate) extern_: wasm_externtype_t,
}
wasm_declare_vec!(tabletype);
impl wasm_tabletype_t {
pub(crate) fn as_tabletype(&self) -> &TableType {
if let ExternType::Table(ref t) = self.extern_.inner {
t
} else {
unreachable!(
"Data corruption detected: `wasm_tabletype_t` does not contain a `TableType`"
);
}
}
}
#[no_mangle]
pub unsafe extern "C" fn wasm_tabletype_new(
// own
valtype: Box<wasm_valtype_t>,
limits: &wasm_limits_t,
) -> Box<wasm_tabletype_t> {
// TODO: investigate if `0` is in fact a sentinel value here
let max_elements = if limits.max == 0 {
None
} else {
Some(limits.max as _)
};
let out = Box::new(wasm_tabletype_t {
extern_: wasm_externtype_t {
inner: ExternType::Table(TableType::new(
(*valtype).into(),
limits.min as _,
max_elements,
)),
},
});
wasm_valtype_delete(Some(valtype));
out
}
// TODO: fix memory leak
// this function leaks memory because the returned limits pointer is not owned
#[no_mangle]
pub unsafe extern "C" fn wasm_tabletype_limits(
tabletype: &wasm_tabletype_t,
) -> *const wasm_limits_t {
let tt = tabletype.as_tabletype();
Box::into_raw(Box::new(wasm_limits_t {
min: tt.minimum as _,
max: tt.maximum.unwrap_or(0),
}))
}
// TODO: fix memory leak
// this function leaks memory because the returned limits pointer is not owned
#[no_mangle]
pub unsafe extern "C" fn wasm_tabletype_element(
tabletype: &wasm_tabletype_t,
) -> *const wasm_valtype_t {
let tt = tabletype.as_tabletype();
Box::into_raw(Box::new(tt.ty.into()))
}
#[no_mangle]
pub unsafe extern "C" fn wasm_tabletype_delete(_tabletype: Option<Box<wasm_tabletype_t>>) {}

View File

@@ -0,0 +1,90 @@
use super::super::value::wasm_valkind_t;
use std::convert::TryInto;
use wasmer::ValType;
#[allow(non_camel_case_types)]
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[repr(u8)]
pub enum wasm_valkind_enum {
WASM_I32 = 0,
WASM_I64 = 1,
WASM_F32 = 2,
WASM_F64 = 3,
WASM_ANYREF = 128,
WASM_FUNCREF = 129,
}
impl From<ValType> for wasm_valkind_enum {
fn from(other: ValType) -> Self {
match other {
ValType::I32 => Self::WASM_I32,
ValType::I64 => Self::WASM_I64,
ValType::F32 => Self::WASM_F32,
ValType::F64 => Self::WASM_F64,
ValType::V128 => todo!("no v128 type in Wasm C API yet!"),
ValType::ExternRef => Self::WASM_ANYREF,
ValType::FuncRef => Self::WASM_FUNCREF,
}
}
}
impl From<wasm_valkind_enum> for ValType {
fn from(other: wasm_valkind_enum) -> Self {
use wasm_valkind_enum::*;
match other {
WASM_I32 => ValType::I32,
WASM_I64 => ValType::I64,
WASM_F32 => ValType::F32,
WASM_F64 => ValType::F64,
WASM_ANYREF => ValType::ExternRef,
WASM_FUNCREF => ValType::FuncRef,
}
}
}
#[allow(non_camel_case_types)]
#[derive(Debug, Clone, Copy)]
pub struct wasm_valtype_t {
valkind: wasm_valkind_enum,
}
impl Default for wasm_valtype_t {
fn default() -> Self {
Self {
valkind: wasm_valkind_enum::WASM_I32,
}
}
}
wasm_declare_boxed_vec!(valtype);
impl From<wasm_valtype_t> for ValType {
fn from(other: wasm_valtype_t) -> Self {
other.valkind.into()
}
}
impl From<ValType> for wasm_valtype_t {
fn from(other: ValType) -> Self {
Self {
valkind: other.into(),
}
}
}
#[no_mangle]
pub extern "C" fn wasm_valtype_new(kind: wasm_valkind_t) -> Option<Box<wasm_valtype_t>> {
let kind_enum = kind.try_into().ok()?;
let valtype = wasm_valtype_t { valkind: kind_enum };
Some(Box::new(valtype))
}
#[no_mangle]
pub unsafe extern "C" fn wasm_valtype_delete(_valtype: Option<Box<wasm_valtype_t>>) {}
#[no_mangle]
pub unsafe extern "C" fn wasm_valtype_kind(valtype: Option<&wasm_valtype_t>) -> wasm_valkind_t {
valtype
.expect("`wasm_valtype_kind: argument is a null pointer")
.valkind as wasm_valkind_t
}

View File

@@ -1,17 +0,0 @@
#[macro_export]
macro_rules! c_try {
($expr:expr) => {{
let res: Result<_, _> = $expr;
match res {
Ok(val) => val,
Err(err) => {
crate::error::update_last_error(err);
return None;
}
}
}};
($expr:expr, $e:expr) => {{
let opt: Option<_> = $expr;
c_try!(opt.ok_or_else(|| $e))
}};
}

View File

@@ -0,0 +1,132 @@
use super::types::{wasm_ref_t, wasm_valkind_enum};
use std::convert::{TryFrom, TryInto};
use std::ptr::NonNull;
use wasmer::Val;
#[allow(non_camel_case_types)]
pub type wasm_valkind_t = u8;
#[allow(non_camel_case_types)]
#[derive(Clone, Copy)]
pub union wasm_val_inner {
pub(crate) int32_t: i32,
pub(crate) int64_t: i64,
pub(crate) float32_t: f32,
pub(crate) float64_t: f64,
pub(crate) wref: *mut wasm_ref_t,
}
#[allow(non_camel_case_types)]
#[repr(C)]
pub struct wasm_val_t {
pub kind: wasm_valkind_t,
pub of: wasm_val_inner,
}
wasm_declare_vec!(val);
impl Clone for wasm_val_t {
fn clone(&self) -> Self {
wasm_val_t {
kind: self.kind,
of: self.of.clone(),
}
}
}
#[no_mangle]
pub unsafe extern "C" fn wasm_val_copy(out_ptr: *mut wasm_val_t, val: &wasm_val_t) {
(*out_ptr).kind = val.kind;
(*out_ptr).of =
// TODO: handle this error
match val.kind.try_into().unwrap() {
wasm_valkind_enum::WASM_I32 => wasm_val_inner { int32_t: val.of.int32_t },
wasm_valkind_enum::WASM_I64 => wasm_val_inner { int64_t: val.of.int64_t },
wasm_valkind_enum::WASM_F32 => wasm_val_inner { float32_t: val.of.float32_t },
wasm_valkind_enum::WASM_F64 => wasm_val_inner { float64_t: val.of.float64_t },
wasm_valkind_enum::WASM_ANYREF => wasm_val_inner { wref: val.of.wref },
wasm_valkind_enum::WASM_FUNCREF => wasm_val_inner { wref: val.of.wref },
};
}
#[no_mangle]
pub unsafe extern "C" fn wasm_val_delete(val: Option<NonNull<wasm_val_t>>) {
if let Some(v_inner) = val {
// TODO: figure out where wasm_val is allocated first...
let _ = Box::from_raw(v_inner.as_ptr());
}
}
impl TryFrom<wasm_valkind_t> for wasm_valkind_enum {
type Error = &'static str;
fn try_from(item: wasm_valkind_t) -> Result<Self, Self::Error> {
Ok(match item {
0 => wasm_valkind_enum::WASM_I32,
1 => wasm_valkind_enum::WASM_I64,
2 => wasm_valkind_enum::WASM_F32,
3 => wasm_valkind_enum::WASM_F64,
128 => wasm_valkind_enum::WASM_ANYREF,
129 => wasm_valkind_enum::WASM_FUNCREF,
_ => return Err("valkind value out of bounds"),
})
}
}
impl TryFrom<wasm_val_t> for Val {
type Error = &'static str;
fn try_from(item: wasm_val_t) -> Result<Self, Self::Error> {
(&item).try_into()
}
}
impl TryFrom<&wasm_val_t> for Val {
type Error = &'static str;
fn try_from(item: &wasm_val_t) -> Result<Self, Self::Error> {
Ok(match item.kind.try_into()? {
wasm_valkind_enum::WASM_I32 => Val::I32(unsafe { item.of.int32_t }),
wasm_valkind_enum::WASM_I64 => Val::I64(unsafe { item.of.int64_t }),
wasm_valkind_enum::WASM_F32 => Val::F32(unsafe { item.of.float32_t }),
wasm_valkind_enum::WASM_F64 => Val::F64(unsafe { item.of.float64_t }),
wasm_valkind_enum::WASM_ANYREF => return Err("ANYREF not supported at this time"),
wasm_valkind_enum::WASM_FUNCREF => return Err("FUNCREF not supported at this time"),
})
}
}
impl TryFrom<Val> for wasm_val_t {
type Error = &'static str;
fn try_from(item: Val) -> Result<Self, Self::Error> {
wasm_val_t::try_from(&item)
}
}
impl TryFrom<&Val> for wasm_val_t {
type Error = &'static str;
fn try_from(item: &Val) -> Result<Self, Self::Error> {
Ok(match *item {
Val::I32(v) => wasm_val_t {
of: wasm_val_inner { int32_t: v },
kind: wasm_valkind_enum::WASM_I32 as _,
},
Val::I64(v) => wasm_val_t {
of: wasm_val_inner { int64_t: v },
kind: wasm_valkind_enum::WASM_I64 as _,
},
Val::F32(v) => wasm_val_t {
of: wasm_val_inner { float32_t: v },
kind: wasm_valkind_enum::WASM_F32 as _,
},
Val::F64(v) => wasm_val_t {
of: wasm_val_inner { float64_t: v },
kind: wasm_valkind_enum::WASM_F64 as _,
},
Val::V128(_) => return Err("128bit SIMD types not yet supported in Wasm C API"),
_ => todo!("Handle these values in TryFrom<Val> for wasm_val_t"),
})
}
}

View File

@@ -5,18 +5,19 @@
mod capture_files; mod capture_files;
use super::{ use super::{
wasm_extern_t, wasm_func_t, wasm_instance_t, wasm_memory_t, wasm_module_t, wasm_store_t, externals::{wasm_extern_t, wasm_extern_vec_t, wasm_func_t, wasm_memory_t},
instance::wasm_instance_t,
module::wasm_module_t,
store::wasm_store_t,
}; };
// required due to really weird Rust resolution rules for macros // required due to really weird Rust resolution rules for macros
// https://github.com/rust-lang/rust/issues/57966 // https://github.com/rust-lang/rust/issues/57966
use crate::c_try;
use crate::error::{update_last_error, CApiError}; use crate::error::{update_last_error, CApiError};
use std::convert::TryFrom; use std::convert::TryFrom;
use std::ffi::CStr; use std::ffi::CStr;
use std::os::raw::c_char; use std::os::raw::c_char;
use std::ptr::NonNull;
use std::slice; use std::slice;
use wasmer::{Extern, NamedResolver, Store}; use wasmer::{Extern, NamedResolver};
use wasmer_wasi::{ use wasmer_wasi::{
generate_import_object_from_env, get_wasi_version, WasiEnv, WasiFile, WasiState, generate_import_object_from_env, get_wasi_version, WasiEnv, WasiFile, WasiState,
WasiStateBuilder, WasiVersion, WasiStateBuilder, WasiVersion,
@@ -24,11 +25,11 @@ use wasmer_wasi::{
#[derive(Debug, Default)] #[derive(Debug, Default)]
#[allow(non_camel_case_types)] #[allow(non_camel_case_types)]
#[repr(C)]
pub struct wasi_config_t { pub struct wasi_config_t {
inherit_stdout: bool, inherit_stdout: bool,
inherit_stderr: bool, inherit_stderr: bool,
inherit_stdin: bool, inherit_stdin: bool,
/// cbindgen:ignore
state_builder: WasiStateBuilder, state_builder: WasiStateBuilder,
} }
@@ -74,6 +75,63 @@ pub unsafe extern "C" fn wasi_config_arg(config: &mut wasi_config_t, arg: *const
config.state_builder.arg(arg_bytes); config.state_builder.arg(arg_bytes);
} }
#[no_mangle]
pub unsafe extern "C" fn wasi_config_preopen_dir(
config: &mut wasi_config_t,
dir: *const c_char,
) -> bool {
let dir_cstr = CStr::from_ptr(dir);
let dir_bytes = dir_cstr.to_bytes();
let dir_str = match std::str::from_utf8(dir_bytes) {
Ok(dir_str) => dir_str,
Err(e) => {
update_last_error(e);
return false;
}
};
if let Err(e) = config.state_builder.preopen_dir(dir_str) {
update_last_error(e);
return false;
}
true
}
#[no_mangle]
pub unsafe extern "C" fn wasi_config_mapdir(
config: &mut wasi_config_t,
alias: *const c_char,
dir: *const c_char,
) -> bool {
let alias_cstr = CStr::from_ptr(alias);
let alias_bytes = alias_cstr.to_bytes();
let alias_str = match std::str::from_utf8(alias_bytes) {
Ok(alias_str) => alias_str,
Err(e) => {
update_last_error(e);
return false;
}
};
let dir_cstr = CStr::from_ptr(dir);
let dir_bytes = dir_cstr.to_bytes();
let dir_str = match std::str::from_utf8(dir_bytes) {
Ok(dir_str) => dir_str,
Err(e) => {
update_last_error(e);
return false;
}
};
if let Err(e) = config.state_builder.map_dir(alias_str, dir_str) {
update_last_error(e);
return false;
}
true
}
#[no_mangle] #[no_mangle]
pub extern "C" fn wasi_config_inherit_stdout(config: &mut wasi_config_t) { pub extern "C" fn wasi_config_inherit_stdout(config: &mut wasi_config_t) {
config.inherit_stdout = true; config.inherit_stdout = true;
@@ -88,8 +146,8 @@ pub extern "C" fn wasi_config_inherit_stdin(config: &mut wasi_config_t) {
} }
#[allow(non_camel_case_types)] #[allow(non_camel_case_types)]
#[repr(C)]
pub struct wasi_env_t { pub struct wasi_env_t {
/// cbindgen:ignore
inner: WasiEnv, inner: WasiEnv,
} }
@@ -239,23 +297,22 @@ pub unsafe extern "C" fn wasi_get_wasi_version(module: &wasm_module_t) -> wasi_v
/// Takes ownership of `wasi_env_t`. /// Takes ownership of `wasi_env_t`.
#[no_mangle] #[no_mangle]
pub unsafe extern "C" fn wasi_get_imports( pub unsafe extern "C" fn wasi_get_imports(
store: Option<NonNull<wasm_store_t>>, store: &wasm_store_t,
module: &wasm_module_t, module: &wasm_module_t,
wasi_env: &wasi_env_t, wasi_env: &wasi_env_t,
imports: *mut *mut wasm_extern_t, imports: &mut wasm_extern_vec_t,
) -> bool { ) -> bool {
wasi_get_imports_inner(store, module, wasi_env, imports).is_some() wasi_get_imports_inner(store, module, wasi_env, imports).is_some()
} }
/// Takes ownership of `wasi_env_t`. /// Takes ownership of `wasi_env_t`.
unsafe extern "C" fn wasi_get_imports_inner( unsafe fn wasi_get_imports_inner(
store: Option<NonNull<wasm_store_t>>, store: &wasm_store_t,
module: &wasm_module_t, module: &wasm_module_t,
wasi_env: &wasi_env_t, wasi_env: &wasi_env_t,
imports: *mut *mut wasm_extern_t, imports: &mut wasm_extern_vec_t,
) -> Option<()> { ) -> Option<()> {
let store_ptr = store?.cast::<Store>(); let store = &store.inner;
let store = store_ptr.as_ref();
let version = c_try!( let version = c_try!(
get_wasi_version(&module.inner, false).ok_or_else(|| CApiError { get_wasi_version(&module.inner, false).ok_or_else(|| CApiError {
@@ -265,28 +322,36 @@ unsafe extern "C" fn wasi_get_imports_inner(
let import_object = generate_import_object_from_env(store, wasi_env.inner.clone(), version); let import_object = generate_import_object_from_env(store, wasi_env.inner.clone(), version);
for (i, it) in module.inner.imports().enumerate() { *imports = module
.inner
.imports()
.map(|import_type| {
let export = c_try!(import_object let export = c_try!(import_object
.resolve_by_name(it.module(), it.name()) .resolve_by_name(import_type.module(), import_type.name())
.ok_or_else(|| CApiError { .ok_or_else(|| CApiError {
msg: format!( msg: format!(
"Failed to resolve import \"{}\" \"{}\"", "Failed to resolve import \"{}\" \"{}\"",
it.module(), import_type.module(),
it.name() import_type.name()
), ),
})); }));
let inner = Extern::from_export(store, export); let inner = Extern::from_export(store, export);
*imports.add(i) = Box::into_raw(Box::new(wasm_extern_t {
Some(Box::new(wasm_extern_t {
instance: None, instance: None,
inner, inner,
})); }))
} })
.collect::<Option<Vec<_>>>()?
.into();
Some(()) Some(())
} }
#[no_mangle] #[no_mangle]
pub unsafe fn wasi_get_start_function(instance: &mut wasm_instance_t) -> Option<Box<wasm_func_t>> { pub unsafe extern "C" fn wasi_get_start_function(
instance: &mut wasm_instance_t,
) -> Option<Box<wasm_func_t>> {
let f = c_try!(instance.inner.exports.get_function("_start")); let f = c_try!(instance.inner.exports.get_function("_start"));
Some(Box::new(wasm_func_t { Some(Box::new(wasm_func_t {
inner: f.clone(), inner: f.clone(),
@@ -295,5 +360,7 @@ pub unsafe fn wasi_get_start_function(instance: &mut wasm_instance_t) -> Option<
} }
/// Delete a `wasm_extern_t` allocated by the API. /// Delete a `wasm_extern_t` allocated by the API.
///
/// cbindgen:ignore
#[no_mangle] #[no_mangle]
pub unsafe fn wasm_extern_delete(_item: Option<Box<wasm_extern_t>>) {} pub unsafe extern "C" fn wasm_extern_delete(_item: Option<Box<wasm_extern_t>>) {}

View File

@@ -0,0 +1,42 @@
//! Wasmer-specific extensions to the Wasm C API.
use super::instance::wasm_instance_t;
use super::module::wasm_module_t;
use super::types::wasm_name_t;
use std::ffi::c_void;
use std::str;
use std::sync::Arc;
#[no_mangle]
pub unsafe extern "C" fn wasm_instance_get_vmctx_ptr(instance: &wasm_instance_t) -> *mut c_void {
instance.inner.vmctx_ptr() as _
}
#[no_mangle]
pub unsafe extern "C" fn wasm_module_name(module: &wasm_module_t, out: &mut wasm_name_t) {
let name = match module.inner.name() {
Some(name) => name,
None => return,
};
*out = name.as_bytes().to_vec().into();
}
#[no_mangle]
pub unsafe extern "C" fn wasm_module_set_name(
module: &mut wasm_module_t,
name: &wasm_name_t,
) -> bool {
let name = match name.into_slice() {
Some(name) => match str::from_utf8(name) {
Ok(name) => name,
Err(_) => return false, // not ideal!
},
None => return false,
};
match Arc::get_mut(&mut module.inner) {
Some(module) => module.set_name(name),
None => false,
}
}

View File

@@ -0,0 +1,14 @@
use super::types::wasm_byte_vec_t;
/// Parses in-memory bytes as either the WAT format, or a binary Wasm
/// module. This is wasmer-specific.
///
/// In case of failure, `wat2wasm` returns `NULL`.
#[cfg(feature = "wat")]
#[no_mangle]
pub unsafe extern "C" fn wat2wasm(wat: &wasm_byte_vec_t) -> Option<Box<wasm_byte_vec_t>> {
let wat: &[u8] = wat.into_slice()?;
let result: wasm_byte_vec_t = c_try!(wasmer::wat2wasm(wat)).into_owned().into();
Some(Box::new(result))
}

View File

@@ -32,6 +32,7 @@ test-emscripten-import-object
# ignore wasm-c-api binaries # ignore wasm-c-api binaries
wasm-c-api-* wasm-c-api-*
test-*
# Unignore files ending with `.c` (i.e. `wasm-c-api-wasi.c`) # Unignore files ending with `.c` (i.e. `wasm-c-api-wasi.c`)
!*.c !*.c

View File

@@ -1,39 +1,22 @@
cmake_minimum_required (VERSION 2.6) cmake_minimum_required (VERSION 2.6)
project (WasmerRuntimeCApiTests) project (WasmerDeprecatedCApiTests)
add_executable(test-context test-context.c)
add_executable(test-exported-memory test-exported-memory.c) add_executable(test-exported-memory test-exported-memory.c)
add_executable(test-exports test-exports.c) add_executable(test-exports test-exports.c)
add_executable(test-globals test-globals.c) add_executable(test-globals test-globals.c)
# trampoline functionality not yet implemented add_executable(test-import-object test-import-object.c)
#add_executable(test-import-function test-import-function.c)
add_executable(test-import-trap test-import-trap.c) add_executable(test-import-trap test-import-trap.c)
add_executable(test-imports test-imports.c) add_executable(test-imports test-imports.c)
add_executable(test-import-object test-import-object.c)
add_executable(test-instantiate test-instantiate.c) add_executable(test-instantiate test-instantiate.c)
add_executable(test-memory test-memory.c) add_executable(test-memory test-memory.c)
add_executable(test-module test-module.c) add_executable(test-module test-module.c)
add_executable(test-module-exports test-module-exports.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-imports test-module-imports.c)
add_executable(test-module-serialize test-module-serialize.c) add_executable(test-module-serialize test-module-serialize.c)
add_executable(test-tables test-tables.c) add_executable(test-tables test-tables.c)
add_executable(test-validate test-validate.c) add_executable(test-validate test-validate.c)
add_executable(test-context test-context.c)
add_executable(test-module-import-instantiate test-module-import-instantiate.c)
# Wasm C API tests
add_executable(wasm-c-api-hello wasm-c-api/example/hello.c)
add_executable(wasm-c-api-memory wasm-c-api/example/memory.c)
add_executable(wasm-c-api-global wasm-c-api/example/global.c)
#add_executable(wasm-c-api-table wasm-c-api/example/table.c)
add_executable(wasm-c-api-serialize wasm-c-api/example/serialize.c)
add_executable(wasm-c-api-callback wasm-c-api/example/callback.c)
#add_executable(wasm-c-api-finalize wasm-c-api/example/finalize.c)
add_executable(wasm-c-api-reflect wasm-c-api/example/reflect.c)
#add_executable(wasm-c-api-start wasm-c-api/example/start.c)
# Custom Wasm C API tests
add_executable(wasm-c-api-wasi wasm-c-api-wasi.c)
if (DEFINED WASI_TESTS) if (DEFINED WASI_TESTS)
add_executable(test-wasi-import-object test-wasi-import-object.c) add_executable(test-wasi-import-object test-wasi-import-object.c)
@@ -43,19 +26,14 @@ if (DEFINED EMSCRIPTEN_TESTS)
add_executable(test-emscripten-import-object test-emscripten-import-object.c) add_executable(test-emscripten-import-object test-emscripten-import-object.c)
endif() endif()
include_directories(wasm-c-api/include) include_directories(../../)
include_directories(..)
find_library( find_library(
WASMER_LIB NAMES libwasmer_c_api.dylib libwasmer_c_api.so wasmer_c_api.dll WASMER_LIB NAMES libwasmer_c_api.dylib libwasmer_c_api.so wasmer_c_api.dll
PATHS ${CMAKE_SOURCE_DIR}/../../../target/release/ PATHS ${CMAKE_SOURCE_DIR}/../../../../target/release/
REQUIRED
) )
if(NOT WASMER_LIB)
message(FATAL_ERROR "wasmer library not found")
endif()
enable_testing() enable_testing()
set( set(
@@ -68,6 +46,10 @@ set(
"/WX" > "/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_link_libraries(test-exported-memory general ${WASMER_LIB})
target_compile_options(test-exported-memory PRIVATE ${COMPILER_OPTIONS}) target_compile_options(test-exported-memory PRIVATE ${COMPILER_OPTIONS})
add_test(test-exported-memory test-exported-memory) add_test(test-exported-memory test-exported-memory)
@@ -80,6 +62,10 @@ target_link_libraries(test-globals general ${WASMER_LIB})
target_compile_options(test-globals PRIVATE ${COMPILER_OPTIONS}) target_compile_options(test-globals PRIVATE ${COMPILER_OPTIONS})
add_test(test-globals test-globals) 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 # trampoline functionality not yet implemented
#target_link_libraries(test-import-function general ${WASMER_LIB}) #target_link_libraries(test-import-function general ${WASMER_LIB})
#target_compile_options(test-import-function PRIVATE ${COMPILER_OPTIONS}) #target_compile_options(test-import-function PRIVATE ${COMPILER_OPTIONS})
@@ -93,24 +79,6 @@ target_link_libraries(test-imports general ${WASMER_LIB})
target_compile_options(test-imports PRIVATE ${COMPILER_OPTIONS}) target_compile_options(test-imports PRIVATE ${COMPILER_OPTIONS})
add_test(test-imports test-imports) add_test(test-imports test-imports)
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)
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()
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()
target_link_libraries(test-instantiate general ${WASMER_LIB}) target_link_libraries(test-instantiate general ${WASMER_LIB})
target_compile_options(test-instantiate PRIVATE ${COMPILER_OPTIONS}) target_compile_options(test-instantiate PRIVATE ${COMPILER_OPTIONS})
add_test(test-instantiate test-instantiate) add_test(test-instantiate test-instantiate)
@@ -127,6 +95,10 @@ target_link_libraries(test-module-exports general ${WASMER_LIB})
target_compile_options(test-module-exports PRIVATE ${COMPILER_OPTIONS}) target_compile_options(test-module-exports PRIVATE ${COMPILER_OPTIONS})
add_test(test-module-exports test-module-exports) 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_link_libraries(test-module-imports general ${WASMER_LIB})
target_compile_options(test-module-imports PRIVATE ${COMPILER_OPTIONS}) target_compile_options(test-module-imports PRIVATE ${COMPILER_OPTIONS})
add_test(test-module-imports test-module-imports) add_test(test-module-imports test-module-imports)
@@ -143,83 +115,16 @@ target_link_libraries(test-validate general ${WASMER_LIB})
target_compile_options(test-validate PRIVATE ${COMPILER_OPTIONS}) target_compile_options(test-validate PRIVATE ${COMPILER_OPTIONS})
add_test(test-validate test-validate) add_test(test-validate test-validate)
target_link_libraries(test-context general ${WASMER_LIB}) if (DEFINED WASI_TESTS)
target_compile_options(test-context PRIVATE ${COMPILER_OPTIONS}) target_link_libraries(test-wasi-import-object general ${WASMER_LIB})
add_test(test-context test-context) target_compile_options(test-wasi-import-object PRIVATE ${COMPILER_OPTIONS})
# TODO: reenable this test
target_link_libraries(test-module-import-instantiate general ${WASMER_LIB}) #add_test(test-wasi-import-object test-wasi-import-object)
target_compile_options(test-module-import-instantiate PRIVATE ${COMPILER_OPTIONS}) endif()
add_test(test-module-import-instantiate test-module-import-instantiate)
target_link_libraries(wasm-c-api-hello general ${WASMER_LIB})
target_compile_options(wasm-c-api-hello PRIVATE ${COMPILER_OPTIONS})
add_test(NAME wasm-c-api-hello
COMMAND wasm-c-api-hello
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/wasm-c-api/example
)
target_link_libraries(wasm-c-api-memory general ${WASMER_LIB})
target_compile_options(wasm-c-api-memory PRIVATE ${COMPILER_OPTIONS})
add_test(NAME wasm-c-api-memory
COMMAND wasm-c-api-memory
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/wasm-c-api/example
)
target_link_libraries(wasm-c-api-global general ${WASMER_LIB})
target_compile_options(wasm-c-api-global PRIVATE ${COMPILER_OPTIONS})
add_test(NAME wasm-c-api-global
COMMAND wasm-c-api-global
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/wasm-c-api/example
)
#target_link_libraries(wasm-c-api-table general ${WASMER_LIB})
#target_compile_options(wasm-c-api-table PRIVATE ${COMPILER_OPTIONS})
#add_test(NAME wasm-c-api-table
# COMMAND wasm-c-api-table
# WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/wasm-c-api/example
#)
target_link_libraries(wasm-c-api-serialize general ${WASMER_LIB})
target_compile_options(wasm-c-api-serialize PRIVATE ${COMPILER_OPTIONS})
add_test(NAME wasm-c-api-serialize
COMMAND wasm-c-api-serialize
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/wasm-c-api/example
)
target_link_libraries(wasm-c-api-callback general ${WASMER_LIB})
target_compile_options(wasm-c-api-callback PRIVATE ${COMPILER_OPTIONS})
add_test(NAME wasm-c-api-callback
COMMAND wasm-c-api-callback
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/wasm-c-api/example
)
#target_link_libraries(wasm-c-api-finalize general ${WASMER_LIB})
#target_compile_options(wasm-c-api-finalize PRIVATE ${COMPILER_OPTIONS})
#add_test(NAME wasm-c-api-finalize
# COMMAND wasm-c-api-finalize
# WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/wasm-c-api/example
#)
target_link_libraries(wasm-c-api-reflect general ${WASMER_LIB})
target_compile_options(wasm-c-api-reflect PRIVATE ${COMPILER_OPTIONS})
add_test(NAME wasm-c-api-reflect
COMMAND wasm-c-api-reflect
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/wasm-c-api/example
)
#target_link_libraries(wasm-c-api-start general ${WASMER_LIB})
#target_compile_options(wasm-c-api-start PRIVATE ${COMPILER_OPTIONS})
#add_test(NAME wasm-c-api-start
# COMMAND wasm-c-api-start
# WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/wasm-c-api/example
#)
set_property(TARGET wasm-c-api-wasi PROPERTY C_STANDARD 11)
target_link_libraries(wasm-c-api-wasi general ${WASMER_LIB})
target_compile_options(wasm-c-api-wasi PRIVATE ${COMPILER_OPTIONS})
add_test(NAME wasm-c-api-wasi
COMMAND wasm-c-api-wasi
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} #/wasm-c-api/example
)
# 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()

View File

@@ -1,5 +1,5 @@
#include <stdio.h> #include <stdio.h>
#include "../wasmer.h" #include "wasmer.h"
#include <assert.h> #include <assert.h>
#include <stdint.h> #include <stdint.h>
#include <string.h> #include <string.h>

View File

@@ -1,5 +1,5 @@
#include <stdio.h> #include <stdio.h>
#include "../wasmer.h" #include "wasmer.h"
#include <assert.h> #include <assert.h>
#include <stdint.h> #include <stdint.h>
#include <string.h> #include <string.h>

View File

@@ -1,5 +1,5 @@
#include <stdio.h> #include <stdio.h>
#include "../wasmer.h" #include "wasmer.h"
#include <assert.h> #include <assert.h>
#include <stdint.h> #include <stdint.h>
#include <string.h> #include <string.h>

View File

@@ -1,6 +1,6 @@
#include <inttypes.h> #include <inttypes.h>
#include <stdio.h> #include <stdio.h>
#include "../wasmer.h" #include "wasmer.h"
#include <assert.h> #include <assert.h>
#include <stdint.h> #include <stdint.h>
#include <string.h> #include <string.h>

View File

@@ -1,5 +1,5 @@
#include <stdio.h> #include <stdio.h>
#include "../wasmer.h" #include "wasmer.h"
#include <assert.h> #include <assert.h>
#include <stdint.h> #include <stdint.h>

Some files were not shown because too many files have changed in this diff Show More