diff --git a/.github/workflows/main.yaml b/.github/workflows/main.yaml index c6c6c898e..6e4b03222 100644 --- a/.github/workflows/main.yaml +++ b/.github/workflows/main.yaml @@ -15,7 +15,7 @@ jobs: uses: actions-rs/toolchain@v1 with: profile: minimal - toolchain: nightly-2019-12-19 + toolchain: 1.45.0 override: true components: rustfmt, clippy - run: make lint @@ -29,7 +29,7 @@ jobs: # uses: actions-rs/toolchain@v1 # with: # profile: minimal - # toolchain: nightly-2019-12-19 + # toolchain: 1.45.0 # override: true # components: rustfmt, clippy # - run: make doc-local @@ -44,13 +44,13 @@ jobs: include: - build: linux os: ubuntu-latest - rust: nightly-2019-12-19 + rust: 1.45.0 - build: macos os: macos-latest - rust: nightly-2019-12-19 + rust: 1.45.0 - build: windows os: windows-latest - rust: nightly-2019-12-19 + rust: 1.45.0 steps: - uses: actions/checkout@v2 - name: Install Rust ${{ matrix.rust }} diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 1685f4722..5665f393d 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -14,7 +14,7 @@ We recommend trying the following commands before sending a pull request to ensu - `cargo fmt --all` Ensures all code is correctly formatted. - Run `cargo test` in the crates that you are modifying. -- Run `cargo build --all` (nightly) or `cargo build --all --exclude wasmer-singlepass-backend` +- Run `cargo build --all`. A comprehensive CI test suite will be run by a Wasmer team member after the PR has been created. @@ -25,9 +25,3 @@ A comprehensive CI test suite will be run by a Wasmer team member after the PR h `Didn't find usable system-wide LLVM` Building Wasmer with the LLVM backend requires LLVM to be installed - -#### Singlepass Nightly Only - -`error[E0554]: #![feature] may not be used on the stable release channel` - -Building Wasmer with the singlepass backend requires the nightly version of Rust diff --git a/Cargo.lock b/Cargo.lock index 73b38fbcb..86e39d73f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -563,14 +563,14 @@ checksum = "9ea835d29036a4087793836fa931b08837ad5e957da9e23886b29586fb9b6650" [[package]] name = "dynasm" -version = "0.6.0" +version = "0.7.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "48be6e89d4c88d2945d5c57d50a2d7c46325a3ae358a11cdf263c545eace97c6" +checksum = "6a93688d3993e998336f7e31d1272bafc078f7665c8b883bd08f140e73d2e9cd" dependencies = [ "bitflags", "byteorder", "lazy_static", - "owning_ref", + "proc-macro-error", "proc-macro2", "quote", "syn", @@ -578,11 +578,12 @@ dependencies = [ [[package]] name = "dynasmrt" -version = "0.6.0" +version = "0.7.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7dce4800e1140e94ad07e35e789df569516fd795223600a96f3b01887a42e0da" +checksum = "acae550ea0de09db4dcb18d4cd49f9f7963edd34783a4571429ba2c4e13e1e09" dependencies = [ "byteorder", + "dynasm", "memmap", ] @@ -1165,15 +1166,6 @@ dependencies = [ "sdl2", ] -[[package]] -name = "owning_ref" -version = "0.4.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6ff55baddef9e4ad00f88b6c743a2a8062d4c6ade126c2a528644b8e444d52ce" -dependencies = [ - "stable_deref_trait", -] - [[package]] name = "parking_lot" version = "0.10.2" diff --git a/Cargo.toml b/Cargo.toml index 74a52b87b..59303d3bf 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -53,6 +53,9 @@ cfg-if = "0.1" members = [ "lib/c-api", ] +exclude = [ + "lib/deprecated", +] [build-dependencies] test-generator = { path = "tests/lib/test-generator" } diff --git a/Makefile b/Makefile index 0b7b99dc6..db099b3c7 100644 --- a/Makefile +++ b/Makefile @@ -10,21 +10,13 @@ endif compilers := -# Singlepass is enabled -RUST_VERSION := $(shell rustc -V) - -ifneq (, $(findstring nightly,$(RUST_VERSION))) - # Singlepass doesn't work yet on Windows - ifneq ($(OS), Windows_NT) - compilers += singlepass - endif -endif - ifeq ($(ARCH), x86_64) # In X64, Cranelift is enabled compilers += cranelift # LLVM could be enabled if not in Windows ifneq ($(OS), Windows_NT) + # Singlepass doesn't work yet on Windows + compilers += singlepass # Autodetect LLVM from llvm-config ifneq (, $(shell which llvm-config)) LLVM_VERSION := $(shell llvm-config --version) @@ -96,7 +88,7 @@ build-capi-llvm: # Testing # ########### -test: $(foreach compiler,$(compilers),test-$(compiler)) test-packages test-examples +test: $(foreach compiler,$(compilers),test-$(compiler)) test-packages test-examples test-deprecated test-singlepass: cargo test --release $(compiler_features) --features "test-singlepass" @@ -135,6 +127,11 @@ test-wasi-unit: test-examples: cargo test --release $(compiler_features) --features wasi --examples +test-deprecated: + cargo test --manifest-path lib/deprecated/runtime-core/Cargo.toml -p wasmer-runtime-core --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 + ############# # Packaging # ############# diff --git a/fuzz/.gitignore b/fuzz/.gitignore new file mode 100644 index 000000000..572e03bdf --- /dev/null +++ b/fuzz/.gitignore @@ -0,0 +1,4 @@ + +target +corpus +artifacts diff --git a/fuzz/Cargo.toml b/fuzz/Cargo.toml new file mode 100644 index 000000000..5750b219e --- /dev/null +++ b/fuzz/Cargo.toml @@ -0,0 +1,49 @@ + +[package] +name = "wasmer-bin-fuzz" +version = "0.0.0" +authors = ["Automatically generated"] +publish = false +edition = "2018" + +[package.metadata] +cargo-fuzz = true + +[dependencies.wasmer] +path = "../lib/api" +[dependencies.wasmer-compiler-cranelift] +path = "../lib/compiler-cranelift" +[dependencies.wasmer-compiler-llvm] +path = "../lib/compiler-llvm" +[dependencies.wasmer-compiler-singlepass] +path = "../lib/compiler-singlepass" +[dependencies.wasmer-engine-jit] +path = "../lib/engine-jit" +[dependencies.wasmer-engine-native] +path = "../lib/engine-native" +[dependencies.libfuzzer-sys] +git = "https://github.com/rust-fuzz/libfuzzer-sys.git" + +# Prevent this from interfering with workspaces +[workspace] +members = ["."] + +[[bin]] +name = "validate" +path = "fuzz_targets/validate.rs" + +[[bin]] +name = "jit_cranelift" +path = "fuzz_targets/jit_cranelift.rs" + +[[bin]] +name = "jit_llvm" +path = "fuzz_targets/jit_llvm.rs" + +[[bin]] +name = "jit_singlepass" +path = "fuzz_targets/jit_singlepass.rs" + +[[bin]] +name = "native_cranelift" +path = "fuzz_targets/native_cranelift.rs" diff --git a/fuzz/README.md b/fuzz/README.md new file mode 100644 index 000000000..55e0fcb16 --- /dev/null +++ b/fuzz/README.md @@ -0,0 +1,52 @@ +This directory contains the fuzz tests for wasmer. To fuzz, we use the `cargo-fuzz` package. + +## Installation + +You may need to install the `cargo-fuzz` package to get the `cargo fuzz` subcommand. Use + +```sh +$ cargo install cargo-fuzz +``` + +`cargo-fuzz` is documented in the [Rust Fuzz Book](https://rust-fuzz.github.io/book/cargo-fuzz.html). + +## Running a fuzzer (validate, jit_llvm, native_cranelift, ...) + +Once `cargo-fuzz` is installed, you can run the `validate` fuzzer with +```sh +cargo fuzz run validate +``` +or the `jit_cranelift` fuzzer +```sh +cargo fuzz run jit_cranelift +``` +See the [fuzz/fuzz_targets](https://github.com/wasmerio/wasmer-reborn/tree/fuzz/fuzz_targets/) directory for the full list of targets. + +You should see output that looks something like this: + +``` +#1408022 NEW cov: 115073 ft: 503843 corp: 4659/1807Kb lim: 4096 exec/s: 889 rss: 857Mb L: 2588/4096 MS: 1 ChangeASCIIInt- +#1408273 NEW cov: 115073 ft: 503844 corp: 4660/1808Kb lim: 4096 exec/s: 888 rss: 857Mb L: 1197/4096 MS: 1 ShuffleBytes- +#1408534 NEW cov: 115073 ft: 503866 corp: 4661/1809Kb lim: 4096 exec/s: 886 rss: 857Mb L: 977/4096 MS: 1 ShuffleBytes- +#1408540 NEW cov: 115073 ft: 503869 corp: 4662/1811Kb lim: 4096 exec/s: 886 rss: 857Mb L: 2067/4096 MS: 1 ChangeBit- +#1408831 NEW cov: 115073 ft: 503945 corp: 4663/1811Kb lim: 4096 exec/s: 885 rss: 857Mb L: 460/4096 MS: 1 CMP- DE: "\x16\x00\x00\x00\x00\x00\x00\x00"- +#1408977 NEW cov: 115073 ft: 503946 corp: 4664/1813Kb lim: 4096 exec/s: 885 rss: 857Mb L: 1972/4096 MS: 1 ShuffleBytes- +#1408999 NEW cov: 115073 ft: 503949 corp: 4665/1814Kb lim: 4096 exec/s: 884 rss: 857Mb L: 964/4096 MS: 2 ChangeBit-ShuffleBytes- +#1409040 NEW cov: 115073 ft: 503950 corp: 4666/1814Kb lim: 4096 exec/s: 884 rss: 857Mb L: 90/4096 MS: 1 ChangeBit- +#1409042 NEW cov: 115073 ft: 503951 corp: 4667/1814Kb lim: 4096 exec/s: 884 rss: 857Mb L: 174/4096 MS: 2 ChangeByte-ChangeASCIIInt- +``` + +It will continue to generate random inputs forever, until it finds a bug or is terminated. The testcases for bugs it finds go into `fuzz/artifacts/jit_cranelift` and you can rerun the fuzzer on a single input by passing it on the command line `cargo fuzz run jit_cranelift my_testcase.wasm`. + +## Seeding the corpus, optional + +The fuzzer works best when it has examples of small Wasm files to start with. Using `wast2json` from [wabt](https://github.com/WebAssembly/wabt), we can easily produce `.wasm` files out of the WebAssembly spec tests. + +```sh +mkdir spec-test-corpus +for i in `find tests/ -name "*.wast"`; do wast2json --enable-all $i -o spec-test-corpus/$(basename $i).json; done +mv spec-test-corpus/*.wasm fuzz/corpus/validate/ +rm -r spec-test-corpus +``` + +The corpus directory is created on the first run of the fuzzer. If it doesn't exist, run it first and then seed the corpus. The fuzzer will pick up new files added to the corpus while it is running. diff --git a/fuzz/fuzz_targets/headless_cranelift.rs b/fuzz/fuzz_targets/headless_cranelift.rs new file mode 100644 index 000000000..526a730a2 --- /dev/null +++ b/fuzz/fuzz_targets/headless_cranelift.rs @@ -0,0 +1,25 @@ +#![no_main] +#[macro_use] +extern crate libfuzzer_sys; + +use wasmer::{imports, Instance, Module, Store}; +use wasmer_compiler_cranelift::Cranelift; +use wasmer_engine_native::Native; + +fuzz_target!(|wasm_bytes: &[u8]| { + let serialized = { + let mut compiler = Cranelift::default(); + let store = Store::new(&Native::new(&mut compiler).engine()); + match Module::validate(&store, wasm_bytes) { + Err(_) => return, + Ok(_) => {} + }; + let module = Module::new(&store, wasm_bytes).unwrap(); + module.serialize().unwrap(); + }; + + let engine = Native::headless().engine(); + let store = Store::new(&engine); + let module = unsafe { Module::deserialize(&store, serialized) }; + let _instance = Instance::new(&module, &imports! {}); +}); diff --git a/fuzz/fuzz_targets/jit_cranelift.rs b/fuzz/fuzz_targets/jit_cranelift.rs new file mode 100644 index 000000000..844582b69 --- /dev/null +++ b/fuzz/fuzz_targets/jit_cranelift.rs @@ -0,0 +1,21 @@ +#![no_main] +#[macro_use] +extern crate libfuzzer_sys; + +use wasmer::{imports, CompilerConfig, Instance, Module, Store}; +use wasmer_compiler_cranelift::Cranelift; +use wasmer_engine_jit::JIT; + +fuzz_target!(|wasm_bytes: &[u8]| { + let mut compiler = Cranelift::default(); + compiler.canonicalize_nans(true); + compiler.enable_verifier(); + let store = Store::new(&JIT::new(&compiler).engine()); + match Module::validate(&store, wasm_bytes) { + Ok(_) => { + let module = Module::new(&store, wasm_bytes).unwrap(); + let _instance = Instance::new(&module, &imports! {}); + } + Err(_) => {} + }; +}); diff --git a/fuzz/fuzz_targets/jit_llvm.rs b/fuzz/fuzz_targets/jit_llvm.rs new file mode 100644 index 000000000..8eb27c91b --- /dev/null +++ b/fuzz/fuzz_targets/jit_llvm.rs @@ -0,0 +1,21 @@ +#![no_main] +#[macro_use] +extern crate libfuzzer_sys; + +use wasmer::{imports, CompilerConfig, Instance, Module, Store}; +use wasmer_compiler_llvm::LLVM; +use wasmer_engine_jit::JIT; + +fuzz_target!(|wasm_bytes: &[u8]| { + let mut compiler = LLVM::default(); + compiler.canonicalize_nans(true); + compiler.enable_verifier(); + let store = Store::new(&JIT::new(&compiler).engine()); + match Module::validate(&store, wasm_bytes) { + Ok(_) => { + let module = Module::new(&store, wasm_bytes).unwrap(); + let _instance = Instance::new(&module, &imports! {}); + } + Err(_) => {} + }; +}); diff --git a/fuzz/fuzz_targets/jit_singlepass.rs b/fuzz/fuzz_targets/jit_singlepass.rs new file mode 100644 index 000000000..504c9ade1 --- /dev/null +++ b/fuzz/fuzz_targets/jit_singlepass.rs @@ -0,0 +1,19 @@ +#![no_main] +#[macro_use] +extern crate libfuzzer_sys; + +use wasmer::{imports, Instance, Module, Store}; +use wasmer_compiler_singlepass::Singlepass; +use wasmer_engine_jit::JIT; + +fuzz_target!(|wasm_bytes: &[u8]| { + let compiler = Singlepass::default(); + let store = Store::new(&JIT::new(&compiler).engine()); + match Module::validate(&store, wasm_bytes) { + Ok(_) => { + let module = Module::new(&store, wasm_bytes).unwrap(); + let _instance = Instance::new(&module, &imports! {}); + } + Err(_) => {} + }; +}); diff --git a/fuzz/fuzz_targets/native_cranelift.rs b/fuzz/fuzz_targets/native_cranelift.rs new file mode 100644 index 000000000..d6ba86034 --- /dev/null +++ b/fuzz/fuzz_targets/native_cranelift.rs @@ -0,0 +1,25 @@ +#![no_main] +#[macro_use] +extern crate libfuzzer_sys; + +use wasmer::{imports, Instance, Module, Store}; +use wasmer_compiler_cranelift::Cranelift; +use wasmer_engine_native::Native; + +fuzz_target!(|wasm_bytes: &[u8]| { + let serialized = { + let mut compiler = Cranelift::default(); + let store = Store::new(&Native::new(&mut compiler).engine()); + match Module::validate(&store, wasm_bytes) { + Err(_) => return, + Ok(_) => {} + }; + let module = Module::new(&store, wasm_bytes).unwrap(); + module.serialize().unwrap() + }; + + let engine = Native::headless().engine(); + let store = Store::new(&engine); + let module = unsafe { Module::deserialize(&store, serialized.as_slice()) }.unwrap(); + let _instance = Instance::new(&module, &imports! {}); +}); diff --git a/fuzz/fuzz_targets/validate.rs b/fuzz/fuzz_targets/validate.rs new file mode 100644 index 000000000..630d5b9e8 --- /dev/null +++ b/fuzz/fuzz_targets/validate.rs @@ -0,0 +1,13 @@ +#![no_main] +#[macro_use] +extern crate libfuzzer_sys; + +use wasmer::{imports, Instance, Module, Store}; +use wasmer_compiler_cranelift::Cranelift; +use wasmer_engine_jit::JIT; + +fuzz_target!(|wasm_bytes: &[u8]| { + let compiler = Cranelift::default(); + let store = Store::new(&JIT::new(&compiler).engine()); + Module::validate(&store, wasm_bytes); +}); diff --git a/lib/api/src/externals/mod.rs b/lib/api/src/externals/mod.rs index 1732854fe..c22941c03 100644 --- a/lib/api/src/externals/mod.rs +++ b/lib/api/src/externals/mod.rs @@ -42,7 +42,8 @@ impl Extern { } } - pub(crate) fn from_export(store: &Store, export: Export) -> Extern { + /// Create an `Extern` from an `Export`. + pub fn from_export(store: &Store, export: Export) -> Extern { match export { Export::Function(f) => Extern::Function(Function::from_export(store, f)), Export::Memory(m) => Extern::Memory(Memory::from_export(store, m)), diff --git a/lib/api/src/lib.rs b/lib/api/src/lib.rs index 636e425b6..dbeb60e2c 100644 --- a/lib/api/src/lib.rs +++ b/lib/api/src/lib.rs @@ -6,7 +6,10 @@ intra_doc_link_resolution_failure )] #![warn(unused_import_braces)] -#![cfg_attr(feature = "cargo-clippy", allow(clippy::new_without_default))] +#![cfg_attr( + feature = "cargo-clippy", + allow(clippy::new_without_default, vtable_address_comparisons) +)] #![cfg_attr( feature = "cargo-clippy", warn( diff --git a/lib/api/tests/externals.rs b/lib/api/tests/externals.rs index 3cf6fecc6..87c19ccbc 100644 --- a/lib/api/tests/externals.rs +++ b/lib/api/tests/externals.rs @@ -172,17 +172,7 @@ fn memory_grow() -> Result<()> { let bad_desc = MemoryType::new(Pages(15), Some(Pages(10)), false); let bad_result = Memory::new(&store, bad_desc); - // due to stack overflow with a modern nightly, we can't update CI to use a version of nightly which will make this work - /*assert!(matches!( - bad_result, - Err(MemoryError::InvalidMemory { .. }) - ));*/ - - assert!(if let Err(MemoryError::InvalidMemory { .. }) = bad_result { - true - } else { - false - }); + assert!(matches!(bad_result, Err(MemoryError::InvalidMemory { .. }))); Ok(()) } diff --git a/lib/compiler-singlepass/Cargo.toml b/lib/compiler-singlepass/Cargo.toml index 7a3b29b44..eafff7bea 100644 --- a/lib/compiler-singlepass/Cargo.toml +++ b/lib/compiler-singlepass/Cargo.toml @@ -19,8 +19,8 @@ rayon = "1.3" hashbrown = { version = "0.8", optional = true } serde = { version = "1.0", features = ["derive"] } more-asserts = "0.2" -dynasm = "0.6" -dynasmrt = "0.6" +dynasm = "0.7" +dynasmrt = "0.7" lazy_static = "1.4" byteorder = "1.3" smallvec = "1" diff --git a/lib/compiler-singlepass/README.md b/lib/compiler-singlepass/README.md index 9f0635eef..4f361469d 100644 --- a/lib/compiler-singlepass/README.md +++ b/lib/compiler-singlepass/README.md @@ -37,13 +37,7 @@ The fact that singlepass is not prone to JIT bombs and offers a very predictable compilation speed makes it ideal for **blockchains** and other systems where fast and consistent compilation times are very critical. -## Requirements - -At the moment, this crate depends on Rust nightly to be compiled, as it uses -[`dynasm-rs`] which can only be compiled in Nightly. - [example]: https://github.com/wasmerio/wasmer-reborn/blob/master/examples/compiler_singlepass.rs [`wasmer-compiler-cranelift`]: https://github.com/wasmerio/wasmer-reborn/tree/master/lib/compiler-cranelift [`wasmer-compiler-llvm`]: https://github.com/wasmerio/wasmer-reborn/tree/master/lib/compiler-llvm -[`dynasm-rs`]: https://github.com/CensoredUsername/dynasm-rs diff --git a/lib/compiler-singlepass/src/lib.rs b/lib/compiler-singlepass/src/lib.rs index 3a890c74a..e549e7d15 100644 --- a/lib/compiler-singlepass/src/lib.rs +++ b/lib/compiler-singlepass/src/lib.rs @@ -7,10 +7,6 @@ //! //! Compared to Cranelift and LLVM, Singlepass compiles much faster but has worse //! runtime performance. -//! -//! > Note: Singlepass currently depends on Rust nightly features. - -#![feature(proc_macro_hygiene)] mod codegen_x64; mod common_decl; diff --git a/lib/deprecated/README.md b/lib/deprecated/README.md index d5bdfa693..b6745d160 100644 --- a/lib/deprecated/README.md +++ b/lib/deprecated/README.md @@ -1,5 +1,30 @@ # Wasmer deprecated packages -We create "wrapping" crates to ease the adodption of new -versions of Wasmer, with minimal or no breaking changes. +## Important Note; Please Read +Thanks to users' feedbacks, collected experience and various usecases, +Wasmer has decided to entirely changed its API to offer the best user +experience and the best features to as many users as possible, just +before the 1.0 release. This new version of Wasmer includes many +improvements in terms of performance or the memory consumption, in +addition to a ton of new features and much better flexibility! + +In order to help our existing users to enjoy the performance boost and +memory improvements without updating their program that much, we have +created a new version of the `wasmer-runtime-core` crate, which is now +*a port* of the new API but with the old API, as much as +possible. Indeed, it was not always possible to provide the exact same +API, but changes are subtle. + +We have carefully documented most of the differences in [the +`runtime-core/CHANGES.md` document](./runtime-core/CHANGES.md). + +It is important to understand the public of this port. We do not +recommend to advanced users of Wasmer to use this port. Advanced API, +like `ModuleInfo` or the `vm` module (incl. `vm::Ctx`) have not been +fully ported because it was very internals to Wasmer. For advanced +users, we highly recommend to migrate to the new version of Wasmer, +which is awesome by the way (completely neutral opinion). The public +for this port is beginners or regular users that do not necesarily +have time to update their code immediately but that want to enjoy a +performance boost and memory improvements. diff --git a/lib/deprecated/runtime-core/CHANGES.md b/lib/deprecated/runtime-core/CHANGES.md new file mode 100644 index 000000000..8fc4290b1 --- /dev/null +++ b/lib/deprecated/runtime-core/CHANGES.md @@ -0,0 +1,698 @@ +# Changes between this port and the old `wasmer-runtime-core` API + +This document lists *only the differences* between the old and the new +API (the port), i.e. API that didn't change are absent. + +## Overall + +* Host function must always take a `vm::Ctx` as first parameter + +## All changes + +By type name in alphabetic order. + +### `Artifact` + +Before: + +```rust +impl Artifact { + fn deserialize(bytes: &[u8]) -> Result; +} +``` + +After: + +```rust +impl Artifact { + unsafe fn deserialize(bytes: &[u8]) -> Result; + fn module(self) -> Module; +} +``` + +The `deserialize` method is now marked as `unsafe` since it is not +checked that `bytes` represent a valid artifact. + +The new `module` method is introduced to fetch the `Module` inside the +artifact. + +### `DynamicFunc` + +Before: + +```rust +impl DynamicFunc { + fn new(signature: Arc, func: F) -> Self; +} +``` + +After: + +```rust +impl DynamicFunc { + fn new(signature: &FuncSig, func: F) -> Self; + fn signature(&self) -> &FuncSig; + fn params(&self) -> &[Type]; + fn returns(&self) -> &[Type]; + fn call(&self, params: &[Value] -> Result, RuntimeError>; +} +``` + +The constructor `new` no longer takes an `Arc` but a reference to +`FuncSig`. + +`signature`, `params`, `returns` and `call` are new +methods. Previously, it was required to convert `DynamicFunc` into +`Func` with `Into>`. Now there is no conversion possible +between the two, and `DynamicFunc` gains its own methods. + +### `DynFunc` + +Before: + +```rust +impl DynFunc { + fn raw(&self) -> *const Func; +} +``` + +After: + +```rust +impl DynFunc { +} +``` + +The `raw` method has been removed. It was present for internal +purposes only, not sure it will impact you. + +### `ExportDescriptor` + +Before: + +```rust +struct ExportDescriptor<'a> { + name: &'a str, + ty: ExternDescriptor, +} +``` + +After: + +```rust +struct ExportDescriptor { + name: String, + ty: ExternDescriptor, +} +``` + +The lifetime on `ExportDescriptor` is no longer necessary: The `name` +field now holds a `String` instead of a `&str`. + +### `Export` + +Before: + +```rust +impl Exports { + fn get<'a, T: Exportable<'a>>(&'a self, name: &str) -> Result; + fn into_iter(&self) -> ExportIter; +} +``` + +After: + +```rust +impl Exports { + fn get<'a, T: Exportable<'a> + Clone + 'a>(&'a self, name: &str) -> Result; + fn iter(&self) -> ExportsIterator>; +} +``` + +The `get` method is different. It returns a `T` where `T` implements +`Exportable<'a>` _and_ `Clone` (that the addition). The returned error +is also `ExportError` instead of `ResolveError`. + +The method `into_iter` is now `iter` and returns references to the +export name and export value. + +### `Func` + +Before: + +```rust +impl Func { + fn params(&self) -> &'static [Type]; + fn returns(&self) -> &'static [Type]; + fn get_vm_func(&self) -> NonNull; +} +``` + +After: + +```rust +impl Func { + fn params(&self) -> &[Type]; + fn returns(&self) -> &[Type]; + fn dyn_call(&self, params: &[Value]) -> Result, RuntimeError>; + fn signature(&self) -> &FuncSig; +} +``` + +The `params` and `returns` return a slice of `[Type]` which has not +the `'static` lifetime. + +The `get_vm_func` method has been removed. It was present for internal +purposes, it unlikely it will have an impact on your project. + +In addition to the `call` method, there is now a `dyn_call` method, +that calls the function with arguments packed in a slice of `Value`. + +Finally, there is a new `signature` method. + +### `FuncSig` + +Before: + +```rust +impl FuncSig { + fn returns(&self) -> &[Type]; + fn check_param_value_types(&self, params: &[Value]) -> bool; +} +``` + +After: + +```rust +impl FuncSig { + fn results(&self) -> &[Type]; +} +``` + +The `returns` method has been renamed `results`. + +The `check_param_value_types` method has been removed, since it is now +possible to compare two `Vec`. + +### `GlobalInit` + +`GlobalInit` has totally changed. It was a `struct`, now it's an +`enum`: + +```rust +enum GlobalInit { + I32Const(i32), + I64Const(i64), + F32Const(f32), + F64Const(f64), + V128Const(V128), + GetGlobal(GlobalIndex), + RefNullConst, + RefFunc(FunctionIndex), +} + +impl GlobalInit { + fn from_value(value: Value) -> Self; + fn to_value(&self) -> Value; +} +``` + +### `HostFunction` + +Before: + +```rust +trait HostFunction { + fn to_raw(self) -> (NonNull, Option>); +} +``` + +After: + +```rust +trait HostFunction { + fn function_body_ptr(self) -> *const VMFunctionBody; +} +``` + +The generic parameters of the `HostFunction` trait has been re-ordered +and a new one has been introduced: `T`. In the new API, it represents +the type of the environment; in this port, it should not be used (or +at worst, use `vm::Ctx`). + +The `to_raw` method, aimed at internal using, has been replaced by +`function_body_ptr`. It is subject to another change, so please don't +use it. + +### `ImportDescriptor` + +Before: + +```rust +struct ImportDescriptor { + namespace: String, +} +``` + +After: + +```rust +struct ImportDescriptor { + module: String, +} +``` + +The `namespace` field has been renamed `module`. + +### `ImportObject` + +Before: + +```rust +impl ImportObject { + fn with_namespace(&self, namespace: &str, f: Func) -> Option; + fn maybe_with_namespace(&self, namespace: &str, f: Func) -> Option; +} +``` + +After: + +```rust +impl ImportObject { + fn call_state_creator(&self) -> Option<(*mut c_void, fn(*mut c_void))>; + fn get_export(&self, module: &str, name: &str) -> Option; + fn clone_ref(&self) -> Self; +} +``` + +The `with_namespace` and `maybe_with_namespace` methods have been +removed. + +The `call_state_creator` method is new, along with `get_export` and +`clone_ref`. + +### `Instance` + +Before: + +```rust +impl Instance { + fn load(&self, loader: T) -> Result; + fn fun(&self, name: &str) -> ResolveResult; + fn resolve_func(&self, name: &str) -> ResolveError; + fn dyn_func(&self, name: &str) -> ResolveResult; + fn call(&self, name: &str, params: &[Value]) -> CallResult>; + fn context(&self) -> &Ctx; + fn context_mut(&mut self) -> &mut Ctx; + fn exports(&self) -> ExportsIter; + fn get_internal(&self, fields: &InternalField) -> u64; + fn set_internal(&self, fields: &InternalField, value: u64); +} +``` + +After: + +```rust +impl Instance { + fn fun(&self, name: &str) -> Result, ExportError>; + fn resolve_func(&self, name: &str) -> Result; + fn dyn_func(&self, name: &str) -> Result; + fn call(&self, name: &str, params: &[Value]) -> Result, Box>; + fn context(&self) -> Ref; + fn context_mut(&mut self) -> RefMut; + fn exports(&self) -> ExportsIterator>; +} +``` + +The `load`, `get_internal` and `set_internal` methods have been removed. + +Some `Result`'s errors have changed: The `func` and `dyn_func` methods +return a `Result<…, ExportError>` instead of `ResolveResult<…>`; The +`resolve_func` method returns a `Result` instead of +`ResolveError`; The `call` method returns a `Result<…, Box>` instead of `CallResult<…>`. + +The `context` and `context_mut` methods respectively return a +`Ref` and `RefMut` instead of `&Ctx` and `&mut Ctx`. + +The `exports` method returns an `ExportsIterator>` instead of `ExportsIter`. That's basically the same. + +### `Memory` + +Before: + +```rust +impl Memory { + fn new(desc: MemoryDescriptor) -> Result; + fn grow(&self, delta: Pages) -> Result; +} + +``` + +After: + +```rust +impl Memory { + fn new(desc: MemoryDescriptor) -> Result; + fn grow(&self, delta: Pages) -> Result; +} +``` + +Only the `Result`'s errors have changed between `new` and `grow` from +respectively `CreationError` and `GrowError` to a general +`MemoryError` type. + +### `MemoryDescriptor` + +Before + +```rust +struct MemoryDescriptor { + memory_type: MemoryType, +} +``` + +After: + +```rust +struct MemoryDescriptor {} +``` + +The `memory_type` field has been removed. + +### `MemoryType` + +Before: + +```rust +enum MemoryType { + Static, + SharedStatic, +} +``` + +After: + +```rust +enum MemoryType { + Static { bound: Pages }, +} +``` + +The `SharedStatic` variant has been removed. + +The `Static` variant is now a structure of type `Static { bound: Pages }`. + +### `Module` + +Before: + +```rust +impl Module { + fn instantiate(&self, import_object: &ImportObject) -> Result; + fn cache(&self) -> Result; + fn custom_sections(&self, key: impl AsRef) -> Option<&[Vec]> +} +``` + +After: + +```rust +impl Module { + fn instantiate(&self, import_object: &ImportObject) -> Result; + fn cache(&self) -> Result; + fn custom_sections(&self, key: impl AsRef) -> Option>>; +} +``` + +The `Result`'s errors of `instantiate` and `cache` have changed +respectively from `Error` and `CacheError` to `InstantiationError` and +`Infallible`. For `cache`, it means that it will never fail. The +`Result` is kept to avoid a change in the API. + +The `custom_sections` method returns an `Option>` instead +of `Option<&[Vec]>`. + +### `ModuleInfo` + +Before: + +```rust +struct ModuleInfo { + backend: String, + custom_sections: HashMap>>, + data_initializers: Vec, + elem_initializers: Vec, + em_symbol_map: Option>, + func_assoc: Map, + generate_debug_info: bool, + globals: Map, + imported_functions: Map, + imported_globals: Map, + imported_memories: Map, + imported_tables: Map, + memories: Map, + name_table: StringTable, + namespace_table: StringTable, + signatures: Map, + start_func: Option, + tables: Map, +} +``` + +After: + +```rust +struct ModuleInfo { + custom_sections: IndexMap, + custom_sections_data: PrimaryMap>, + func_names: HashMap, + functions: PrimaryMap, + global_initializers: PrimaryMap, + globals: PrimaryMap, + id: ModuleId, + imports: IndexMap<(String, String, u32), ImportIndex>, + memories: PrimaryMap, + name: Option, + num_imported_funcs: usize, + num_imported_globals: usize, + num_imported_memories: usize, + num_imported_tables: usize, + passive_data: HashMap>, + passive_elements: HashMap>, + signatures: PrimaryMap, + start_func: Option, + table_elements: Vec, + tables: PrimaryMap, +} +``` + +We are not going to re-phrase the differences here, but clearly a lot +has changed. + +### `Namespace` + +Before: + +```rust +impl Namespace { + fn insert(&mut self, name: S, export: E) -> Option>; +} +``` + +After: + +```rust +impl Namespace { + fn insert(&mut self, name: S, export: E); +} +``` + +The `insert` method no longer returns a value. + +### `NativeWasmType` + +Before: + +```rust +trait NativeWasmType { + const TYPE: Type; + + fn from_binary(bits: u64) -> Self; + fn to_binary(self) -> u64; +} +``` + +After: + +```rust +trait NativeWasmType { + type Abi: Copy + std::fmt::Debug; + const WASM_TYPE: Type; + + fn from_binary(binary: i128) -> Self; + fn to_binary(self) -> i128; + fn into_abi(self) -> Self::Abi; + fn from_abi(abi: Self::Abi) -> Self; + fn to_value(self) -> Value; +} +``` + +The `TYPE` constant has been renamed `WASM_TYPE`. + +The `into_abi`, `from_abi` and `to_value` methods are new, in addition +to the `Abi` type. + +The `to_binary` and `from_binary` methods now take a `i128` instead of +a `u64`. + +### `Pages` + +Before: + +```rust +impl Pages { + fn checked_add(self, rhs: Self) -> Result; +} +``` + +After: + +```rust +impl Pages { + fn checked_add(self, rhs: Self) -> Option; + const fn max_values() -> Self; +} +``` + +The `checked_add` method now returns an `Option` rather than a +`Result`. + +The constant `max_values` function has been introduced. + +### `Table` + +Before: + +```rust +impl Table { + fn new(desc: TableDescriptor) -> Result; + fn set(&self, index: u32, element: T) -> Result<(), TableAccessError>; + fn grow(&self, delta: u32) -> Result; + fn vm_local_table(&mut self) -> *mut LocalTable; +} +``` + +After: + +```rust +impl Table { + fn new(desc: TableDescriptor, initial_value: Value) -> Result; + fn set(&self, index: u32, element: Value) -> Result<(), RuntimeError>; + fn get(&self, index: u32) -> Option; + fn grow(&self, delta: u32, initial_value: Value) -> Result; +} +``` + +The `new` constructor takes an `initial_value` and returns a +`RuntimeError` in case of an error instead of a `CreationError`. + +The `set` method takes a `Value` rather a `T: StorableInTable`. It +also returns a `RuntimeError` rather than a `TableAccessError` in case +of an error. + +The `get` method is new! + +The `grow` method takes an `initial_value`, just like `new`, and also +returns a `RuntimeError` rather than a `GrowError`. + +Finally, the `vm_local_table` method has been removed. It was quite an +internal API, it's unlikely it will impact your project. + +### `TableDescriptor` + +Before: + +```rust +struct TableDescriptor { + element: ElementType, +} +``` + +After: + +```rust +struct TableDescriptor { + ty: Type, +} +``` + +The `element` field has been renamed `ty`. + +A `new` constructor has been introduced: `fn new(ty: Type, minimum: +u32, maximum: Option) -> Self`. + +### `WasmTypeList` + +Before: + +```rust +trait WasmTypeList { + type RetArray: AsMut<[u64]>; + + fn from_ret_array(array: Self::RetArray) -> Self; + fn empty_ret_array() -> Self::RetArray; + fn types() -> &'static [Type]; + fn call(self, f: NonNull, wasm: Wasm, ctx: *mut Ctx) -> Result; +} +``` + +After: + +```rust +trait WasmTypeList { + type Array: AsMut<[i128]>; + + fn from_array(array: Self::Array) -> Self; + fn empty_array(self) -> Self::Array; + fn wasm_types() -> &'static [Type]; + fn from_slice(slice: &[i128]) -> Result; + fn into_array(self) -> Self::Array; +} +``` + +The `RetArray` type has been renamed `Array`. The concrete type must +now implement the `AsMut<[i128]>` trait instead of `AsMut<[u64]>`. + +`from_ret_array` and `empty_ret_array` have been renamed +accordingly like `from_array` and `empty_array`. Note that +`empty_array` is now a method instead of an associated function. + +The `types` function has been renamed `wasm_types`. + +The `call` method has been removed. It was part of an internal API, +it's unlikely it will break your code. + +The `from_slice` constructor and the `into_array` method are new! + +### `WasmHash` + +Before: + +```rust +impl WasmHash { + fn decode(hex_str: &str) -> Result; +} +``` + +After: + +```rust +impl WasmHash { + fn decode(hex_str: &str) -> Result; +} +``` + +The `Result`'s error has changed from `Error` to `DeserializeError` +for the `decode` method. diff --git a/lib/deprecated/runtime-core/Cargo.lock b/lib/deprecated/runtime-core/Cargo.lock new file mode 100644 index 000000000..39bafb7c2 --- /dev/null +++ b/lib/deprecated/runtime-core/Cargo.lock @@ -0,0 +1,1314 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +[[package]] +name = "addr2line" +version = "0.13.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1b6a2d3371669ab3ca9797670853d61402b03d0b4b9ebf33d677dfa720203072" +dependencies = [ + "gimli 0.22.0", +] + +[[package]] +name = "adler" +version = "0.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ee2a4ec343196209d6594e19543ae87a39f96d5534d7174822a3ad825dd6ed7e" + +[[package]] +name = "aho-corasick" +version = "0.7.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "043164d8ba5c4c3035fec9bbee8647c0261d788f3474306f93bb65901cae0e86" +dependencies = [ + "memchr", +] + +[[package]] +name = "arrayref" +version = "0.3.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a4c527152e37cf757a3f78aae5a06fbeefdb07ccc535c980a3208ee3060dd544" + +[[package]] +name = "arrayvec" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cff77d8686867eceff3105329d4698d96c2391c176d5d03adc90c7389162b5b8" + +[[package]] +name = "autocfg" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f8aac770f1885fd7e387acedd76065302551364496e46b3dd00860b2f8359b9d" + +[[package]] +name = "backtrace" +version = "0.3.50" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "46254cf2fdcdf1badb5934448c1bcbe046a56537b3987d96c51a7afc5d03f293" +dependencies = [ + "addr2line", + "cfg-if", + "libc", + "miniz_oxide", + "object 0.20.0", + "rustc-demangle", +] + +[[package]] +name = "bincode" +version = "1.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f30d3a39baa26f9651f17b375061f3233dde33424a8b72b0dbe93a68a0bc896d" +dependencies = [ + "byteorder", + "serde", +] + +[[package]] +name = "bitflags" +version = "1.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cf1de2fe8c75bc145a2f577add951f8134889b4795d47466a54a5c846d691693" + +[[package]] +name = "blake3" +version = "0.3.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "59f88a20f7dc23e3896bcbd85add056543c87215de721468b90e0c85d5a9f365" +dependencies = [ + "arrayref", + "arrayvec", + "cc", + "cfg-if", + "constant_time_eq", + "crypto-mac", + "digest", +] + +[[package]] +name = "byteorder" +version = "1.3.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "08c48aae112d48ed9f069b33538ea9e3e90aa263cfa3d1c24309612b1f7472de" + +[[package]] +name = "cc" +version = "1.0.58" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f9a06fb2e53271d7c279ec1efea6ab691c35a2ae67ec0d91d7acec0caf13b518" + +[[package]] +name = "cfg-if" +version = "0.1.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4785bdd1c96b2a846b2bd7cc02e86b6b3dbf14e7e53446c4f54c92a361040822" + +[[package]] +name = "cloudabi" +version = "0.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ddfc5b9aa5d4507acaf872de71051dfd0e309860e88966e1051e462a077aac4f" +dependencies = [ + "bitflags", +] + +[[package]] +name = "constant_time_eq" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "245097e9a4535ee1e3e3931fcfcd55a796a44c643e8596ff6566d68f09b87bbc" + +[[package]] +name = "cranelift-bforest" +version = "0.65.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d9413a2c6bdb01ab8acc867421bd7343ddea491d015453f4e56f4f60c816d120" +dependencies = [ + "cranelift-entity", +] + +[[package]] +name = "cranelift-codegen" +version = "0.65.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f28d389588c2375bb95292e0bc6cbf010e7f30fb4e9734738b576521b737826a" +dependencies = [ + "byteorder", + "cranelift-bforest", + "cranelift-codegen-meta", + "cranelift-codegen-shared", + "cranelift-entity", + "gimli 0.21.0", + "log", + "regalloc", + "serde", + "smallvec", + "target-lexicon", + "thiserror", +] + +[[package]] +name = "cranelift-codegen-meta" +version = "0.65.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "74dd3cf6f107c1df4c2b8aab91ec4181aee7ff17289673fcbec63325e7e40a83" +dependencies = [ + "cranelift-codegen-shared", + "cranelift-entity", +] + +[[package]] +name = "cranelift-codegen-shared" +version = "0.65.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "efaf050fab2dbf324544489443ff3cc8c67c9420c8902ec6628bd906bd7393e9" + +[[package]] +name = "cranelift-entity" +version = "0.65.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f07eb8aa0a5da94b56339e4e3052c496a3df4354357cd5da8c7b02c6e8f1dc1d" +dependencies = [ + "serde", +] + +[[package]] +name = "cranelift-frontend" +version = "0.65.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0f6fe1d3e968576f4b60d23f40ee90281f8de2cdf23d2110f3b0296ff420555e" +dependencies = [ + "cranelift-codegen", + "log", + "smallvec", + "target-lexicon", +] + +[[package]] +name = "crc32fast" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ba125de2af0df55319f41944744ad91c71113bf74a4646efff39afe1f6842db1" +dependencies = [ + "cfg-if", +] + +[[package]] +name = "crossbeam-deque" +version = "0.7.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9f02af974daeee82218205558e51ec8768b48cf524bd01d550abe5573a608285" +dependencies = [ + "crossbeam-epoch", + "crossbeam-utils", + "maybe-uninit", +] + +[[package]] +name = "crossbeam-epoch" +version = "0.8.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "058ed274caafc1f60c4997b5fc07bf7dc7cca454af7c6e81edffe5f33f70dace" +dependencies = [ + "autocfg", + "cfg-if", + "crossbeam-utils", + "lazy_static", + "maybe-uninit", + "memoffset", + "scopeguard", +] + +[[package]] +name = "crossbeam-queue" +version = "0.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "774ba60a54c213d409d5353bda12d49cd68d14e45036a285234c8d6f91f92570" +dependencies = [ + "cfg-if", + "crossbeam-utils", + "maybe-uninit", +] + +[[package]] +name = "crossbeam-utils" +version = "0.7.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c3c7c73a2d1e9fc0886a08b93e98eb643461230d5f1925e4036204d5f2e261a8" +dependencies = [ + "autocfg", + "cfg-if", + "lazy_static", +] + +[[package]] +name = "crypto-mac" +version = "0.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b584a330336237c1eecd3e94266efb216c56ed91225d634cb2991c5f3fd1aeab" +dependencies = [ + "generic-array", + "subtle", +] + +[[package]] +name = "darling" +version = "0.10.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0d706e75d87e35569db781a9b5e2416cff1236a47ed380831f959382ccd5f858" +dependencies = [ + "darling_core", + "darling_macro", +] + +[[package]] +name = "darling_core" +version = "0.10.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f0c960ae2da4de88a91b2d920c2a7233b400bc33cb28453a2987822d8392519b" +dependencies = [ + "fnv", + "ident_case", + "proc-macro2", + "quote", + "strsim", + "syn", +] + +[[package]] +name = "darling_macro" +version = "0.10.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d9b5a2f4ac4969822c62224815d069952656cadc7084fdca9751e6d959189b72" +dependencies = [ + "darling_core", + "quote", + "syn", +] + +[[package]] +name = "digest" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d3dd60d1080a57a05ab032377049e0591415d2b31afd7028356dbf3cc6dcb066" +dependencies = [ + "generic-array", +] + +[[package]] +name = "dynasm" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "48be6e89d4c88d2945d5c57d50a2d7c46325a3ae358a11cdf263c545eace97c6" +dependencies = [ + "bitflags", + "byteorder", + "lazy_static", + "owning_ref", + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "dynasmrt" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7dce4800e1140e94ad07e35e789df569516fd795223600a96f3b01887a42e0da" +dependencies = [ + "byteorder", + "memmap", +] + +[[package]] +name = "either" +version = "1.5.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bb1f6b1ce1c140482ea30ddd3335fc0024ac7ee112895426e0a629a6c20adfe3" + +[[package]] +name = "enumset" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3691ce759534316ad900d57dd8e688e2c4263f9750c0f7c1e9b9a4516d4ca241" +dependencies = [ + "enumset_derive", + "num-traits", +] + +[[package]] +name = "enumset_derive" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "74bef436ac71820c5cf768d7af9ba33121246b09a00e09a55d94ef8095a875ac" +dependencies = [ + "darling", + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "fallible-iterator" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4443176a9f2c162692bd3d352d745ef9413eec5782a80d8fd6f8a1ac692a07f7" + +[[package]] +name = "fnv" +version = "1.0.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" + +[[package]] +name = "generic-array" +version = "0.14.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "60fb4bb6bba52f78a471264d9a3b7d026cc0af47b22cd2cffbc0b787ca003e63" +dependencies = [ + "typenum", + "version_check", +] + +[[package]] +name = "getrandom" +version = "0.1.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7abc8dd8451921606d809ba32e95b6111925cd2906060d2dcc29c070220503eb" +dependencies = [ + "cfg-if", + "libc", + "wasi", +] + +[[package]] +name = "gimli" +version = "0.21.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bcc8e0c9bce37868955864dbecd2b1ab2bdf967e6f28066d65aaac620444b65c" +dependencies = [ + "fallible-iterator", + "indexmap", + "stable_deref_trait", +] + +[[package]] +name = "gimli" +version = "0.22.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "aaf91faf136cb47367fa430cd46e37a788775e7fa104f8b4bcb3861dc389b724" + +[[package]] +name = "goblin" +version = "0.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d20fd25aa456527ce4f544271ae4fea65d2eda4a6561ea56f39fb3ee4f7e3884" +dependencies = [ + "log", + "plain", + "scroll", +] + +[[package]] +name = "hermit-abi" +version = "0.1.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3deed196b6e7f9e44a2ae8d94225d80302d81208b1bb673fd21fe634645c85a9" +dependencies = [ + "libc", +] + +[[package]] +name = "hex" +version = "0.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "644f9158b2f133fd50f5fb3242878846d9eb792e445c893805ff0e3824006e35" + +[[package]] +name = "ident_case" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b9e0384b61958566e926dc50660321d12159025e767c18e043daf26b70104c39" + +[[package]] +name = "indexmap" +version = "1.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c398b2b113b55809ceb9ee3e753fcbac793f1956663f3c36549c1346015c2afe" +dependencies = [ + "autocfg", + "serde", +] + +[[package]] +name = "inkwell" +version = "0.1.0" +source = "git+https://github.com/theDan64/inkwell?rev=fdf895777e937c974204e879cf1102cf7a727c42#fdf895777e937c974204e879cf1102cf7a727c42" +dependencies = [ + "either", + "inkwell_internals", + "libc", + "llvm-sys", + "once_cell", + "parking_lot", + "regex", +] + +[[package]] +name = "inkwell_internals" +version = "0.2.0" +source = "git+https://github.com/theDan64/inkwell?rev=fdf895777e937c974204e879cf1102cf7a727c42#fdf895777e937c974204e879cf1102cf7a727c42" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "itertools" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "284f18f85651fe11e8a991b2adb42cb078325c996ed026d994719efcfca1d54b" +dependencies = [ + "either", +] + +[[package]] +name = "lazy_static" +version = "1.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" + +[[package]] +name = "leb128" +version = "0.2.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3576a87f2ba00f6f106fdfcd16db1d698d648a26ad8e0573cad8537c3c362d2a" + +[[package]] +name = "libc" +version = "0.2.72" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a9f8082297d534141b30c8d39e9b1773713ab50fdbe4ff30f750d063b3bfd701" + +[[package]] +name = "libloading" +version = "0.6.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2cadb8e769f070c45df05c78c7520eb4cd17061d4ab262e43cfc68b4d00ac71c" +dependencies = [ + "winapi", +] + +[[package]] +name = "llvm-sys" +version = "100.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5545bf9a09267c644e4d0ac68f37ac200af6579ae2e82aebce382654eb4abab1" +dependencies = [ + "cc", + "lazy_static", + "libc", + "regex", + "semver", +] + +[[package]] +name = "lock_api" +version = "0.3.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c4da24a77a3d8a6d4862d95f72e6fdb9c09a643ecdb402d754004a557f2bec75" +dependencies = [ + "scopeguard", +] + +[[package]] +name = "log" +version = "0.4.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4fabed175da42fed1fa0746b0ea71f412aa9d35e76e95e59b192c64b9dc2bf8b" +dependencies = [ + "cfg-if", +] + +[[package]] +name = "mach" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b823e83b2affd8f40a9ee8c29dbc56404c1e34cd2710921f2801e2cf29527afa" +dependencies = [ + "libc", +] + +[[package]] +name = "maybe-uninit" +version = "2.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "60302e4db3a61da70c0cb7991976248362f30319e88850c487b9b95bbf059e00" + +[[package]] +name = "memchr" +version = "2.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3728d817d99e5ac407411fa471ff9800a778d88a24685968b36824eaf4bee400" + +[[package]] +name = "memmap" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6585fd95e7bb50d6cc31e20d4cf9afb4e2ba16c5846fc76793f11218da9c475b" +dependencies = [ + "libc", + "winapi", +] + +[[package]] +name = "memoffset" +version = "0.5.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c198b026e1bbf08a937e94c6c60f9ec4a2267f5b0d2eec9c1b21b061ce2be55f" +dependencies = [ + "autocfg", +] + +[[package]] +name = "miniz_oxide" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "be0f75932c1f6cfae3c04000e40114adf955636e19040f9c0a2c380702aa1c7f" +dependencies = [ + "adler", +] + +[[package]] +name = "more-asserts" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0debeb9fcf88823ea64d64e4a815ab1643f33127d995978e099942ce38f25238" + +[[package]] +name = "num-traits" +version = "0.2.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ac267bcc07f48ee5f8935ab0d24f316fb722d7a1292e2913f0cc196b29ffd611" +dependencies = [ + "autocfg", +] + +[[package]] +name = "num_cpus" +version = "1.13.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "05499f3756671c15885fee9034446956fff3f243d6077b91e5767df161f766b3" +dependencies = [ + "hermit-abi", + "libc", +] + +[[package]] +name = "object" +version = "0.19.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9cbca9424c482ee628fa549d9c812e2cd22f1180b9222c9200fdfa6eb31aecb2" +dependencies = [ + "crc32fast", + "indexmap", +] + +[[package]] +name = "object" +version = "0.20.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1ab52be62400ca80aa00285d25253d7f7c437b7375c4de678f5405d3afe82ca5" + +[[package]] +name = "once_cell" +version = "1.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b631f7e854af39a1739f401cf34a8a013dfe09eac4fa4dba91e9768bd28168d" + +[[package]] +name = "owning_ref" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6ff55baddef9e4ad00f88b6c743a2a8062d4c6ade126c2a528644b8e444d52ce" +dependencies = [ + "stable_deref_trait", +] + +[[package]] +name = "parking_lot" +version = "0.10.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d3a704eb390aafdc107b0e392f56a82b668e3a71366993b5340f5833fd62505e" +dependencies = [ + "lock_api", + "parking_lot_core", +] + +[[package]] +name = "parking_lot_core" +version = "0.7.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d58c7c768d4ba344e3e8d72518ac13e259d7c7ade24167003b8488e10b6740a3" +dependencies = [ + "cfg-if", + "cloudabi", + "libc", + "redox_syscall", + "smallvec", + "winapi", +] + +[[package]] +name = "plain" +version = "0.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b4596b6d070b27117e987119b4dac604f3c58cfb0b191112e24771b2faeac1a6" + +[[package]] +name = "ppv-lite86" +version = "0.2.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "237a5ed80e274dbc66f86bd59c1e25edc039660be53194b5fe0a482e0f2612ea" + +[[package]] +name = "proc-macro2" +version = "1.0.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "beae6331a816b1f65d04c45b078fd8e6c93e8071771f41b8163255bbd8d7c8fa" +dependencies = [ + "unicode-xid", +] + +[[package]] +name = "quote" +version = "1.0.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "aa563d17ecb180e500da1cfd2b028310ac758de548efdd203e18f283af693f37" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "rand" +version = "0.7.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6a6b1679d49b24bbfe0c803429aa1874472f50d9b363131f0e89fc356b544d03" +dependencies = [ + "getrandom", + "libc", + "rand_chacha", + "rand_core", + "rand_hc", +] + +[[package]] +name = "rand_chacha" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f4c8ed856279c9737206bf725bf36935d8666ead7aa69b52be55af369d193402" +dependencies = [ + "ppv-lite86", + "rand_core", +] + +[[package]] +name = "rand_core" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "90bde5296fc891b0cef12a6d03ddccc162ce7b2aff54160af9338f8d40df6d19" +dependencies = [ + "getrandom", +] + +[[package]] +name = "rand_hc" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ca3129af7b92a17112d59ad498c6f81eaf463253766b90396d39ea7a39d6613c" +dependencies = [ + "rand_core", +] + +[[package]] +name = "raw-cpuid" +version = "7.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b4a349ca83373cfa5d6dbb66fd76e58b2cca08da71a5f6400de0a0a6a9bceeaf" +dependencies = [ + "bitflags", + "cc", + "rustc_version", +] + +[[package]] +name = "rayon" +version = "1.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "62f02856753d04e03e26929f820d0a0a337ebe71f849801eea335d464b349080" +dependencies = [ + "autocfg", + "crossbeam-deque", + "either", + "rayon-core", +] + +[[package]] +name = "rayon-core" +version = "1.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e92e15d89083484e11353891f1af602cc661426deb9564c298b270c726973280" +dependencies = [ + "crossbeam-deque", + "crossbeam-queue", + "crossbeam-utils", + "lazy_static", + "num_cpus", +] + +[[package]] +name = "redox_syscall" +version = "0.1.57" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "41cc0f7e4d5d4544e8861606a285bb08d3e70712ccc7d2b84d7c0ccfaf4b05ce" + +[[package]] +name = "regalloc" +version = "0.0.26" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7c03092d79e0fd610932d89ed53895a38c0dd3bcd317a0046e69940de32f1d95" +dependencies = [ + "log", + "rustc-hash", + "smallvec", +] + +[[package]] +name = "regex" +version = "1.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9c3780fcf44b193bc4d09f36d2a3c87b251da4a046c87795a0d35f4f927ad8e6" +dependencies = [ + "aho-corasick", + "memchr", + "regex-syntax", + "thread_local", +] + +[[package]] +name = "regex-syntax" +version = "0.6.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "26412eb97c6b088a6997e05f69403a802a92d520de2f8e63c2b65f9e0f47c4e8" + +[[package]] +name = "region" +version = "2.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "877e54ea2adcd70d80e9179344c97f93ef0dffd6b03e1f4529e6e83ab2fa9ae0" +dependencies = [ + "bitflags", + "libc", + "mach", + "winapi", +] + +[[package]] +name = "remove_dir_all" +version = "0.5.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3acd125665422973a33ac9d3dd2df85edad0f4ae9b00dafb1a05e43a9f5ef8e7" +dependencies = [ + "winapi", +] + +[[package]] +name = "rustc-demangle" +version = "0.1.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4c691c0e608126e00913e33f0ccf3727d5fc84573623b8d65b2df340b5201783" + +[[package]] +name = "rustc-hash" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "08d43f7aa6b08d49f382cde6a7982047c3426db949b1424bc4b7ec9ae12c6ce2" + +[[package]] +name = "rustc_version" +version = "0.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "138e3e0acb6c9fb258b19b67cb8abd63c00679d2851805ea151465464fe9030a" +dependencies = [ + "semver", +] + +[[package]] +name = "scopeguard" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d29ab0c6d3fc0ee92fe66e2d99f700eab17a8d57d1c1d3b748380fb20baa78cd" + +[[package]] +name = "scroll" +version = "0.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "abb2332cb595d33f7edd5700f4cbf94892e680c7f0ae56adab58a35190b66cb1" +dependencies = [ + "scroll_derive", +] + +[[package]] +name = "scroll_derive" +version = "0.10.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e367622f934864ffa1c704ba2b82280aab856e3d8213c84c5720257eb34b15b9" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "semver" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1d7eb9ef2c18661902cc47e535f9bc51b78acd254da71d375c2f6720d9a40403" +dependencies = [ + "semver-parser", +] + +[[package]] +name = "semver-parser" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "388a1df253eca08550bef6c72392cfe7c30914bf41df5269b68cbd6ff8f570a3" + +[[package]] +name = "serde" +version = "1.0.114" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5317f7588f0a5078ee60ef675ef96735a1442132dc645eb1d12c018620ed8cd3" +dependencies = [ + "serde_derive", +] + +[[package]] +name = "serde_bytes" +version = "0.11.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "16ae07dd2f88a366f15bd0632ba725227018c69a1c8550a927324f8eb8368bb9" +dependencies = [ + "serde", +] + +[[package]] +name = "serde_derive" +version = "1.0.114" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2a0be94b04690fbaed37cddffc5c134bf537c8e3329d53e982fe04c374978f8e" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "smallvec" +version = "1.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3757cb9d89161a2f24e1cf78efa0c1fcff485d18e3f55e0aa3480824ddaa0f3f" + +[[package]] +name = "stable_deref_trait" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a8f112729512f8e442d81f95a8a7ddf2b7c6b8a1a6f509a95864142b30cab2d3" + +[[package]] +name = "strsim" +version = "0.9.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6446ced80d6c486436db5c078dde11a9f73d42b57fb273121e160b84f63d894c" + +[[package]] +name = "subtle" +version = "2.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "502d53007c02d7605a05df1c1a73ee436952781653da5d0bf57ad608f66932c1" + +[[package]] +name = "syn" +version = "1.0.34" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "936cae2873c940d92e697597c5eee105fb570cd5689c695806f672883653349b" +dependencies = [ + "proc-macro2", + "quote", + "unicode-xid", +] + +[[package]] +name = "target-lexicon" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ab0e7238dcc7b40a7be719a25365910f6807bd864f4cce6b2e6b873658e2b19d" + +[[package]] +name = "tempfile" +version = "3.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7a6e24d9338a0a5be79593e2fa15a648add6138caa803e2d5bc782c371732ca9" +dependencies = [ + "cfg-if", + "libc", + "rand", + "redox_syscall", + "remove_dir_all", + "winapi", +] + +[[package]] +name = "thiserror" +version = "1.0.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7dfdd070ccd8ccb78f4ad66bf1982dc37f620ef696c6b5028fe2ed83dd3d0d08" +dependencies = [ + "thiserror-impl", +] + +[[package]] +name = "thiserror-impl" +version = "1.0.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bd80fc12f73063ac132ac92aceea36734f04a1d93c1240c6944e23a3b8841793" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "thread_local" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d40c6d1b69745a6ec6fb1ca717914848da4b44ae29d9b3080cbee91d72a69b14" +dependencies = [ + "lazy_static", +] + +[[package]] +name = "tracing" +version = "0.1.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c2e2a2de6b0d5cbb13fc21193a2296888eaab62b6044479aafb3c54c01c29fcd" +dependencies = [ + "cfg-if", + "tracing-attributes", + "tracing-core", +] + +[[package]] +name = "tracing-attributes" +version = "0.1.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f0693bf8d6f2bf22c690fc61a9d21ac69efdbb894a17ed596b9af0f01e64b84b" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "tracing-core" +version = "0.1.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "94ae75f0d28ae10786f3b1895c55fe72e79928fd5ccdebb5438c75e93fec178f" +dependencies = [ + "lazy_static", +] + +[[package]] +name = "typenum" +version = "1.12.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "373c8a200f9e67a0c95e62a4f52fbf80c23b4381c05a17845531982fa99e6b33" + +[[package]] +name = "unicode-xid" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f7fe0bb3479651439c9112f72b6c505038574c9fbb575ed1bf3b797fa39dd564" + +[[package]] +name = "version_check" +version = "0.9.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b5a972e5669d67ba988ce3dc826706fb0a8b01471c088cb0b6110b805cc36aed" + +[[package]] +name = "wasi" +version = "0.9.0+wasi-snapshot-preview1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cccddf32554fecc6acb585f82a32a72e28b48f8c4c1883ddfeeeaa96f7d8e519" + +[[package]] +name = "wasm-common" +version = "1.0.0-alpha.1" +dependencies = [ + "cranelift-entity", + "serde", +] + +[[package]] +name = "wasmer" +version = "1.0.0-alpha.1" +dependencies = [ + "cfg-if", + "indexmap", + "more-asserts", + "target-lexicon", + "thiserror", + "wasm-common", + "wasmer-compiler", + "wasmer-compiler-cranelift", + "wasmer-compiler-llvm", + "wasmer-compiler-singlepass", + "wasmer-engine", + "wasmer-engine-jit", + "wasmer-engine-native", + "wasmer-vm", + "wat", + "winapi", +] + +[[package]] +name = "wasmer-cache" +version = "1.0.0-alpha.1" +dependencies = [ + "blake3", + "hex", + "memmap", + "thiserror", + "wasmer", +] + +[[package]] +name = "wasmer-compiler" +version = "1.0.0-alpha.1" +dependencies = [ + "enumset", + "raw-cpuid", + "serde", + "serde_bytes", + "smallvec", + "target-lexicon", + "thiserror", + "wasm-common", + "wasmer-vm", + "wasmparser", +] + +[[package]] +name = "wasmer-compiler-cranelift" +version = "1.0.0-alpha.1" +dependencies = [ + "cranelift-codegen", + "cranelift-frontend", + "gimli 0.21.0", + "more-asserts", + "rayon", + "serde", + "tracing", + "wasm-common", + "wasmer-compiler", + "wasmer-vm", +] + +[[package]] +name = "wasmer-compiler-llvm" +version = "1.0.0-alpha.1" +dependencies = [ + "byteorder", + "cc", + "goblin", + "inkwell", + "itertools", + "lazy_static", + "libc", + "rayon", + "regex", + "rustc_version", + "semver", + "smallvec", + "target-lexicon", + "wasm-common", + "wasmer-compiler", + "wasmer-vm", +] + +[[package]] +name = "wasmer-compiler-singlepass" +version = "1.0.0-alpha.1" +dependencies = [ + "byteorder", + "dynasm", + "dynasmrt", + "lazy_static", + "more-asserts", + "rayon", + "serde", + "smallvec", + "wasm-common", + "wasmer-compiler", + "wasmer-vm", +] + +[[package]] +name = "wasmer-engine" +version = "1.0.0-alpha.1" +dependencies = [ + "backtrace", + "bincode", + "lazy_static", + "more-asserts", + "rustc-demangle", + "serde", + "serde_bytes", + "target-lexicon", + "thiserror", + "wasm-common", + "wasmer-compiler", + "wasmer-vm", + "winapi", +] + +[[package]] +name = "wasmer-engine-jit" +version = "1.0.0-alpha.1" +dependencies = [ + "bincode", + "cfg-if", + "region", + "serde", + "serde_bytes", + "wasm-common", + "wasmer-compiler", + "wasmer-engine", + "wasmer-vm", + "winapi", +] + +[[package]] +name = "wasmer-engine-native" +version = "1.0.0-alpha.1" +dependencies = [ + "bincode", + "cfg-if", + "leb128", + "libloading", + "serde", + "serde_bytes", + "tempfile", + "tracing", + "wasm-common", + "wasmer-compiler", + "wasmer-engine", + "wasmer-object", + "wasmer-vm", +] + +[[package]] +name = "wasmer-object" +version = "1.0.0-alpha.1" +dependencies = [ + "object 0.19.0", + "thiserror", + "wasm-common", + "wasmer-compiler", +] + +[[package]] +name = "wasmer-runtime-core" +version = "0.18.0" +dependencies = [ + "blake3", + "lazy_static", + "wasm-common", + "wasmer", + "wasmer-cache", + "wasmer-compiler", + "wasmer-compiler-cranelift", + "wasmer-compiler-llvm", + "wasmer-compiler-singlepass", + "wasmer-engine", + "wasmer-engine-jit", + "wasmer-vm", +] + +[[package]] +name = "wasmer-vm" +version = "1.0.0-alpha.1" +dependencies = [ + "backtrace", + "cc", + "cfg-if", + "indexmap", + "libc", + "memoffset", + "more-asserts", + "region", + "serde", + "thiserror", + "wasm-common", + "winapi", +] + +[[package]] +name = "wasmparser" +version = "0.57.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "32fddd575d477c6e9702484139cf9f23dcd554b06d185ed0f56c857dd3a47aa6" + +[[package]] +name = "wast" +version = "21.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b1844f66a2bc8526d71690104c0e78a8e59ffa1597b7245769d174ebb91deb5" +dependencies = [ + "leb128", +] + +[[package]] +name = "wat" +version = "1.0.22" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ce85d72b74242c340e9e3492cfb602652d7bb324c3172dd441b5577e39a2e18c" +dependencies = [ + "wast", +] + +[[package]] +name = "winapi" +version = "0.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419" +dependencies = [ + "winapi-i686-pc-windows-gnu", + "winapi-x86_64-pc-windows-gnu", +] + +[[package]] +name = "winapi-i686-pc-windows-gnu" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" + +[[package]] +name = "winapi-x86_64-pc-windows-gnu" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" diff --git a/lib/deprecated/runtime-core/Cargo.toml b/lib/deprecated/runtime-core/Cargo.toml new file mode 100644 index 000000000..a0832312d --- /dev/null +++ b/lib/deprecated/runtime-core/Cargo.toml @@ -0,0 +1,39 @@ +[package] +name = "wasmer-runtime-core" +version = "0.18.0" +description = "Wasmer runtime core library" +license = "MIT" +authors = ["The Wasmer Engineering Team "] +repository = "https://github.com/wasmerio/wasmer" +keywords = ["wasm", "webassembly", "runtime"] +categories = ["wasm"] +edition = "2018" + +[badges] +maintenance = { status = "deprecated" } + +[dependencies] +wasm-common = { path = "../../wasm-common", version = "1.0.0-alpha.1" } +wasmer = { path = "../../api", version = "1.0.0-alpha.1" } +wasmer-cache = { path = "../../cache", version = "1.0.0-alpha.1" } +wasmer-compiler = { path = "../../compiler", version = "1.0.0-alpha.1", features = ["translator"] } +wasmer-compiler-llvm = { path = "../../compiler-llvm", version = "1.0.0-alpha.1", optional = true } +wasmer-compiler-cranelift = { path = "../../compiler-cranelift", version = "1.0.0-alpha.1", optional = true } +wasmer-compiler-singlepass = { path = "../../compiler-singlepass", version = "1.0.0-alpha.1", optional = true } +wasmer-engine = { path = "../../engine", version = "1.0.0-alpha.1" } +wasmer-engine-jit = { path = "../../engine-jit", version = "1.0.0-alpha.1" } +wasmer-vm = { path = "../../vm", version = "1.0.0-alpha.1" } +lazy_static = "1.4" + +[build-dependencies] +blake3 = "0.3.4" + +[features] +default = ["wasmer/default"] +cranelift = ["wasmer/cranelift", "wasmer-compiler-cranelift"] +llvm = ["wasmer/llvm", "wasmer-compiler-llvm"] +singlepass = ["wasmer/singlepass", "wasmer-compiler-singlepass"] +default-backend-cranelift = ["cranelift"] +default-backend-llvm = ["llvm"] +default-backend-singlepass = ["singlepass"] +dynamicfunc-fat-closures = [] \ No newline at end of file diff --git a/lib/deprecated/runtime-core/README.md b/lib/deprecated/runtime-core/README.md new file mode 100644 index 000000000..0a81b70ee --- /dev/null +++ b/lib/deprecated/runtime-core/README.md @@ -0,0 +1,41 @@ +# Wasmer Runtime Core Library [DEPRECATED] + +## Important Note; Please Read + +Thanks to users' feedbacks, collected experience and various usecases, +Wasmer has decided to entirely changed its API to offer the best user +experience and the best features to as many users as possible, just +before the 1.0 release. This new version of Wasmer includes many +improvements in terms of performance or the memory consumption, in +addition to a ton of new features and much better flexibility! + +In order to help our existing users to enjoy the performance boost and +memory improvements without updating their program that much, we have +created a new version of the `wasmer-runtime-core` crate, which is now +*a port* of the new API but with the old API, as much as +possible. Indeed, it was not always possible to provide the exact same +API, but changes are subtle. + +We have carefully documented most of the differences in [the +`CHANGES.md` document](./CHANGES.md). + +It is important to understand the public of this port. We do not +recommend to advanced users of Wasmer to use this port. Advanced API, +like `ModuleInfo` or the `vm` module (incl. `vm::Ctx`) have not been +fully ported because it was very internals to Wasmer. For advanced +users, we highly recommend to migrate to the new version of Wasmer, +which is awesome by the way (completely neutral opinion). The public +for this port is beginners or regular users that do not necesarily +have time to update their code immediately but that want to enjoy a +performance boost and memory improvements. + +## Introduction + +The `wasmer-runtime-core` was the entry point to the Wasmer Runtime, +by providing common types to compile and to instantiate a WebAssembly +module. + +Most Wasmer users should prefer the API which is re-exported by the +[`wasmer-runtime`](https://github.com/wasmerio/wasmer-reborn/tree/master/lib/deprecated/runtime) +library by default. This crate provides additional APIs which may be +useful to users that wish to customize the Wasmer runtime. diff --git a/lib/deprecated/runtime-core/build.rs b/lib/deprecated/runtime-core/build.rs new file mode 100644 index 000000000..38c38661f --- /dev/null +++ b/lib/deprecated/runtime-core/build.rs @@ -0,0 +1,29 @@ +use blake3::Hasher; +use std::{env, fs, io::Write, path::PathBuf}; + +const WASMER_VERSION: &'static str = env!("CARGO_PKG_VERSION"); + +fn main() { + // `wasmer_version_hash.txt` + { + let mut hasher = Hasher::new(); + hasher.update(WASMER_VERSION.as_bytes()); + + let hasher = hasher.finalize(); + let hash_string = hasher.to_hex().as_str().to_owned(); + + let crate_dir = env::var("OUT_DIR").unwrap(); + let wasmer_version_hash_file = { + let mut path = PathBuf::from(&crate_dir); + path.push("wasmer_version_hash.txt"); + path + }; + + let mut f_out = fs::File::create(wasmer_version_hash_file) + .expect("Could not create file for wasmer hash value"); + + f_out + .write_all(hash_string.as_bytes()) + .expect("Could not write to file for wasmer hash value"); + } +} diff --git a/lib/deprecated/runtime-core/doc/new-api/artifact.rs b/lib/deprecated/runtime-core/doc/new-api/artifact.rs new file mode 100644 index 000000000..9ab8dc364 --- /dev/null +++ b/lib/deprecated/runtime-core/doc/new-api/artifact.rs @@ -0,0 +1,8 @@ +struct Artifact {} + +impl Artifact { + unsafe fn deserialize(bytes: &[u8]) -> Result; + fn info(&self) -> &ModuleInfo; + fn serialize(&self) -> Result, Error>; + fn module(self) -> Module; +} diff --git a/lib/deprecated/runtime-core/doc/new-api/bytes.rs b/lib/deprecated/runtime-core/doc/new-api/bytes.rs new file mode 100644 index 000000000..0ba4d85df --- /dev/null +++ b/lib/deprecated/runtime-core/doc/new-api/bytes.rs @@ -0,0 +1 @@ +struct Bytes(pub usize); diff --git a/lib/deprecated/runtime-core/doc/new-api/dynamicfunc.rs b/lib/deprecated/runtime-core/doc/new-api/dynamicfunc.rs new file mode 100644 index 000000000..427e2a0b6 --- /dev/null +++ b/lib/deprecated/runtime-core/doc/new-api/dynamicfunc.rs @@ -0,0 +1,9 @@ +struct DynamicFunc {} + +impl DynamicFunc { + fn new(signature: &FuncSig, func: F) -> Self; + fn signature(&self) -> &FuncSig; + fn params(&self) -> &[Type]; + fn returns(&self) -> &[Type]; + fn call(&self, params: &[Value]) -> Result, RuntimeError>; +} diff --git a/lib/deprecated/runtime-core/doc/new-api/dynfunc.rs b/lib/deprecated/runtime-core/doc/new-api/dynfunc.rs new file mode 100644 index 000000000..3c7a31930 --- /dev/null +++ b/lib/deprecated/runtime-core/doc/new-api/dynfunc.rs @@ -0,0 +1,6 @@ +struct DynFunc {} + +impl DynFunc { + fn call(&self, params: &[Value]) -> Result, CallError>; + fn signature(&self) -> &FuncSig; +} diff --git a/lib/deprecated/runtime-core/doc/new-api/export_descriptor.rs b/lib/deprecated/runtime-core/doc/new-api/export_descriptor.rs new file mode 100644 index 000000000..7f45d5630 --- /dev/null +++ b/lib/deprecated/runtime-core/doc/new-api/export_descriptor.rs @@ -0,0 +1,4 @@ +struct ExportDescriptor { + name: String, + ty: ExternDescriptor, +} diff --git a/lib/deprecated/runtime-core/doc/new-api/exports.rs b/lib/deprecated/runtime-core/doc/new-api/exports.rs new file mode 100644 index 000000000..aab0311ad --- /dev/null +++ b/lib/deprecated/runtime-core/doc/new-api/exports.rs @@ -0,0 +1,6 @@ +struct Exports {} + +impl Exports { + fn get<'a, T: Exportable<'a> + Clone + 'a>(&'a self, name: &str) -> Result; + fn iter(&self) -> ExportsIterator>; +} diff --git a/lib/deprecated/runtime-core/doc/new-api/func.rs b/lib/deprecated/runtime-core/doc/new-api/func.rs new file mode 100644 index 000000000..bab0f7e6e --- /dev/null +++ b/lib/deprecated/runtime-core/doc/new-api/func.rs @@ -0,0 +1,10 @@ +struct Func {} + +impl Func { + fn new(func: F) -> Self; + fn params(&self) -> &[Type]; + fn returns(&self) -> &[Type]; + fn call(...) -> Result; + fn dyn_call(&self, params: &[Value]) -> Result, RuntimeError>; + fn signature(&self) -> &FuncSig; +} diff --git a/lib/deprecated/runtime-core/doc/new-api/func_sig.rs b/lib/deprecated/runtime-core/doc/new-api/func_sig.rs new file mode 100644 index 000000000..740bb0aa3 --- /dev/null +++ b/lib/deprecated/runtime-core/doc/new-api/func_sig.rs @@ -0,0 +1,7 @@ +struct FuncSig {} + +impl FuncSig { + fn new(params: Params, returns: Returns) -> Self; + fn params(&self) -> &[Type]; + fn results(&self) -> &[Type]; +} diff --git a/lib/deprecated/runtime-core/doc/new-api/global.rs b/lib/deprecated/runtime-core/doc/new-api/global.rs new file mode 100644 index 000000000..9311cd8bc --- /dev/null +++ b/lib/deprecated/runtime-core/doc/new-api/global.rs @@ -0,0 +1,9 @@ +struct Global {} + +impl Global { + fn new(value: Value) -> Self; + fn new_mutable(value: Value) -> Self; + fn descriptor(&self) -> GlobalDescriptor; + fn set(&self, value: Value); + fn get(&self) -> Value; +} diff --git a/lib/deprecated/runtime-core/doc/new-api/global_descriptor.rs b/lib/deprecated/runtime-core/doc/new-api/global_descriptor.rs new file mode 100644 index 000000000..05dd84898 --- /dev/null +++ b/lib/deprecated/runtime-core/doc/new-api/global_descriptor.rs @@ -0,0 +1,4 @@ +struct GlobalDescriptor { + mutable: bool, + ty: Type, +} diff --git a/lib/deprecated/runtime-core/doc/new-api/global_init.rs b/lib/deprecated/runtime-core/doc/new-api/global_init.rs new file mode 100644 index 000000000..1a6a857aa --- /dev/null +++ b/lib/deprecated/runtime-core/doc/new-api/global_init.rs @@ -0,0 +1,15 @@ +enum GlobalInit { + I32Const(i32), + I64Const(i64), + F32Const(f32), + F64Const(f64), + V128Const(V128), + GetGlobal(GlobalIndex), + RefNullConst, + RefFunc(FunctionIndex), +} + +impl GlobalInit { + fn from_value(value: Value) -> Self; + fn to_value(&self) -> Value; +} diff --git a/lib/deprecated/runtime-core/doc/new-api/host_function.rs b/lib/deprecated/runtime-core/doc/new-api/host_function.rs new file mode 100644 index 000000000..6eb82dfa8 --- /dev/null +++ b/lib/deprecated/runtime-core/doc/new-api/host_function.rs @@ -0,0 +1,3 @@ +trait HostFunction { + fn function_body_ptr(self) -> *const VMFunctionBody; +} diff --git a/lib/deprecated/runtime-core/doc/new-api/import_descriptor.rs b/lib/deprecated/runtime-core/doc/new-api/import_descriptor.rs new file mode 100644 index 000000000..59b9f91d6 --- /dev/null +++ b/lib/deprecated/runtime-core/doc/new-api/import_descriptor.rs @@ -0,0 +1,5 @@ +struct ImportDescriptor { + module: String, + name: String, + ty: ExternDescriptor, +} diff --git a/lib/deprecated/runtime-core/doc/new-api/import_object.rs b/lib/deprecated/runtime-core/doc/new-api/import_object.rs new file mode 100644 index 000000000..a6e499667 --- /dev/null +++ b/lib/deprecated/runtime-core/doc/new-api/import_object.rs @@ -0,0 +1,11 @@ +struct ImportObject {} + +impl ImportObject { + fn new() -> Self; + fn new_with_data(state_creator: F) -> Self; + fn register(&mut self, name: S, namespace: N) -> Option>; + fn contains_namespace(&self, name: &str) -> bool; + fn call_state_creator(&self) -> Option<(*mut c_void, fn(*mut c_void))>; + fn get_export(&self, module: &str, name: &str) -> Option; + fn clone_ref(&self) -> Self; +} diff --git a/lib/deprecated/runtime-core/doc/new-api/instance.rs b/lib/deprecated/runtime-core/doc/new-api/instance.rs new file mode 100644 index 000000000..0c96618c6 --- /dev/null +++ b/lib/deprecated/runtime-core/doc/new-api/instance.rs @@ -0,0 +1,14 @@ +struct Instance { + exports: Exports, +} + +impl Instance { + fn fun(&self, name: &str) -> Result, ExportError>; + fn resolve_func(&self, name: &str) -> Result; + fn dyn_func(&self, name: &str) -> Result; + fn call(&self, name: &str, params: &[Value]) -> Result, Box>; + fn context(&self) -> Ref; + fn context_mut(&mut self) -> RefMut; + fn exports(&self) -> ExportsIterator>; + fn module(&self) -> Module; +} diff --git a/lib/deprecated/runtime-core/doc/new-api/memory.rs b/lib/deprecated/runtime-core/doc/new-api/memory.rs new file mode 100644 index 000000000..c6dcee831 --- /dev/null +++ b/lib/deprecated/runtime-core/doc/new-api/memory.rs @@ -0,0 +1,9 @@ +struct Memory {} + +impl Memory { + fn new(desc: MemoryDescriptor) -> Result; + fn descriptor(&self) -> MemoryDescriptor; + fn grow(&self, delta: Pages) -> Result; + fn size(&self) -> Pages; + fn view(&self) -> MemoryView; +} diff --git a/lib/deprecated/runtime-core/doc/new-api/memory_descriptor.rs b/lib/deprecated/runtime-core/doc/new-api/memory_descriptor.rs new file mode 100644 index 000000000..88cee38a0 --- /dev/null +++ b/lib/deprecated/runtime-core/doc/new-api/memory_descriptor.rs @@ -0,0 +1,5 @@ +struct MemoryDescriptor { + minimum: Pages, + maximum: Option, + shared: bool, +} diff --git a/lib/deprecated/runtime-core/doc/new-api/memory_type.rs b/lib/deprecated/runtime-core/doc/new-api/memory_type.rs new file mode 100644 index 000000000..4a8d9b9e6 --- /dev/null +++ b/lib/deprecated/runtime-core/doc/new-api/memory_type.rs @@ -0,0 +1,4 @@ +enum MemoryType { + Dynamic, + Static { bound: Pages }, +} diff --git a/lib/deprecated/runtime-core/doc/new-api/memory_view.rs b/lib/deprecated/runtime-core/doc/new-api/memory_view.rs new file mode 100644 index 000000000..e58fec52c --- /dev/null +++ b/lib/deprecated/runtime-core/doc/new-api/memory_view.rs @@ -0,0 +1,5 @@ +struct MemoryView {} + +impl MemoryView { + fn atomically(&self) -> MemoryView<'a, T::Output, Atomically>; +} diff --git a/lib/deprecated/runtime-core/doc/new-api/module.rs b/lib/deprecated/runtime-core/doc/new-api/module.rs new file mode 100644 index 000000000..87af11fbd --- /dev/null +++ b/lib/deprecated/runtime-core/doc/new-api/module.rs @@ -0,0 +1,10 @@ +struct Module {} + +impl Module { + fn instantiate(&self, import_object: &ImportObject) -> Result; + fn cache(&self) -> Result; + fn info(&self) -> &ModuleInfo; + fn imports(&self) -> Vec; + fn exports(&self) -> Vec; + fn custom_sections(&self, key: impl AsRef) -> Option>>; +} diff --git a/lib/deprecated/runtime-core/doc/new-api/module_info.rs b/lib/deprecated/runtime-core/doc/new-api/module_info.rs new file mode 100644 index 000000000..d92ce28ec --- /dev/null +++ b/lib/deprecated/runtime-core/doc/new-api/module_info.rs @@ -0,0 +1,23 @@ +struct ModuleInfo { + custom_sections: IndexMap, + custom_sections_data: PrimaryMap>, + exports: IndexMap, + func_names: HashMap, + functions: PrimaryMap, + global_initializers: PrimaryMap, + globals: PrimaryMap, + id: ModuleId, + imports: IndexMap<(String, String, u32), ImportIndex>, + memories: PrimaryMap, + name: Option, + num_imported_funcs: usize, + num_imported_globals: usize, + num_imported_memories: usize, + num_imported_tables: usize, + passive_data: HashMap>, + passive_elements: HashMap>, + signatures: PrimaryMap, + start_func: Option, + table_elements: Vec, + tables: PrimaryMap, +} diff --git a/lib/deprecated/runtime-core/doc/new-api/namespace.rs b/lib/deprecated/runtime-core/doc/new-api/namespace.rs new file mode 100644 index 000000000..443813959 --- /dev/null +++ b/lib/deprecated/runtime-core/doc/new-api/namespace.rs @@ -0,0 +1,7 @@ +struct Namespace {} + +impl Namespace { + fn new() -> Self; + fn insert(&mut self, name: S, export: E); + fn contains_key(&mut self, key: S) -> bool; +} diff --git a/lib/deprecated/runtime-core/doc/new-api/native_wasm_type.rs b/lib/deprecated/runtime-core/doc/new-api/native_wasm_type.rs new file mode 100644 index 000000000..665f35897 --- /dev/null +++ b/lib/deprecated/runtime-core/doc/new-api/native_wasm_type.rs @@ -0,0 +1,10 @@ +trait NativeWasmType { + type Abi: Copy + std::fmt::Debug; + const WASM_TYPE: Type; + + fn from_binary(binary: i128) -> Self; + fn to_binary(self) -> i128; + fn into_abi(self) -> Self::Abi; + fn from_abi(abi: Self::Abi) -> Self; + fn to_value(self) -> Value; +} diff --git a/lib/deprecated/runtime-core/doc/new-api/pages.rs b/lib/deprecated/runtime-core/doc/new-api/pages.rs new file mode 100644 index 000000000..11e28c330 --- /dev/null +++ b/lib/deprecated/runtime-core/doc/new-api/pages.rs @@ -0,0 +1,7 @@ +struct Pages(pub u32); + +impl Pages { + fn checked_add(self, rhs: Self) -> Option; + fn bytes(self) -> Bytes; + const fn max_values() -> Self; +} diff --git a/lib/deprecated/runtime-core/doc/new-api/table.rs b/lib/deprecated/runtime-core/doc/new-api/table.rs new file mode 100644 index 000000000..ed24ac60b --- /dev/null +++ b/lib/deprecated/runtime-core/doc/new-api/table.rs @@ -0,0 +1,10 @@ +struct Table {} + +impl Table { + fn new(desc: TableDescriptor, initial_value: Value) -> Result; + fn descriptor(&self) -> TableDescriptor; + fn set(&self, index: u32, element: Value) -> Result<(), RuntimeError>; + fn get(&self, index: u32) -> Option; + fn size(&self) -> u32; + fn grow(&self, delta: u32, initial_value: Value) -> Result; +} diff --git a/lib/deprecated/runtime-core/doc/new-api/table_descriptor.rs b/lib/deprecated/runtime-core/doc/new-api/table_descriptor.rs new file mode 100644 index 000000000..dede0a884 --- /dev/null +++ b/lib/deprecated/runtime-core/doc/new-api/table_descriptor.rs @@ -0,0 +1,9 @@ +struct TableDescriptor { + ty: Type, + minimum: u32, + maximum: Option, +} + +impl TableDescriptor { + fn new(ty: Type, minimum: u32, maximum: Option) -> Self; +} diff --git a/lib/deprecated/runtime-core/doc/new-api/wasm_extern_type.rs b/lib/deprecated/runtime-core/doc/new-api/wasm_extern_type.rs new file mode 100644 index 000000000..e3aa4572a --- /dev/null +++ b/lib/deprecated/runtime-core/doc/new-api/wasm_extern_type.rs @@ -0,0 +1,6 @@ +trait WasmExternType { + type Native: NativeWasmType; + + fn from_native(native: Self::Native) -> Self; + fn to_native(self) -> Self::Native; +} diff --git a/lib/deprecated/runtime-core/doc/new-api/wasm_type_list.rs b/lib/deprecated/runtime-core/doc/new-api/wasm_type_list.rs new file mode 100644 index 000000000..33c1966f3 --- /dev/null +++ b/lib/deprecated/runtime-core/doc/new-api/wasm_type_list.rs @@ -0,0 +1,12 @@ +trait WasmTypeList { + type CStruct; + type Array: AsMut<[i128]>; + + fn from_array(array: Self::Array) -> Self; + fn empty_array(self) -> Self::Array; + fn from_c_struct(c_struct: Self::CStruct) -> Self; + fn into_c_struct(self) -> Self::CStruct; + fn wasm_types() -> &'static [Type]; + fn from_slice(slice: &[i128]) -> Result; + fn into_array(self) -> Self::Array; +} diff --git a/lib/deprecated/runtime-core/doc/new-api/wasmhash.rs b/lib/deprecated/runtime-core/doc/new-api/wasmhash.rs new file mode 100644 index 000000000..7215bbd85 --- /dev/null +++ b/lib/deprecated/runtime-core/doc/new-api/wasmhash.rs @@ -0,0 +1,7 @@ +struct WasmHash {} + +impl WasmHash { + fn generate(wasm: &[u8]) -> Self; + fn encode(self) -> String; + fn decode(hex_str: &str) -> Result; +} diff --git a/lib/deprecated/runtime-core/doc/old-api/artifact.rs b/lib/deprecated/runtime-core/doc/old-api/artifact.rs new file mode 100644 index 000000000..75184b8fd --- /dev/null +++ b/lib/deprecated/runtime-core/doc/old-api/artifact.rs @@ -0,0 +1,7 @@ +struct Artifact {} + +impl Artifact { + fn deserialize(bytes: &[u8]) -> Result; + fn info(&self) -> &ModuleInfo; + fn serialize(&self) -> Result, Error>; +} diff --git a/lib/deprecated/runtime-core/doc/old-api/bytes.rs b/lib/deprecated/runtime-core/doc/old-api/bytes.rs new file mode 100644 index 000000000..0ba4d85df --- /dev/null +++ b/lib/deprecated/runtime-core/doc/old-api/bytes.rs @@ -0,0 +1 @@ +struct Bytes(pub usize); diff --git a/lib/deprecated/runtime-core/doc/old-api/dynamicfunc.rs b/lib/deprecated/runtime-core/doc/old-api/dynamicfunc.rs new file mode 100644 index 000000000..423eb7d97 --- /dev/null +++ b/lib/deprecated/runtime-core/doc/old-api/dynamicfunc.rs @@ -0,0 +1,5 @@ +struct DynamicFunc {} + +impl DynamicFunc { + fn new(signature: Arc, func: F) -> Self; +} diff --git a/lib/deprecated/runtime-core/doc/old-api/dynfunc.rs b/lib/deprecated/runtime-core/doc/old-api/dynfunc.rs new file mode 100644 index 000000000..c82a25102 --- /dev/null +++ b/lib/deprecated/runtime-core/doc/old-api/dynfunc.rs @@ -0,0 +1,7 @@ +struct DynFunc {} + +impl DynFunc { + fn call(&self, params: &[Value]) -> Result, CallError>; + fn signature(&self) -> &FuncSig; + fn raw(&self) -> *const Func; +} diff --git a/lib/deprecated/runtime-core/doc/old-api/export_descriptor.rs b/lib/deprecated/runtime-core/doc/old-api/export_descriptor.rs new file mode 100644 index 000000000..4fc6a0c25 --- /dev/null +++ b/lib/deprecated/runtime-core/doc/old-api/export_descriptor.rs @@ -0,0 +1,4 @@ +struct ExportDescriptor<'a> { + name: &'a str, + ty: ExternDescriptor, +} diff --git a/lib/deprecated/runtime-core/doc/old-api/exports.rs b/lib/deprecated/runtime-core/doc/old-api/exports.rs new file mode 100644 index 000000000..25a8c868b --- /dev/null +++ b/lib/deprecated/runtime-core/doc/old-api/exports.rs @@ -0,0 +1,6 @@ +struct Exports {} + +impl Exports { + fn get<'a, T: Exportable<'a>>(&'a self, name: &str) -> Result; + fn into_iter(&self) -> ExportIter; +} diff --git a/lib/deprecated/runtime-core/doc/old-api/func.rs b/lib/deprecated/runtime-core/doc/old-api/func.rs new file mode 100644 index 000000000..5643fec04 --- /dev/null +++ b/lib/deprecated/runtime-core/doc/old-api/func.rs @@ -0,0 +1,9 @@ +struct Func {} + +impl Func { + fn new(func: F) -> Self; + fn params(&self) -> &'static [Type]; + fn returns(&self) -> &'static [Type]; + fn call(...) -> Result; + fn get_vm_func(&self) -> NonNull; +} diff --git a/lib/deprecated/runtime-core/doc/old-api/func_sig.rs b/lib/deprecated/runtime-core/doc/old-api/func_sig.rs new file mode 100644 index 000000000..f8521a187 --- /dev/null +++ b/lib/deprecated/runtime-core/doc/old-api/func_sig.rs @@ -0,0 +1,8 @@ +struct FuncSig {} + +impl FuncSig { + fn new(params: Params, returns: Returns) -> Self; + fn params(&self) -> &[Type]; + fn returns(&self) -> &[Type]; + fn check_param_value_types(&self, params: &[Value]) -> bool; +} diff --git a/lib/deprecated/runtime-core/doc/old-api/global.rs b/lib/deprecated/runtime-core/doc/old-api/global.rs new file mode 100644 index 000000000..9311cd8bc --- /dev/null +++ b/lib/deprecated/runtime-core/doc/old-api/global.rs @@ -0,0 +1,9 @@ +struct Global {} + +impl Global { + fn new(value: Value) -> Self; + fn new_mutable(value: Value) -> Self; + fn descriptor(&self) -> GlobalDescriptor; + fn set(&self, value: Value); + fn get(&self) -> Value; +} diff --git a/lib/deprecated/runtime-core/doc/old-api/global_descriptor.rs b/lib/deprecated/runtime-core/doc/old-api/global_descriptor.rs new file mode 100644 index 000000000..05dd84898 --- /dev/null +++ b/lib/deprecated/runtime-core/doc/old-api/global_descriptor.rs @@ -0,0 +1,4 @@ +struct GlobalDescriptor { + mutable: bool, + ty: Type, +} diff --git a/lib/deprecated/runtime-core/doc/old-api/global_init.rs b/lib/deprecated/runtime-core/doc/old-api/global_init.rs new file mode 100644 index 000000000..a2c46342c --- /dev/null +++ b/lib/deprecated/runtime-core/doc/old-api/global_init.rs @@ -0,0 +1,4 @@ +struct GlobalInit { + desc: GlobalDescriptor, + init: Initializer, +} diff --git a/lib/deprecated/runtime-core/doc/old-api/host_function.rs b/lib/deprecated/runtime-core/doc/old-api/host_function.rs new file mode 100644 index 000000000..431ca38c3 --- /dev/null +++ b/lib/deprecated/runtime-core/doc/old-api/host_function.rs @@ -0,0 +1,3 @@ +trait HostFunction { + fn to_raw(self) -> (NonNull, Option>); +} diff --git a/lib/deprecated/runtime-core/doc/old-api/import_descriptor.rs b/lib/deprecated/runtime-core/doc/old-api/import_descriptor.rs new file mode 100644 index 000000000..af9557aec --- /dev/null +++ b/lib/deprecated/runtime-core/doc/old-api/import_descriptor.rs @@ -0,0 +1,5 @@ +struct ImportDescriptor { + namespace: String, + name: String, + ty: ExternDescriptor, +} diff --git a/lib/deprecated/runtime-core/doc/old-api/import_object.rs b/lib/deprecated/runtime-core/doc/old-api/import_object.rs new file mode 100644 index 000000000..b6ab7696a --- /dev/null +++ b/lib/deprecated/runtime-core/doc/old-api/import_object.rs @@ -0,0 +1,12 @@ +struct ImportObject { + allow_missing_functions: bool, +} + +impl ImportObject { + fn new() -> Self; + fn new_with_data(state_creator: F) -> Self; + fn register(&mut self, name: S, namespace: N) -> Option>; + fn with_namespace(&self, namespace: &str, f: Func) -> Option; + fn maybe_with_namespace(&self, namespace: &str, f: Func) -> Option; + fn contains_namespace(&self, name: &str) -> bool; +} diff --git a/lib/deprecated/runtime-core/doc/old-api/instance.rs b/lib/deprecated/runtime-core/doc/old-api/instance.rs new file mode 100644 index 000000000..9063a27e5 --- /dev/null +++ b/lib/deprecated/runtime-core/doc/old-api/instance.rs @@ -0,0 +1,18 @@ +struct Instance { + module: Arc, + exports: Exports, +} + +impl Instance { + fn load(&self, loader: T) -> Result; + fn fun(&self, name: &str) -> ResolveResult; + fn resolve_func(&self, name: &str) -> ResolveError; + fn dyn_func(&self, name: &str) -> ResolveResult; + fn call(&self, name: &str, params: &[Value]) -> CallResult>; + fn context(&self) -> &Ctx; + fn context_mut(&mut self) -> &mut Ctx; + fn exports(&self) -> ExportsIter; + fn module(&self) -> Module; + fn get_internal(&self, fields: &InternalField) -> u64; + fn set_internal(&self, fields: &InternalField, value: u64); +} diff --git a/lib/deprecated/runtime-core/doc/old-api/memory.rs b/lib/deprecated/runtime-core/doc/old-api/memory.rs new file mode 100644 index 000000000..9d453038c --- /dev/null +++ b/lib/deprecated/runtime-core/doc/old-api/memory.rs @@ -0,0 +1,9 @@ +struct Memory {} + +impl Memory { + fn new(desc: MemoryDescriptor) -> Result; + fn descriptor(&self) -> MemoryDescriptor; + fn grow(&self, delta: Pages) -> Result; + fn size(&self) -> Pages; + fn view(&self) -> MemoryView; +} diff --git a/lib/deprecated/runtime-core/doc/old-api/memory_descriptor.rs b/lib/deprecated/runtime-core/doc/old-api/memory_descriptor.rs new file mode 100644 index 000000000..42e6c8fa7 --- /dev/null +++ b/lib/deprecated/runtime-core/doc/old-api/memory_descriptor.rs @@ -0,0 +1,6 @@ +struct MemoryDescriptor { + minimum: Pages, + maximum: Option, + shared: bool, + memory_type: MemoryType, +} diff --git a/lib/deprecated/runtime-core/doc/old-api/memory_type.rs b/lib/deprecated/runtime-core/doc/old-api/memory_type.rs new file mode 100644 index 000000000..1b5d509c6 --- /dev/null +++ b/lib/deprecated/runtime-core/doc/old-api/memory_type.rs @@ -0,0 +1,5 @@ +enum MemoryType { + Dynamic, + Static, + SharedStatic, +} diff --git a/lib/deprecated/runtime-core/doc/old-api/memory_view.rs b/lib/deprecated/runtime-core/doc/old-api/memory_view.rs new file mode 100644 index 000000000..e58fec52c --- /dev/null +++ b/lib/deprecated/runtime-core/doc/old-api/memory_view.rs @@ -0,0 +1,5 @@ +struct MemoryView {} + +impl MemoryView { + fn atomically(&self) -> MemoryView<'a, T::Output, Atomically>; +} diff --git a/lib/deprecated/runtime-core/doc/old-api/module.rs b/lib/deprecated/runtime-core/doc/old-api/module.rs new file mode 100644 index 000000000..2963786ec --- /dev/null +++ b/lib/deprecated/runtime-core/doc/old-api/module.rs @@ -0,0 +1,10 @@ +struct Module {} + +impl Module { + fn instantiate(&self, import_object: &ImportObject) -> Result; + fn cache(&self) -> Result; + fn info(&self) -> &ModuleInfo; + fn imports(&self) -> Vec; + fn exports(&self) -> Vec; + fn custom_sections(&self, key: impl AsRef) -> Option<&[Vec]> +} diff --git a/lib/deprecated/runtime-core/doc/old-api/module_info.rs b/lib/deprecated/runtime-core/doc/old-api/module_info.rs new file mode 100644 index 000000000..7dc79b4f7 --- /dev/null +++ b/lib/deprecated/runtime-core/doc/old-api/module_info.rs @@ -0,0 +1,21 @@ +struct ModuleInfo { + backend: String, + custom_sections: HashMap>>, + data_initializers: Vec, + elem_initializers: Vec, + em_symbol_map: Option>, + exports: IndexMap, + func_assoc: Map, + generate_debug_info: bool, + globals: Map, + imported_functions: Map, + imported_globals: Map, + imported_memories: Map, + imported_tables: Map, + memories: Map, + name_table: StringTable, + namespace_table: StringTable, + signatures: Map, + start_func: Option, + tables: Map, +} diff --git a/lib/deprecated/runtime-core/doc/old-api/namespace.rs b/lib/deprecated/runtime-core/doc/old-api/namespace.rs new file mode 100644 index 000000000..75a5defaa --- /dev/null +++ b/lib/deprecated/runtime-core/doc/old-api/namespace.rs @@ -0,0 +1,7 @@ +struct Namespace {} + +impl Namespace { + fn new() -> Self; + fn insert(&mut self, name: S, export: E) -> Option>; + fn contains_key(&mut self, key: S) -> bool; +} diff --git a/lib/deprecated/runtime-core/doc/old-api/native_wasm_type.rs b/lib/deprecated/runtime-core/doc/old-api/native_wasm_type.rs new file mode 100644 index 000000000..a6ef9d578 --- /dev/null +++ b/lib/deprecated/runtime-core/doc/old-api/native_wasm_type.rs @@ -0,0 +1,6 @@ +trait NativeWasmType { + const TYPE: Type; + + fn from_binary(bits: u64) -> Self; + fn to_binary(self) -> u64; +} diff --git a/lib/deprecated/runtime-core/doc/old-api/pages.rs b/lib/deprecated/runtime-core/doc/old-api/pages.rs new file mode 100644 index 000000000..f82bf58c6 --- /dev/null +++ b/lib/deprecated/runtime-core/doc/old-api/pages.rs @@ -0,0 +1,6 @@ +struct Pages(pub u32); + +impl Pages { + fn checked_add(self, rhs: Self) -> Result; + fn bytes(self) -> Bytes; +} diff --git a/lib/deprecated/runtime-core/doc/old-api/table.rs b/lib/deprecated/runtime-core/doc/old-api/table.rs new file mode 100644 index 000000000..d7ef46bab --- /dev/null +++ b/lib/deprecated/runtime-core/doc/old-api/table.rs @@ -0,0 +1,10 @@ +struct Table {} + +impl Table { + fn new(desc: TableDescriptor) -> Result; + fn descriptor(&self) -> TableDescriptor; + fn set(&self, index: u32, element: T) -> Result<(), TableAccessError>; + fn size(&self) -> u32; + fn grow(&self, delta: u32) -> Result; + fn vm_local_table(&mut self) -> *mut LocalTable; +} diff --git a/lib/deprecated/runtime-core/doc/old-api/table_descriptor.rs b/lib/deprecated/runtime-core/doc/old-api/table_descriptor.rs new file mode 100644 index 000000000..59d719f3d --- /dev/null +++ b/lib/deprecated/runtime-core/doc/old-api/table_descriptor.rs @@ -0,0 +1,5 @@ +struct TableDescriptor { + element: ElementType, + minimum: u32, + maximum: Option, +} diff --git a/lib/deprecated/runtime-core/doc/old-api/wasm_extern_type.rs b/lib/deprecated/runtime-core/doc/old-api/wasm_extern_type.rs new file mode 100644 index 000000000..e3aa4572a --- /dev/null +++ b/lib/deprecated/runtime-core/doc/old-api/wasm_extern_type.rs @@ -0,0 +1,6 @@ +trait WasmExternType { + type Native: NativeWasmType; + + fn from_native(native: Self::Native) -> Self; + fn to_native(self) -> Self::Native; +} diff --git a/lib/deprecated/runtime-core/doc/old-api/wasm_type_list.rs b/lib/deprecated/runtime-core/doc/old-api/wasm_type_list.rs new file mode 100644 index 000000000..f2dd7c36a --- /dev/null +++ b/lib/deprecated/runtime-core/doc/old-api/wasm_type_list.rs @@ -0,0 +1,11 @@ +trait WasmTypeList { + type CStruct; + type RetArray: AsMut<[u64]>; + + fn from_ret_array(array: Self::RetArray) -> Self; + fn empty_ret_array() -> Self::RetArray; + fn from_c_struct(c_struct: Self::CStruct) -> Self; + fn into_c_struct(self) -> Self::CStruct; + fn types() -> &'static [Type]; + fn call(self, f: NonNull, wasm: Wasm, ctx: *mut Ctx) -> Result; +} diff --git a/lib/deprecated/runtime-core/doc/old-api/wasmhash.rs b/lib/deprecated/runtime-core/doc/old-api/wasmhash.rs new file mode 100644 index 000000000..3e8942ad7 --- /dev/null +++ b/lib/deprecated/runtime-core/doc/old-api/wasmhash.rs @@ -0,0 +1,7 @@ +struct WasmHash {} + +impl WasmHash { + fn generate(wasm: &[u8]) -> Self; + fn encode(self) -> String; + fn decode(hex_str: &str) -> Result; +} diff --git a/lib/deprecated/runtime-core/doc/review.sh b/lib/deprecated/runtime-core/doc/review.sh new file mode 100755 index 000000000..e5afd456c --- /dev/null +++ b/lib/deprecated/runtime-core/doc/review.sh @@ -0,0 +1,10 @@ +#!/bin/bash + +for i in `\ls new-api | grep "${1-.}"`; do + clear + echo -e "#######\n### ${i}\n#######\n\n\n\n" + diff --report-identical-files --unified=10 old-api/${i} new-api/${i} | diffr + + echo -e "\n\n\n\nPress any key to diff the next file…" + read +done diff --git a/lib/deprecated/runtime-core/src/backend.rs b/lib/deprecated/runtime-core/src/backend.rs new file mode 100644 index 000000000..ccbec0325 --- /dev/null +++ b/lib/deprecated/runtime-core/src/backend.rs @@ -0,0 +1,84 @@ +use crate::new; + +pub use new::wasmer_compiler::{Architecture, CpuFeature as Features}; + +/// Enum used to select which compiler should be used to generate code. +#[derive(Debug, Copy, Clone, PartialEq, Eq)] +pub enum Backend { + #[cfg(feature = "singlepass")] + /// Singlepass backend + Singlepass, + #[cfg(feature = "cranelift")] + /// Cranelift backend + Cranelift, + #[cfg(feature = "llvm")] + /// LLVM backend + LLVM, + /// Auto backend + Auto, +} + +impl Backend { + /// Get a list of the currently enabled (via feature flag) backends. + pub fn variants() -> &'static [&'static str] { + &[ + #[cfg(feature = "singlepass")] + "singlepass", + #[cfg(feature = "cranelift")] + "cranelift", + #[cfg(feature = "llvm")] + "llvm", + "auto", + ] + } + + /// Stable string representation of the backend. + /// It can be used as part of a cache key, for example. + pub fn to_string(&self) -> &'static str { + match self { + #[cfg(feature = "singlepass")] + Backend::Singlepass => "singlepass", + #[cfg(feature = "cranelift")] + Backend::Cranelift => "cranelift", + #[cfg(feature = "llvm")] + Backend::LLVM => "llvm", + Backend::Auto => "auto", + } + } +} + +impl Default for Backend { + fn default() -> Self { + #[cfg(feature = "default-backend-singlepass")] + return Backend::Singlepass; + + #[cfg(feature = "default-backend-cranelift")] + return Backend::Cranelift; + + #[cfg(feature = "default-backend-llvm")] + return Backend::LLVM; + + #[cfg(not(any( + feature = "default-backend-singlepass", + feature = "default-backend-cranelift", + feature = "default-backend-llvm", + )))] + panic!("There is no default-backend set."); + } +} + +impl std::str::FromStr for Backend { + type Err = String; + fn from_str(s: &str) -> Result { + match s.to_lowercase().as_str() { + #[cfg(feature = "singlepass")] + "singlepass" => Ok(Backend::Singlepass), + #[cfg(feature = "cranelift")] + "cranelift" => Ok(Backend::Cranelift), + #[cfg(feature = "llvm")] + "llvm" => Ok(Backend::LLVM), + "auto" => Ok(Backend::Auto), + _ => Err(format!("The backend {} doesn't exist", s)), + } + } +} diff --git a/lib/deprecated/runtime-core/src/cache.rs b/lib/deprecated/runtime-core/src/cache.rs new file mode 100644 index 000000000..181059481 --- /dev/null +++ b/lib/deprecated/runtime-core/src/cache.rs @@ -0,0 +1,94 @@ +//! The cache module provides the common data structures used by compiler backends to allow +//! serializing compiled wasm code to a binary format. The binary format can be persisted, +//! and loaded to allow skipping compilation and fast startup. + +use crate::{ + get_global_store, + module::{Module, ModuleInfo}, + new, +}; +use std::str::FromStr; + +pub use new::wasmer_cache::FileSystemCache; + +/// Kinds of caching errors +#[derive(Debug)] +pub enum Error { + /// An error deserializing bytes into a cache data structure. + DeserializeError(new::wasmer_engine::DeserializeError), + + /// An error serializing bytes from a cache data structure. + SerializeError(new::wasmer_engine::SerializeError), +} + +/// Artifact are produced by caching, are serialized/deserialized to binaries, and contain +/// module info, backend metadata, and compiled code. +pub struct Artifact { + new_module: new::wasmer::Module, +} + +impl Artifact { + pub(crate) fn new(new_module: new::wasmer::Module) -> Self { + Self { new_module } + } + + /// Serializes the `Artifact` into a vector of bytes + pub fn serialize(&self) -> Result, Error> { + self.new_module.serialize().map_err(Error::SerializeError) + } + + /// Deserializes an `Artifact` from the given byte slice. + pub unsafe fn deserialize(bytes: &[u8]) -> Result { + Ok(Self::new( + new::wasmer::Module::deserialize(&get_global_store(), bytes) + .map_err(Error::DeserializeError)?, + )) + } + + /// Get the associated module to this artifact. + pub fn module(self) -> Module { + Module::new(self.new_module) + } + + /// A reference to the `Artifact`'s stored `ModuleInfo` + pub fn info(&self) -> &ModuleInfo { + self.new_module.info() + } +} + +/// The hash of a wasm module. +#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] +pub struct WasmHash { + new_hash: new::wasmer_cache::WasmHash, +} + +impl WasmHash { + /// Hash a wasm module. + /// + /// # Note + /// + /// This does no verification that the supplied data + /// is, in fact, a wasm module. + pub fn generate(wasm_bytes: &[u8]) -> Self { + Self { + new_hash: new::wasmer_cache::WasmHash::generate(wasm_bytes), + } + } + + /// Create the hexadecimal representation of the + /// stored hash. + pub fn encode(self) -> String { + self.new_hash.to_string() + } + + /// Create hash from hexadecimal representation + pub fn decode(hex_str: &str) -> Result { + Ok(Self { + new_hash: new::wasmer_cache::WasmHash::from_str(hex_str)?, + }) + } +} + +/// A unique ID generated from the version of Wasmer for use with cache versioning +pub const WASMER_VERSION_HASH: &'static str = + include_str!(concat!(env!("OUT_DIR"), "/wasmer_version_hash.txt")); diff --git a/lib/deprecated/runtime-core/src/error.rs b/lib/deprecated/runtime-core/src/error.rs new file mode 100644 index 000000000..a8cba4efa --- /dev/null +++ b/lib/deprecated/runtime-core/src/error.rs @@ -0,0 +1,3 @@ +pub use crate::new::wasmer::{ExportError, MemoryError}; +pub use crate::new::wasmer_compiler::CompileError; +pub use crate::new::wasmer_engine::{InstantiationError, LinkError, RuntimeError}; diff --git a/lib/deprecated/runtime-core/src/export.rs b/lib/deprecated/runtime-core/src/export.rs new file mode 100644 index 000000000..359822b8d --- /dev/null +++ b/lib/deprecated/runtime-core/src/export.rs @@ -0,0 +1,4 @@ +pub use crate::new::{ + wasmer::{Exportable, Extern as Export}, + wasmer_vm::Export as RuntimeExport, +}; diff --git a/lib/deprecated/runtime-core/src/functional_api.rs b/lib/deprecated/runtime-core/src/functional_api.rs new file mode 100644 index 000000000..793991b21 --- /dev/null +++ b/lib/deprecated/runtime-core/src/functional_api.rs @@ -0,0 +1,110 @@ +use crate::{ + backend::Backend, cache::Artifact, get_global_store, module::Module, new, + renew_global_store_with, +}; +use std::{convert::Infallible, error::Error}; + +pub use new::wasmer::wat2wasm; + +/// Compile WebAssembly binary code into a [`Module`]. +/// This function is useful if it is necessary to +/// compile a module before it can be instantiated +/// (otherwise, the [`instantiate`] function should be used). +/// +/// [`Module`]: struct.Module.html +/// [`instantiate`]: fn.instantiate.html +/// +/// # Params +/// +/// * `wasm`: A `&[u8]` containing the +/// binary code of the wasm module you want to compile. +/// +/// # Errors +/// +/// If the operation fails, the function returns `Err(error::CompileError::...)`. +/// +/// This function only exists if one of `default-backend-llvm`, `default-backend-cranelift`, +/// or `default-backend-singlepass` is set. +pub fn compile(bytes: &[u8]) -> Result> { + compile_with(bytes, Backend::Auto) +} + +/// Creates a new module from the given cache [`Artifact`] +pub fn load_cache_with(cache: Artifact) -> Result { + Ok(cache.module()) +} + +/// Compile a [`Module`] using the provided compiler from +/// WebAssembly binary code. This function is useful if it +/// is necessary to a compile a module before it can be instantiated +/// and must be used if you wish to use a different backend from the default. +pub fn compile_with(bytes: &[u8], compiler: Backend) -> Result> { + renew_global_store_with(compiler); + + Ok(Module::new(new::wasmer::Module::new( + &get_global_store(), + bytes, + )?)) +} + +/// The same as `compile_with` but changes the compiler behavior +/// with the values in the `CompilerConfig` +/// +/// # Note +/// +/// The third parameter isn't used any more in the deprecated version +/// of `wasmer-runtime-core`. +pub fn compile_with_config( + bytes: &[u8], + compiler: Backend, + _compiler_config: (), +) -> Result> { + renew_global_store_with(compiler); + + Ok(Module::new(new::wasmer::Module::new( + &get_global_store(), + bytes, + )?)) +} + +/// Perform validation as defined by the +/// WebAssembly specification. Returns `true` if validation +/// succeeded, `false` if validation failed. +pub fn validate(bytes: &[u8]) -> bool { + new::wasmer::Module::validate(&get_global_store(), bytes).is_ok() +} + +/// Helper macro to create a new `Func` object using the provided function pointer. +/// +/// # Usage +/// +/// Function pointers or closures are supported. Closures can capture +/// their environment (with `move`). The first parameter is of kind +/// `vm::Ctx`. +/// +/// ``` +/// # use wasmer_runtime_core::{imports, func, vm}; +/// +/// // A host function. +/// fn func(ctx: &mut vm::Ctx, n: i32) -> i32 { +/// n +/// } +/// +/// let i = 7; +/// +/// let import_object = imports! { +/// "env" => { +/// "foo" => func!(func), +/// // A closure with a captured environment. +/// "bar" => func!(move |_: &mut vm::Ctx, n: i32| -> i32 { +/// n + i +/// }), +/// }, +/// }; +/// ``` +#[macro_export] +macro_rules! func { + ($function:expr) => { + $crate::typed_func::Func::new($function) + }; +} diff --git a/lib/deprecated/runtime-core/src/global.rs b/lib/deprecated/runtime-core/src/global.rs new file mode 100644 index 000000000..bf2aa45fc --- /dev/null +++ b/lib/deprecated/runtime-core/src/global.rs @@ -0,0 +1,105 @@ +use crate::{ + error::ExportError, + get_global_store, new, + types::{GlobalDescriptor, Value}, +}; +use std::fmt; + +/// A handle to a Wasm Global +#[derive(Clone)] +pub struct Global { + new_global: new::wasmer::Global, +} + +impl Global { + /// Create a new `Global` value. + /// + /// # Example + /// + /// ``` + /// # use wasmer_runtime_core::{global::Global, types::Value}; + /// let global = Global::new(Value::I32(42)); + /// ``` + pub fn new(value: Value) -> Self { + Self { + new_global: new::wasmer::Global::new(&get_global_store(), value), + } + } + + /// Create a new, mutable `Global` value. + /// + /// # Example + /// + /// ``` + /// # use wasmer_runtime_core::{global::Global, types::Value}; + /// let global = Global::new_mutable(Value::I32(42)); + /// ``` + pub fn new_mutable(value: Value) -> Self { + Self { + new_global: new::wasmer::Global::new_mut(&get_global_store(), value), + } + } + + /// Get the [`GlobalDescriptor`] generated for this global. + /// + /// [`GlobalDescriptor`]: struct.GlobalDescriptor.html + pub fn descriptor(&self) -> GlobalDescriptor { + self.new_global.ty().into() + } + + /// Set the value help by this global. + /// + /// This method will panic if the value is + /// the wrong type. + pub fn set(&self, value: Value) { + self.new_global.set(value).unwrap() + } + + /// Get the value held by this global. + /// + /// # Example + /// + /// ``` + /// # use wasmer_runtime_core::{global::Global, types::Value}; + /// let global = Global::new_mutable(Value::I32(42)); + /// assert_eq!(global.get(), Value::I32(42)); + /// + /// global.set(Value::I32(7)); + /// assert_eq!(global.get(), Value::I32(7)); + /// ``` + pub fn get(&self) -> Value { + self.new_global.get() + } +} + +impl fmt::Debug for Global { + fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result { + write!(formatter, "{:?}", &self.new_global) + } +} + +impl From<&new::wasmer::Global> for Global { + fn from(new_global: &new::wasmer::Global) -> Self { + Self { + new_global: new_global.clone(), + } + } +} + +impl<'a> new::wasmer::Exportable<'a> for Global { + fn to_export(&self) -> new::wasmer_vm::Export { + self.new_global.to_export() + } + + fn get_self_from_extern(r#extern: &'a new::wasmer::Extern) -> Result<&'a Self, ExportError> { + match r#extern { + new::wasmer::Extern::Global(global) => Ok( + // It's not ideal to call `Box::leak` here, but it + // would introduce too much changes in the + // `new::wasmer` API to support `Cow` or similar. + Box::leak(Box::::new(global.into())), + ), + _ => Err(ExportError::IncompatibleType), + } + } +} diff --git a/lib/deprecated/runtime-core/src/import.rs b/lib/deprecated/runtime-core/src/import.rs new file mode 100644 index 000000000..148421de5 --- /dev/null +++ b/lib/deprecated/runtime-core/src/import.rs @@ -0,0 +1,215 @@ +use crate::{instance::Exports, new}; + +pub use new::wasmer::{namespace, ImportObject, ImportObjectIterator, LikeNamespace}; + +pub struct Namespace { + exports: Exports, +} + +impl Namespace { + pub fn new() -> Self { + Self { + exports: Exports::new(), + } + } + + pub fn insert(&mut self, name: N, value: V) + where + N: Into, + V: Into + 'static, + { + self.exports.new_exports.insert(name, value); + } + + pub fn contains_key(&mut self, name: N) -> bool + where + N: Into, + { + self.exports.new_exports.contains(name) + } +} + +impl LikeNamespace for Namespace { + fn get_namespace_export(&self, name: &str) -> Option { + self.exports.new_exports.get_namespace_export(name) + } + + fn get_namespace_exports(&self) -> Vec<(String, new::wasmer_vm::Export)> { + self.exports.new_exports.get_namespace_exports() + } +} + +#[deprecated( + since = "__NEXT_VERSION__", + note = "Please use the `Exportable` trait instead." +)] +pub trait IsExport {} + +/// Generate an `ImportObject` easily with the `imports!` macro. +/// +/// # Usage +/// +/// ``` +/// # use wasmer_runtime_core::{imports, func, vm::Ctx}; +/// +/// let import_object = imports! { +/// "env" => { +/// "foo" => func!(foo) +/// }, +/// }; +/// +/// fn foo(_: &mut Ctx, n: i32) -> i32 { +/// n +/// } +/// ``` +/// +/// or by passing a state creator for the import object: +/// +/// ``` +/// # use wasmer_runtime_core::{imports, func, vm::Ctx}; +/// +/// let import_object = imports! { +/// || (0 as _, |_a| {}), +/// "env" => { +/// "foo" => func!(foo) +/// }, +/// }; +/// +/// # fn foo(_: &mut Ctx, n: i32) -> i32 { +/// # n +/// # } +/// ``` +#[macro_export] +macro_rules! imports { + ( $( $namespace_name:expr => $namespace:tt ),* $(,)? ) => { + { + let mut import_object = $crate::import::ImportObject::new(); + + $({ + let namespace = $crate::import_namespace!($namespace); + + import_object.register($namespace_name, namespace); + })* + + import_object + } + }; + + ($state_creator:expr, $( $namespace_name:expr => $namespace:tt ),* $(,)? ) => { + { + let mut import_object = $crate::import::ImportObject::new_with_data($state_creator); + + $({ + let namespace = $crate::import_namespace!($namespace); + + import_object.register($namespace_name, namespace); + })* + + import_object + } + }; +} + +#[macro_export] +#[doc(hidden)] +macro_rules! import_namespace { + ( { $( $import_name:expr => $import_item:expr ),* $(,)? } ) => { + { + let mut namespace = $crate::import::Namespace::new(); + + $( + namespace.insert($import_name, $import_item); + )* + + namespace + } + }; + + ( $namespace:ident ) => { + $namespace + }; +} + +#[cfg(test)] +mod test { + use crate::{func, vm}; + + fn func(_: &mut vm::Ctx, arg: i32) -> i32 { + arg + 1 + } + + #[test] + fn imports_macro_allows_trailing_comma_and_none() { + let _ = imports! { + "env" => { + "func" => func!(func), + }, + }; + let _ = imports! { + "env" => { + "func" => func!(func), + } + }; + let _ = imports! { + "env" => { + "func" => func!(func), + }, + "abc" => { + "def" => func!(func), + } + }; + let _ = imports! { + "env" => { + "func" => func!(func) + }, + }; + let _ = imports! { + "env" => { + "func" => func!(func) + } + }; + let _ = imports! { + "env" => { + "func1" => func!(func), + "func2" => func!(func) + } + }; + let _ = imports! { + "env" => { + "func1" => func!(func), + "func2" => func!(func), + } + }; + } + + #[test] + fn imports_macro_allows_trailing_comma_and_none_with_state() { + use std::{ffi, ptr}; + + fn dtor(_arg: *mut ffi::c_void) {} + fn state_creator() -> (*mut ffi::c_void, fn(*mut ffi::c_void)) { + (ptr::null_mut() as *mut ffi::c_void, dtor) + } + let _ = imports! { + state_creator, + "env" => { + "func1" => func!(func), + "func2" => func!(func), + } + }; + let _ = imports! { + state_creator, + "env" => { + "func1" => func!(func), + "func2" => func!(func) + }, + }; + let _ = imports! { + state_creator, + "env" => { + "func1" => func!(func), + "func2" => func!(func), + }, + }; + } +} diff --git a/lib/deprecated/runtime-core/src/instance.rs b/lib/deprecated/runtime-core/src/instance.rs new file mode 100644 index 000000000..8bc6bd4f5 --- /dev/null +++ b/lib/deprecated/runtime-core/src/instance.rs @@ -0,0 +1,272 @@ +use crate::{ + error::ExportError, + export::{Export, Exportable}, + import::LikeNamespace, + module::{ExportIndex, Module}, + new, + structures::TypedIndex, + typed_func::Func, + types::Value, + vm, +}; +use std::{ + cell::{Ref, RefCell, RefMut}, + error::Error, + rc::Rc, +}; + +pub use crate::typed_func::DynamicFunc as DynFunc; + +#[derive(Debug)] +pub(crate) struct PreInstance { + pub(crate) vmctx: Rc>, +} + +impl PreInstance { + pub(crate) fn new() -> Self { + Self { + vmctx: Rc::new(RefCell::new(unsafe { vm::Ctx::new_uninit() })), + } + } + + pub(crate) fn vmctx(&self) -> Rc> { + self.vmctx.clone() + } + + pub(crate) fn vmctx_ptr(&self) -> *mut vm::Ctx { + self.vmctx.as_ptr() + } +} + +/// An instantiated WebAssembly module. +/// +/// An `Instance` represents a WebAssembly module that +/// has been instantiated with an [`ImportObject`] and is +/// ready to be called. +/// +/// [`ImportObject`]: struct.ImportObject.html +pub struct Instance { + pre_instance: Box, + /// The exports of this instance. + pub exports: Exports, + pub(crate) new_instance: new::wasmer::Instance, +} + +impl Instance { + pub(crate) fn new(pre_instance: Box, new_instance: new::wasmer::Instance) -> Self { + // Initialize the `vm::Ctx` + { + let mut vmctx = pre_instance.vmctx.borrow_mut(); + + vmctx.module_info = new_instance.module().info() as *const _; + } + + Self { + pre_instance, + exports: new_instance.exports.clone().into(), + new_instance, + } + } + + /// Through generic magic and the awe-inspiring power of traits, we bring you... + /// + /// # "Func" + /// + /// A [`Func`] allows you to call functions exported from wasm with + /// near zero overhead. + /// + /// [`Func`]: struct.Func.html + /// + /// # Usage + /// + /// ``` + /// # #![allow(deprecated)] + /// # use wasmer_runtime_core::{Func, Instance, error::ExportError}; + /// # fn typed_func(instance: Instance) -> Result<(), ExportError> { + /// let func: Func<(i32, i32)> = instance.func("foo")?; + /// + /// func.call(42, 43); + /// # Ok(()) + /// # } + /// ``` + #[deprecated( + since = "0.17.0", + note = "Please use `instance.exports.get(name)` instead" + )] + pub fn func(&self, name: &str) -> Result, ExportError> + where + Args: new::wasmer::WasmTypeList + Clone, + Rets: new::wasmer::WasmTypeList + Clone, + { + self.exports.get(name) + } + + /// This returns the representation of a function that can be called + /// safely. + /// + /// # Usage + /// + /// ``` + /// # #![allow(deprecated)] + /// # use wasmer_runtime_core::{Instance}; + /// # fn call_foo(instance: &mut Instance) -> Result<(), Box> { + /// instance + /// .dyn_func("foo")? + /// .call(&[])?; + /// # Ok(()) + /// # } + /// ``` + #[deprecated( + since = "0.17.0", + note = "Please use `instance.exports.get(name)` instead" + )] + pub fn dyn_func(&self, name: &str) -> Result { + self.exports.get(name) + } + + /// Resolve an exported function by name. + pub fn resolve_func(&self, name: &str) -> Result { + self.new_instance + .module() + .info() + .exports + .iter() + .find_map(|(export_name, export_index)| { + if name == export_name { + match export_index { + ExportIndex::Function(index) => Some(index.index()), + _ => None, + } + } else { + None + } + }) + .ok_or(()) + } + + /// Call an exported WebAssembly function given the export name. + /// Pass arguments by wrapping each one in the [`Value`] enum. + /// The returned values are also each wrapped in a [`Value`]. + /// + /// [`Value`]: enum.Value.html + /// + /// # Note + /// + /// This returns `Result, _>` in order to support + /// the future multi-value returns WebAssembly feature. + /// + /// # Usage + /// + /// Consider using the more explicit [`Exports::get`]` with [`DynFunc::call`] + /// instead. For example: + /// + /// ``` + /// # use wasmer_runtime_core::{types::Value, Instance, DynFunc}; + /// # fn call_foo(instance: &mut Instance) -> Result<(), Box> { + /// // … + /// let foo: DynFunc = instance.exports.get("foo")?; + /// let results = foo.call(&[Value::I32(42)])?; + /// // … + /// # Ok(()) + /// # } + /// ``` + /// + /// Another example with `Instance::call` directly: + /// + /// ``` + /// # use wasmer_runtime_core::{types::Value, Instance}; + /// # fn call_foo(instance: &mut Instance) -> Result<(), Box> { + /// // ... + /// let results = instance.call("foo", &[Value::I32(42)])?; + /// // ... + /// # Ok(()) + /// # } + /// ``` + pub fn call(&self, name: &str, params: &[Value]) -> Result, Box> { + Ok(self + .new_instance + .exports + .get_function(name)? + .call(params)? + .into_vec()) + } + + /// The module used to instantiate this Instance. + pub fn module(&self) -> Module { + Module::new(self.new_instance.module().clone()) + } + + /// Returns an immutable reference to the + /// [`Ctx`] used by this Instance. + /// + /// [`Ctx`]: struct.Ctx.html + pub fn context(&self) -> Ref { + self.pre_instance.vmctx.borrow() + } + + /// Returns a mutable reference to the + /// [`Ctx`] used by this Instance. + /// + /// [`Ctx`]: struct.Ctx.html + pub fn context_mut(&mut self) -> RefMut { + self.pre_instance.vmctx.borrow_mut() + } + + /// Returns an iterator over all of the items + /// exported from this instance. + pub fn exports( + &self, + ) -> new::wasmer::ExportsIterator> { + self.new_instance.exports.iter() + } +} + +impl LikeNamespace for Instance { + fn get_namespace_export(&self, name: &str) -> Option { + self.exports.new_exports.get_namespace_export(name) + } + + fn get_namespace_exports(&self) -> Vec<(String, new::wasmer_vm::Export)> { + self.exports.new_exports.get_namespace_exports() + } +} + +#[derive(Clone)] +pub struct Exports { + pub(crate) new_exports: new::wasmer::Exports, +} + +impl Exports { + pub(crate) fn new() -> Self { + Self { + new_exports: new::wasmer::Exports::new(), + } + } + + pub fn get<'a, T>(&'a self, name: &str) -> Result + where + T: Exportable<'a> + Clone + 'a, + { + Ok(self.new_exports.get::(name)?.clone()) + } + + pub fn iter(&self) -> new::wasmer::ExportsIterator> { + self.new_exports.iter() + } +} + +impl LikeNamespace for Exports { + fn get_namespace_export(&self, name: &str) -> Option { + self.new_exports.get_namespace_export(name) + } + + fn get_namespace_exports(&self) -> Vec<(String, new::wasmer_vm::Export)> { + self.new_exports.get_namespace_exports() + } +} + +impl From for Exports { + fn from(new_exports: new::wasmer::Exports) -> Self { + Self { new_exports } + } +} diff --git a/lib/deprecated/runtime-core/src/lib.rs b/lib/deprecated/runtime-core/src/lib.rs new file mode 100644 index 000000000..f93ab4a02 --- /dev/null +++ b/lib/deprecated/runtime-core/src/lib.rs @@ -0,0 +1,161 @@ +//! Wasmer Runtime Core Library +//! +//! # Important Note; Please Read +//! +//! Wasmer has entirely changed its API (called the “new API” +//! here). This new version of Wasmer improves the performance and the +//! memory consumption, in addition to a ton of new features and much +//! more flexibility! In order to help users to enjoy the performance +//! boost and memory improvements without updating your program that +//! much, we have created a new version of the `wasmer-runtime-core` +//! crate, which is now *a port* of the new API but with the old API, +//! as much as possible. Indeed, it was not always possible to provide +//! the exact same API, but changes are subtle. +//! +//! We have carefully documented most of the differences. It is +//! important to understand the public of this port (see the +//! `CHANGES.md`) document. We do not recommend to advanced users of +//! Wasmer to use this port. Advanced API, like `ModuleInfo` or the +//! `vm` module (incl. `vm::Ctx`) have not been fully ported because +//! it was very internals to Wasmer. For advanced users, we highly +//! recommend to migrate to the new version of Wasmer, which is +//! awesome by the way (completely neutral opinion). The public for +//! this port is beginners or regular users that do not necesarily +//! have time to update their code immediately but that want to enjoy +//! a performance boost and memory improvements. +//! +//! # Introduction +//! +//! This crate provides common data structures which are shared by +//! compiler backends to implement a WebAssembly runtime. +//! +//! This crate also provides an API for users who use wasmer as an +//! embedded wasm runtime which allows operations like compiling, +//! instantiating, providing imports, access exports, memories, and +//! tables for example. +//! +//! Most wasmer users should prefer the API which is re-exported by +//! the `wasmer-runtime` library by default. This crate provides +//! additional APIs which may be useful to users that wish to +//! customize the wasmer runtime. + +pub(crate) mod new { + pub use wasm_common; + pub use wasmer; + pub use wasmer_cache; + pub use wasmer_compiler; + #[cfg(feature = "cranelift")] + pub use wasmer_compiler_cranelift; + #[cfg(feature = "llvm")] + pub use wasmer_compiler_llvm; + #[cfg(feature = "singlepass")] + pub use wasmer_compiler_singlepass; + pub use wasmer_engine; + pub use wasmer_engine_jit; + pub use wasmer_vm; +} + +pub mod backend; +pub mod cache; +pub mod error; +pub mod export; +mod functional_api; +pub mod global; +pub mod import; +pub mod instance; +pub mod memory; +pub mod module; +pub mod structures; +pub mod table; +pub mod typed_func; +pub mod types; +pub mod units; +pub mod vm; + +pub use crate::cache::{Artifact, WasmHash}; +#[allow(deprecated)] +pub use crate::import::IsExport; +pub use crate::instance::{DynFunc, Exports, Instance}; +pub use crate::module::Module; +pub use crate::new::wasmer_compiler::wasmparser; +pub use crate::typed_func::{DynamicFunc, Func}; +pub use crate::units::{Bytes, Pages, WASM_MAX_PAGES, WASM_MIN_PAGES, WASM_PAGE_SIZE}; +pub use functional_api::{ + compile, compile_with, compile_with_config, load_cache_with, validate, wat2wasm, +}; + +pub mod prelude { + pub use crate::import::{namespace, ImportObject, Namespace}; + pub use crate::typed_func::{DynamicFunc, Func}; + pub use crate::types::{FuncIndex, GlobalIndex, MemoryIndex, TableIndex, Type, Value}; +} + +/// The current version of this crate +pub const VERSION: &'static str = env!("CARGO_PKG_VERSION"); + +use backend::Backend; +use std::sync::{Arc, Mutex}; + +struct GlobalStore { + store: Mutex>, + backend: Backend, +} + +impl GlobalStore { + fn new() -> Self { + Self { + store: Mutex::new(Arc::new(Default::default())), + backend: Backend::Auto, + } + } + + fn renew_with(&self, compiler: backend::Backend) { + if compiler == self.backend { + return; + } + + #[allow(unused_variables)] + let update = |compiler_config: &dyn new::wasmer_compiler::CompilerConfig, + global_store: &GlobalStore| { + let engine = new::wasmer_engine_jit::JIT::new(compiler_config).engine(); + + *self.store.lock().unwrap() = Arc::new(new::wasmer::Store::new(&engine)); + }; + + match compiler { + #[cfg(feature = "singlepass")] + Backend::Singlepass => update( + &new::wasmer_compiler_singlepass::Singlepass::default(), + &self, + ), + + #[cfg(feature = "cranelift")] + Backend::Cranelift => { + update(&new::wasmer_compiler_cranelift::Cranelift::default(), &self) + } + + #[cfg(feature = "llvm")] + Backend::LLVM => update(&new::wasmer_compiler_llvm::LLVM::default(), &self), + + Backend::Auto => *self.store.lock().unwrap() = Arc::new(Default::default()), + }; + } + + fn inner_store(&self) -> Arc { + (*self.store.lock().unwrap()).clone() + } +} + +lazy_static::lazy_static! { + static ref GLOBAL_STORE: GlobalStore = GlobalStore::new(); +} + +/// Useful if one needs to update the global store. +pub(crate) fn renew_global_store_with(backend: Backend) { + GLOBAL_STORE.renew_with(backend); +} + +/// Useful if one needs to migrate to the new Wasmer's API gently. +pub fn get_global_store() -> Arc { + GLOBAL_STORE.inner_store() +} diff --git a/lib/deprecated/runtime-core/src/memory.rs b/lib/deprecated/runtime-core/src/memory.rs new file mode 100644 index 000000000..a5830a8f6 --- /dev/null +++ b/lib/deprecated/runtime-core/src/memory.rs @@ -0,0 +1,139 @@ +use crate::{ + error::{ExportError, MemoryError}, + get_global_store, new, + types::ValueType, + units::Pages, +}; + +pub mod ptr { + pub use crate::new::wasmer::{Array, Item, WasmPtr}; +} + +pub use new::wasm_common::MemoryType as MemoryDescriptor; +pub use new::wasmer::{Atomically, MemoryView}; +pub use new::wasmer_vm::MemoryStyle as MemoryType; + +/// A Wasm linear memory. +/// +/// A `Memory` represents the memory used by a Wasm instance. +#[derive(Clone)] +pub struct Memory { + new_memory: new::wasmer::Memory, +} + +impl Memory { + /// Create a new `Memory` from a [`MemoryDescriptor`] + /// + /// [`MemoryDescriptor`]: struct.MemoryDescriptor.html + /// + /// Usage: + /// + /// ``` + /// # use wasmer_runtime_core::{types::MemoryDescriptor, error::MemoryError, memory::Memory, units::Pages}; + /// fn create_memory() -> Result<(), MemoryError> { + /// let descriptor = MemoryDescriptor::new(Pages(10), None, false); + /// + /// let memory = Memory::new(descriptor)?; + /// Ok(()) + /// } + /// ``` + pub fn new(descriptor: MemoryDescriptor) -> Result { + Ok(Memory { + new_memory: new::wasmer::Memory::new(&get_global_store(), descriptor)?, + }) + } + + /// Return the [`MemoryDescriptor`] that this memory + /// was created with. + /// + /// [`MemoryDescriptor`]: struct.MemoryDescriptor.html + pub fn descriptor(&self) -> MemoryDescriptor { + self.new_memory.ty().clone() + } + + /// Grow this memory by the specified number of pages. + pub fn grow(&self, delta: Pages) -> Result { + self.new_memory.grow(delta) + } + + /// The size, in wasm pages, of this memory. + pub fn size(&self) -> Pages { + self.new_memory.size() + } + + /// Return a "view" of the currently accessible memory. By + /// default, the view is unsynchronized, using regular memory + /// accesses. You can force a memory view to use atomic accesses + /// by calling the [`atomically`] method. + /// + /// [`atomically`]: struct.MemoryView.html#method.atomically + /// + /// # Notes + /// + /// This method is safe (as in, it won't cause the host to crash or have UB), + /// but it doesn't obey rust's rules involving data races, especially concurrent ones. + /// Therefore, if this memory is shared between multiple threads, a single memory + /// location can be mutated concurrently without synchronization. + /// + /// # Usage + /// + /// ``` + /// # use wasmer_runtime_core::memory::{Memory, MemoryView}; + /// # use std::{cell::Cell, sync::atomic::Ordering}; + /// # fn view_memory(memory: Memory) { + /// // Without synchronization. + /// let view: MemoryView = memory.view(); + /// for byte in view[0x1000 .. 0x1010].iter().map(Cell::get) { + /// println!("byte: {}", byte); + /// } + /// + /// // With synchronization. + /// let atomic_view = view.atomically(); + /// for byte in atomic_view[0x1000 .. 0x1010].iter().map(|atom| atom.load(Ordering::SeqCst)) { + /// println!("byte: {}", byte); + /// } + /// # } + /// ``` + pub fn view(&self) -> MemoryView { + self.new_memory.view() + } +} + +impl From<&new::wasmer::Memory> for Memory { + fn from(new_memory: &new::wasmer::Memory) -> Self { + Self { + new_memory: new_memory.clone(), + } + } +} + +impl<'a> new::wasmer::Exportable<'a> for Memory { + fn to_export(&self) -> new::wasmer_vm::Export { + self.new_memory.to_export() + } + + fn get_self_from_extern(r#extern: &'a new::wasmer::Extern) -> Result<&'a Self, ExportError> { + match r#extern { + new::wasmer::Extern::Memory(memory) => Ok( + // It's not ideal to call `Box::leak` here, but it + // would introduce too much changes in the + // `new::wasmer` API to support `Cow` or similar. + Box::leak(Box::::new(memory.into())), + ), + _ => Err(ExportError::IncompatibleType), + } + } +} + +#[cfg(test)] +mod memory_tests { + use super::{Memory, MemoryDescriptor, Pages}; + + #[test] + fn test_initial_memory_size() { + let memory_desc = MemoryDescriptor::new(Pages(10), Some(Pages(20)), false); + let unshared_memory = Memory::new(memory_desc).unwrap(); + + assert_eq!(unshared_memory.size(), Pages(10)); + } +} diff --git a/lib/deprecated/runtime-core/src/module.rs b/lib/deprecated/runtime-core/src/module.rs new file mode 100644 index 000000000..dca11e835 --- /dev/null +++ b/lib/deprecated/runtime-core/src/module.rs @@ -0,0 +1,241 @@ +use crate::{ + cache::Artifact, + error::{InstantiationError, RuntimeError}, + import::{ImportObject, Namespace}, + instance::{Instance, PreInstance}, + new, + typed_func::DynamicCtx, + types::{FuncSig, Value}, + vm, +}; +use new::wasmer_vm::Export; +use std::{ + cell::RefCell, + collections::HashMap, + convert::{AsRef, Infallible}, + ptr, +}; + +pub use new::wasm_common::{DataInitializer, ExportIndex}; +pub use new::wasmer_vm::{ + // + MemoryStyle as MemoryType, + ModuleInfo, + TableElements as TableInitializer, +}; + +/// A compiled WebAssembly module. +/// +/// `Module` is returned by the [`compile`] function. +/// +/// [`compile`]: crate::compile +#[derive(Clone)] +pub struct Module { + pub(crate) new_module: new::wasmer::Module, +} + +impl Module { + pub(crate) fn new(new_module: new::wasmer::Module) -> Self { + Self { new_module } + } + + /// Instantiate a WebAssembly module with the provided [`ImportObject`]. + /// + /// [`ImportObject`]: struct.ImportObject.html + /// + /// # Note + /// + /// Instantiating a `Module` will also call the function designated as `start` + /// in the WebAssembly module, if there is one. + /// + /// # Usage + /// + /// ``` + /// # use wasmer_runtime_core::{Module, imports, error::InstantiationError}; + /// # fn instantiate(module: &Module) -> Result<(), InstantiationError> { + /// let import_object = imports! { + /// // ... + /// }; + /// let instance = module.instantiate(&import_object)?; + /// // ... + /// # Ok(()) + /// # } + /// ``` + pub fn instantiate( + &self, + import_object: &ImportObject, + ) -> Result { + let pre_instance = Box::new(PreInstance::new()); + + let import_object = { + // The problem is the following: + // + // * In the old API, `Instance` owns the host functions' + // environments of kind `vm::Ctx`, and mutably shares it + // with all host functions. + // * In the new API, every host function owns its env of + // any kind; `Instance` knows nothing about this + // environment. + // + // To reproduce the old API with the new API, host + // functions create an empty environment of kind + // `vm::Ctx`. It is stored internally behind a `VMContext` + // pointer. The hack consists of rebuilding an + // `ImportObject` (that holds all the host functions), and + // updates the `VMContext` pointer to use a shared + // `vm::Ctx` value owned by `Instance` (actually, + // `PreInstance`). + + let mut new_import_object = ImportObject::new(); + let mut new_namespaces: HashMap = HashMap::new(); + let store = self.new_module.store(); + + import_object + .clone_ref() + .into_iter() + .map(|((namespace, name), export)| match export { + Export::Function(mut function) => { + { + // `function` is a static host function + // constructed with + // `new::wasmer::Function::new_env`. + if !function.address.is_null() { + // Properly drop the empty `vm::Ctx` + // created by the host function. + unsafe { + ptr::drop_in_place::(function.vmctx as _); + } + + // Update the pointer to `VMContext`, + // which is actually a `vm::Ctx` + // pointer, to fallback on the + // environment hack. + function.vmctx = pre_instance.vmctx_ptr() as _; + } + // `function` is a dynamic host function + // constructed with + // `new::wasmer::Function::new_dynamic_env`. + else { + // `VMContext` holds a complex type: + // `Box>>`. + // + // The type `VMDynamicFunctionWithEnv` + // is private to `new::wasmer`. Let's + // replicate it, and hope the layout + // is the same! + struct VMDynamicFunctionWithEnv + where + Env: Sized + 'static, + { + #[allow(unused)] + function_type: FuncSig, + #[allow(unused)] + func: Box< + dyn Fn( + &mut Env, + &[Value], + ) + -> Result, RuntimeError> + + 'static, + >, + env: RefCell, + } + + // Get back the `vmctx` as it is + // stored by + // `new::wasmer::Function::new_dynamic_env`. + let vmctx: Box< + new::wasmer_vm::VMDynamicFunctionContext< + VMDynamicFunctionWithEnv, + >, + > = unsafe { Box::from_raw(function.vmctx as *mut _) }; + + // Replace the environment by ours. + vmctx.ctx.env.borrow_mut().vmctx = pre_instance.vmctx(); + + // … without anyone noticing… + function.vmctx = Box::into_raw(vmctx) as _; + } + } + + ( + (namespace, name), + new::wasmer::Extern::from_export(store, Export::Function(function)), + ) + } + export => ( + (namespace, name), + new::wasmer::Extern::from_export(store, export), + ), + }) + .for_each(|((namespace, name), extern_)| { + if !new_namespaces.contains_key(&namespace) { + new_namespaces.insert(namespace.clone(), Namespace::new()); + } + + let new_namespace = new_namespaces.get_mut(&namespace).unwrap(); // it is safe because it has been verified that the key exists. + new_namespace.insert(&name, extern_); + }); + + new_namespaces + .into_iter() + .for_each(|(namespace_name, namespace)| { + new_import_object.register(namespace_name, namespace); + }); + + new_import_object + }; + + Ok(Instance::new( + pre_instance, + new::wasmer::Instance::new(&self.new_module, &import_object)?, + )) + } + + /// Create a cache artifact from this module. + pub fn cache(&self) -> Result { + Ok(Artifact::new(self.new_module.clone())) + } + + /// Get the module data for this module. + pub fn info(&self) -> &ModuleInfo { + &self.new_module.info() + } + + /// Get the [`ImportDescriptor`]s describing the imports this [`Module`] + /// requires to be instantiated. + pub fn imports(&self) -> Vec { + self.new_module.imports().collect() + } + + /// Get the [`ExportDescriptor`]s of the exports this [`Module`] provides. + pub fn exports(&self) -> Vec { + self.new_module.exports().collect() + } + + /// Get the custom sections matching the given name. + pub fn custom_sections(&self, name: impl AsRef) -> Option>> { + let custom_sections: Vec> = self + .new_module + .custom_sections(name.as_ref()) + .map(|custom_section| custom_section.to_vec()) + .collect(); + + if custom_sections.is_empty() { + None + } else { + Some(custom_sections) + } + } + + #[doc(hidden)] + pub fn into_inner(&self) -> new::wasmer::Module { + self.new_module.clone() + } +} + +impl Into for Module { + fn into(self) -> new::wasmer::Module { + self.into_inner() + } +} diff --git a/lib/deprecated/runtime-core/src/structures.rs b/lib/deprecated/runtime-core/src/structures.rs new file mode 100644 index 000000000..7958fb772 --- /dev/null +++ b/lib/deprecated/runtime-core/src/structures.rs @@ -0,0 +1 @@ +pub use crate::new::wasm_common::entity::EntityRef as TypedIndex; diff --git a/lib/deprecated/runtime-core/src/table.rs b/lib/deprecated/runtime-core/src/table.rs new file mode 100644 index 000000000..ece88e5fb --- /dev/null +++ b/lib/deprecated/runtime-core/src/table.rs @@ -0,0 +1,108 @@ +use crate::{ + error::{ExportError, RuntimeError}, + get_global_store, new, + types::{TableDescriptor, Value}, +}; + +/// Container with a descriptor and a reference to a table storage. +#[derive(Clone)] +pub struct Table { + new_table: new::wasmer::Table, +} + +impl Table { + /// Create a new `Table` from a [`TableDescriptor`] + /// + /// [`TableDescriptor`]: struct.TableDescriptor.html + /// + /// # Usage + /// + /// ``` + /// # use wasmer_runtime_core::{types::{TableDescriptor, Type, Value}, table::Table, error::RuntimeError}; + /// # fn create_table() -> Result<(), RuntimeError> { + /// let descriptor = TableDescriptor { + /// ty: Type::ExternRef, + /// minimum: 10, + /// maximum: None, + /// }; + /// + /// let table = Table::new(descriptor, Value::null())?; + /// # Ok(()) + /// # } + /// ``` + pub fn new(descriptor: TableDescriptor, initial_value: Value) -> Result { + Ok(Self { + new_table: new::wasmer::Table::new(&get_global_store(), descriptor, initial_value)?, + }) + } + + /// Get the `TableDescriptor` used to create this `Table`. + pub fn descriptor(&self) -> TableDescriptor { + self.new_table.ty().clone() + } + + /// Set the element at index. + pub fn set(&self, index: u32, value: Value) -> Result<(), RuntimeError> { + self.new_table.set(index, value) + } + + pub fn get(&self, index: u32) -> Option { + self.new_table.get(index) + } + + /// The current size of this table. + pub fn size(&self) -> u32 { + self.new_table.size() + } + + /// Grow this table by `delta`. + pub fn grow(&self, delta: u32, initial_value: Value) -> Result { + self.new_table.grow(delta, initial_value) + } +} + +impl From<&new::wasmer::Table> for Table { + fn from(new_table: &new::wasmer::Table) -> Self { + Self { + new_table: new_table.clone(), + } + } +} + +impl<'a> new::wasmer::Exportable<'a> for Table { + fn to_export(&self) -> new::wasmer_vm::Export { + self.new_table.to_export() + } + + fn get_self_from_extern(r#extern: &'a new::wasmer::Extern) -> Result<&'a Self, ExportError> { + match r#extern { + new::wasmer::Extern::Table(table) => Ok( + // It's not ideal to call `Box::leak` here, but it + // would introduce too much changes in the + // `new::wasmer` API to support `Cow` or similar. + Box::leak(Box::::new(table.into())), + ), + _ => Err(ExportError::IncompatibleType), + } + } +} + +#[cfg(test)] +mod table_tests { + use super::{Table, TableDescriptor}; + use crate::types::{Type, Value}; + + #[test] + fn test_initial_table_size() { + let table = Table::new( + TableDescriptor { + ty: Type::FuncRef, + minimum: 10, + maximum: Some(20), + }, + Value::null(), + ) + .unwrap(); + assert_eq!(table.size(), 10); + } +} diff --git a/lib/deprecated/runtime-core/src/typed_func.rs b/lib/deprecated/runtime-core/src/typed_func.rs new file mode 100644 index 000000000..22e4b11f4 --- /dev/null +++ b/lib/deprecated/runtime-core/src/typed_func.rs @@ -0,0 +1,409 @@ +use crate::{ + error::{ExportError, RuntimeError}, + get_global_store, new, + types::{FuncSig, NativeWasmType, Type, Value, WasmExternType}, + vm, +}; +use std::marker::PhantomData; + +pub use new::wasmer::{HostFunction, WasmTypeList}; + +/// Represents a function that can be used by WebAssembly. +#[derive(Clone)] +pub struct Func +where + Args: WasmTypeList, + Rets: WasmTypeList, +{ + new_function: new::wasmer::Function, + _phantom: PhantomData<(Args, Rets)>, +} + +impl Func +where + Args: WasmTypeList, + Rets: WasmTypeList, +{ + /// Creates a new `Func`. + pub fn new(func: F) -> Self + where + F: HostFunction, + { + // Create an empty `vm::Ctx`, that is going to be overwritten by `Instance::new`. + let ctx = unsafe { vm::Ctx::new_uninit() }; + + Self { + new_function: new::wasmer::Function::new_env::( + &get_global_store(), + ctx, + func, + ), + _phantom: PhantomData, + } + } + + /// Returns the full function signature. + pub fn signature(&self) -> &FuncSig { + self.new_function.ty() + } + + /// Returns the types of the function inputs. + pub fn params(&self) -> &[Type] { + self.signature().params() + } + + /// Returns the types of the function outputs. + pub fn returns(&self) -> &[Type] { + self.signature().results() + } + + /// Call the function by passing all arguments in a slice of `Value`. + pub fn dyn_call(&self, params: &[Value]) -> Result, RuntimeError> { + self.new_function.call(params) + } +} + +pub unsafe trait WasmExternTypeInner: WasmExternType +where + Self: Sized, +{ +} + +unsafe impl WasmExternTypeInner for i8 {} +unsafe impl WasmExternTypeInner for u8 {} +unsafe impl WasmExternTypeInner for i16 {} +unsafe impl WasmExternTypeInner for u16 {} +unsafe impl WasmExternTypeInner for i32 {} +unsafe impl WasmExternTypeInner for u32 {} +unsafe impl WasmExternTypeInner for i64 {} +unsafe impl WasmExternTypeInner for u64 {} +unsafe impl WasmExternTypeInner for f32 {} +unsafe impl WasmExternTypeInner for f64 {} + +macro_rules! func_call { + ( $( $x:ident ),* ) => { + #[allow(unused_parens)] + impl< $( $x, )* Rets: WasmTypeList > Func<( $( $x ),* ), Rets> + where + $( $x: WasmExternType + WasmExternTypeInner, )* + Rets: WasmTypeList + { + /// Call the function. + #[allow(non_snake_case, clippy::too_many_arguments)] + pub fn call(&self, $( $x: $x, )* ) -> Result { + // Two implementation choices: + // 1. Either by using the `NativeFunc` API, but a + // new native function must be created for each + // call, + // 2. Pack the parameters into a slice, call + // `dyn_call` with it, and unpack the results. + // + // The first implementation is the following: + // + // self.new_function.native::<( $( $x ),* ), Rets>().unwrap().call( $( $x ),* ) + // + // The second implementation is the following active one: + + // Pack the argument into a slice. + let params: &[Value] = &[ + $( + $x.to_native().to_value() + ),* + ]; + + // Call the function with `dyn_call`, and transform the results into a vector. + let results: Vec = self.dyn_call(params)?.to_vec(); + + // Map the results into their binary form. + let rets: Vec = results + .iter() + .map(|value| { + Ok(match value { + Value::I32(value) => ::from_native(*value).to_binary(), + Value::I64(value) => ::from_native(*value).to_binary(), + Value::F32(value) => ::from_native(*value).to_binary(), + Value::F64(value) => ::from_native(*value).to_binary(), + value => return Err(RuntimeError::new(format!( + "value `{:?}` is not supported as a returned value of a host function for the moment; please use `dyn_call` or the new API", + value + ))), + }) + }) + .collect::>()?; + + // Convert `Vec` into a `WasmTypeList`. + let rets: Rets = Rets::from_slice(rets.as_slice()).map_err(|_| { + RuntimeError::new(format!( + "returned values (`{:?}`) do not match the expected returned type (`{:?}`)", + results, + Rets::wasm_types() + )) + })?; + + Ok(rets) + } + } + } +} + +func_call!(); +func_call!(A1); +func_call!(A1, A2); +func_call!(A1, A2, A3); +func_call!(A1, A2, A3, A4); +func_call!(A1, A2, A3, A4, A5); +func_call!(A1, A2, A3, A4, A5, A6); +func_call!(A1, A2, A3, A4, A5, A6, A7); +func_call!(A1, A2, A3, A4, A5, A6, A7, A8); +func_call!(A1, A2, A3, A4, A5, A6, A7, A8, A9); +func_call!(A1, A2, A3, A4, A5, A6, A7, A8, A9, A10); +func_call!(A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11); +func_call!(A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12); +func_call!(A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12, A13); +func_call!(A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12, A13, A14); +func_call!(A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12, A13, A14, A15); +func_call!(A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12, A13, A14, A15, A16); +func_call!(A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12, A13, A14, A15, A16, A17); +func_call!(A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12, A13, A14, A15, A16, A17, A18); +func_call!(A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12, A13, A14, A15, A16, A17, A18, A19); +func_call!( + A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12, A13, A14, A15, A16, A17, A18, A19, A20 +); + +impl From> for new::wasmer::Extern +where + Args: WasmTypeList, + Rets: WasmTypeList, +{ + fn from(func: Func) -> Self { + new::wasmer::Extern::Function(func.new_function) + } +} + +impl From<&new::wasmer::Function> for Func +where + Args: WasmTypeList, + Rets: WasmTypeList, +{ + fn from(new_function: &new::wasmer::Function) -> Self { + Self { + new_function: new_function.clone(), + _phantom: PhantomData, + } + } +} + +impl<'a, Args, Rets> new::wasmer::Exportable<'a> for Func +where + Args: WasmTypeList, + Rets: WasmTypeList, +{ + fn to_export(&self) -> new::wasmer_vm::Export { + self.new_function.to_export() + } + + fn get_self_from_extern(r#extern: &'a new::wasmer::Extern) -> Result<&'a Self, ExportError> { + match r#extern { + new::wasmer::Extern::Function(func) => Ok( + // It's not ideal to call `Box::leak` here, but it + // would introduce too much changes in the + // `new::wasmer` API to support `Cow` or similar. + Box::leak(Box::>::new(func.into())), + ), + _ => Err(ExportError::IncompatibleType), + } + } +} + +/// Represents a type-erased function provided by either the host or the WebAssembly program. +#[derive(Clone)] +pub struct DynamicFunc { + new_function: new::wasmer::Function, +} + +use std::{ + cell::{RefCell, RefMut}, + ops::DerefMut, + rc::Rc, +}; + +/// Specific context for `DynamicFunc`. It's a hack. +/// +/// Initially, it holds an empty `vm::Ctx`, but it is replaced by the +/// `vm::Ctx` from `instance::PreInstance` in +/// `module::Module::instantiate`. +pub(crate) struct DynamicCtx { + pub(crate) vmctx: Rc>, +} + +impl DynamicFunc { + /// Create a new `DynamicFunc`. + pub fn new(signature: &FuncSig, func: F) -> Self + where + F: Fn(&mut vm::Ctx, &[Value]) -> Result, RuntimeError> + 'static, + { + // Create an empty `vm::Ctx`, that is going to be overwritten by `Instance::new`. + let ctx = DynamicCtx { + vmctx: Rc::new(RefCell::new(unsafe { vm::Ctx::new_uninit() })), + }; + + Self { + new_function: new::wasmer::Function::new_dynamic_env( + &get_global_store(), + signature, + ctx, + // Wrapper to safely extract a `&mut vm::Ctx` to pass + // to `func`. + move |dyn_ctx: &mut DynamicCtx, + params: &[Value]| + -> Result, RuntimeError> { + let cell: Rc> = dyn_ctx.vmctx.clone(); + let mut vmctx: RefMut = cell.borrow_mut(); + + func(vmctx.deref_mut(), params) + }, + ), + } + } + + /// Returns the full function signature. + pub fn signature(&self) -> &FuncSig { + self.new_function.ty() + } + + /// Returns the types of the function inputs. + pub fn params(&self) -> &[Type] { + self.signature().params() + } + + /// Returns the types of the function outputs. + pub fn returns(&self) -> &[Type] { + self.signature().results() + } + + /// Call the function. In this case, it's an alias to `dyn_call`. + pub fn call(&self, params: &[Value]) -> Result, RuntimeError> { + self.dyn_call(params) + } + + /// Call the function. + pub fn dyn_call(&self, params: &[Value]) -> Result, RuntimeError> { + self.new_function.call(params) + } +} + +impl From for new::wasmer::Extern { + fn from(dynamic_func: DynamicFunc) -> Self { + new::wasmer::Extern::Function(dynamic_func.new_function) + } +} + +impl From<&new::wasmer::Function> for DynamicFunc { + fn from(new_function: &new::wasmer::Function) -> Self { + Self { + new_function: new_function.clone(), + } + } +} + +impl<'a> new::wasmer::Exportable<'a> for DynamicFunc { + fn to_export(&self) -> new::wasmer_vm::Export { + self.new_function.to_export() + } + + fn get_self_from_extern(r#extern: &'a new::wasmer::Extern) -> Result<&'a Self, ExportError> { + match r#extern { + new::wasmer::Extern::Function(dynamic_func) => Ok( + // It's not ideal to call `Box::leak` here, but it + // would introduce too much changes in the + // `new::wasmer` API to support `Cow` or similar. + Box::leak(Box::::new(dynamic_func.into())), + ), + _ => Err(ExportError::IncompatibleType), + } + } +} + +#[cfg(test)] +mod tests { + use super::*; + + macro_rules! test_func_arity_n { + ($test_name:ident, $($x:ident),*) => { + #[test] + fn $test_name() { + use crate::vm; + + fn with_vmctx(_: &mut vm::Ctx, $($x: i32),*) -> i32 { + vec![$($x),*].iter().sum() + } + + let _ = Func::new(with_vmctx); + let _ = Func::new(|_: &mut vm::Ctx, $($x: i32),*| -> i32 { + vec![$($x),*].iter().sum() + }); + } + } + } + + #[test] + fn test_func_arity_0() { + fn foo(_: &mut vm::Ctx) -> i32 { + 0 + } + + let _ = Func::new(foo); + let _ = Func::new(|_: &mut vm::Ctx| -> i32 { 0 }); + } + + test_func_arity_n!(test_func_arity_1, a); + test_func_arity_n!(test_func_arity_2, a, b); + test_func_arity_n!(test_func_arity_3, a, b, c); + test_func_arity_n!(test_func_arity_4, a, b, c, d); + test_func_arity_n!(test_func_arity_5, a, b, c, d, e); + test_func_arity_n!(test_func_arity_6, a, b, c, d, e, f); + test_func_arity_n!(test_func_arity_7, a, b, c, d, e, f, g); + test_func_arity_n!(test_func_arity_8, a, b, c, d, e, f, g, h); + test_func_arity_n!(test_func_arity_9, a, b, c, d, e, f, g, h, i); + test_func_arity_n!(test_func_arity_10, a, b, c, d, e, f, g, h, i, j); + test_func_arity_n!(test_func_arity_11, a, b, c, d, e, f, g, h, i, j, k); + test_func_arity_n!(test_func_arity_12, a, b, c, d, e, f, g, h, i, j, k, l); + test_func_arity_n!(test_func_arity_13, a, b, c, d, e, f, g, h, i, j, k, l, m); + test_func_arity_n!(test_func_arity_14, a, b, c, d, e, f, g, h, i, j, k, l, m, n); + #[rustfmt::skip] test_func_arity_n!(test_func_arity_15, a, b, c, d, e, f, g, h, i, j, k, l, m, n, o); + #[rustfmt::skip] test_func_arity_n!(test_func_arity_16, a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p); + #[rustfmt::skip] test_func_arity_n!(test_func_arity_17, a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q); + #[rustfmt::skip] test_func_arity_n!(test_func_arity_18, a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r); + #[rustfmt::skip] test_func_arity_n!(test_func_arity_19, a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s); + #[rustfmt::skip] test_func_arity_n!(test_func_arity_20, a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t); + #[rustfmt::skip] test_func_arity_n!(test_func_arity_21, a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u); + #[rustfmt::skip] test_func_arity_n!(test_func_arity_22, a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v); + #[rustfmt::skip] test_func_arity_n!(test_func_arity_23, a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w); + #[rustfmt::skip] test_func_arity_n!(test_func_arity_24, a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x); + #[rustfmt::skip] test_func_arity_n!(test_func_arity_25, a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y); + #[rustfmt::skip] test_func_arity_n!(test_func_arity_26, a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z); + + #[test] + fn test_call() { + fn foo(_ctx: &mut vm::Ctx, a: i32, b: i32) -> (i32, i32) { + (a, b) + } + + let _f = Func::new(foo); + } + + #[test] + fn test_imports() { + use crate::{func, imports}; + + fn foo(_ctx: &mut vm::Ctx, a: i32) -> i32 { + a + } + + let _import_object = imports! { + "env" => { + "foo" => func!(foo), + }, + }; + } +} diff --git a/lib/deprecated/runtime-core/src/types.rs b/lib/deprecated/runtime-core/src/types.rs new file mode 100644 index 000000000..e32d1d0fc --- /dev/null +++ b/lib/deprecated/runtime-core/src/types.rs @@ -0,0 +1,99 @@ +use crate::new; + +pub use new::wasm_common::{ + // + ExportType as ExportDescriptor, + ExternType as ExternDescriptor, + FunctionIndex as FuncIndex, + FunctionIndex as ImportedFuncIndex, + FunctionType as FuncDescriptor, + FunctionType as FuncSig, + GlobalIndex as ImportedGlobalIndex, + GlobalIndex, + GlobalInit, + ImportType as ImportDescriptor, + LocalFunctionIndex as LocalFuncIndex, + LocalGlobalIndex, + LocalMemoryIndex, + LocalTableIndex, + MemoryIndex as ImportedMemoryIndex, + MemoryIndex, + MemoryType as MemoryDescriptor, + NativeWasmType, + SignatureIndex as SigIndex, + TableIndex as ImportedTableIndex, + TableIndex, + TableType as TableDescriptor, + Type, + ValueType, +}; +pub use new::wasmer::{FromToNativeWasmType as WasmExternType, Val as Value}; + +/// Describes the mutability and type of a Global +#[derive(Debug, Copy, Clone, Eq, PartialEq)] +pub struct GlobalDescriptor { + pub mutable: bool, + pub ty: Type, +} + +impl From<&new::wasm_common::GlobalType> for GlobalDescriptor { + fn from(value: &new::wasm_common::GlobalType) -> Self { + Self { + mutable: value.mutability.into(), + ty: value.ty, + } + } +} + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn test_native_types_round_trip() { + assert_eq!( + 42i32, + i32::from_native(i32::from_binary((42i32).to_native().to_binary())) + ); + + assert_eq!( + -42i32, + i32::from_native(i32::from_binary((-42i32).to_native().to_binary())) + ); + + use std::i64; + let xi64 = i64::MAX; + assert_eq!( + xi64, + i64::from_native(i64::from_binary((xi64).to_native().to_binary())) + ); + let yi64 = i64::MIN; + assert_eq!( + yi64, + i64::from_native(i64::from_binary((yi64).to_native().to_binary())) + ); + + assert_eq!( + 16.5f32, + f32::from_native(f32::from_binary((16.5f32).to_native().to_binary())) + ); + + assert_eq!( + -16.5f32, + f32::from_native(f32::from_binary((-16.5f32).to_native().to_binary())) + ); + + use std::f64; + let xf64: f64 = f64::MAX; + assert_eq!( + xf64, + f64::from_native(f64::from_binary((xf64).to_native().to_binary())) + ); + + let yf64: f64 = f64::MIN; + assert_eq!( + yf64, + f64::from_native(f64::from_binary((yf64).to_native().to_binary())) + ); + } +} diff --git a/lib/deprecated/runtime-core/src/units.rs b/lib/deprecated/runtime-core/src/units.rs new file mode 100644 index 000000000..105d15754 --- /dev/null +++ b/lib/deprecated/runtime-core/src/units.rs @@ -0,0 +1,10 @@ +use crate::new; + +pub use new::wasm_common::{ + // + Bytes, + Pages, + WASM_MAX_PAGES, + WASM_MIN_PAGES, + WASM_PAGE_SIZE, +}; diff --git a/lib/deprecated/runtime-core/src/vm.rs b/lib/deprecated/runtime-core/src/vm.rs new file mode 100644 index 000000000..8b129e3c6 --- /dev/null +++ b/lib/deprecated/runtime-core/src/vm.rs @@ -0,0 +1,81 @@ +use crate::module::ModuleInfo; +use std::{ffi::c_void, ptr}; + +/// The context of the currently running WebAssembly instance. +/// +/// This is implicitly passed to every WebAssembly function. +/// Since this is per-instance, each field has a statically +/// (as in after compiling the wasm) known size, so no +/// runtime checks are necessary. +/// +/// While the runtime currently just passes this around +/// as the first, implicit parameter of every function, +/// it may someday be pinned to a register (especially +/// on arm, which has a ton of registers) to reduce +/// register shuffling. +#[derive(Debug, Clone)] +#[repr(C)] +pub struct Ctx { + /// A pointer to the `ModuleInfo` of this instance. + pub module_info: *const ModuleInfo, + + /// This is intended to be user-supplied, per-instance + /// contextual data. There are currently some issue with it, + /// notably that it cannot be set before running the `start` + /// function in a WebAssembly module. Additionally, the `data` + /// field may be taken by another ABI implementation that the user + /// wishes to use in addition to their own, such as WASI. This issue is + /// being discussed at [#1111](https://github.com/wasmerio/wasmer/pull/1111). + /// + /// Alternatively, per-function data can be used if the function in the + /// [`ImportObject`] is a closure. This cannot duplicate data though, + /// so if data may be shared if the [`ImportObject`] is reused. + pub data: *mut c_void, + + /// If there's a function set in this field, it gets called + /// when the context is destructed, e.g. when an `Instance` + /// is dropped. + pub data_finalizer: Option, +} + +impl Ctx { + pub(crate) unsafe fn new_uninit() -> Self { + Self { + module_info: ptr::null(), + data: ptr::null_mut(), + data_finalizer: None, + } + } +} + +impl Drop for Ctx { + fn drop(&mut self) { + if let Some(ref finalizer) = self.data_finalizer { + finalizer(self.data); + } + } +} + +#[cfg(test)] +mod tests { + use super::*; + use std::mem::forget; + + #[test] + fn test_callback_on_drop() { + let foo = String::from("foo"); + let mut ctx = unsafe { Ctx::new_uninit() }; + + ctx.data = foo.as_ptr() as *const _ as *mut _; + ctx.data_finalizer = Some(|data| { + let foo = unsafe { String::from_raw_parts(data as *mut _, 3, 3) }; + + assert_eq!(String::from("foo"), foo); + + drop(foo); + }); + + drop(ctx); + forget(foo); + } +} diff --git a/lib/deprecated/runtime/.empty b/lib/deprecated/runtime/.empty new file mode 100644 index 000000000..e69de29bb diff --git a/lib/deprecated/runtime/Cargo.lock b/lib/deprecated/runtime/Cargo.lock new file mode 100644 index 000000000..ef436d63b --- /dev/null +++ b/lib/deprecated/runtime/Cargo.lock @@ -0,0 +1,1321 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +[[package]] +name = "addr2line" +version = "0.13.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1b6a2d3371669ab3ca9797670853d61402b03d0b4b9ebf33d677dfa720203072" +dependencies = [ + "gimli 0.22.0", +] + +[[package]] +name = "adler" +version = "0.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ee2a4ec343196209d6594e19543ae87a39f96d5534d7174822a3ad825dd6ed7e" + +[[package]] +name = "aho-corasick" +version = "0.7.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "043164d8ba5c4c3035fec9bbee8647c0261d788f3474306f93bb65901cae0e86" +dependencies = [ + "memchr", +] + +[[package]] +name = "arrayref" +version = "0.3.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a4c527152e37cf757a3f78aae5a06fbeefdb07ccc535c980a3208ee3060dd544" + +[[package]] +name = "arrayvec" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cff77d8686867eceff3105329d4698d96c2391c176d5d03adc90c7389162b5b8" + +[[package]] +name = "autocfg" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f8aac770f1885fd7e387acedd76065302551364496e46b3dd00860b2f8359b9d" + +[[package]] +name = "backtrace" +version = "0.3.50" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "46254cf2fdcdf1badb5934448c1bcbe046a56537b3987d96c51a7afc5d03f293" +dependencies = [ + "addr2line", + "cfg-if", + "libc", + "miniz_oxide", + "object 0.20.0", + "rustc-demangle", +] + +[[package]] +name = "bincode" +version = "1.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f30d3a39baa26f9651f17b375061f3233dde33424a8b72b0dbe93a68a0bc896d" +dependencies = [ + "byteorder", + "serde", +] + +[[package]] +name = "bitflags" +version = "1.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cf1de2fe8c75bc145a2f577add951f8134889b4795d47466a54a5c846d691693" + +[[package]] +name = "blake3" +version = "0.3.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "59f88a20f7dc23e3896bcbd85add056543c87215de721468b90e0c85d5a9f365" +dependencies = [ + "arrayref", + "arrayvec", + "cc", + "cfg-if", + "constant_time_eq", + "crypto-mac", + "digest", +] + +[[package]] +name = "byteorder" +version = "1.3.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "08c48aae112d48ed9f069b33538ea9e3e90aa263cfa3d1c24309612b1f7472de" + +[[package]] +name = "cc" +version = "1.0.58" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f9a06fb2e53271d7c279ec1efea6ab691c35a2ae67ec0d91d7acec0caf13b518" + +[[package]] +name = "cfg-if" +version = "0.1.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4785bdd1c96b2a846b2bd7cc02e86b6b3dbf14e7e53446c4f54c92a361040822" + +[[package]] +name = "cloudabi" +version = "0.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ddfc5b9aa5d4507acaf872de71051dfd0e309860e88966e1051e462a077aac4f" +dependencies = [ + "bitflags", +] + +[[package]] +name = "constant_time_eq" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "245097e9a4535ee1e3e3931fcfcd55a796a44c643e8596ff6566d68f09b87bbc" + +[[package]] +name = "cranelift-bforest" +version = "0.65.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d9413a2c6bdb01ab8acc867421bd7343ddea491d015453f4e56f4f60c816d120" +dependencies = [ + "cranelift-entity", +] + +[[package]] +name = "cranelift-codegen" +version = "0.65.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f28d389588c2375bb95292e0bc6cbf010e7f30fb4e9734738b576521b737826a" +dependencies = [ + "byteorder", + "cranelift-bforest", + "cranelift-codegen-meta", + "cranelift-codegen-shared", + "cranelift-entity", + "gimli 0.21.0", + "log", + "regalloc", + "serde", + "smallvec", + "target-lexicon", + "thiserror", +] + +[[package]] +name = "cranelift-codegen-meta" +version = "0.65.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "74dd3cf6f107c1df4c2b8aab91ec4181aee7ff17289673fcbec63325e7e40a83" +dependencies = [ + "cranelift-codegen-shared", + "cranelift-entity", +] + +[[package]] +name = "cranelift-codegen-shared" +version = "0.65.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "efaf050fab2dbf324544489443ff3cc8c67c9420c8902ec6628bd906bd7393e9" + +[[package]] +name = "cranelift-entity" +version = "0.65.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f07eb8aa0a5da94b56339e4e3052c496a3df4354357cd5da8c7b02c6e8f1dc1d" +dependencies = [ + "serde", +] + +[[package]] +name = "cranelift-frontend" +version = "0.65.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0f6fe1d3e968576f4b60d23f40ee90281f8de2cdf23d2110f3b0296ff420555e" +dependencies = [ + "cranelift-codegen", + "log", + "smallvec", + "target-lexicon", +] + +[[package]] +name = "crc32fast" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ba125de2af0df55319f41944744ad91c71113bf74a4646efff39afe1f6842db1" +dependencies = [ + "cfg-if", +] + +[[package]] +name = "crossbeam-deque" +version = "0.7.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9f02af974daeee82218205558e51ec8768b48cf524bd01d550abe5573a608285" +dependencies = [ + "crossbeam-epoch", + "crossbeam-utils", + "maybe-uninit", +] + +[[package]] +name = "crossbeam-epoch" +version = "0.8.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "058ed274caafc1f60c4997b5fc07bf7dc7cca454af7c6e81edffe5f33f70dace" +dependencies = [ + "autocfg", + "cfg-if", + "crossbeam-utils", + "lazy_static", + "maybe-uninit", + "memoffset", + "scopeguard", +] + +[[package]] +name = "crossbeam-queue" +version = "0.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "774ba60a54c213d409d5353bda12d49cd68d14e45036a285234c8d6f91f92570" +dependencies = [ + "cfg-if", + "crossbeam-utils", + "maybe-uninit", +] + +[[package]] +name = "crossbeam-utils" +version = "0.7.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c3c7c73a2d1e9fc0886a08b93e98eb643461230d5f1925e4036204d5f2e261a8" +dependencies = [ + "autocfg", + "cfg-if", + "lazy_static", +] + +[[package]] +name = "crypto-mac" +version = "0.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b584a330336237c1eecd3e94266efb216c56ed91225d634cb2991c5f3fd1aeab" +dependencies = [ + "generic-array", + "subtle", +] + +[[package]] +name = "darling" +version = "0.10.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0d706e75d87e35569db781a9b5e2416cff1236a47ed380831f959382ccd5f858" +dependencies = [ + "darling_core", + "darling_macro", +] + +[[package]] +name = "darling_core" +version = "0.10.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f0c960ae2da4de88a91b2d920c2a7233b400bc33cb28453a2987822d8392519b" +dependencies = [ + "fnv", + "ident_case", + "proc-macro2", + "quote", + "strsim", + "syn", +] + +[[package]] +name = "darling_macro" +version = "0.10.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d9b5a2f4ac4969822c62224815d069952656cadc7084fdca9751e6d959189b72" +dependencies = [ + "darling_core", + "quote", + "syn", +] + +[[package]] +name = "digest" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d3dd60d1080a57a05ab032377049e0591415d2b31afd7028356dbf3cc6dcb066" +dependencies = [ + "generic-array", +] + +[[package]] +name = "dynasm" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "48be6e89d4c88d2945d5c57d50a2d7c46325a3ae358a11cdf263c545eace97c6" +dependencies = [ + "bitflags", + "byteorder", + "lazy_static", + "owning_ref", + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "dynasmrt" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7dce4800e1140e94ad07e35e789df569516fd795223600a96f3b01887a42e0da" +dependencies = [ + "byteorder", + "memmap", +] + +[[package]] +name = "either" +version = "1.5.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bb1f6b1ce1c140482ea30ddd3335fc0024ac7ee112895426e0a629a6c20adfe3" + +[[package]] +name = "enumset" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3691ce759534316ad900d57dd8e688e2c4263f9750c0f7c1e9b9a4516d4ca241" +dependencies = [ + "enumset_derive", + "num-traits", +] + +[[package]] +name = "enumset_derive" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "74bef436ac71820c5cf768d7af9ba33121246b09a00e09a55d94ef8095a875ac" +dependencies = [ + "darling", + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "fallible-iterator" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4443176a9f2c162692bd3d352d745ef9413eec5782a80d8fd6f8a1ac692a07f7" + +[[package]] +name = "fnv" +version = "1.0.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" + +[[package]] +name = "generic-array" +version = "0.14.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "60fb4bb6bba52f78a471264d9a3b7d026cc0af47b22cd2cffbc0b787ca003e63" +dependencies = [ + "typenum", + "version_check", +] + +[[package]] +name = "getrandom" +version = "0.1.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7abc8dd8451921606d809ba32e95b6111925cd2906060d2dcc29c070220503eb" +dependencies = [ + "cfg-if", + "libc", + "wasi", +] + +[[package]] +name = "gimli" +version = "0.21.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bcc8e0c9bce37868955864dbecd2b1ab2bdf967e6f28066d65aaac620444b65c" +dependencies = [ + "fallible-iterator", + "indexmap", + "stable_deref_trait", +] + +[[package]] +name = "gimli" +version = "0.22.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "aaf91faf136cb47367fa430cd46e37a788775e7fa104f8b4bcb3861dc389b724" + +[[package]] +name = "goblin" +version = "0.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d20fd25aa456527ce4f544271ae4fea65d2eda4a6561ea56f39fb3ee4f7e3884" +dependencies = [ + "log", + "plain", + "scroll", +] + +[[package]] +name = "hermit-abi" +version = "0.1.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3deed196b6e7f9e44a2ae8d94225d80302d81208b1bb673fd21fe634645c85a9" +dependencies = [ + "libc", +] + +[[package]] +name = "hex" +version = "0.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "644f9158b2f133fd50f5fb3242878846d9eb792e445c893805ff0e3824006e35" + +[[package]] +name = "ident_case" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b9e0384b61958566e926dc50660321d12159025e767c18e043daf26b70104c39" + +[[package]] +name = "indexmap" +version = "1.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c398b2b113b55809ceb9ee3e753fcbac793f1956663f3c36549c1346015c2afe" +dependencies = [ + "autocfg", + "serde", +] + +[[package]] +name = "inkwell" +version = "0.1.0" +source = "git+https://github.com/theDan64/inkwell?rev=fdf895777e937c974204e879cf1102cf7a727c42#fdf895777e937c974204e879cf1102cf7a727c42" +dependencies = [ + "either", + "inkwell_internals", + "libc", + "llvm-sys", + "once_cell", + "parking_lot", + "regex", +] + +[[package]] +name = "inkwell_internals" +version = "0.2.0" +source = "git+https://github.com/theDan64/inkwell?rev=fdf895777e937c974204e879cf1102cf7a727c42#fdf895777e937c974204e879cf1102cf7a727c42" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "itertools" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "284f18f85651fe11e8a991b2adb42cb078325c996ed026d994719efcfca1d54b" +dependencies = [ + "either", +] + +[[package]] +name = "lazy_static" +version = "1.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" + +[[package]] +name = "leb128" +version = "0.2.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3576a87f2ba00f6f106fdfcd16db1d698d648a26ad8e0573cad8537c3c362d2a" + +[[package]] +name = "libc" +version = "0.2.72" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a9f8082297d534141b30c8d39e9b1773713ab50fdbe4ff30f750d063b3bfd701" + +[[package]] +name = "libloading" +version = "0.6.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2cadb8e769f070c45df05c78c7520eb4cd17061d4ab262e43cfc68b4d00ac71c" +dependencies = [ + "winapi", +] + +[[package]] +name = "llvm-sys" +version = "100.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5545bf9a09267c644e4d0ac68f37ac200af6579ae2e82aebce382654eb4abab1" +dependencies = [ + "cc", + "lazy_static", + "libc", + "regex", + "semver", +] + +[[package]] +name = "lock_api" +version = "0.3.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c4da24a77a3d8a6d4862d95f72e6fdb9c09a643ecdb402d754004a557f2bec75" +dependencies = [ + "scopeguard", +] + +[[package]] +name = "log" +version = "0.4.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4fabed175da42fed1fa0746b0ea71f412aa9d35e76e95e59b192c64b9dc2bf8b" +dependencies = [ + "cfg-if", +] + +[[package]] +name = "mach" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b823e83b2affd8f40a9ee8c29dbc56404c1e34cd2710921f2801e2cf29527afa" +dependencies = [ + "libc", +] + +[[package]] +name = "maybe-uninit" +version = "2.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "60302e4db3a61da70c0cb7991976248362f30319e88850c487b9b95bbf059e00" + +[[package]] +name = "memchr" +version = "2.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3728d817d99e5ac407411fa471ff9800a778d88a24685968b36824eaf4bee400" + +[[package]] +name = "memmap" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6585fd95e7bb50d6cc31e20d4cf9afb4e2ba16c5846fc76793f11218da9c475b" +dependencies = [ + "libc", + "winapi", +] + +[[package]] +name = "memoffset" +version = "0.5.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c198b026e1bbf08a937e94c6c60f9ec4a2267f5b0d2eec9c1b21b061ce2be55f" +dependencies = [ + "autocfg", +] + +[[package]] +name = "miniz_oxide" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "be0f75932c1f6cfae3c04000e40114adf955636e19040f9c0a2c380702aa1c7f" +dependencies = [ + "adler", +] + +[[package]] +name = "more-asserts" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0debeb9fcf88823ea64d64e4a815ab1643f33127d995978e099942ce38f25238" + +[[package]] +name = "num-traits" +version = "0.2.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ac267bcc07f48ee5f8935ab0d24f316fb722d7a1292e2913f0cc196b29ffd611" +dependencies = [ + "autocfg", +] + +[[package]] +name = "num_cpus" +version = "1.13.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "05499f3756671c15885fee9034446956fff3f243d6077b91e5767df161f766b3" +dependencies = [ + "hermit-abi", + "libc", +] + +[[package]] +name = "object" +version = "0.19.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9cbca9424c482ee628fa549d9c812e2cd22f1180b9222c9200fdfa6eb31aecb2" +dependencies = [ + "crc32fast", + "indexmap", +] + +[[package]] +name = "object" +version = "0.20.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1ab52be62400ca80aa00285d25253d7f7c437b7375c4de678f5405d3afe82ca5" + +[[package]] +name = "once_cell" +version = "1.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b631f7e854af39a1739f401cf34a8a013dfe09eac4fa4dba91e9768bd28168d" + +[[package]] +name = "owning_ref" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6ff55baddef9e4ad00f88b6c743a2a8062d4c6ade126c2a528644b8e444d52ce" +dependencies = [ + "stable_deref_trait", +] + +[[package]] +name = "parking_lot" +version = "0.10.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d3a704eb390aafdc107b0e392f56a82b668e3a71366993b5340f5833fd62505e" +dependencies = [ + "lock_api", + "parking_lot_core", +] + +[[package]] +name = "parking_lot_core" +version = "0.7.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d58c7c768d4ba344e3e8d72518ac13e259d7c7ade24167003b8488e10b6740a3" +dependencies = [ + "cfg-if", + "cloudabi", + "libc", + "redox_syscall", + "smallvec", + "winapi", +] + +[[package]] +name = "plain" +version = "0.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b4596b6d070b27117e987119b4dac604f3c58cfb0b191112e24771b2faeac1a6" + +[[package]] +name = "ppv-lite86" +version = "0.2.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "237a5ed80e274dbc66f86bd59c1e25edc039660be53194b5fe0a482e0f2612ea" + +[[package]] +name = "proc-macro2" +version = "1.0.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "beae6331a816b1f65d04c45b078fd8e6c93e8071771f41b8163255bbd8d7c8fa" +dependencies = [ + "unicode-xid", +] + +[[package]] +name = "quote" +version = "1.0.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "aa563d17ecb180e500da1cfd2b028310ac758de548efdd203e18f283af693f37" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "rand" +version = "0.7.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6a6b1679d49b24bbfe0c803429aa1874472f50d9b363131f0e89fc356b544d03" +dependencies = [ + "getrandom", + "libc", + "rand_chacha", + "rand_core", + "rand_hc", +] + +[[package]] +name = "rand_chacha" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f4c8ed856279c9737206bf725bf36935d8666ead7aa69b52be55af369d193402" +dependencies = [ + "ppv-lite86", + "rand_core", +] + +[[package]] +name = "rand_core" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "90bde5296fc891b0cef12a6d03ddccc162ce7b2aff54160af9338f8d40df6d19" +dependencies = [ + "getrandom", +] + +[[package]] +name = "rand_hc" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ca3129af7b92a17112d59ad498c6f81eaf463253766b90396d39ea7a39d6613c" +dependencies = [ + "rand_core", +] + +[[package]] +name = "raw-cpuid" +version = "7.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b4a349ca83373cfa5d6dbb66fd76e58b2cca08da71a5f6400de0a0a6a9bceeaf" +dependencies = [ + "bitflags", + "cc", + "rustc_version", +] + +[[package]] +name = "rayon" +version = "1.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "62f02856753d04e03e26929f820d0a0a337ebe71f849801eea335d464b349080" +dependencies = [ + "autocfg", + "crossbeam-deque", + "either", + "rayon-core", +] + +[[package]] +name = "rayon-core" +version = "1.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e92e15d89083484e11353891f1af602cc661426deb9564c298b270c726973280" +dependencies = [ + "crossbeam-deque", + "crossbeam-queue", + "crossbeam-utils", + "lazy_static", + "num_cpus", +] + +[[package]] +name = "redox_syscall" +version = "0.1.57" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "41cc0f7e4d5d4544e8861606a285bb08d3e70712ccc7d2b84d7c0ccfaf4b05ce" + +[[package]] +name = "regalloc" +version = "0.0.26" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7c03092d79e0fd610932d89ed53895a38c0dd3bcd317a0046e69940de32f1d95" +dependencies = [ + "log", + "rustc-hash", + "smallvec", +] + +[[package]] +name = "regex" +version = "1.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9c3780fcf44b193bc4d09f36d2a3c87b251da4a046c87795a0d35f4f927ad8e6" +dependencies = [ + "aho-corasick", + "memchr", + "regex-syntax", + "thread_local", +] + +[[package]] +name = "regex-syntax" +version = "0.6.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "26412eb97c6b088a6997e05f69403a802a92d520de2f8e63c2b65f9e0f47c4e8" + +[[package]] +name = "region" +version = "2.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "877e54ea2adcd70d80e9179344c97f93ef0dffd6b03e1f4529e6e83ab2fa9ae0" +dependencies = [ + "bitflags", + "libc", + "mach", + "winapi", +] + +[[package]] +name = "remove_dir_all" +version = "0.5.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3acd125665422973a33ac9d3dd2df85edad0f4ae9b00dafb1a05e43a9f5ef8e7" +dependencies = [ + "winapi", +] + +[[package]] +name = "rustc-demangle" +version = "0.1.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4c691c0e608126e00913e33f0ccf3727d5fc84573623b8d65b2df340b5201783" + +[[package]] +name = "rustc-hash" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "08d43f7aa6b08d49f382cde6a7982047c3426db949b1424bc4b7ec9ae12c6ce2" + +[[package]] +name = "rustc_version" +version = "0.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "138e3e0acb6c9fb258b19b67cb8abd63c00679d2851805ea151465464fe9030a" +dependencies = [ + "semver", +] + +[[package]] +name = "scopeguard" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d29ab0c6d3fc0ee92fe66e2d99f700eab17a8d57d1c1d3b748380fb20baa78cd" + +[[package]] +name = "scroll" +version = "0.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "abb2332cb595d33f7edd5700f4cbf94892e680c7f0ae56adab58a35190b66cb1" +dependencies = [ + "scroll_derive", +] + +[[package]] +name = "scroll_derive" +version = "0.10.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e367622f934864ffa1c704ba2b82280aab856e3d8213c84c5720257eb34b15b9" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "semver" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1d7eb9ef2c18661902cc47e535f9bc51b78acd254da71d375c2f6720d9a40403" +dependencies = [ + "semver-parser", +] + +[[package]] +name = "semver-parser" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "388a1df253eca08550bef6c72392cfe7c30914bf41df5269b68cbd6ff8f570a3" + +[[package]] +name = "serde" +version = "1.0.114" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5317f7588f0a5078ee60ef675ef96735a1442132dc645eb1d12c018620ed8cd3" +dependencies = [ + "serde_derive", +] + +[[package]] +name = "serde_bytes" +version = "0.11.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "16ae07dd2f88a366f15bd0632ba725227018c69a1c8550a927324f8eb8368bb9" +dependencies = [ + "serde", +] + +[[package]] +name = "serde_derive" +version = "1.0.114" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2a0be94b04690fbaed37cddffc5c134bf537c8e3329d53e982fe04c374978f8e" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "smallvec" +version = "1.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3757cb9d89161a2f24e1cf78efa0c1fcff485d18e3f55e0aa3480824ddaa0f3f" + +[[package]] +name = "stable_deref_trait" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a8f112729512f8e442d81f95a8a7ddf2b7c6b8a1a6f509a95864142b30cab2d3" + +[[package]] +name = "strsim" +version = "0.9.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6446ced80d6c486436db5c078dde11a9f73d42b57fb273121e160b84f63d894c" + +[[package]] +name = "subtle" +version = "2.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "502d53007c02d7605a05df1c1a73ee436952781653da5d0bf57ad608f66932c1" + +[[package]] +name = "syn" +version = "1.0.34" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "936cae2873c940d92e697597c5eee105fb570cd5689c695806f672883653349b" +dependencies = [ + "proc-macro2", + "quote", + "unicode-xid", +] + +[[package]] +name = "target-lexicon" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ab0e7238dcc7b40a7be719a25365910f6807bd864f4cce6b2e6b873658e2b19d" + +[[package]] +name = "tempfile" +version = "3.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7a6e24d9338a0a5be79593e2fa15a648add6138caa803e2d5bc782c371732ca9" +dependencies = [ + "cfg-if", + "libc", + "rand", + "redox_syscall", + "remove_dir_all", + "winapi", +] + +[[package]] +name = "thiserror" +version = "1.0.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7dfdd070ccd8ccb78f4ad66bf1982dc37f620ef696c6b5028fe2ed83dd3d0d08" +dependencies = [ + "thiserror-impl", +] + +[[package]] +name = "thiserror-impl" +version = "1.0.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bd80fc12f73063ac132ac92aceea36734f04a1d93c1240c6944e23a3b8841793" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "thread_local" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d40c6d1b69745a6ec6fb1ca717914848da4b44ae29d9b3080cbee91d72a69b14" +dependencies = [ + "lazy_static", +] + +[[package]] +name = "tracing" +version = "0.1.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c2e2a2de6b0d5cbb13fc21193a2296888eaab62b6044479aafb3c54c01c29fcd" +dependencies = [ + "cfg-if", + "tracing-attributes", + "tracing-core", +] + +[[package]] +name = "tracing-attributes" +version = "0.1.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f0693bf8d6f2bf22c690fc61a9d21ac69efdbb894a17ed596b9af0f01e64b84b" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "tracing-core" +version = "0.1.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "94ae75f0d28ae10786f3b1895c55fe72e79928fd5ccdebb5438c75e93fec178f" +dependencies = [ + "lazy_static", +] + +[[package]] +name = "typenum" +version = "1.12.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "373c8a200f9e67a0c95e62a4f52fbf80c23b4381c05a17845531982fa99e6b33" + +[[package]] +name = "unicode-xid" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f7fe0bb3479651439c9112f72b6c505038574c9fbb575ed1bf3b797fa39dd564" + +[[package]] +name = "version_check" +version = "0.9.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b5a972e5669d67ba988ce3dc826706fb0a8b01471c088cb0b6110b805cc36aed" + +[[package]] +name = "wasi" +version = "0.9.0+wasi-snapshot-preview1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cccddf32554fecc6acb585f82a32a72e28b48f8c4c1883ddfeeeaa96f7d8e519" + +[[package]] +name = "wasm-common" +version = "1.0.0-alpha.1" +dependencies = [ + "cranelift-entity", + "serde", +] + +[[package]] +name = "wasmer" +version = "1.0.0-alpha.1" +dependencies = [ + "cfg-if", + "indexmap", + "more-asserts", + "target-lexicon", + "thiserror", + "wasm-common", + "wasmer-compiler", + "wasmer-compiler-cranelift", + "wasmer-compiler-llvm", + "wasmer-compiler-singlepass", + "wasmer-engine", + "wasmer-engine-jit", + "wasmer-engine-native", + "wasmer-vm", + "wat", + "winapi", +] + +[[package]] +name = "wasmer-cache" +version = "1.0.0-alpha.1" +dependencies = [ + "blake3", + "hex", + "memmap", + "thiserror", + "wasmer", +] + +[[package]] +name = "wasmer-compiler" +version = "1.0.0-alpha.1" +dependencies = [ + "enumset", + "raw-cpuid", + "serde", + "serde_bytes", + "smallvec", + "target-lexicon", + "thiserror", + "wasm-common", + "wasmer-vm", + "wasmparser", +] + +[[package]] +name = "wasmer-compiler-cranelift" +version = "1.0.0-alpha.1" +dependencies = [ + "cranelift-codegen", + "cranelift-frontend", + "gimli 0.21.0", + "more-asserts", + "rayon", + "serde", + "tracing", + "wasm-common", + "wasmer-compiler", + "wasmer-vm", +] + +[[package]] +name = "wasmer-compiler-llvm" +version = "1.0.0-alpha.1" +dependencies = [ + "byteorder", + "cc", + "goblin", + "inkwell", + "itertools", + "lazy_static", + "libc", + "rayon", + "regex", + "rustc_version", + "semver", + "smallvec", + "target-lexicon", + "wasm-common", + "wasmer-compiler", + "wasmer-vm", +] + +[[package]] +name = "wasmer-compiler-singlepass" +version = "1.0.0-alpha.1" +dependencies = [ + "byteorder", + "dynasm", + "dynasmrt", + "lazy_static", + "more-asserts", + "rayon", + "serde", + "smallvec", + "wasm-common", + "wasmer-compiler", + "wasmer-vm", +] + +[[package]] +name = "wasmer-engine" +version = "1.0.0-alpha.1" +dependencies = [ + "backtrace", + "bincode", + "lazy_static", + "more-asserts", + "rustc-demangle", + "serde", + "serde_bytes", + "target-lexicon", + "thiserror", + "wasm-common", + "wasmer-compiler", + "wasmer-vm", + "winapi", +] + +[[package]] +name = "wasmer-engine-jit" +version = "1.0.0-alpha.1" +dependencies = [ + "bincode", + "cfg-if", + "region", + "serde", + "serde_bytes", + "wasm-common", + "wasmer-compiler", + "wasmer-engine", + "wasmer-vm", + "winapi", +] + +[[package]] +name = "wasmer-engine-native" +version = "1.0.0-alpha.1" +dependencies = [ + "bincode", + "cfg-if", + "leb128", + "libloading", + "serde", + "serde_bytes", + "tempfile", + "tracing", + "wasm-common", + "wasmer-compiler", + "wasmer-engine", + "wasmer-object", + "wasmer-vm", +] + +[[package]] +name = "wasmer-object" +version = "1.0.0-alpha.1" +dependencies = [ + "object 0.19.0", + "thiserror", + "wasm-common", + "wasmer-compiler", +] + +[[package]] +name = "wasmer-runtime" +version = "0.18.0" +dependencies = [ + "wasmer-runtime-core", +] + +[[package]] +name = "wasmer-runtime-core" +version = "0.18.0" +dependencies = [ + "blake3", + "lazy_static", + "wasm-common", + "wasmer", + "wasmer-cache", + "wasmer-compiler", + "wasmer-compiler-cranelift", + "wasmer-compiler-llvm", + "wasmer-compiler-singlepass", + "wasmer-engine", + "wasmer-engine-jit", + "wasmer-vm", +] + +[[package]] +name = "wasmer-vm" +version = "1.0.0-alpha.1" +dependencies = [ + "backtrace", + "cc", + "cfg-if", + "indexmap", + "libc", + "memoffset", + "more-asserts", + "region", + "serde", + "thiserror", + "wasm-common", + "winapi", +] + +[[package]] +name = "wasmparser" +version = "0.57.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "32fddd575d477c6e9702484139cf9f23dcd554b06d185ed0f56c857dd3a47aa6" + +[[package]] +name = "wast" +version = "21.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b1844f66a2bc8526d71690104c0e78a8e59ffa1597b7245769d174ebb91deb5" +dependencies = [ + "leb128", +] + +[[package]] +name = "wat" +version = "1.0.22" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ce85d72b74242c340e9e3492cfb602652d7bb324c3172dd441b5577e39a2e18c" +dependencies = [ + "wast", +] + +[[package]] +name = "winapi" +version = "0.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419" +dependencies = [ + "winapi-i686-pc-windows-gnu", + "winapi-x86_64-pc-windows-gnu", +] + +[[package]] +name = "winapi-i686-pc-windows-gnu" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" + +[[package]] +name = "winapi-x86_64-pc-windows-gnu" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" diff --git a/lib/deprecated/runtime/Cargo.toml b/lib/deprecated/runtime/Cargo.toml new file mode 100644 index 000000000..9f9f19cd2 --- /dev/null +++ b/lib/deprecated/runtime/Cargo.toml @@ -0,0 +1,26 @@ +[package] +name = "wasmer-runtime" +version = "0.18.0" +description = "Wasmer runtime library" +license = "MIT" +authors = ["The Wasmer Engineering Team "] +repository = "https://github.com/wasmerio/wasmer" +keywords = ["wasm", "webassembly", "runtime", "sandbox", "secure"] +categories = ["wasm", "api-bindings"] +edition = "2018" +readme = "README.md" + +[badges] +maintenance = { status = "deprecated" } + +[dependencies] +wasmer-runtime-core = { path = "../runtime-core/", version = "0.18.0" } + +[features] +default = ["cranelift", "wasmer-runtime-core/default"] +cranelift = ["wasmer-runtime-core/cranelift"] +llvm = ["wasmer-runtime-core/llvm"] +singlepass = ["wasmer-runtime-core/singlepass"] +default-backend-cranelift = ["cranelift", "wasmer-runtime-core/default-backend-cranelift"] +default-backend-llvm = ["llvm", "wasmer-runtime-core/default-backend-llvm"] +default-backend-singlepass = ["singlepass", "wasmer-runtime-core/default-backend-singlepass"] \ No newline at end of file diff --git a/lib/deprecated/runtime/README.md b/lib/deprecated/runtime/README.md new file mode 100644 index 000000000..3a6c22557 --- /dev/null +++ b/lib/deprecated/runtime/README.md @@ -0,0 +1,120 @@ +# Wasmer Runtime Library [DEPRECATED] + +## Important Note; Please Read + +Thanks to users' feedbacks, collected experience and various usecases, +Wasmer has decided to entirely changed its API to offer the best user +experience and the best features to as many users as possible, just +before the 1.0 release. This new version of Wasmer includes many +improvements in terms of performance or the memory consumption, in +addition to a ton of new features and much better flexibility! + +In order to help our existing users to enjoy the performance boost and +memory improvements without updating their program that much, we have +created a new version of the `wasmer-runtime-core` crate, which is now +*a port* of the new API but with the old API, as much as +possible. Indeed, it was not always possible to provide the exact same +API, but changes are subtle. + +We have carefully documented most of the differences in [the +`CHANGES.md` document](./CHANGES.md). + +It is important to understand the public of this port. We do not +recommend to advanced users of Wasmer to use this port. Advanced API, +like `ModuleInfo` or the `vm` module (incl. `vm::Ctx`) have not been +fully ported because it was very internals to Wasmer. For advanced +users, we highly recommend to migrate to the new version of Wasmer, +which is awesome by the way (completely neutral opinion). The public +for this port is beginners or regular users that do not necesarily +have time to update their code immediately but that want to enjoy a +performance boost and memory improvements. + +## Introduction + +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 represents the high-level runtime API, making embedding +WebAssembly in your application easy, efficient, and safe. + +### How to use Wasmer Runtime + +The easiest way is to use the [`instantiate`] function to create an +[`Instance`]. Then you can use [`call`] or [`func`] and then +[`call`][func.call] to call an exported function safely. + +[`instantiate`]: https://docs.rs/wasmer-runtime/*/wasmer_runtime/fn.instantiate.html +[`Instance`]: https://docs.rs/wasmer-runtime/*/wasmer_runtime/struct.Instance.html +[`call`]: https://docs.rs/wasmer-runtime/*/wasmer_runtime/struct.Instance.html#method.call +[`func`]: https://docs.rs/wasmer-runtime/*/wasmer_runtime/struct.Instance.html#method.func +[func.call]: https://docs.rs/wasmer-runtime/*/wasmer_runtime/struct.Function.html#method.call + +### Example + +Given this WebAssembly: + +```wat +(module + (type $t0 (func (param i32) (result i32))) + (func $add_one (export "add_one") (type $t0) (param $p0 i32) (result i32) + get_local $p0 + i32.const 1 + i32.add)) +``` + +compiled into Wasm bytecode, we can call the exported `add_one` function: + +```rust +use wasmer_runtime::{imports, instantiate, DynFunc, Value}; + +static WASM: &'static [u8] = &[ + // The module above compiled to bytecode goes here. + 0x00, 0x61, 0x73, 0x6d, 0x01, 0x00, 0x00, 0x00, 0x01, 0x06, 0x01, 0x60, + 0x01, 0x7f, 0x01, 0x7f, 0x03, 0x02, 0x01, 0x00, 0x07, 0x0b, 0x01, 0x07, + 0x61, 0x64, 0x64, 0x5f, 0x6f, 0x6e, 0x65, 0x00, 0x00, 0x0a, 0x09, 0x01, + 0x07, 0x00, 0x20, 0x00, 0x41, 0x01, 0x6a, 0x0b, 0x00, 0x1a, 0x04, 0x6e, + 0x61, 0x6d, 0x65, 0x01, 0x0a, 0x01, 0x00, 0x07, 0x61, 0x64, 0x64, 0x5f, + 0x6f, 0x6e, 0x65, 0x02, 0x07, 0x01, 0x00, 0x01, 0x00, 0x02, 0x70, 0x30, +]; + +fn main() -> error::Result<()> { + // We're not importing anything, so make an empty import object. + let import_object = imports! {}; + + // Compile _and_ instantiate the Wasm module. + let instance = instantiate(WASM, &import_object)?; + + // Call the `add_one` exported function. + let values = instance + .exports + .get::("add_one")? + .call(&[Value::I32(42)])?; + + assert_eq!(values[0], Value::I32(43)); + + Ok(()) +} +``` + +### Additional Notes + +The `wasmer-runtime` crate is built to support multiple compiler +backends: + +* [`wasmer-compiler-singlepass`], +* [`wasmer-compiler-cranelift`], +* [`wasmer-compiler-llvm`]. + +You can specify the compiler you wish to use with the [`compile_with`] function: + +```rust +use wasmer_runtime::{compile_with, Backend}; + +let module = compile_with(wasm_bytes, Backend::LLVM)?; +``` + +[`compile_with`]: https://docs.rs/wasmer-runtime/*/wasmer_runtime/fn.compile_with.html +[`wasmer-compiler-singlepass`]: https://github.com/wasmerio/wasmer-reborn/tree/master/lib/compiler-singlepass +[`wasmer-compiler-cranelift`]: https://github.com/wasmerio/wasmer-reborn/tree/master/lib/compiler-cranelift +[`wasmer-compiler-llvm`]: https://github.com/wasmerio/wasmer-reborn/tree/master/lib/compiler-llvm diff --git a/lib/deprecated/runtime/examples/call.rs b/lib/deprecated/runtime/examples/call.rs new file mode 100644 index 000000000..b56914dd9 --- /dev/null +++ b/lib/deprecated/runtime/examples/call.rs @@ -0,0 +1,63 @@ +use std::{error, fmt}; +use wasmer_runtime::{compile, error::RuntimeError, imports, wat2wasm, Ctx, Func}; + +static WAT: &'static str = r#" + (module + (type (;0;) (func (result i32))) + (import "env" "do_panic" (func $do_panic (type 0))) + (func $dbz (result i32) + call $do_panic + drop + i32.const 42 + i32.const 0 + i32.div_u + ) + (export "dbz" (func $dbz)) + ) +"#; + +fn get_wasm() -> Vec { + wat2wasm(WAT.as_bytes()).unwrap().to_vec() +} + +#[derive(Debug)] +struct ExitCode { + code: i32, +} + +impl error::Error for ExitCode {} + +impl fmt::Display for ExitCode { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + write!(f, "{:?}", self) + } +} + +fn do_panic(_ctx: &mut Ctx) -> Result { + Err(RuntimeError::new(ExitCode { code: 42 }.to_string())) +} + +fn main() -> Result<(), Box> { + let wasm = get_wasm(); + let module = compile(&wasm)?; + + println!("instantiating"); + + let instance = module.instantiate(&imports! { + "env" => { + "do_panic" => Func::new(do_panic), + }, + })?; + + let foo: Func<(), i32> = instance.exports.get("dbz")?; + let result = foo.call(); + + println!("result: {:?}", result.unwrap_err().message()); + + Ok(()) +} + +#[test] +fn test_call() -> Result<(), Box> { + main() +} diff --git a/lib/deprecated/runtime/examples/readme.rs b/lib/deprecated/runtime/examples/readme.rs new file mode 100644 index 000000000..5626d8c1b --- /dev/null +++ b/lib/deprecated/runtime/examples/readme.rs @@ -0,0 +1,29 @@ +use wasmer_runtime::{imports, instantiate, DynFunc, Value}; + +static WASM: &'static [u8] = &[ + 0x00, 0x61, 0x73, 0x6d, 0x01, 0x00, 0x00, 0x00, 0x01, 0x06, 0x01, 0x60, 0x01, 0x7f, 0x01, 0x7f, + 0x03, 0x02, 0x01, 0x00, 0x07, 0x0b, 0x01, 0x07, 0x61, 0x64, 0x64, 0x5f, 0x6f, 0x6e, 0x65, 0x00, + 0x00, 0x0a, 0x09, 0x01, 0x07, 0x00, 0x20, 0x00, 0x41, 0x01, 0x6a, 0x0b, 0x00, 0x1a, 0x04, 0x6e, + 0x61, 0x6d, 0x65, 0x01, 0x0a, 0x01, 0x00, 0x07, 0x61, 0x64, 0x64, 0x5f, 0x6f, 0x6e, 0x65, 0x02, + 0x07, 0x01, 0x00, 0x01, 0x00, 0x02, 0x70, 0x30, +]; + +fn main() -> Result<(), Box> { + let import_object = imports! {}; + + let instance = instantiate(WASM, &import_object)?; + + let values = instance + .exports + .get::("add_one")? + .call(&[Value::I32(42)])?; + + assert_eq!(values[0], Value::I32(43)); + + Ok(()) +} + +#[test] +fn test_readme() -> Result<(), Box> { + main() +} diff --git a/lib/deprecated/runtime/src/lib.rs b/lib/deprecated/runtime/src/lib.rs new file mode 100644 index 000000000..182167293 --- /dev/null +++ b/lib/deprecated/runtime/src/lib.rs @@ -0,0 +1,159 @@ +//! Wasmer-runtime is a library that makes embedding WebAssembly +//! in your application easy, efficient, and safe. +//! +//! # How to use Wasmer-Runtime +//! +//! The easiest way is to use the [`instantiate`] function to create an [`Instance`]. +//! Then you can use [`call`] or [`func`] and then [`call`][func.call] to call an exported function safely. +//! +//! [`instantiate`]: fn.instantiate.html +//! [`Instance`]: struct.Instance.html +//! [`call`]: struct.Instance.html#method.call +//! [`func`]: struct.Instance.html#method.func +//! [func.call]: struct.Function.html#method.call +//! +//! ## Example +//! +//! Given this WebAssembly: +//! +//! ```wat +//! (module +//! (type $t0 (func (param i32) (result i32))) +//! (func $add_one (export "add_one") (type $t0) (param $p0 i32) (result i32) +//! get_local $p0 +//! i32.const 1 +//! i32.add)) +//! ``` +//! +//! compiled into wasm bytecode, we can call the exported `add_one` function: +//! +//! ```rust +//! static WASM: &'static [u8] = &[ +//! 0x00, 0x61, 0x73, 0x6d, 0x01, 0x00, 0x00, 0x00, 0x01, 0x06, 0x01, 0x60, +//! 0x01, 0x7f, 0x01, 0x7f, 0x03, 0x02, 0x01, 0x00, 0x07, 0x0b, 0x01, 0x07, +//! 0x61, 0x64, 0x64, 0x5f, 0x6f, 0x6e, 0x65, 0x00, 0x00, 0x0a, 0x09, 0x01, +//! 0x07, 0x00, 0x20, 0x00, 0x41, 0x01, 0x6a, 0x0b, 0x00, 0x1a, 0x04, 0x6e, +//! 0x61, 0x6d, 0x65, 0x01, 0x0a, 0x01, 0x00, 0x07, 0x61, 0x64, 0x64, 0x5f, +//! 0x6f, 0x6e, 0x65, 0x02, 0x07, 0x01, 0x00, 0x01, 0x00, 0x02, 0x70, 0x30, +//! ]; +//! +//! use wasmer_runtime::{ +//! instantiate, +//! Value, +//! imports, +//! Func, +//! }; +//! +//! fn main() -> Result<(), Box> { +//! let import_object = imports! {}; +//! let mut instance = instantiate(WASM, &import_object)?; +//! +//! let add_one: Func = instance.exports.get("add_one")?; +//! +//! let value = add_one.call(42)?; +//! assert_eq!(value, 43); +//! +//! Ok(()) +//! } +//! ``` + +use std::{error::Error, fmt}; + +pub use wasmer_runtime_core::{ + backend::Backend, + compile, compile_with, + export::{Export, RuntimeExport}, + func, + global::Global, + import::{ImportObject, LikeNamespace}, + imports, + instance::{DynFunc, Instance}, + load_cache_with, + memory::ptr::{Array, Item, WasmPtr}, + memory::Memory, + module::Module, + table::Table, + typed_func::{DynamicFunc, Func}, + types::Value, + validate, + vm::Ctx, + wat2wasm, +}; + +pub mod memory { + //! The memory module contains the implementation data structures + //! and helper functions used to manipulate and access wasm + //! memory. + pub use wasmer_runtime_core::memory::{Atomically, Memory, MemoryView}; +} + +pub mod wasm { + //! Various types exposed by the Wasmer Runtime. + pub use wasmer_runtime_core::{ + global::Global, + table::Table, + types::{FuncSig, GlobalDescriptor, MemoryDescriptor, TableDescriptor, Type, Value}, + }; +} + +pub mod error { + //! The error module contains the data structures and helper + //! functions used to implement errors that are produced and + //! returned from the wasmer runtime. + pub use wasmer_runtime_core::error::*; +} + +pub mod units { + //! Various unit types. + pub use wasmer_runtime_core::units::{Bytes, Pages}; +} + +pub mod types { + //! Types used in the Wasm runtime and conversion functions. + pub use wasmer_runtime_core::types::*; +} + +pub mod cache { + //! The cache module provides the common data structures used by + //! compiler backends to allow serializing compiled wasm code to a + //! binary format. The binary format can be persisted, and loaded + //! to allow skipping compilation and fast startup. + pub use wasmer_runtime_core::cache::*; +} + +#[derive(Debug)] +pub enum InstantiateError { + CompileError(Box), + InstantiationError(wasmer_runtime_core::error::InstantiationError), +} + +impl Error for InstantiateError { + fn source(&self) -> Option<&(dyn Error + 'static)> { + match self { + Self::CompileError(e) => e.source(), + Self::InstantiationError(e) => e.source(), + } + } +} + +impl fmt::Display for InstantiateError { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + match self { + Self::CompileError(e) => e.fmt(f), + Self::InstantiationError(e) => e.fmt(f), + } + } +} + +pub fn instantiate( + wasm: &[u8], + import_object: &ImportObject, +) -> Result { + let module = compile(wasm).map_err(InstantiateError::CompileError)?; + + module + .instantiate(import_object) + .map_err(InstantiateError::InstantiationError) +} + +pub const VERSION: &str = env!("CARGO_PKG_VERSION"); diff --git a/lib/vm/src/export.rs b/lib/vm/src/export.rs index 68fee484c..cd6160efa 100644 --- a/lib/vm/src/export.rs +++ b/lib/vm/src/export.rs @@ -30,7 +30,7 @@ pub struct ExportFunction { pub address: *const VMFunctionBody, /// Pointer to the containing `VMContext`. pub vmctx: *mut VMContext, - /// The function type, used for compatibilty checking. + /// The function type, used for compatibility checking. pub signature: FunctionType, /// The function kind (it defines how it's the signature that provided `address` have) pub kind: VMFunctionKind, diff --git a/lib/vm/src/lib.rs b/lib/vm/src/lib.rs index 85c0fbd27..bee36835d 100644 --- a/lib/vm/src/lib.rs +++ b/lib/vm/src/lib.rs @@ -4,7 +4,7 @@ #![warn(unused_import_braces)] #![cfg_attr( feature = "cargo-clippy", - allow(clippy::new_without_default, clippy::new_without_default) + allow(clippy::new_without_default, vtable_address_comparisons) )] #![cfg_attr( feature = "cargo-clippy", diff --git a/lib/wasi/src/lib.rs b/lib/wasi/src/lib.rs index 3d42cea06..32b769175 100644 --- a/lib/wasi/src/lib.rs +++ b/lib/wasi/src/lib.rs @@ -22,8 +22,8 @@ mod utils; use crate::syscalls::*; pub use crate::state::{ - Fd, WasiFile, WasiFs, WasiFsError, WasiState, WasiStateCreationError, ALL_RIGHTS, - VIRTUAL_ROOT_FD, + Fd, WasiFile, WasiFs, WasiFsError, WasiState, WasiStateBuilder, WasiStateCreationError, + ALL_RIGHTS, VIRTUAL_ROOT_FD, }; pub use crate::syscalls::types; pub use crate::utils::{get_wasi_version, is_wasi_module, WasiVersion}; diff --git a/tests/ignores.txt b/tests/ignores.txt index e05c5545d..7add73b2d 100644 --- a/tests/ignores.txt +++ b/tests/ignores.txt @@ -3,6 +3,12 @@ singlepass::spec::multi_value singlepass on windows # Singlepass is not yet supported on Windows +# TODO: We need to fix this. The issue happens only in Cranelift/LLVM and macOS, +# is caused by libunwind overflowing the stack while creating the stacktrace. +# https://github.com/rust-lang/backtrace-rs/issues/356 +cranelift::spec::skip_stack_guard_page on darwin +llvm::spec::skip_stack_guard_page on darwin + # Frontends ## WASI