diff --git a/.github/cross-linux-riscv64/Dockerfile b/.github/cross-linux-riscv64/Dockerfile index 0d3bccb418c..0ff67fa7bd4 100644 --- a/.github/cross-linux-riscv64/Dockerfile +++ b/.github/cross-linux-riscv64/Dockerfile @@ -28,7 +28,7 @@ RUN apt-get update && \ # install rust tools RUN curl --proto "=https" --tlsv1.2 --retry 3 -sSfL https://sh.rustup.rs | sh -s -- -y ENV PATH="/root/.cargo/bin:${PATH}" -RUN rustup -v toolchain install 1.78 +RUN rustup -v toolchain install 1.79 # add docker the manual way COPY install_docker.sh / RUN /install_docker.sh @@ -61,7 +61,7 @@ ENV CARGO_TARGET_RISCV64GC_UNKNOWN_LINUX_GNU_LINKER="$CROSS_TOOLCHAIN_PREFIX"gcc RUST_TEST_THREADS=1 \ PKG_CONFIG_PATH="/usr/lib/riscv64-linux-gnu/pkgconfig/:${PKG_CONFIG_PATH}" -RUN rustup target add riscv64gc-unknown-linux-gnu --toolchain 1.78-x86_64-unknown-linux-gnu +RUN rustup target add riscv64gc-unknown-linux-gnu --toolchain 1.79-x86_64-unknown-linux-gnu #compile libssl-dev for riscv64! COPY build_openssl.sh / diff --git a/.github/workflows/benchmark.yaml b/.github/workflows/benchmark.yaml index 1b4e4c6df09..7819c10ee93 100644 --- a/.github/workflows/benchmark.yaml +++ b/.github/workflows/benchmark.yaml @@ -7,7 +7,7 @@ on: env: CARGO_REGISTRIES_CRATES_IO_PROTOCOL: git - MSRV: "1.78" + MSRV: "1.79" jobs: run_benchmark: diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index ab0437253db..3241e4128be 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -3,7 +3,7 @@ name: Builds env: RUST_BACKTRACE: 1 CARGO_REGISTRIES_CRATES_IO_PROTOCOL: git - MSRV: "1.78" + MSRV: "1.79" on: push: diff --git a/.github/workflows/cloudcompiler.yaml b/.github/workflows/cloudcompiler.yaml index 9ed2e666182..9f6b853de38 100644 --- a/.github/workflows/cloudcompiler.yaml +++ b/.github/workflows/cloudcompiler.yaml @@ -2,7 +2,7 @@ name: Release cloudcompiler.wasm env: RUST_BACKTRACE: 1 - MSRV: "1.78" + MSRV: "1.79" on: push: diff --git a/.github/workflows/documentation.yaml b/.github/workflows/documentation.yaml index 152f6954aa8..6cc0fa14118 100644 --- a/.github/workflows/documentation.yaml +++ b/.github/workflows/documentation.yaml @@ -8,7 +8,7 @@ on: - 'lib/**' env: - MSRV: "1.78" + MSRV: "1.79" jobs: documentation: diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index 1bdb0a1985b..0a9d3715b0a 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -24,7 +24,7 @@ env: # Rust, but it's not stable on 1.69 yet. By explicitly setting the protocol we # can override that behaviour CARGO_REGISTRIES_CRATES_IO_PROTOCOL: git - MSRV: "1.78" + MSRV: "1.79" NEXTEST_PROFILE: "ci" RUSTUP_WINDOWS_PATH_ADD_BIN: 1 WASI_SDK_VERSION: "22" @@ -230,6 +230,54 @@ jobs: - name: make build-wasmer-jsc run: make build-wasmer-jsc + test_interpreter_api: + name: ${{ matrix.build-what.name }} on ${{ matrix.metadata.build }} + runs-on: ${{ matrix.metadata.os }} + strategy: + fail-fast: false + matrix: + build-what: [ + { + key: wamr, + build-cmd: 'make test-wamr-api', + name: 'Test API for wamr feature' + }, + { + key: wasmi, + build-cmd: 'make test-wasmi-api', + name: 'Test API for wasmi feature' + } + ] + metadata: [ + { + build: linux-x64, + os: ubuntu-22.04, + }, + { + build: macos-arm, + os: macos-14, + }, + { + build: windows-x64, + os: windows-2022, + } + ] + container: ${{ matrix.metadata.container }} + steps: + - uses: actions/checkout@v3 + - uses: dtolnay/rust-toolchain@stable + with: + toolchain: ${{ env.MSRV }} + - name: Install Nextest + uses: taiki-e/install-action@nextest + - name: Test WAMR API + if: ${{ matrix.build-what.key == 'wamr' }} + run: ${{ matrix.build-what.build-cmd }} + + - name: Test wasmi API + if: ${{ matrix.build-what.key == 'wasmi' }} + run: ${{ matrix.build-what.build-cmd }} + test_build_docs_rs: name: Test build docs rs runs-on: ubuntu-22.04 @@ -934,6 +982,30 @@ jobs: CARGO_TARGET: ${{ matrix.target }} WAPM_DEV_TOKEN: ${{ secrets.WAPM_DEV_TOKEN }} GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + - name: Test CLI integration (WAMR) + shell: bash + run: | + export WASMER_PATH=`pwd`/target/${{ matrix.target }}/release/wasmer${{ matrix.exe }} + export WASMER_DIR=`pwd`/package && make test-integration-cli-wamr-ci + env: + TARGET: ${{ matrix.target }} + TARGET_DIR: target/${{ matrix.target }}/release + CARGO_TARGET: ${{ matrix.target }} + WAPM_DEV_TOKEN: ${{ secrets.WAPM_DEV_TOKEN }} + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + + - name: Test CLI integration (WASMI) + shell: bash + run: | + export WASMER_PATH=`pwd`/target/${{ matrix.target }}/release/wasmer${{ matrix.exe }} + export WASMER_DIR=`pwd`/package && make test-integration-cli-wasmi-ci + env: + TARGET: ${{ matrix.target }} + TARGET_DIR: target/${{ matrix.target }}/release + CARGO_TARGET: ${{ matrix.target }} + WAPM_DEV_TOKEN: ${{ secrets.WAPM_DEV_TOKEN }} + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + # there is another set of integration tests in 'wasmer-integration-tests' repo. Run those test-wasmer-integration-tests: diff --git a/Cargo.lock b/Cargo.lock index bb567d336de..68aa56eb139 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1572,6 +1572,12 @@ version = "0.15.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1aaf95b3e5c8f23aa320147307562d361db0ae0d51242340f558153b4eb2439b" +[[package]] +name = "downcast-rs" +version = "1.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "75b325c5dbd37f80359721ad39aca5a29fb04c89279657cffdda8736d0c0b9d2" + [[package]] name = "dunce" version = "1.0.5" @@ -2635,6 +2641,12 @@ dependencies = [ "serde", ] +[[package]] +name = "indexmap-nostd" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e04e2fd2b8188ea827b32ef11de88377086d690286ab35747ef7f9bf3ccb590" + [[package]] name = "indicatif" version = "0.17.8" @@ -2915,9 +2927,15 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0c2a198fb6b0eada2a8df47933734e6d35d350665a33a3593d7164fa52c75c19" dependencies = [ "cfg-if 1.0.0", - "windows-targets 0.48.5", + "windows-targets 0.52.6", ] +[[package]] +name = "libm" +version = "0.2.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4ec2a862134d2a7d32d7983ddcdd1c4923530833c9f2ea1a44fc5fa473989058" + [[package]] name = "libredox" version = "0.1.3" @@ -3328,6 +3346,12 @@ version = "0.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7843ec2de400bcbc6a6328c958dc38e5359da6e93e72e37bc5246bf1ae776389" +[[package]] +name = "multi-stash" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "685a9ac4b61f4e728e1d2c6a7844609c16527aeb5e6c865915c08e619c16410f" + [[package]] name = "native-tls" version = "0.2.12" @@ -5146,6 +5170,16 @@ version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a2eb9349b6444b326872e140eb1cf5e7c522154d69e7a0ffb0fb81c06b37543f" +[[package]] +name = "string-interner" +version = "0.17.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1c6a0d765f5807e98a091107bae0a56ea3799f66a5de47b2c84c94a39c09974e" +dependencies = [ + "cfg-if 1.0.0", + "hashbrown 0.14.5", +] + [[package]] name = "strsim" version = "0.10.0" @@ -6843,6 +6877,7 @@ dependencies = [ "wasmer-derive", "wasmer-types", "wasmer-vm", + "wasmi_c_api_impl", "wasmparser 0.216.0", "wat", "windows-sys 0.59.0", @@ -7673,6 +7708,74 @@ dependencies = [ "wasmer-wast", ] +[[package]] +name = "wasmi" +version = "0.37.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4b86f2293bfa33e392bb06392846d7cbda4b2dd6175c3e3de6005439a0c481a0" +dependencies = [ + "arrayvec 0.7.4", + "multi-stash", + "smallvec 1.13.2", + "spin", + "wasmi_collections", + "wasmi_core", + "wasmi_ir", + "wasmparser-nostd", +] + +[[package]] +name = "wasmi_c_api_impl" +version = "0.37.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7de5f36cf2ed39fe9a063fd2bd7302758999d8f49c3574ca17a3749d92132ffa" +dependencies = [ + "wasmi", + "wasmi_c_api_macros", +] + +[[package]] +name = "wasmi_c_api_macros" +version = "0.37.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f4b876c940d1989c0e98b5e1c871afece98e9e43a2fc2d1b03f1f5ecf424fda7" +dependencies = [ + "proc-macro2", + "quote", +] + +[[package]] +name = "wasmi_collections" +version = "0.37.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7e092d1164284a49206258cca7294c806517676ec4d7c80bffeafc11000df7e5" +dependencies = [ + "ahash 0.8.11", + "hashbrown 0.14.5", + "string-interner", +] + +[[package]] +name = "wasmi_core" +version = "0.37.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "19f6fe14a130901f6f1414d6da4e3791db55445a0329bf4363994a936d677078" +dependencies = [ + "downcast-rs", + "libm", + "num-traits", + "paste", +] + +[[package]] +name = "wasmi_ir" +version = "0.37.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "06cd31d091e8fb80919f7b6526b4778ba49b5c7ee2fd021de5e7617d0a7d7ead" +dependencies = [ + "wasmi_core", +] + [[package]] name = "wasmparser" version = "0.95.0" @@ -7707,6 +7810,15 @@ dependencies = [ "semver 1.0.23", ] +[[package]] +name = "wasmparser-nostd" +version = "0.100.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d5a015fe95f3504a94bb1462c717aae75253e39b9dd6c3fb1062c934535c64aa" +dependencies = [ + "indexmap-nostd", +] + [[package]] name = "wasmprinter" version = "0.2.80" diff --git a/Cargo.toml b/Cargo.toml index c2e65f89586..ece006d42f2 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -14,7 +14,7 @@ version.workspace = true [dependencies] wasmer = { version = "=4.3.7", path = "lib/api", default-features = false } wasmer-compiler = { version = "=4.3.7", path = "lib/compiler", features = [ - "compiler", + "compiler", ], optional = true } wasmer-compiler-cranelift = { version = "=4.3.7", path = "lib/compiler-cranelift", optional = true } @@ -105,14 +105,16 @@ hyper = "1" reqwest = { version = "0.12.0", default-features = false } enumset = "1.1.0" memoffset = "0.9.0" -wasmparser = { version = "0.216.0", default-features = false, features = ["validate"]} +wasmparser = { version = "0.216.0", default-features = false, features = [ + "validate", +] } rkyv = { version = "0.7.40", features = ["indexmap", "validation", "strict"] } memmap2 = { version = "0.6.2" } toml = { version = "0.5.9", features = ["preserve_order"] } indexmap = "2" serde_yaml = "0.9.34" libc = { version = "^0.2", default-features = false } -gimli = { version = "0.28.1"} +gimli = { version = "0.28.1" } [build-dependencies] test-generator = { path = "tests/lib/test-generator" } @@ -123,9 +125,9 @@ rustc_version = "0.4" [dev-dependencies] wasmer = { version = "=4.3.7", path = "lib/api", features = [ - "compiler", - "singlepass", - "sys", + "compiler", + "singlepass", + "sys", ] } anyhow = "1.0" criterion = { version = "0.5", default-features = false } @@ -163,6 +165,7 @@ default = [ backend = [] jsc = ["wasmer/jsc", "backend", "wat", "wasmer/std"] wamr = ["wasmer/wamr"] +wasmi = ["wasmer/wasmi"] engine = ["universal"] universal = [] cache = ["wasmer-cache"] diff --git a/Makefile b/Makefile index 06a3d718f95..47ff178a935 100644 --- a/Makefile +++ b/Makefile @@ -390,6 +390,9 @@ build-wasmer: build-wasmer-wamr: $(CARGO_BINARY) build $(CARGO_TARGET_FLAG) --release --manifest-path lib/cli/Cargo.toml --no-default-features --features="wamr" --bin wasmer --locked +build-wasmer-wasmi: + $(CARGO_BINARY) build $(CARGO_TARGET_FLAG) --release --manifest-path lib/cli/Cargo.toml --no-default-features --features="wasmi" --bin wasmer --locked + build-wasmer-jsc: $(CARGO_BINARY) build $(CARGO_TARGET_FLAG) --release --manifest-path lib/cli/Cargo.toml --no-default-features --features="jsc,wat" --bin wasmer --locked @@ -570,6 +573,17 @@ test-packages: test-stage-1-test-all test-stage-2-test-compiler-cranelift-nostd test-examples: test-stage-5-test-examples test-stage-6-test-examples-release + +test-wamr: test-wamr-api + +test-wamr-api: + cargo nextest run --package=wasmer --release --features=wamr --no-default-features + +test-wasmi: test-wasmi-api + +test-wasmi-api: + cargo nextest run --package=wasmer --release --features=wasmi --no-default-features + test-js: test-js-api test-js-wasi # TODO: disabled because the no-std / core feature doesn't actually work at the moment. @@ -654,6 +668,10 @@ test-integration-cli-wamr-ci: require-nextest build-wasmer-wamr rustup target add wasm32-wasi $(CARGO_BINARY) nextest run $(CARGO_TARGET_FLAG) --features webc_runner,wamr -p wasmer-integration-tests-cli --locked --no-fail-fast -E "not (test(deploy) | test(snapshot) | test(login) | test(init) | test(gen_c_header) | test(up_to_date) | test(publish) | test(create) | test(whoami) | test(config) | test(c_flags))" +test-integration-cli-wasmi-ci: require-nextest build-wasmer-wasmi + rustup target add wasm32-wasi + $(CARGO_BINARY) nextest run $(CARGO_TARGET_FLAG) --features webc_runner,wamr -p wasmer-integration-tests-cli --locked --no-fail-fast -E "not (test(deploy) | test(snapshot) | test(login) | test(init) | test(gen_c_header) | test(up_to_date) | test(publish) | test(create) | test(whoami) | test(config) | test(c_flags))" + test-integration-ios: $(CARGO_BINARY) test $(CARGO_TARGET_FLAG) --features webc_runner -p wasmer-integration-tests-ios --locked diff --git a/lib/api/Cargo.toml b/lib/api/Cargo.toml index e4fdcff7788..518ceb9a20b 100644 --- a/lib/api/Cargo.toml +++ b/lib/api/Cargo.toml @@ -37,6 +37,7 @@ tracing = { version = "0.1" } wat = { version = "=1.216.0", optional = true } rustc-demangle = "0.1" shared-buffer = { workspace = true } +wasmi_c_api = { version = "0.37.1", package = "wasmi_c_api_impl", optional = true } # Dependencies and Development Dependencies for `sys`. [target.'cfg(not(target_arch = "wasm32"))'.dependencies] @@ -69,7 +70,9 @@ macro-wasmer-universal-test = { version = "4.3.7", path = "./macro-wasmer-univer # Dependencies and Develoment Dependencies for `js`. [target.'cfg(target_arch = "wasm32")'.dependencies] # - Mandatory dependencies for `js`. -wasmer-types = { path = "../types", version = "=4.3.7", default-features = false, features = ["std"] } +wasmer-types = { path = "../types", version = "=4.3.7", default-features = false, features = [ + "std", +] } wasm-bindgen = "0.2.74" js-sys = "0.3.51" wasmer-derive = { path = "../derive", version = "=4.3.7" } @@ -114,6 +117,7 @@ llvm = ["compiler", "wasmer-compiler-llvm"] # - Engines. engine = ["sys"] wamr = ["wasm-c-api", "std", "wat"] +wasmi = ["wasm-c-api", "std", "wat", "dep:wasmi_c_api"] wasm-c-api = ["wasm-types-polyfill"] # - Deprecated features. diff --git a/lib/api/build.rs b/lib/api/build.rs index fb4d1d6188b..e24188ff77a 100644 --- a/lib/api/build.rs +++ b/lib/api/build.rs @@ -80,7 +80,27 @@ fn main() { .derive_default(true) .derive_debug(true) .generate() - .expect("Unable to generate bindings"); + .expect("Unable to generate bindings for `wamr`!"); + let out_path = PathBuf::from(env::var("OUT_DIR").unwrap()); + bindings + .write_to_file(out_path.join("bindings.rs")) + .expect("Couldn't write bindings"); + } + + #[cfg(feature = "wasmi")] + { + use std::{env, path::PathBuf}; + + let bindings = bindgen::Builder::default() + .header( + PathBuf::from(std::env::var("DEP_WASMI_C_API_INCLUDE").unwrap()) + .join("wasm.h") + .to_string_lossy(), + ) + .derive_default(true) + .derive_debug(true) + .generate() + .expect("Unable to generate bindings for `wasmi`!"); let out_path = PathBuf::from(env::var("OUT_DIR").unwrap()); bindings .write_to_file(out_path.join("bindings.rs")) diff --git a/lib/api/src/c_api/as_c.rs b/lib/api/src/c_api/as_c.rs index 17bb2084c3d..e3cd25f3db9 100644 --- a/lib/api/src/c_api/as_c.rs +++ b/lib/api/src/c_api/as_c.rs @@ -2,7 +2,7 @@ use crate::bindings::{ wasm_extern_as_ref, wasm_func_as_ref, wasm_val_t, wasm_val_t__bindgen_ty_1, wasm_valkind_enum_WASM_EXTERNREF, wasm_valkind_enum_WASM_F32, wasm_valkind_enum_WASM_F64, wasm_valkind_enum_WASM_FUNCREF, wasm_valkind_enum_WASM_I32, wasm_valkind_enum_WASM_I64, - wasm_valkind_enum_WASM_V128, wasm_valkind_t, wasm_valtype_kind, wasm_valtype_t, + wasm_valkind_t, wasm_valtype_kind, wasm_valtype_t, }; //use crate::js::externals::Function; // use crate::store::{Store, StoreObject}; @@ -38,46 +38,101 @@ pub trait AsC: Sized { #[inline] pub fn param_from_c(value: &wasm_val_t) -> Value { match value.kind as u32 { - wasm_valkind_enum_WASM_I32 => Value::I32(unsafe { value.of.i32_ }), - wasm_valkind_enum_WASM_I64 => Value::I64(unsafe { value.of.i64_ }), - wasm_valkind_enum_WASM_F32 => Value::F32(unsafe { value.of.f32_ }), - wasm_valkind_enum_WASM_F64 => Value::F64(unsafe { value.of.f64_ }), - _ => unimplemented!("FuncRef and AnyRef aren't implemented as of now"), + crate::bindings::wasm_valkind_enum_WASM_I32 => Value::I32(unsafe { value.of.i32_ }), + crate::bindings::wasm_valkind_enum_WASM_I64 => Value::I64(unsafe { value.of.i64_ }), + crate::bindings::wasm_valkind_enum_WASM_F32 => Value::F32(unsafe { value.of.f32_ }), + crate::bindings::wasm_valkind_enum_WASM_F64 => Value::F64(unsafe { value.of.f64_ }), + crate::bindings::wasm_valkind_enum_WASM_FUNCREF => { + Value::FuncRef(Some(Function(super::externals::function::Function { + handle: unsafe { value.of.ref_ as _ }, + }))) + } + crate::bindings::wasm_valkind_enum_WASM_EXTERNREF => { + panic!("ExternRefs are not currently supported through wasm_c_api") + } + + _ => unimplemented!("V128 are not supported currently"), } } #[inline] pub fn result_to_value(param: &Value) -> wasm_val_t { - match param { - Value::I32(val) => wasm_val_t { - kind: wasm_valkind_enum_WASM_I32 as _, - _paddings: Default::default(), - of: wasm_val_t__bindgen_ty_1 { i32_: *val }, - }, - Value::I64(val) => wasm_val_t { - kind: wasm_valkind_enum_WASM_I64 as _, - _paddings: Default::default(), - of: wasm_val_t__bindgen_ty_1 { i64_: *val }, - }, - Value::F32(val) => wasm_val_t { - kind: wasm_valkind_enum_WASM_F32 as _, - _paddings: Default::default(), - of: wasm_val_t__bindgen_ty_1 { f32_: *val }, - }, - Value::F64(val) => wasm_val_t { - kind: wasm_valkind_enum_WASM_F64 as _, - _paddings: Default::default(), - of: wasm_val_t__bindgen_ty_1 { f64_: *val }, - }, - Value::FuncRef(val) => wasm_val_t { - kind: wasm_valkind_enum_WASM_FUNCREF as _, - _paddings: Default::default(), - of: wasm_val_t__bindgen_ty_1 { - ref_: unsafe { wasm_func_as_ref(val.as_ref().unwrap().0.handle) }, + #[cfg(feature = "wamr")] + { + match param { + Value::I32(val) => wasm_val_t { + kind: wasm_valkind_enum_WASM_I32 as _, + _paddings: Default::default(), + of: wasm_val_t__bindgen_ty_1 { i32_: *val }, + }, + Value::I64(val) => wasm_val_t { + kind: wasm_valkind_enum_WASM_I64 as _, + _paddings: Default::default(), + of: wasm_val_t__bindgen_ty_1 { i64_: *val }, + }, + Value::F32(val) => wasm_val_t { + kind: wasm_valkind_enum_WASM_F32 as _, + _paddings: Default::default(), + of: wasm_val_t__bindgen_ty_1 { f32_: *val }, + }, + Value::F64(val) => wasm_val_t { + kind: wasm_valkind_enum_WASM_F64 as _, + _paddings: Default::default(), + of: wasm_val_t__bindgen_ty_1 { f64_: *val }, + }, + Value::FuncRef(Some(val)) => wasm_val_t { + kind: wasm_valkind_enum_WASM_FUNCREF as _, + _paddings: Default::default(), + of: wasm_val_t__bindgen_ty_1 { + ref_: unsafe { wasm_func_as_ref(val.0.handle) }, + }, + }, + Value::FuncRef(None) => wasm_val_t { + kind: wasm_valkind_enum_WASM_FUNCREF as _, + _paddings: Default::default(), + of: wasm_val_t__bindgen_ty_1 { + ref_: unsafe { wasm_func_as_ref(std::ptr::null_mut()) }, + }, }, - }, - Value::ExternRef(val) => todo!(), - Value::V128(_) => todo!(), + Value::ExternRef(_) => panic!("Creating host values from guest ExternRefs is not currently supported through wasm_c_api.") , + Value::V128(_) => panic!("Creating host values from guest V128s is not currently supported through wasm_c_api."), + } + } + + #[cfg(feature = "wasmi")] + { + match param { + Value::I32(val) => wasm_val_t { + kind: wasm_valkind_enum_WASM_I32 as _, + of: wasm_val_t__bindgen_ty_1 { i32_: *val }, + }, + Value::I64(val) => wasm_val_t { + kind: wasm_valkind_enum_WASM_I64 as _, + of: wasm_val_t__bindgen_ty_1 { i64_: *val }, + }, + Value::F32(val) => wasm_val_t { + kind: wasm_valkind_enum_WASM_F32 as _, + of: wasm_val_t__bindgen_ty_1 { f32_: *val }, + }, + Value::F64(val) => wasm_val_t { + kind: wasm_valkind_enum_WASM_F64 as _, + of: wasm_val_t__bindgen_ty_1 { f64_: *val }, + }, + Value::FuncRef(Some(val)) => wasm_val_t { + kind: wasm_valkind_enum_WASM_FUNCREF as _, + of: wasm_val_t__bindgen_ty_1 { + ref_: unsafe { wasm_func_as_ref(val.0.handle) }, + }, + }, + Value::FuncRef(None) => wasm_val_t { + kind: wasm_valkind_enum_WASM_FUNCREF as _, + of: wasm_val_t__bindgen_ty_1 { + ref_: unsafe { wasm_func_as_ref(std::ptr::null_mut()) }, + }, + }, + Value::ExternRef(_) => panic!("Creating host values from guest ExternRefs is not currently supported through wasm_c_api.") , + Value::V128(_) => panic!("Creating host values from guest V128s is not currently supported through wasm_c_api."), + } } } @@ -90,21 +145,45 @@ pub fn type_to_c(type_: &Type) -> wasm_valkind_t { Type::F64 => wasm_valkind_enum_WASM_F64 as _, Type::FuncRef => wasm_valkind_enum_WASM_FUNCREF as _, Type::ExternRef => wasm_valkind_enum_WASM_EXTERNREF as _, - Type::V128 => wasm_valkind_enum_WASM_V128 as _, + Type::V128 => { + #[cfg(feature = "wamr")] + { + crate::bindings::wasm_valkind_enum_WASM_V128 as _ + } + #[cfg(feature = "wasmi")] + { + panic!("wasmi does not support V128 kinds as of now"); + } + } } } #[inline] pub fn valtype_to_type(type_: *const wasm_valtype_t) -> Type { let type_ = unsafe { wasm_valtype_kind(type_) }; + + #[cfg(feature = "wamr")] + match type_ as u32 { + crate::bindings::wasm_valkind_enum_WASM_I32 => Type::I32, + crate::bindings::wasm_valkind_enum_WASM_I64 => Type::I64, + crate::bindings::wasm_valkind_enum_WASM_F32 => Type::F32, + crate::bindings::wasm_valkind_enum_WASM_F64 => Type::F64, + crate::bindings::wasm_valkind_enum_WASM_V128 => Type::V128, + crate::bindings::wasm_valkind_enum_WASM_EXTERNREF => Type::ExternRef, + crate::bindings::wasm_valkind_enum_WASM_FUNCREF => Type::FuncRef, + _ => unreachable!( + "valtype {:?} has no matching valkind and therefore no matching wasmer_types::Type", + type_ + ), + } + #[cfg(feature = "wasmi")] match type_ as u32 { - wasm_valkind_enum_WASM_I32 => Type::I32, - wasm_valkind_enum_WASM_I64 => Type::I64, - wasm_valkind_enum_WASM_F32 => Type::F32, - wasm_valkind_enum_WASM_F64 => Type::F64, - wasm_valkind_enum_WASM_V128 => Type::V128, - wasm_valkind_enum_WASM_EXTERNREF => Type::ExternRef, - wasm_valkind_enum_WASM_FUNCREF => Type::FuncRef, + crate::bindings::wasm_valkind_enum_WASM_I32 => Type::I32, + crate::bindings::wasm_valkind_enum_WASM_I64 => Type::I64, + crate::bindings::wasm_valkind_enum_WASM_F32 => Type::F32, + crate::bindings::wasm_valkind_enum_WASM_F64 => Type::F64, + crate::bindings::wasm_valkind_enum_WASM_EXTERNREF => Type::ExternRef, + crate::bindings::wasm_valkind_enum_WASM_FUNCREF => Type::FuncRef, _ => unreachable!( "valtype {:?} has no matching valkind and therefore no matching wasmer_types::Type", type_ diff --git a/lib/api/src/c_api/bindings.rs b/lib/api/src/c_api/bindings.rs index 5fb22803f41..e7abcbbcc33 100644 --- a/lib/api/src/c_api/bindings.rs +++ b/lib/api/src/c_api/bindings.rs @@ -5,3 +5,8 @@ // This matches bindgen::Builder output include!(concat!(env!("OUT_DIR"), "/bindings.rs")); + +#[cfg(feature = "wasmi")] +#[allow(unused_imports)] +// This is here to force its linking. +use wasmi_c_api::*; diff --git a/lib/api/src/c_api/extern_ref.rs b/lib/api/src/c_api/extern_ref.rs index e6af4ed43b6..05b51ed8f67 100644 --- a/lib/api/src/c_api/extern_ref.rs +++ b/lib/api/src/c_api/extern_ref.rs @@ -12,25 +12,25 @@ impl ExternRef { where T: Any + Send + Sync + 'static + Sized, { - unimplemented!("ExternRef is not yet supported in Javascript"); + unimplemented!("ExternRef is not yet supported with wasm_c_api"); } pub fn downcast<'a, T>(&self, _store: &'a impl AsStoreRef) -> Option<&'a T> where T: Any + Send + Sync + 'static + Sized, { - unimplemented!("ExternRef is not yet supported in Javascript"); + unimplemented!("ExternRef is not yet supported in wasm_c_api"); } pub(crate) fn vm_externref(&self) -> VMExternRef { - unimplemented!("ExternRef is not yet supported in Javascript"); + unimplemented!("ExternRef is not yet supported in wasm_c_api"); } pub(crate) unsafe fn from_vm_externref( _store: &mut impl AsStoreMut, _vm_externref: VMExternRef, ) -> Self { - unimplemented!("ExternRef is not yet supported in Javascript"); + unimplemented!("ExternRef is not yet supported in wasm_c_api"); } pub fn is_from_store(&self, _store: &impl AsStoreRef) -> bool { diff --git a/lib/api/src/c_api/externals/memory.rs b/lib/api/src/c_api/externals/memory.rs index c1e376e9e6d..245c9efb004 100644 --- a/lib/api/src/c_api/externals/memory.rs +++ b/lib/api/src/c_api/externals/memory.rs @@ -63,7 +63,7 @@ impl Memory { MemoryType { // [TODO]: Find a way to extract this from the inner memory type instead // of hardcoding. - shared: true, + shared: if cfg!(feature = "wamr") { true } else { false }, minimum: unsafe { wasmer_types::Pages((*limits).min) }, maximum: unsafe { Some(wasmer_types::Pages((*limits).max)) }, } diff --git a/lib/api/src/c_api/instance.rs b/lib/api/src/c_api/instance.rs index 99ee526655b..f33c153d1dd 100644 --- a/lib/api/src/c_api/instance.rs +++ b/lib/api/src/c_api/instance.rs @@ -10,9 +10,8 @@ use wasmer_types::CompileError; use crate::bindings::{ wasm_extern_t, wasm_extern_vec_new, wasm_extern_vec_new_empty, wasm_extern_vec_new_uninitialized, wasm_extern_vec_t, wasm_instance_delete, - wasm_instance_exports, wasm_instance_new, wasm_instance_new_with_args, wasm_instance_t, - wasm_module_imports, wasm_module_t, wasm_runtime_init_thread_env, wasm_runtime_instantiate, - wasm_runtime_thread_env_inited, wasm_store_t, wasm_trap_t, + wasm_instance_exports, wasm_instance_new, wasm_instance_t, wasm_module_imports, wasm_module_t, + wasm_store_t, wasm_trap_t, }; use crate::c_api::vm::VMInstance; use crate::errors::InstantiationError; @@ -37,11 +36,14 @@ impl InstanceHandle { module: *mut wasm_module_t, mut externs: Vec, ) -> Result { - // Check if the thread env was already initialised. - unsafe { - if !wasm_runtime_thread_env_inited() { - if !wasm_runtime_init_thread_env() { - panic!("Failed to initialize the thread environment!"); + #[cfg(feature = "wamr")] + { + // Check if the thread env was already initialised. + unsafe { + if !crate::bindings::wasm_runtime_thread_env_inited() { + if !crate::bindings::wasm_runtime_init_thread_env() { + panic!("Failed to initialize the thread environment!"); + } } } } @@ -57,17 +59,24 @@ impl InstanceHandle { let mut trap: *mut wasm_trap_t = std::ptr::null_mut() as _; let instance = unsafe { - let stack_size = 2 * 1024 * 1024; - let heap_size = 2 * 1024 * 1024; - - wasm_instance_new_with_args( - store, - module, - &mut imports, - &mut trap, - stack_size, - heap_size, - ) + #[cfg(feature = "wamr")] + { + let stack_size = 2 * 1024 * 1024; + let heap_size = 2 * 1024 * 1024; + + crate::bindings::wasm_instance_new_with_args( + store, + module, + &mut imports, + &mut trap, + stack_size, + heap_size, + ) + } + #[cfg(feature = "wasmi")] + { + wasm_instance_new(store, module, &mut imports, &mut trap) + } }; if instance.is_null() { @@ -117,7 +126,7 @@ pub struct Instance { impl Instance { pub(crate) fn new( - _store: &mut impl AsStoreMut, + store: &mut impl AsStoreMut, module: &Module, imports: &Imports, ) -> Result<(Self, Exports), InstantiationError> { @@ -130,11 +139,19 @@ impl Instance { }) .collect::>(); - // Hacky: we need to tie a *module* to a store before instantiating it.. - let mut store_from_module = module.0.handle.store.lock().unwrap(); - let mut store = store_from_module.as_store_mut(); + #[cfg(feature = "wamr")] + { + _ = store; + // Hacky: we need to tie a *module* to a store before instantiating it.. + let mut store_from_module = module.0.handle.store.lock().unwrap(); + let mut store = store_from_module.as_store_mut(); - Self::new_by_index(&mut store, module, &externs) + return Self::new_by_index(&mut store, module, &externs); + } + #[cfg(feature = "wasmi")] + { + return Self::new_by_index(&mut store.as_store_mut(), module, &externs); + } } pub(crate) fn new_by_index( diff --git a/lib/api/src/c_api/mod.rs b/lib/api/src/c_api/mod.rs index 02bc7488bcd..7035f19471d 100644 --- a/lib/api/src/c_api/mod.rs +++ b/lib/api/src/c_api/mod.rs @@ -16,6 +16,9 @@ compile_error!( #[cfg(all(not(feature = "std"), not(feature = "core")))] compile_error!("Both the `std` and `core` features are disabled. Please enable one of them."); +#[cfg(all(not(feature = "wamr"), not(feature = "wasmi")))] +compile_error!("Both the `wamr` and `wasmi` features are disabled. Please enable one of them."); + #[cfg(feature = "core")] pub(crate) extern crate alloc; diff --git a/lib/api/src/c_api/module.rs b/lib/api/src/c_api/module.rs index f2c393d1a08..914cfadbf21 100644 --- a/lib/api/src/c_api/module.rs +++ b/lib/api/src/c_api/module.rs @@ -40,6 +40,7 @@ impl Eq for ModuleHandle {} impl ModuleHandle { fn new(engine: &impl AsEngineRef, binary: &[u8]) -> Result { + #[cfg(feature = "wamr")] let bytes = wasm_byte_vec_t { size: binary.len(), data: binary.as_ptr() as _, @@ -48,6 +49,12 @@ impl ModuleHandle { lock: std::ptr::null_mut(), }; + #[cfg(feature = "wasmi")] + let bytes = wasm_byte_vec_t { + size: binary.len(), + data: binary.as_ptr() as _, + }; + let store = crate::store::Store::new(engine.as_engine_ref().engine().clone()); let inner = unsafe { wasm_module_new(store.inner.store.inner, &bytes as *const _) }; diff --git a/lib/api/src/c_api/trap.rs b/lib/api/src/c_api/trap.rs index 85baa584077..3f34603d6cf 100644 --- a/lib/api/src/c_api/trap.rs +++ b/lib/api/src/c_api/trap.rs @@ -131,13 +131,7 @@ impl fmt::Display for Trap { // let message: wasm_message_t; // wasm_trap_message(value, &mut message); let mut out = unsafe { - let mut vec = wasm_byte_vec_t { - size: 0, - data: std::ptr::null_mut(), - num_elems: 0, - size_of_elem: 0, - lock: std::ptr::null_mut(), - }; + let mut vec: wasm_byte_vec_t = Default::default(); wasm_byte_vec_new_empty(&mut vec); &mut vec as *mut _ }; diff --git a/lib/api/src/lib.rs b/lib/api/src/lib.rs index f47cc32f347..2d9f5cd27eb 100644 --- a/lib/api/src/lib.rs +++ b/lib/api/src/lib.rs @@ -514,6 +514,7 @@ pub use jsc::*; mod c_api; #[cfg(feature = "wasm-c-api")] /// Re-export `c-api` definitions. +#[allow(unused_imports)] pub use c_api::*; pub use crate::externals::{ diff --git a/lib/api/src/mem_access.rs b/lib/api/src/mem_access.rs index 7c0b031c98d..0acc2b2850d 100644 --- a/lib/api/src/mem_access.rs +++ b/lib/api/src/mem_access.rs @@ -217,7 +217,7 @@ impl<'a, T: ValueType> WasmSlice<'a, T> { /// Get a `WasmSlice` for a subslice of this slice. #[inline] - pub fn subslice(self, range: Range) -> WasmSlice<'a, T> { + pub fn subslice(self, range: Range) -> Self { if range.start > range.end || range.end > self.len { panic!("WasmSlice out of bounds"); } diff --git a/lib/api/src/store.rs b/lib/api/src/store.rs index 7225ba11171..db18a65cc19 100644 --- a/lib/api/src/store.rs +++ b/lib/api/src/store.rs @@ -221,10 +221,12 @@ impl<'a> StoreMut<'a> { (&self.inner.store.engine, &mut self.inner.objects) } + #[allow(unused)] pub(crate) fn as_raw(&self) -> *mut StoreInner { self.inner as *const StoreInner as *mut StoreInner } + #[allow(unused)] pub(crate) unsafe fn from_raw(raw: *mut StoreInner) -> Self { Self { inner: &mut *raw } } diff --git a/lib/api/tests/externals.rs b/lib/api/tests/externals.rs index 76352f0c280..67a5fc4e8f1 100644 --- a/lib/api/tests/externals.rs +++ b/lib/api/tests/externals.rs @@ -61,7 +61,7 @@ fn global_get() -> Result<(), String> { #[universal_test] #[cfg_attr( - feature = "wasm-c-api", + feature = "wamr", ignore = "wamr does not support globals unattached to instances" )] fn global_set() -> Result<(), String> { @@ -84,6 +84,10 @@ fn global_set() -> Result<(), String> { } #[universal_test] +#[cfg_attr( + feature = "wasmi", + ignore = "wasmi does not support globals unattached to instances" +)] fn table_new() -> Result<(), String> { let mut store = Store::default(); let table_type = TableType { @@ -406,18 +410,22 @@ fn function_new_dynamic() -> Result<(), String> { ); assert_eq!(function.ty(&store), function_type); - // Using array signature - let function_type = ([Type::V128], [Type::I32, Type::F32, Type::F64]); - let function = Function::new( - &mut store, - function_type, - |_values: &[Value]| unimplemented!(), - ); - assert_eq!(function.ty(&store).params(), [Type::V128]); - assert_eq!( - function.ty(&store).results(), - [Type::I32, Type::F32, Type::F64] - ); + // wasmi does not support V128 through its wasm_c_api bindings. + #[cfg(not(feature = "wasmi"))] + { + // Using array signature + let function_type = ([Type::V128], [Type::I32, Type::F32, Type::F64]); + let function = Function::new( + &mut store, + function_type, + |_values: &[Value]| unimplemented!(), + ); + assert_eq!(function.ty(&store).params(), [Type::V128]); + assert_eq!( + function.ty(&store).results(), + [Type::I32, Type::F32, Type::F64] + ); + } Ok(()) } @@ -472,19 +480,22 @@ fn function_new_dynamic_env() -> Result<(), String> { ); assert_eq!(function.ty(&store), function_type); - // Using array signature - let function_type = ([Type::V128], [Type::I32, Type::F32, Type::F64]); - let function = Function::new_with_env( - &mut store, - &env, - function_type, - |_env: FunctionEnvMut, _values: &[Value]| unimplemented!(), - ); - assert_eq!(function.ty(&store).params(), [Type::V128]); - assert_eq!( - function.ty(&store).results(), - [Type::I32, Type::F32, Type::F64] - ); - + // wasmi does not support V128 through its wasm_c_api bindings. + #[cfg(not(feature = "wasmi"))] + { + // Using array signature + let function_type = ([Type::V128], [Type::I32, Type::F32, Type::F64]); + let function = Function::new_with_env( + &mut store, + &env, + function_type, + |_env: FunctionEnvMut, _values: &[Value]| unimplemented!(), + ); + assert_eq!(function.ty(&store).params(), [Type::V128]); + assert_eq!( + function.ty(&store).results(), + [Type::I32, Type::F32, Type::F64] + ); + } Ok(()) } diff --git a/lib/api/tests/function_env.rs b/lib/api/tests/function_env.rs index 221f088c782..f6305dc0192 100644 --- a/lib/api/tests/function_env.rs +++ b/lib/api/tests/function_env.rs @@ -6,8 +6,8 @@ use wasmer::*; #[universal_test] #[cfg_attr( - feature = "wasm-c-api", - ignore = "wasm-c-api does not support globals without an instance" + feature = "wamr", + ignore = "wamr does not support globals without an instance" )] fn data_and_store_mut() -> Result<(), String> { let mut store = Store::default(); diff --git a/lib/api/tests/instance.rs b/lib/api/tests/instance.rs index 15a1198ec58..2ef15be0145 100644 --- a/lib/api/tests/instance.rs +++ b/lib/api/tests/instance.rs @@ -50,8 +50,8 @@ fn exports_work_after_multiple_instances_have_been_freed() -> Result<(), String> #[universal_test] #[cfg_attr( - feature = "wasm-c-api", - ignore = "wasm-c-api does not support function calls without an instance" + feature = "wamr", + ignore = "wamr does not support function calls without an instance" )] fn unit_native_function_env() -> Result<(), String> { let mut store = Store::default(); diff --git a/lib/api/tests/memory.rs b/lib/api/tests/memory.rs index 676efedbde3..f29fddcd424 100644 --- a/lib/api/tests/memory.rs +++ b/lib/api/tests/memory.rs @@ -5,6 +5,7 @@ use std::sync::{ use wasmer::{imports, Instance, Memory, MemoryLocation, MemoryType, Module, Store}; #[test] +#[cfg_attr(feature = "wasmi", ignore = "wasmi does not support threads")] fn test_shared_memory_atomics_notify_send() { let mut store = Store::default(); let wat = r#"(module diff --git a/lib/api/tests/module.rs b/lib/api/tests/module.rs index e77cd08002a..73ef59cefa7 100644 --- a/lib/api/tests/module.rs +++ b/lib/api/tests/module.rs @@ -275,10 +275,8 @@ fn calling_host_functions_with_negative_values_works() -> Result<(), String> { } #[universal_test] -#[cfg_attr( - feature = "wasm-c-api", - ignore = "wasm-c-api does not support custom sections" -)] +#[cfg_attr(feature = "wamr", ignore = "wamr does not support custom sections")] +#[cfg_attr(feature = "wasmi", ignore = "wasmi does not support custom sections")] fn module_custom_sections() -> Result<(), String> { let store = Store::default(); let custom_section_wasm_bytes = include_bytes!("simple-name-section.wasm"); diff --git a/lib/c-api/src/wasm_c_api/types/memory.rs b/lib/c-api/src/wasm_c_api/types/memory.rs index 0cbbba7ce96..a3506925d84 100644 --- a/lib/c-api/src/wasm_c_api/types/memory.rs +++ b/lib/c-api/src/wasm_c_api/types/memory.rs @@ -75,7 +75,7 @@ pub struct wasm_limits_t { pub max: u32, } -const LIMITS_MAX_SENTINEL: u32 = u32::max_value(); +const LIMITS_MAX_SENTINEL: u32 = u32::MAX; #[no_mangle] pub unsafe extern "C" fn wasm_memorytype_limits(memory_type: &wasm_memorytype_t) -> &wasm_limits_t { diff --git a/lib/c-api/src/wasm_c_api/types/table.rs b/lib/c-api/src/wasm_c_api/types/table.rs index 3affb52296d..108f11c0de9 100644 --- a/lib/c-api/src/wasm_c_api/types/table.rs +++ b/lib/c-api/src/wasm_c_api/types/table.rs @@ -6,7 +6,7 @@ use wasmer_api::{ExternType, TableType}; #[allow(non_camel_case_types)] pub type wasm_table_size_t = u32; -const LIMITS_MAX_SENTINEL: u32 = u32::max_value(); +const LIMITS_MAX_SENTINEL: u32 = u32::MAX; #[derive(Debug, Clone)] pub(crate) struct WasmTableType { diff --git a/lib/c-api/src/wasm_c_api/unstable/middlewares/metering.rs b/lib/c-api/src/wasm_c_api/unstable/middlewares/metering.rs index 41958eafd5b..ba61250e9f3 100644 --- a/lib/c-api/src/wasm_c_api/unstable/middlewares/metering.rs +++ b/lib/c-api/src/wasm_c_api/unstable/middlewares/metering.rs @@ -206,7 +206,7 @@ pub unsafe extern "C" fn wasmer_metering_get_remaining_points( ) -> u64 { match get_remaining_points(&mut instance.store.store_mut(), &instance.inner) { MeteringPoints::Remaining(value) => value, - MeteringPoints::Exhausted => std::u64::MAX, + MeteringPoints::Exhausted => u64::MAX, } } diff --git a/lib/cli/Cargo.toml b/lib/cli/Cargo.toml index cdc0cf3c76b..59e2eb0c7ed 100644 --- a/lib/cli/Cargo.toml +++ b/lib/cli/Cargo.toml @@ -52,6 +52,7 @@ backend = [] coredump = ["wasm-coredump-builder"] sys = ["compiler", "wasmer-vm"] wamr = ["backend", "wasmer/wamr"] +wasmi = ["backend", "wasmer/wasmi"] jsc = ["backend", "wasmer/jsc", "wasmer/std"] wast = ["wasmer-wast"] host-net = ["virtual-net/host-net"] diff --git a/lib/cli/src/bin/wasmer.rs b/lib/cli/src/bin/wasmer.rs index 15ce065e7ca..e4633ac634b 100644 --- a/lib/cli/src/bin/wasmer.rs +++ b/lib/cli/src/bin/wasmer.rs @@ -1,6 +1,6 @@ #[cfg(not(feature = "backend"))] compile_error!( - "Either enable at least one backend, or compile the wasmer-headless binary instead.\nWith cargo, you can provide a compiler option with the --features flag.\n\nExample values:\n\n\t\t--features cranelift,singlepass\n\t\t--features jsc\n\t\t--features wamr\n\n\n" + "Either enable at least one backend, or compile the wasmer-headless binary instead.\nWith cargo, you can provide a compiler option with the --features flag.\n\nExample values:\n\n\t\t--features cranelift,singlepass\n\t\t--features jsc\n\t\t--features wamr\n\t\t--features wamr\n\n\n" ); fn main() { diff --git a/lib/cli/src/commands/app/deploy.rs b/lib/cli/src/commands/app/deploy.rs index fda80cb8009..25c3dd6a2f7 100644 --- a/lib/cli/src/commands/app/deploy.rs +++ b/lib/cli/src/commands/app/deploy.rs @@ -602,6 +602,7 @@ pub struct DeployAppOpts<'a> { // Present here to enable forwarding unknown fields to the backend, which // preserves forwards-compatibility for schema changes. pub original_config: Option, + #[allow(dead_code)] pub allow_create: bool, pub make_default: bool, pub owner: Option, diff --git a/lib/cli/src/commands/app/util.rs b/lib/cli/src/commands/app/util.rs index df1265a387b..72987a2a214 100644 --- a/lib/cli/src/commands/app/util.rs +++ b/lib/cli/src/commands/app/util.rs @@ -121,6 +121,7 @@ pub struct AppIdentOpts { #[allow(clippy::large_enum_variant)] pub enum ResolvedAppIdent { Ident(AppIdent), + #[allow(dead_code)] Config { ident: AppIdent, config: AppConfigV1, diff --git a/lib/cli/src/commands/mod.rs b/lib/cli/src/commands/mod.rs index dc70bcf5fd6..f2f46c4e31c 100644 --- a/lib/cli/src/commands/mod.rs +++ b/lib/cli/src/commands/mod.rs @@ -494,9 +494,18 @@ fn print_version(verbose: bool) -> Result<(), anyhow::Error> { } println!("compiler: {}", compilers.join(",")); + let mut interpreters = Vec::<&'static str>::new(); + if cfg!(feature = "wamr") { - println!("interpreter: wamr"); + interpreters.push("wamr"); + } + + if cfg!(feature = "wasmi") { + // Can't use wamr and wasmi together as of now, but maybe we'll support more + // interepreters. + interpreters.push("wasmi"); } + println!("interpreter: {}", interpreters.join(",")); Ok(()) } diff --git a/lib/cli/src/store.rs b/lib/cli/src/store.rs index 7fffa3c0431..3ca29d4acaf 100644 --- a/lib/cli/src/store.rs +++ b/lib/cli/src/store.rs @@ -383,7 +383,12 @@ impl StoreOptions { } // If we don't have a compiler, but we have an engine -#[cfg(not(any(feature = "compiler", feature = "jsc", feature = "wamr")))] +#[cfg(not(any( + feature = "compiler", + feature = "jsc", + feature = "wamr", + feature = "wasmi" +)))] impl StoreOptions { fn get_engine_headless(&self) -> Result { let engine: wasmer_compiler::Engine = wasmer_compiler::EngineBuilder::headless().engine(); @@ -398,7 +403,10 @@ impl StoreOptions { } } -#[cfg(all(not(feature = "compiler"), any(feature = "jsc", feature = "wamr")))] +#[cfg(all( + not(feature = "compiler"), + any(feature = "jsc", feature = "wamr", feature = "wasmi") +))] impl StoreOptions { /// Get the store (headless engine) pub fn get_store(&self) -> Result<(Store, CompilerType)> { diff --git a/lib/compiler-cranelift/src/translator/translation_utils.rs b/lib/compiler-cranelift/src/translator/translation_utils.rs index 3ee8156e385..952b5db800e 100644 --- a/lib/compiler-cranelift/src/translator/translation_utils.rs +++ b/lib/compiler-cranelift/src/translator/translation_utils.rs @@ -2,7 +2,6 @@ use super::func_environ::TargetEnvironment; use crate::std::string::ToString; -use core::u32; use cranelift_codegen::binemit::Reloc; use cranelift_codegen::ir::{self, AbiParam}; use cranelift_codegen::isa::TargetFrontendConfig; diff --git a/lib/compiler-llvm/src/config.rs b/lib/compiler-llvm/src/config.rs index e98d4ed23dd..9d00085a544 100644 --- a/lib/compiler-llvm/src/config.rs +++ b/lib/compiler-llvm/src/config.rs @@ -238,7 +238,9 @@ impl LLVM { 6, ); - std::mem::transmute(my_target_machine) + std::mem::transmute::( + my_target_machine, + ) } } else { llvm_target_machine diff --git a/lib/compiler-llvm/src/translator/code.rs b/lib/compiler-llvm/src/translator/code.rs index a7441326c81..ef894aecfdb 100644 --- a/lib/compiler-llvm/src/translator/code.rs +++ b/lib/compiler-llvm/src/translator/code.rs @@ -697,11 +697,11 @@ impl<'ctx, 'a> LLVMFunctionCodeGenerator<'ctx, 'a> { let int_type = left.get_type(); let (min_value, neg_one_value) = if int_type == self.intrinsics.i32_ty { - let min_value = int_type.const_int(i32::min_value() as u64, false); + let min_value = int_type.const_int(i32::MIN as u64, false); let neg_one_value = int_type.const_int(-1i32 as u32 as u64, false); (min_value, neg_one_value) } else if int_type == self.intrinsics.i64_ty { - let min_value = int_type.const_int(i64::min_value() as u64, false); + let min_value = int_type.const_int(i64::MIN as u64, false); let neg_one_value = int_type.const_int(-1i64 as u64, false); (min_value, neg_one_value) } else { @@ -3053,10 +3053,7 @@ impl<'ctx, 'a> LLVMFunctionCodeGenerator<'ctx, 'a> { let (v1, _) = self.v128_into_i16x8(v1, i1)?; let (v2, _) = self.v128_into_i16x8(v2, i2)?; - let max_value = self - .intrinsics - .i16_ty - .const_int(i16::max_value() as u64, false); + let max_value = self.intrinsics.i16_ty.const_int(i16::MAX as u64, false); let max_values = VectorType::const_vector(&[max_value; 8]); let v1 = err!(self @@ -3352,11 +3349,11 @@ impl<'ctx, 'a> LLVMFunctionCodeGenerator<'ctx, 'a> { let (v1, v2) = (v1.into_int_value(), v2.into_int_value()); let int_type = v1.get_type(); let (min_value, neg_one_value) = if int_type == self.intrinsics.i32_ty { - let min_value = int_type.const_int(i32::min_value() as u64, false); + let min_value = int_type.const_int(i32::MIN as u64, false); let neg_one_value = int_type.const_int(-1i32 as u32 as u64, false); (min_value, neg_one_value) } else if int_type == self.intrinsics.i64_ty { - let min_value = int_type.const_int(i64::min_value() as u64, false); + let min_value = int_type.const_int(i64::MIN as u64, false); let neg_one_value = int_type.const_int(-1i64 as u64, false); (min_value, neg_one_value) } else { @@ -7466,8 +7463,8 @@ impl<'ctx, 'a> LLVMFunctionCodeGenerator<'ctx, 'a> { self.intrinsics.i32x4_ty, LEF32_GEQ_I32_MIN, GEF32_LEQ_I32_MAX, - std::i32::MIN as u64, - std::i32::MAX as u64, + i32::MIN as u64, + i32::MAX as u64, v, )?; self.state.push1(res); @@ -7481,8 +7478,8 @@ impl<'ctx, 'a> LLVMFunctionCodeGenerator<'ctx, 'a> { self.intrinsics.i32x4_ty, LEF32_GEQ_U32_MIN, GEF32_LEQ_U32_MAX, - std::u32::MIN as u64, - std::u32::MAX as u64, + u32::MIN as u64, + u32::MAX as u64, v, )?; self.state.push1(res); @@ -7490,11 +7487,11 @@ impl<'ctx, 'a> LLVMFunctionCodeGenerator<'ctx, 'a> { Operator::I32x4TruncSatF64x2SZero | Operator::I32x4TruncSatF64x2UZero => { let ((min, max), (cmp_min, cmp_max)) = match op { Operator::I32x4TruncSatF64x2SZero => ( - (std::i32::MIN as u64, std::i32::MAX as u64), + (i32::MIN as u64, i32::MAX as u64), (LEF64_GEQ_I32_MIN, GEF64_LEQ_I32_MAX), ), Operator::I32x4TruncSatF64x2UZero => ( - (std::u32::MIN as u64, std::u32::MAX as u64), + (u32::MIN as u64, u32::MAX as u64), (LEF64_GEQ_U32_MIN, GEF64_LEQ_U32_MAX), ), _ => unreachable!("Unhandled internal variant"), @@ -7537,10 +7534,10 @@ impl<'ctx, 'a> LLVMFunctionCodeGenerator<'ctx, 'a> { // let res = self.trunc_sat_into_int( // self.intrinsics.f64x2_ty, // self.intrinsics.i64x2_ty, - // std::i64::MIN as u64, - // std::i64::MAX as u64, - // std::i64::MIN as u64, - // std::i64::MAX as u64, + // i64::MIN as u64, + // i64::MAX as u64, + // i64::MIN as u64, + // i64::MAX as u64, // v, // )?; // self.state.push1(res); @@ -7552,10 +7549,10 @@ impl<'ctx, 'a> LLVMFunctionCodeGenerator<'ctx, 'a> { // let res = self.trunc_sat_into_int( // self.intrinsics.f64x2_ty, // self.intrinsics.i64x2_ty, - // std::u64::MIN, - // std::u64::MAX, - // std::u64::MIN, - // std::u64::MAX, + // u64::MIN, + // u64::MAX, + // u64::MIN, + // u64::MAX, // v, // )?; // self.state.push1(res); @@ -7594,8 +7591,8 @@ impl<'ctx, 'a> LLVMFunctionCodeGenerator<'ctx, 'a> { self.intrinsics.i32_ty, LEF32_GEQ_I32_MIN, GEF32_LEQ_I32_MAX, - std::i32::MIN as u32 as u64, - std::i32::MAX as u32 as u64, + i32::MIN as u32 as u64, + i32::MAX as u32 as u64, v, )?; self.state.push1(res); @@ -7608,8 +7605,8 @@ impl<'ctx, 'a> LLVMFunctionCodeGenerator<'ctx, 'a> { self.intrinsics.i32_ty, LEF64_GEQ_I32_MIN, GEF64_LEQ_I32_MAX, - std::i32::MIN as u64, - std::i32::MAX as u64, + i32::MIN as u64, + i32::MAX as u64, v, )?; self.state.push1(res); @@ -7648,8 +7645,8 @@ impl<'ctx, 'a> LLVMFunctionCodeGenerator<'ctx, 'a> { self.intrinsics.i64_ty, LEF32_GEQ_I64_MIN, GEF32_LEQ_I64_MAX, - std::i64::MIN as u64, - std::i64::MAX as u64, + i64::MIN as u64, + i64::MAX as u64, v, )?; self.state.push1(res); @@ -7662,8 +7659,8 @@ impl<'ctx, 'a> LLVMFunctionCodeGenerator<'ctx, 'a> { self.intrinsics.i64_ty, LEF64_GEQ_I64_MIN, GEF64_LEQ_I64_MAX, - std::i64::MIN as u64, - std::i64::MAX as u64, + i64::MIN as u64, + i64::MAX as u64, v, )?; self.state.push1(res); @@ -7702,8 +7699,8 @@ impl<'ctx, 'a> LLVMFunctionCodeGenerator<'ctx, 'a> { self.intrinsics.i32_ty, LEF32_GEQ_U32_MIN, GEF32_LEQ_U32_MAX, - std::u32::MIN as u64, - std::u32::MAX as u64, + u32::MIN as u64, + u32::MAX as u64, v, )?; self.state.push1(res); @@ -7716,8 +7713,8 @@ impl<'ctx, 'a> LLVMFunctionCodeGenerator<'ctx, 'a> { self.intrinsics.i32_ty, LEF64_GEQ_U32_MIN, GEF64_LEQ_U32_MAX, - std::u32::MIN as u64, - std::u32::MAX as u64, + u32::MIN as u64, + u32::MAX as u64, v, )?; self.state.push1(res); @@ -7756,8 +7753,8 @@ impl<'ctx, 'a> LLVMFunctionCodeGenerator<'ctx, 'a> { self.intrinsics.i64_ty, LEF32_GEQ_U64_MIN, GEF32_LEQ_U64_MAX, - std::u64::MIN, - std::u64::MAX, + u64::MIN, + u64::MAX, v, )?; self.state.push1(res); @@ -7770,8 +7767,8 @@ impl<'ctx, 'a> LLVMFunctionCodeGenerator<'ctx, 'a> { self.intrinsics.i64_ty, LEF64_GEQ_U64_MIN, GEF64_LEQ_U64_MAX, - std::u64::MIN, - std::u64::MAX, + u64::MIN, + u64::MAX, v, )?; self.state.push1(res); @@ -8967,7 +8964,7 @@ impl<'ctx, 'a> LLVMFunctionCodeGenerator<'ctx, 'a> { let res = err!(self.builder.build_int_compare( IntPredicate::EQ, cmask, - lane_int_ty.const_int(std::u64::MAX, true), + lane_int_ty.const_int(u64::MAX, true), "", )); let res = err!(self @@ -11995,34 +11992,34 @@ fn is_f64_arithmetic(bits: u64) -> bool { // rounding towards zero. /// Least Exact Float (32 bits) greater-than-or-equal-to i32::MIN when rounding towards zero. -const LEF32_GEQ_I32_MIN: u64 = std::i32::MIN as u64; +const LEF32_GEQ_I32_MIN: u64 = i32::MIN as u64; /// Greatest Exact Float (32 bits) less-than-or-equal-to i32::MAX when rounding towards zero. const GEF32_LEQ_I32_MAX: u64 = 2147483520; // bits as f32: 0x4eff_ffff /// Least Exact Float (64 bits) greater-than-or-equal-to i32::MIN when rounding towards zero. -const LEF64_GEQ_I32_MIN: u64 = std::i32::MIN as u64; +const LEF64_GEQ_I32_MIN: u64 = i32::MIN as u64; /// Greatest Exact Float (64 bits) less-than-or-equal-to i32::MAX when rounding towards zero. -const GEF64_LEQ_I32_MAX: u64 = std::i32::MAX as u64; +const GEF64_LEQ_I32_MAX: u64 = i32::MAX as u64; /// Least Exact Float (32 bits) greater-than-or-equal-to u32::MIN when rounding towards zero. -const LEF32_GEQ_U32_MIN: u64 = std::u32::MIN as u64; +const LEF32_GEQ_U32_MIN: u64 = u32::MIN as u64; /// Greatest Exact Float (32 bits) less-than-or-equal-to u32::MAX when rounding towards zero. const GEF32_LEQ_U32_MAX: u64 = 4294967040; // bits as f32: 0x4f7f_ffff /// Least Exact Float (64 bits) greater-than-or-equal-to u32::MIN when rounding towards zero. -const LEF64_GEQ_U32_MIN: u64 = std::u32::MIN as u64; +const LEF64_GEQ_U32_MIN: u64 = u32::MIN as u64; /// Greatest Exact Float (64 bits) less-than-or-equal-to u32::MAX when rounding towards zero. const GEF64_LEQ_U32_MAX: u64 = 4294967295; // bits as f64: 0x41ef_ffff_ffff_ffff /// Least Exact Float (32 bits) greater-than-or-equal-to i64::MIN when rounding towards zero. -const LEF32_GEQ_I64_MIN: u64 = std::i64::MIN as u64; +const LEF32_GEQ_I64_MIN: u64 = i64::MIN as u64; /// Greatest Exact Float (32 bits) less-than-or-equal-to i64::MAX when rounding towards zero. const GEF32_LEQ_I64_MAX: u64 = 9223371487098961920; // bits as f32: 0x5eff_ffff /// Least Exact Float (64 bits) greater-than-or-equal-to i64::MIN when rounding towards zero. -const LEF64_GEQ_I64_MIN: u64 = std::i64::MIN as u64; +const LEF64_GEQ_I64_MIN: u64 = i64::MIN as u64; /// Greatest Exact Float (64 bits) less-than-or-equal-to i64::MAX when rounding towards zero. const GEF64_LEQ_I64_MAX: u64 = 9223372036854774784; // bits as f64: 0x43df_ffff_ffff_ffff /// Least Exact Float (32 bits) greater-than-or-equal-to u64::MIN when rounding towards zero. -const LEF32_GEQ_U64_MIN: u64 = std::u64::MIN; +const LEF32_GEQ_U64_MIN: u64 = u64::MIN; /// Greatest Exact Float (32 bits) less-than-or-equal-to u64::MAX when rounding towards zero. const GEF32_LEQ_U64_MAX: u64 = 18446742974197923840; // bits as f32: 0x5f7f_ffff /// Least Exact Float (64 bits) greater-than-or-equal-to u64::MIN when rounding towards zero. -const LEF64_GEQ_U64_MIN: u64 = std::u64::MIN; +const LEF64_GEQ_U64_MIN: u64 = u64::MIN; /// Greatest Exact Float (64 bits) less-than-or-equal-to u64::MAX when rounding towards zero. const GEF64_LEQ_U64_MAX: u64 = 18446744073709549568; // bits as f64: 0x43ef_ffff_ffff_ffff diff --git a/lib/compiler-llvm/src/translator/intrinsics.rs b/lib/compiler-llvm/src/translator/intrinsics.rs index 59516fab70f..ca48b07e533 100644 --- a/lib/compiler-llvm/src/translator/intrinsics.rs +++ b/lib/compiler-llvm/src/translator/intrinsics.rs @@ -55,6 +55,7 @@ pub fn type_to_llvm<'ctx>( } /// Struct containing LLVM and VM intrinsics. +#[allow(dead_code)] pub struct Intrinsics<'ctx> { pub ctlz_i32: FunctionValue<'ctx>, pub ctlz_i64: FunctionValue<'ctx>, diff --git a/lib/compiler-llvm/src/translator/state.rs b/lib/compiler-llvm/src/translator/state.rs index b6e1d7d2a38..564fde673e7 100644 --- a/lib/compiler-llvm/src/translator/state.rs +++ b/lib/compiler-llvm/src/translator/state.rs @@ -7,6 +7,7 @@ use std::ops::{BitAnd, BitOr, BitOrAssign}; use wasmer_types::CompileError; #[derive(Debug)] +#[allow(dead_code)] pub enum ControlFrame<'ctx> { Block { next: BasicBlock<'ctx>, diff --git a/lib/compiler-singlepass/src/arm64_decl.rs b/lib/compiler-singlepass/src/arm64_decl.rs index b000bdde838..2292d29b935 100644 --- a/lib/compiler-singlepass/src/arm64_decl.rs +++ b/lib/compiler-singlepass/src/arm64_decl.rs @@ -312,6 +312,6 @@ pub fn new_machine_state() -> MachineState { register_values: vec![MachineValue::Undefined; 32 + 32], prev_frame: BTreeMap::new(), wasm_stack: vec![], - wasm_inst_offset: std::usize::MAX, + wasm_inst_offset: usize::MAX, } } diff --git a/lib/compiler-singlepass/src/codegen.rs b/lib/compiler-singlepass/src/codegen.rs index da419a4200a..91f3f487404 100644 --- a/lib/compiler-singlepass/src/codegen.rs +++ b/lib/compiler-singlepass/src/codegen.rs @@ -1048,7 +1048,7 @@ impl<'a, M: Machine> FuncGen<'a, M> { pub fn get_state_diff(&mut self) -> usize { if !self.track_state { - return std::usize::MAX; + return usize::MAX; } let last_frame = self.control_stack.last_mut().unwrap(); let mut diff = self.state.diff(&last_frame.state); @@ -1104,9 +1104,9 @@ impl<'a, M: Machine> FuncGen<'a, M> { // anywhere in the function prologue. self.machine.insert_stackoverflow(); - if self.state.wasm_inst_offset != std::usize::MAX { + if self.state.wasm_inst_offset != usize::MAX { return Err(CompileError::Codegen( - "emit_head: wasm_inst_offset not std::usize::MAX".to_owned(), + "emit_head: wasm_inst_offset not usize::MAX".to_owned(), )); } Ok(()) diff --git a/lib/compiler-singlepass/src/common_decl.rs b/lib/compiler-singlepass/src/common_decl.rs index 7dd4cbfe682..00090c344af 100644 --- a/lib/compiler-singlepass/src/common_decl.rs +++ b/lib/compiler-singlepass/src/common_decl.rs @@ -32,6 +32,7 @@ pub struct MachineState { /// A `MachineStateDiff` can only be applied after the `MachineStateDiff` its `last` field /// points to is already applied. #[derive(Clone, Debug, Default)] +#[allow(dead_code)] pub struct MachineStateDiff { /// Link to the previous diff this diff is based on, or `None` if this is the first diff. pub last: Option, @@ -83,6 +84,7 @@ pub enum MachineValue { /// A map of function states. #[derive(Clone, Debug)] +#[allow(dead_code)] pub struct FunctionStateMap { /// Initial. pub initial: MachineState, @@ -115,6 +117,7 @@ pub enum Size { } /// A kind of suspend offset. +#[allow(dead_code)] #[derive(Clone, Copy, Debug)] pub enum SuspendOffset { /// A loop. @@ -126,6 +129,7 @@ pub enum SuspendOffset { } /// Description of a machine code range following an offset. +#[allow(dead_code)] #[derive(Clone, Debug)] pub struct OffsetInfo { /// Exclusive range-end offset. diff --git a/lib/compiler-singlepass/src/machine_x64.rs b/lib/compiler-singlepass/src/machine_x64.rs index 5bb3655d374..f5e8c4d1022 100644 --- a/lib/compiler-singlepass/src/machine_x64.rs +++ b/lib/compiler-singlepass/src/machine_x64.rs @@ -1105,7 +1105,7 @@ impl MachineX86_64 { |this| { this.assembler.emit_mov( Size::S64, - Location::Imm64(std::u64::MAX), + Location::Imm64(u64::MAX), Location::GPR(tmp_out), ) }, @@ -1256,14 +1256,14 @@ impl MachineX86_64 { |this| { this.assembler.emit_mov( Size::S64, - Location::Imm64(std::i64::MIN as u64), + Location::Imm64(i64::MIN as u64), Location::GPR(tmp_out), ) }, |this| { this.assembler.emit_mov( Size::S64, - Location::Imm64(std::i64::MAX as u64), + Location::Imm64(i64::MAX as u64), Location::GPR(tmp_out), ) }, @@ -1348,14 +1348,14 @@ impl MachineX86_64 { |this| { this.assembler.emit_mov( Size::S32, - Location::Imm32(std::i32::MIN as u32), + Location::Imm32(i32::MIN as u32), Location::GPR(tmp_out), ) }, |this| { this.assembler.emit_mov( Size::S32, - Location::Imm32(std::i32::MAX as u32), + Location::Imm32(i32::MAX as u32), Location::GPR(tmp_out), ) }, @@ -1444,7 +1444,7 @@ impl MachineX86_64 { |this| { this.assembler.emit_mov( Size::S32, - Location::Imm32(std::u32::MAX), + Location::Imm32(u32::MAX), Location::GPR(tmp_out), ) }, @@ -1518,7 +1518,7 @@ impl MachineX86_64 { |this| { this.assembler.emit_mov( Size::S64, - Location::Imm64(std::u64::MAX), + Location::Imm64(u64::MAX), Location::GPR(tmp_out), ) }, @@ -1669,14 +1669,14 @@ impl MachineX86_64 { |this| { this.assembler.emit_mov( Size::S64, - Location::Imm64(std::i64::MIN as u64), + Location::Imm64(i64::MIN as u64), Location::GPR(tmp_out), ) }, |this| { this.assembler.emit_mov( Size::S64, - Location::Imm64(std::i64::MAX as u64), + Location::Imm64(i64::MAX as u64), Location::GPR(tmp_out), ) }, @@ -1748,14 +1748,14 @@ impl MachineX86_64 { |this| { this.assembler.emit_mov( Size::S32, - Location::Imm32(std::i32::MIN as u32), + Location::Imm32(i32::MIN as u32), Location::GPR(tmp_out), ) }, |this| { this.assembler.emit_mov( Size::S32, - Location::Imm32(std::i32::MAX as u32), + Location::Imm32(i32::MAX as u32), Location::GPR(tmp_out), ) }, @@ -1831,7 +1831,7 @@ impl MachineX86_64 { |this| { this.assembler.emit_mov( Size::S32, - Location::Imm32(std::u32::MAX), + Location::Imm32(u32::MAX), Location::GPR(tmp_out), ) }, diff --git a/lib/compiler-singlepass/src/unwind_winx64.rs b/lib/compiler-singlepass/src/unwind_winx64.rs index 389cba3c927..979e7406441 100644 --- a/lib/compiler-singlepass/src/unwind_winx64.rs +++ b/lib/compiler-singlepass/src/unwind_winx64.rs @@ -106,7 +106,7 @@ impl UnwindCode { }; writer.write_u8(*instruction_offset); let scaled_stack_offset = stack_offset / 16; - if scaled_stack_offset <= core::u16::MAX as u32 { + if scaled_stack_offset <= u16::MAX as u32 { writer.write_u8((*reg << 4) | (op_small as u8)); writer.write_u16_le(scaled_stack_offset as u16); } else { @@ -155,7 +155,7 @@ impl UnwindCode { } } Self::SaveXmm { stack_offset, .. } | Self::SaveReg { stack_offset, .. } => { - if *stack_offset <= core::u16::MAX as u32 { + if *stack_offset <= u16::MAX as u32 { 2 } else { 3 diff --git a/lib/compiler-singlepass/src/x64_decl.rs b/lib/compiler-singlepass/src/x64_decl.rs index 6178a17015b..b60ee172400 100644 --- a/lib/compiler-singlepass/src/x64_decl.rs +++ b/lib/compiler-singlepass/src/x64_decl.rs @@ -337,6 +337,6 @@ pub fn new_machine_state() -> MachineState { register_values: vec![MachineValue::Undefined; 16 + 8], prev_frame: BTreeMap::new(), wasm_stack: vec![], - wasm_inst_offset: std::usize::MAX, + wasm_inst_offset: usize::MAX, } } diff --git a/lib/compiler/src/engine/trap/frame_info.rs b/lib/compiler/src/engine/trap/frame_info.rs index f09dae724a9..795e631ef48 100644 --- a/lib/compiler/src/engine/trap/frame_info.rs +++ b/lib/compiler/src/engine/trap/frame_info.rs @@ -359,7 +359,7 @@ pub fn register( finished_functions: &BoxedSlice, frame_infos: FrameInfosVariant, ) -> Option { - let mut min = usize::max_value(); + let mut min = usize::MAX; let mut max = 0; let mut functions = BTreeMap::new(); for ( diff --git a/lib/compiler/src/translator/environ.rs b/lib/compiler/src/translator/environ.rs index c0b376b02c5..fecde4e20aa 100644 --- a/lib/compiler/src/translator/environ.rs +++ b/lib/compiler/src/translator/environ.rs @@ -85,7 +85,7 @@ impl<'data> ModuleEnvironment<'data> { /// Translate a wasm module using this environment. This consumes the /// `ModuleEnvironment` and produces a `ModuleInfoTranslation`. - pub fn translate(mut self, data: &'data [u8]) -> WasmResult> { + pub fn translate(mut self, data: &'data [u8]) -> WasmResult { assert!(self.module_translation_state.is_none()); let module_translation_state = translate_module(data, &mut self)?; self.module_translation_state = Some(module_translation_state); diff --git a/lib/compiler/src/translator/sections.rs b/lib/compiler/src/translator/sections.rs index e44662d2cfc..d033b718628 100644 --- a/lib/compiler/src/translator/sections.rs +++ b/lib/compiler/src/translator/sections.rs @@ -182,7 +182,7 @@ pub fn parse_function_section( environ: &mut ModuleEnvironment, ) -> WasmResult<()> { let num_functions = functions.count(); - if num_functions == std::u32::MAX { + if num_functions == u32::MAX { // We reserve `u32::MAX` for our own use. return Err(WasmError::ImplLimitExceeded); } @@ -501,7 +501,7 @@ pub fn parse_name_section<'data>( match subsection { wasmparser::Name::Function(function_subsection) => { for naming in function_subsection.into_iter().flatten() { - if naming.index != std::u32::MAX { + if naming.index != u32::MAX { environ.declare_function_name( FunctionIndex::from_u32(naming.index), naming.name, diff --git a/lib/emscripten/src/env/mod.rs b/lib/emscripten/src/env/mod.rs index 6482a80f0a4..7b52b1eb07a 100644 --- a/lib/emscripten/src/env/mod.rs +++ b/lib/emscripten/src/env/mod.rs @@ -113,7 +113,7 @@ pub fn ___build_environment(mut ctx: FunctionEnvMut, environ: c_int) { unsafe { for (i, s) in strings.iter().enumerate() { for (j, c) in s.chars().enumerate() { - debug_assert!(c < u8::max_value() as char); + debug_assert!(c < u8::MAX as char); *pool_ptr.add(j) = c as u8; } *env_ptr.add(i * 4) = pool_offset as i32; diff --git a/lib/types/src/entity/mod.rs b/lib/types/src/entity/mod.rs index f7de0b1cfeb..f4b527124c7 100644 --- a/lib/types/src/entity/mod.rs +++ b/lib/types/src/entity/mod.rs @@ -19,7 +19,7 @@ macro_rules! entity_impl { ($entity:ident) => { impl $crate::entity::EntityRef for $entity { fn new(index: usize) -> Self { - debug_assert!(index < ($crate::lib::std::u32::MAX as usize)); + debug_assert!(index < (u32::MAX as usize)); $entity(index as u32) } @@ -30,11 +30,11 @@ macro_rules! entity_impl { impl $crate::entity::packed_option::ReservedValue for $entity { fn reserved_value() -> $entity { - $entity($crate::lib::std::u32::MAX) + $entity(u32::MAX) } fn is_reserved_value(&self) -> bool { - self.0 == $crate::lib::std::u32::MAX + self.0 == u32::MAX } } @@ -42,7 +42,7 @@ macro_rules! entity_impl { /// Create a new instance from a `u32`. #[allow(dead_code)] pub fn from_u32(x: u32) -> Self { - debug_assert!(x < $crate::lib::std::u32::MAX); + debug_assert!(x < u32::MAX); $entity(x) } diff --git a/lib/types/src/indexes.rs b/lib/types/src/indexes.rs index 3bf3883f3f1..5d161d61eee 100644 --- a/lib/types/src/indexes.rs +++ b/lib/types/src/indexes.rs @@ -1,6 +1,5 @@ //! Helper functions and structures for the translation. use crate::entity::entity_impl; -use core::u32; use rkyv::{Archive, Deserialize as RkyvDeserialize, Serialize as RkyvSerialize}; #[cfg(feature = "enable-serde")] use serde::{Deserialize, Serialize}; diff --git a/lib/types/src/lib.rs b/lib/types/src/lib.rs index 117f88408f2..0e1d4f1a946 100644 --- a/lib/types/src/lib.rs +++ b/lib/types/src/lib.rs @@ -37,7 +37,7 @@ pub mod lib { #[cfg(feature = "core")] pub mod std { pub use alloc::{borrow, boxed, format, iter, rc, slice, string, vec}; - pub use core::{any, cell, cmp, convert, fmt, hash, marker, mem, ops, ptr, sync, u32}; + pub use core::{any, cell, cmp, convert, fmt, hash, marker, mem, ops, ptr, sync}; } /// Custom `std` module. @@ -45,7 +45,7 @@ pub mod lib { pub mod std { pub use std::{ any, borrow, boxed, cell, cmp, convert, fmt, format, hash, iter, marker, mem, ops, ptr, - rc, slice, string, sync, u32, vec, + rc, slice, string, sync, vec, }; } } diff --git a/lib/virtual-fs/src/mem_fs/file.rs b/lib/virtual-fs/src/mem_fs/file.rs index 3c0f3837b47..25ac7a5ef36 100644 --- a/lib/virtual-fs/src/mem_fs/file.rs +++ b/lib/virtual-fs/src/mem_fs/file.rs @@ -680,8 +680,12 @@ impl AsyncRead for FileHandle { match inode { Some(Node::File(node)) => { let read = unsafe { - node.file - .read(std::mem::transmute(buf.unfilled_mut()), &mut cursor) + node.file.read( + std::mem::transmute::<&mut [std::mem::MaybeUninit], &mut [u8]>( + buf.unfilled_mut(), + ), + &mut cursor, + ) }; if let Ok(read) = &read { unsafe { buf.assume_init(*read) }; @@ -691,8 +695,12 @@ impl AsyncRead for FileHandle { } Some(Node::OffloadedFile(node)) => { let read = unsafe { - node.file - .read(std::mem::transmute(buf.unfilled_mut()), &mut cursor) + node.file.read( + std::mem::transmute::<&mut [std::mem::MaybeUninit], &mut [u8]>( + buf.unfilled_mut(), + ), + &mut cursor, + ) }; if let Ok(read) = &read { unsafe { buf.assume_init(*read) }; @@ -702,8 +710,12 @@ impl AsyncRead for FileHandle { } Some(Node::ReadOnlyFile(node)) => { let read = unsafe { - node.file - .read(std::mem::transmute(buf.unfilled_mut()), &mut cursor) + node.file.read( + std::mem::transmute::<&mut [std::mem::MaybeUninit], &mut [u8]>( + buf.unfilled_mut(), + ), + &mut cursor, + ) }; if let Ok(read) = &read { unsafe { buf.assume_init(*read) }; diff --git a/lib/vm/src/lib.rs b/lib/vm/src/lib.rs index e8058469e4c..9e88e572202 100644 --- a/lib/vm/src/lib.rs +++ b/lib/vm/src/lib.rs @@ -1,7 +1,6 @@ //! Runtime library support for Wasmer. #![deny(missing_docs, trivial_numeric_casts, unused_extern_crates)] -#![deny(trivial_numeric_casts, unused_extern_crates)] #![warn(unused_import_braces)] #![allow(clippy::new_without_default, ambiguous_wide_pointer_comparisons)] #![warn( diff --git a/lib/vm/src/libcalls.rs b/lib/vm/src/libcalls.rs index 04a2a9a1b7e..594cd060ca9 100644 --- a/lib/vm/src/libcalls.rs +++ b/lib/vm/src/libcalls.rs @@ -156,7 +156,7 @@ pub unsafe extern "C" fn wasmer_vm_memory32_grow( instance .memory_grow(memory_index, delta) .map(|pages| pages.0) - .unwrap_or(u32::max_value()) + .unwrap_or(u32::MAX) }) } @@ -178,7 +178,7 @@ pub unsafe extern "C" fn wasmer_vm_imported_memory32_grow( instance .imported_memory_grow(memory_index, delta) .map(|pages| pages.0) - .unwrap_or(u32::max_value()) + .unwrap_or(u32::MAX) }) } @@ -454,7 +454,7 @@ pub unsafe extern "C" fn wasmer_vm_table_grow( instance .table_grow(table_index, delta, init_value) - .unwrap_or(u32::max_value()) + .unwrap_or(u32::MAX) }) } @@ -481,7 +481,7 @@ pub unsafe extern "C" fn wasmer_vm_imported_table_grow( instance .imported_table_grow(table_index, delta, init_value) - .unwrap_or(u32::max_value()) + .unwrap_or(u32::MAX) }) } diff --git a/lib/vm/src/sig_registry.rs b/lib/vm/src/sig_registry.rs index 1ae661a7edc..78dcbce8ecd 100644 --- a/lib/vm/src/sig_registry.rs +++ b/lib/vm/src/sig_registry.rs @@ -49,7 +49,7 @@ impl SignatureRegistry { // is reserved for VMSharedSignatureIndex::default(). debug_assert_lt!( len, - std::u32::MAX as usize, + u32::MAX as usize, "Invariant check: signature_hash.len() < std::u32::MAX" ); let sig_id = VMSharedSignatureIndex::new(u32::try_from(len).unwrap()); diff --git a/lib/vm/src/trap/traphandlers.rs b/lib/vm/src/trap/traphandlers.rs index 95b1b2b5890..8c1149a902f 100644 --- a/lib/vm/src/trap/traphandlers.rs +++ b/lib/vm/src/trap/traphandlers.rs @@ -77,7 +77,7 @@ use libc::ucontext_t; /// Default stack size is 1MB. pub fn set_stack_size(size: usize) { - DEFAULT_STACK_SIZE.store(size.max(8 * 1024).min(100 * 1024 * 1024), Ordering::Relaxed); + DEFAULT_STACK_SIZE.store(size.clamp(8 * 1024, 100 * 1024 * 1024), Ordering::Relaxed); } cfg_if::cfg_if! { @@ -675,9 +675,14 @@ pub unsafe fn wasmer_call_trampoline( values_vec: *mut u8, ) -> Result<(), Trap> { catch_traps(trap_handler, config, || { - mem::transmute::<_, extern "C" fn(VMFunctionContext, *const VMFunctionBody, *mut u8)>( - trampoline, - )(vmctx, callee, values_vec); + mem::transmute::< + unsafe extern "C" fn( + *mut crate::vmcontext::VMContext, + *const VMFunctionBody, + *mut wasmer_types::RawValue, + ), + extern "C" fn(crate::vmcontext::VMFunctionContext, *const VMFunctionBody, *mut u8), + >(trampoline)(vmctx, callee, values_vec); }) } diff --git a/lib/vm/src/vmcontext.rs b/lib/vm/src/vmcontext.rs index 151b31ef171..f99de4efe2e 100644 --- a/lib/vm/src/vmcontext.rs +++ b/lib/vm/src/vmcontext.rs @@ -15,7 +15,6 @@ use crate::{VMBuiltinFunctionIndex, VMFunction}; use std::convert::TryFrom; use std::ptr::{self, NonNull}; use std::sync::atomic::{AtomicPtr, Ordering}; -use std::u32; use wasmer_types::RawValue; /// Union representing the first parameter passed when calling a function. diff --git a/lib/wasix/src/net/mod.rs b/lib/wasix/src/net/mod.rs index 76600a3c864..853f5395431 100644 --- a/lib/wasix/src/net/mod.rs +++ b/lib/wasix/src/net/mod.rs @@ -30,7 +30,7 @@ pub(crate) fn read_ip( Ok(match addr.tag { Addressfamily::Inet4 => IpAddr::V4(Ipv4Addr::new(o[0], o[1], o[2], o[3])), Addressfamily::Inet6 => { - let [a, b, c, d, e, f, g, h] = unsafe { transmute::<_, [u16; 8]>(o) }; + let [a, b, c, d, e, f, g, h] = unsafe { transmute::<[u8; 16], [u16; 8]>(o) }; IpAddr::V6(Ipv6Addr::new(a, b, c, d, e, f, g, h)) } _ => return Err(Errno::Inval), @@ -55,7 +55,7 @@ pub(crate) fn read_ip_v6( let addr_ptr = ptr.deref(memory); let addr = addr_ptr.read().map_err(crate::mem_error_to_wasi)?; - let [a, b, c, d, e, f, g, h] = unsafe { transmute::<_, [u16; 8]>(addr.segs) }; + let [a, b, c, d, e, f, g, h] = unsafe { transmute::<[u8; 16], [u16; 8]>(addr.segs) }; Ok(Ipv6Addr::new(a, b, c, d, e, f, g, h)) } @@ -110,7 +110,7 @@ pub(crate) fn read_cidr( o[0], o[1], o[2], o[3], o[4], o[5], o[6], o[7], o[8], o[9], o[10], o[11], o[12], o[13], o[14], o[15], ]; - unsafe { transmute::<_, [u16; 8]>(o) } + unsafe { transmute::<[u8; 16], [u16; 8]>(o) } }; IpCidr { ip: IpAddr::V6(Ipv6Addr::new(a, b, c, d, e, f, g, h)), @@ -250,7 +250,7 @@ pub(crate) fn read_route( o[0], o[1], o[2], o[3], o[4], o[5], o[6], o[7], o[8], o[9], o[10], o[11], o[12], o[13], o[14], o[15], ]; - unsafe { transmute::<_, [u16; 8]>(o) } + unsafe { transmute::<[u8; 16], [u16; 8]>(o) } }; IpCidr { ip: IpAddr::V6(Ipv6Addr::new(a, b, c, d, e, f, g, h)), @@ -265,7 +265,7 @@ pub(crate) fn read_route( match route.via_router.tag { Addressfamily::Inet4 => IpAddr::V4(Ipv4Addr::new(o[0], o[1], o[2], o[3])), Addressfamily::Inet6 => { - let [a, b, c, d, e, f, g, h] = unsafe { transmute::<_, [u16; 8]>(o) }; + let [a, b, c, d, e, f, g, h] = unsafe { transmute::<[u8; 16], [u16; 8]>(o) }; IpAddr::V6(Ipv6Addr::new(a, b, c, d, e, f, g, h)) } _ => return Err(Errno::Inval), diff --git a/lib/wasix/src/runtime/mod.rs b/lib/wasix/src/runtime/mod.rs index b99cfcd65a7..a5c4f66363a 100644 --- a/lib/wasix/src/runtime/mod.rs +++ b/lib/wasix/src/runtime/mod.rs @@ -331,11 +331,7 @@ impl Runtime for PluggableRuntime { } fn engine(&self) -> wasmer::Engine { - if let Some(engine) = self.engine.clone() { - engine - } else { - wasmer::Engine::default() - } + self.engine.clone().unwrap_or_default() } fn new_store(&self) -> wasmer::Store { diff --git a/lib/wasix/src/syscalls/wasi/path_link.rs b/lib/wasix/src/syscalls/wasi/path_link.rs index 9b0388d6cd2..b5cd63e510c 100644 --- a/lib/wasix/src/syscalls/wasi/path_link.rs +++ b/lib/wasix/src/syscalls/wasi/path_link.rs @@ -111,7 +111,7 @@ pub(crate) fn path_link_internal( .fs .get_parent_inode_at_path(inodes, new_fd, &target_path_arg, false)?; - if source_inode.stat.write().unwrap().st_nlink == Linkcount::max_value() { + if source_inode.stat.write().unwrap().st_nlink == Linkcount::MAX { return Err(Errno::Mlink); } { diff --git a/rust-toolchain b/rust-toolchain index 8e95c75dac7..17420a571fe 100644 --- a/rust-toolchain +++ b/rust-toolchain @@ -1 +1 @@ -1.78 +1.79 diff --git a/tests/integration/cli/Cargo.toml b/tests/integration/cli/Cargo.toml index fdce7c93660..cde7db1068d 100644 --- a/tests/integration/cli/Cargo.toml +++ b/tests/integration/cli/Cargo.toml @@ -39,4 +39,5 @@ wasmer-registry = { path = "../../../lib/registry", default-features = false } default = ["webc_runner"] webc_runner = [] wamr = [] +wasmi = [] debug = [] diff --git a/tests/integration/cli/tests/run.rs b/tests/integration/cli/tests/run.rs index 4094021bdd0..03851b70a01 100644 --- a/tests/integration/cli/tests/run.rs +++ b/tests/integration/cli/tests/run.rs @@ -48,6 +48,7 @@ static CACHE_RUST_LOG: Lazy = Lazy::new(|| { }); #[test] +#[cfg_attr(feature = "wasmi", ignore = "wasmi currently does not support threads")] fn list_cwd() { let package = packages().join("list-cwd"); @@ -58,6 +59,7 @@ fn list_cwd() { .unwrap(); let stdout = output.stdout; + eprintln!("{}", String::from_utf8(output.stderr).unwrap()); let expected = ". .. @@ -71,6 +73,7 @@ wasmer.toml } #[test] +#[cfg_attr(feature = "wasmi", ignore = "wasmi currently does not support threads")] fn nested_mounted_paths() { let package = packages().join("nested-mounted-paths"); @@ -82,6 +85,7 @@ fn nested_mounted_paths() { .output() .unwrap(); let host_stdout = host_output.stdout; + println!("{}", String::from_utf8(host_output.stderr).unwrap()); let webc_output = Command::new(get_wasmer_path()) .arg("run") @@ -89,7 +93,9 @@ fn nested_mounted_paths() { .arg(".") .output() .unwrap(); + let webc_stdout = webc_output.stdout; + println!("{}", String::from_utf8(webc_output.stderr).unwrap()); let expected = "/: . @@ -302,6 +308,7 @@ fn test_wasmer_run_works_with_dir() { // FIXME: Re-enable. See https://github.com/wasmerio/wasmer/issues/3717 #[test] +#[cfg_attr(feature = "wasmi", ignore = "wasmi currently does not support threads")] fn test_wasmer_run_works() { let assert = Command::new(get_wasmer_path()) .arg("https://wasmer.io/python/python@0.2.0") @@ -813,6 +820,7 @@ fn wcgi_runner_on_disk_with_mounted_directories() { all(target_env = "musl", target_os = "linux"), ignore = "wasmer run-unstable segfaults on musl" )] +#[cfg_attr(feature = "wasmi", ignore = "wasmi currently does not support threads")] fn issue_3794_unable_to_mount_relative_paths() { let temp = TempDir::new().unwrap(); std::fs::write(temp.path().join("message.txt"), b"Hello, World!").unwrap(); @@ -1016,6 +1024,7 @@ fn run_quickjs_via_url() { feature = "wamr", ignore = "FIXME(xdoardo): Bash is currently not working in wamr" )] +#[cfg_attr(feature = "wasmi", ignore = "wasmi currently does not support threads")] fn run_bash_using_coreutils() { let assert = Command::new(get_wasmer_path()) .arg("run") @@ -1063,6 +1072,7 @@ fn run_a_package_that_uses_an_atom_from_a_dependency() { } #[test] +#[cfg_attr(feature = "wasmi", ignore = "wasmi currently does not support threads")] fn local_package_has_write_access_to_its_volumes() { let temp = tempfile::tempdir().unwrap();