From 165ceab3d90b1e5b1cc2ba7cf1400ead9bc71ebf Mon Sep 17 00:00:00 2001 From: James Sturtevant Date: Tue, 9 Dec 2025 20:19:57 -0800 Subject: [PATCH] Add support for both wasmtime latest (39.x) and LTS (36.x) versions Introduces wasmtime_lts feature flag to switch between wasmtime versions. Default uses latest (39.0.1), pass --lts flag to AOT compiler or enable wasmtime_lts feature for LTS version (36.0.3). CI updated to test both. Signed-off-by: James Sturtevant --- .github/workflows/Benchmarks.yml | 2 +- .github/workflows/CreateRelease.yml | 2 +- .github/workflows/dep_build_wasm_examples.yml | 48 +- .github/workflows/dep_rust.yml | 37 +- Cargo.lock | 617 ++++++++++++++++-- Justfile | 17 +- src/hyperlight_wasm/Cargo.toml | 2 + src/hyperlight_wasm/build.rs | 9 + .../examples/guest-debugging/main.rs | 2 +- .../scripts/build-wasm-examples.sh | 17 +- src/hyperlight_wasm_aot/Cargo.toml | 10 +- src/hyperlight_wasm_aot/src/main.rs | 227 ++++--- src/wasm_runtime/Cargo.lock | 584 +++++++++++++++-- src/wasm_runtime/Cargo.toml | 11 +- src/wasm_runtime/src/component.rs | 10 + src/wasm_runtime/src/main.rs | 14 + src/wasm_runtime/src/module.rs | 11 + 17 files changed, 1357 insertions(+), 263 deletions(-) diff --git a/.github/workflows/Benchmarks.yml b/.github/workflows/Benchmarks.yml index 92aed51f..2454000e 100644 --- a/.github/workflows/Benchmarks.yml +++ b/.github/workflows/Benchmarks.yml @@ -45,7 +45,7 @@ jobs: - name: Download Wasm Modules uses: actions/download-artifact@v5 with: - name: guest-modules + name: guest-modules-latest path: ./x64/${{ matrix.config }} ### Benchmarks ### diff --git a/.github/workflows/CreateRelease.yml b/.github/workflows/CreateRelease.yml index db15e4db..c2aa6952 100644 --- a/.github/workflows/CreateRelease.yml +++ b/.github/workflows/CreateRelease.yml @@ -69,7 +69,7 @@ jobs: - name: Download Wasm Modules uses: actions/download-artifact@v5 with: - name: guest-modules + name: guest-modules-latest path: ${{ env.PLATFORM }}/${{ env.CONFIG }} - name: Build rust wasm modules run: just build-rust-wasm-examples ${{ env.CONFIG }} diff --git a/.github/workflows/dep_build_wasm_examples.yml b/.github/workflows/dep_build_wasm_examples.yml index a29f4f8c..71575a1a 100644 --- a/.github/workflows/dep_build_wasm_examples.yml +++ b/.github/workflows/dep_build_wasm_examples.yml @@ -21,19 +21,13 @@ permissions: contents: read jobs: - build-wasm-examples: + build-docker-image: if: ${{ inputs.docs_only == 'false' || github.event_name == 'schedule' || github.event_name == 'workflow_dispatch' }} runs-on: ubuntu-latest steps: - uses: actions/checkout@v5 with: fetch-depth: 0 - - name: Remove default clang - run: sudo rm /usr/bin/clang - - name: Hyperlight setup workflow - uses: hyperlight-dev/ci-setup-workflow@v1.8.0 - with: - rust-toolchain: "1.89" - name: Set up Docker Buildx uses: docker/setup-buildx-action@v3 - name: Login to Registry @@ -76,15 +70,47 @@ jobs: tags: ghcr.io/${{ github.repository_owner }}/wasm-clang-builder:latest cache-from: type=registry,ref=ghcr.io/${{ github.repository_owner }}/wasm-clang-builder:buildcache cache-to: ${{ env.CACHE_TO }} - - name: Build Modules + + build-wasm-examples: + needs: build-docker-image + runs-on: ubuntu-latest + strategy: + matrix: + wasmtime_version: + - name: latest + features: "" + - name: lts + features: "wasmtime_lts" + steps: + - uses: actions/checkout@v5 + with: + fetch-depth: 0 + - name: Remove default clang + run: sudo rm /usr/bin/clang + - name: Hyperlight setup workflow + uses: hyperlight-dev/ci-setup-workflow@v1.8.0 + with: + rust-toolchain: "1.89" + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + - name: Login to Registry + uses: docker/login-action@v3 + with: + registry: ghcr.io + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + - name: Pull wasm-clang-builder + run: | + docker pull ghcr.io/${{ github.repository_owner }}/wasm-clang-builder:latest + - name: Build Modules (wasmtime ${{ matrix.wasmtime_version.name }}) run: | just ensure-tools - just build-wasm-examples release + just build-wasm-examples release ${{ matrix.wasmtime_version.features }} shell: bash working-directory: src/wasmsamples - - name: Upload Wasm Modules + - name: Upload Wasm Modules (wasmtime ${{ matrix.wasmtime_version.name }}) uses: actions/upload-artifact@v4 with: - name: guest-modules + name: guest-modules-${{ matrix.wasmtime_version.name }} path: | x64/release/*.aot diff --git a/.github/workflows/dep_rust.yml b/.github/workflows/dep_rust.yml index 540d77cc..e74e2053 100644 --- a/.github/workflows/dep_rust.yml +++ b/.github/workflows/dep_rust.yml @@ -40,12 +40,28 @@ jobs: hypervisor: [hyperv, mshv3, kvm] # hyperv is windows, mshv and kvm are linux cpu: [amd, intel] config: [debug, release] + wasmtime: [latest, lts] + exclude: + # Latest testing: skip Windows, Intel, and debug builds to reduce CI load + - wasmtime: latest + hypervisor: hyperv + - wasmtime: latest + cpu: intel + - wasmtime: latest + config: debug runs-on: ${{ fromJson( format('["self-hosted", "{0}", "X64", "1ES.Pool=hld-{1}-{2}"]', matrix.hypervisor == 'hyperv' && 'Windows' || 'Linux', matrix.hypervisor == 'hyperv' && 'win2022' || matrix.hypervisor == 'mshv3' && 'azlinux3-mshv' || matrix.hypervisor, - matrix.cpu)) }} + matrix.cpu)) }} + env: + # Features to pass to cargo. + # On windows hyperv do not pass any features. + # On Windows LTS builds, only add wasmtime_lts. + # On Linux, always pass the hypervisor feature (kvm/mshv3). + # On Linux LTS builds, also add wasmtime_lts. + FEATURES: ${{ matrix.hypervisor != 'hyperv' && format('{0}{1}', matrix.hypervisor, matrix.wasmtime == 'lts' && ',wasmtime_lts' || '') || (matrix.wasmtime == 'lts' && 'wasmtime_lts' || '') }} steps: - uses: actions/checkout@v5 @@ -70,7 +86,7 @@ jobs: - name: Download Wasm Modules uses: actions/download-artifact@v5 with: - name: guest-modules + name: guest-modules-${{ matrix.wasmtime }} path: ./x64/${{ matrix.config }} - name: Build Rust component model examples @@ -79,7 +95,7 @@ jobs: # because the component model example depends on the wasm component built here just ensure-tools just compile-wit - just build-rust-component-examples ${{ matrix.config }} + just build-rust-component-examples ${{ matrix.config }} ${{ matrix.wasmtime == 'lts' && 'wasmtime_lts' || '' }} - name: Fmt run: just fmt-check @@ -88,15 +104,15 @@ jobs: run: just clippy ${{ matrix.config }} - name: Build - run: just build ${{ matrix.config }} + run: just build ${{ matrix.config }} ${{ env.FEATURES }} working-directory: ./src/hyperlight_wasm - name: Build Rust Wasm examples - run: just build-rust-wasm-examples ${{ matrix.config }} + run: just build-rust-wasm-examples ${{ matrix.config }} ${{ matrix.wasmtime == 'lts' && 'wasmtime_lts' || '' }} working-directory: ./src/hyperlight_wasm - name: Test - run: just test ${{ matrix.config }} + run: just test ${{ matrix.config }} ${{ env.FEATURES }} working-directory: ./src/hyperlight_wasm - name: Install github-cli (Windows) @@ -114,21 +130,21 @@ jobs: shell: pwsh - name: Test Examples - run: just examples-ci ${{ matrix.config }} + run: just examples-ci ${{ matrix.config }} ${{ env.FEATURES }} working-directory: ./src/hyperlight_wasm env: # required for gh cli when downloading GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} - name: Test Component Model Examples - run: just examples-components ${{ matrix.config }} + run: just examples-components ${{ matrix.config }} ${{ env.FEATURES }} working-directory: ./src/hyperlight_wasm ### Benchmarks ### - name: Download benchmarks from "latest" run: | - just bench-download ${{ runner.os }} ${{ matrix.hypervisor }} ${{ matrix.cpu }} dev-latest + just bench-download ${{ runner.os }} ${{ matrix.hypervisor }} ${{ matrix.cpu }} dev-latest ${{ matrix.wasmtime }} env: GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} continue-on-error: true @@ -137,6 +153,7 @@ jobs: - name: Run benchmarks run: | - just bench-ci dev ${{ matrix.config }} + just bench-ci dev ${{ matrix.config }} ${{ env.FEATURES }} working-directory: ./src/hyperlight_wasm if: ${{ matrix.config == 'release' }} + diff --git a/Cargo.lock b/Cargo.lock index 7ece26c4..eb7b6672 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -561,7 +561,16 @@ version = "0.123.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "90431884c6dd00d473229135f69cb43a2257c12f05ca478f994f4778c0607f28" dependencies = [ - "cranelift-assembler-x64-meta", + "cranelift-assembler-x64-meta 0.123.3", +] + +[[package]] +name = "cranelift-assembler-x64" +version = "0.126.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "30054f4aef4d614d37f27d5b77e36e165f0b27a71563be348e7c9fcfac41eed8" +dependencies = [ + "cranelift-assembler-x64-meta 0.126.1", ] [[package]] @@ -570,7 +579,16 @@ version = "0.123.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7e023ca3e629d01bb1215a0846099dfd9065060c07e4727b2e4d49060c2a6e4b" dependencies = [ - "cranelift-srcgen", + "cranelift-srcgen 0.123.3", +] + +[[package]] +name = "cranelift-assembler-x64-meta" +version = "0.126.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0beab56413879d4f515e08bcf118b1cb85f294129bb117057f573d37bfbb925a" +dependencies = [ + "cranelift-srcgen 0.126.1", ] [[package]] @@ -579,7 +597,16 @@ version = "0.123.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a61a409e5403fe1b7d4f49fecde2a950790c8dfed897c60da0dfb30af7689011" dependencies = [ - "cranelift-entity", + "cranelift-entity 0.123.3", +] + +[[package]] +name = "cranelift-bforest" +version = "0.126.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6d054747549a69b264d5299c8ca1b0dd45dc6bd0ee43f1edfcc42a8b12952c7a" +dependencies = [ + "cranelift-entity 0.126.1", ] [[package]] @@ -592,6 +619,16 @@ dependencies = [ "serde_derive", ] +[[package]] +name = "cranelift-bitset" +version = "0.126.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "98b92d481b77a7dc9d07c96e24a16f29e0c9c27d042828fdf7e49e54ee9819bf" +dependencies = [ + "serde", + "serde_derive", +] + [[package]] name = "cranelift-codegen" version = "0.123.3" @@ -599,24 +636,51 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "134d091c729077b82b14cfad1ed9df542901175c70eefa453c26a375bd1de1c8" dependencies = [ "bumpalo", - "cranelift-assembler-x64", - "cranelift-bforest", - "cranelift-bitset", - "cranelift-codegen-meta", - "cranelift-codegen-shared", - "cranelift-control", - "cranelift-entity", - "cranelift-isle", + "cranelift-assembler-x64 0.123.3", + "cranelift-bforest 0.123.3", + "cranelift-bitset 0.123.3", + "cranelift-codegen-meta 0.123.3", + "cranelift-codegen-shared 0.123.3", + "cranelift-control 0.123.3", + "cranelift-entity 0.123.3", + "cranelift-isle 0.123.3", + "gimli", + "hashbrown 0.15.5", + "log", + "pulley-interpreter 36.0.3", + "regalloc2 0.12.2", + "rustc-hash", + "serde", + "smallvec", + "target-lexicon", + "wasmtime-internal-math 36.0.3", +] + +[[package]] +name = "cranelift-codegen" +version = "0.126.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6eeccfc043d599b0ef1806942707fc51cdd1c3965c343956dc975a55d82a920f" +dependencies = [ + "bumpalo", + "cranelift-assembler-x64 0.126.1", + "cranelift-bforest 0.126.1", + "cranelift-bitset 0.126.1", + "cranelift-codegen-meta 0.126.1", + "cranelift-codegen-shared 0.126.1", + "cranelift-control 0.126.1", + "cranelift-entity 0.126.1", + "cranelift-isle 0.126.1", "gimli", "hashbrown 0.15.5", "log", - "pulley-interpreter", - "regalloc2", + "pulley-interpreter 39.0.1", + "regalloc2 0.13.3", "rustc-hash", "serde", "smallvec", "target-lexicon", - "wasmtime-internal-math", + "wasmtime-internal-math 39.0.1", ] [[package]] @@ -625,11 +689,24 @@ version = "0.123.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9c1529f8643e11f6c5d3954295f3b3923ab251cd3220d0eb034115345e0c953e" dependencies = [ - "cranelift-assembler-x64-meta", - "cranelift-codegen-shared", - "cranelift-srcgen", + "cranelift-assembler-x64-meta 0.123.3", + "cranelift-codegen-shared 0.123.3", + "cranelift-srcgen 0.123.3", + "heck", + "pulley-interpreter 36.0.3", +] + +[[package]] +name = "cranelift-codegen-meta" +version = "0.126.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1174cdb9d9d43b2bdaa612a07ed82af13db9b95526bc2c286c2aec4689bcc038" +dependencies = [ + "cranelift-assembler-x64-meta 0.126.1", + "cranelift-codegen-shared 0.126.1", + "cranelift-srcgen 0.126.1", "heck", - "pulley-interpreter", + "pulley-interpreter 39.0.1", ] [[package]] @@ -638,6 +715,12 @@ version = "0.123.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3a17d7ff63eb0ef851174f4c31a073bcc5886664327e00416dc4fd01aa0d00a8" +[[package]] +name = "cranelift-codegen-shared" +version = "0.126.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7d572be73fae802eb115f45e7e67a9ed16acb4ee683b67c4086768786545419a" + [[package]] name = "cranelift-control" version = "0.123.3" @@ -647,13 +730,33 @@ dependencies = [ "arbitrary", ] +[[package]] +name = "cranelift-control" +version = "0.126.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e1587465cc84c5cc793b44add928771945f3132bbf6b3621ee9473c631a87156" +dependencies = [ + "arbitrary", +] + [[package]] name = "cranelift-entity" version = "0.123.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b48f2b24fc3eec954a1d17e5a9c04957ba24f6202dbaa8df52472ba7624e854a" dependencies = [ - "cranelift-bitset", + "cranelift-bitset 0.123.3", + "serde", + "serde_derive", +] + +[[package]] +name = "cranelift-entity" +version = "0.126.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "063b83448b1343e79282c3c7cbda7ed5f0816f0b763a4c15f7cecb0a17d87ea6" +dependencies = [ + "cranelift-bitset 0.126.1", "serde", "serde_derive", ] @@ -664,7 +767,19 @@ version = "0.123.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ca8aea478d61a71f7f56d19ee2642359c00fc2fa54bc0db0d6c5edd52f1d3efd" dependencies = [ - "cranelift-codegen", + "cranelift-codegen 0.123.3", + "log", + "smallvec", + "target-lexicon", +] + +[[package]] +name = "cranelift-frontend" +version = "0.126.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "aa4461c2d2ca48bc72883f5f5c3129d9aefac832df1db824af9db8db3efee109" +dependencies = [ + "cranelift-codegen 0.126.1", "log", "smallvec", "target-lexicon", @@ -676,13 +791,30 @@ version = "0.123.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "da142f3cc42beaa44bf2558567751816c6adf776f2cfc40ba79ff9e5c232d808" +[[package]] +name = "cranelift-isle" +version = "0.126.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "acd811b25e18f14810d09c504e06098acc1d9dbfa24879bf0d6b6fb44415fc66" + [[package]] name = "cranelift-native" version = "0.123.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "be7b57410e388de0828fa9178e8693abe996bf2356a7f55be35719ee5b162755" dependencies = [ - "cranelift-codegen", + "cranelift-codegen 0.123.3", + "libc", + "target-lexicon", +] + +[[package]] +name = "cranelift-native" +version = "0.126.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2417046989d8d6367a55bbab2e406a9195d176f4779be4aa484d645887217d37" +dependencies = [ + "cranelift-codegen 0.126.1", "libc", "target-lexicon", ] @@ -693,6 +825,12 @@ version = "0.123.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bd9641751da85481f0e04033228403eca2becd2a3d9aff56f6c8bed8b9147bfc" +[[package]] +name = "cranelift-srcgen" +version = "0.126.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8d039de901c8d928222b8128e1b9a9ab27b82a7445cb749a871c75d9cb25c57d" + [[package]] name = "crc32fast" version = "1.5.0" @@ -934,9 +1072,9 @@ checksum = "877a4ace8713b0bcf2a4e7eec82529c029f1d0619886d18145fea96c3ffe5c0f" [[package]] name = "erased-serde" -version = "0.4.8" +version = "0.4.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "259d404d09818dec19332e31d94558aeb442fea04c817006456c24b5460bbd4b" +checksum = "89e8918065695684b2b0702da20382d5ae6065cf3327bc2d6436bd49a71ce9f3" dependencies = [ "serde", "serde_core", @@ -1548,7 +1686,8 @@ dependencies = [ "cargo-util-schemas", "cargo_metadata", "clap", - "wasmtime", + "wasmtime 36.0.3", + "wasmtime 39.0.1", ] [[package]] @@ -2473,10 +2612,22 @@ version = "36.0.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0f18b4e1b955bf4d6077dbc9d1d43a3a16f8c8b011a67dbafbd671ab4335c48b" dependencies = [ - "cranelift-bitset", + "cranelift-bitset 0.123.3", "log", - "pulley-macros", - "wasmtime-internal-math", + "pulley-macros 36.0.3", + "wasmtime-internal-math 36.0.3", +] + +[[package]] +name = "pulley-interpreter" +version = "39.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0a09eb45f768f3a0396e85822790d867000c8b5f11551e7268c279e991457b16" +dependencies = [ + "cranelift-bitset 0.126.1", + "log", + "pulley-macros 39.0.1", + "wasmtime-internal-math 39.0.1", ] [[package]] @@ -2490,6 +2641,17 @@ dependencies = [ "syn", ] +[[package]] +name = "pulley-macros" +version = "39.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e29368432b8b7a8a343b75a6914621fad905c95d5c5297449a6546c127224f7a" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + [[package]] name = "quanta" version = "0.12.6" @@ -2631,6 +2793,20 @@ dependencies = [ "smallvec", ] +[[package]] +name = "regalloc2" +version = "0.13.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4e249c660440317032a71ddac302f25f1d5dff387667bcc3978d1f77aa31ac34" +dependencies = [ + "allocator-api2", + "bumpalo", + "hashbrown 0.15.5", + "log", + "rustc-hash", + "smallvec", +] + [[package]] name = "regex" version = "1.12.2" @@ -3726,6 +3902,16 @@ dependencies = [ "wasmparser 0.236.1", ] +[[package]] +name = "wasm-encoder" +version = "0.240.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "06d642d8c5ecc083aafe9ceb32809276a304547a3a6eeecceb5d8152598bc71f" +dependencies = [ + "leb128fmt", + "wasmparser 0.240.0", +] + [[package]] name = "wasmparser" version = "0.236.1" @@ -3739,6 +3925,19 @@ dependencies = [ "serde", ] +[[package]] +name = "wasmparser" +version = "0.240.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b722dcf61e0ea47440b53ff83ccb5df8efec57a69d150e4f24882e4eba7e24a4" +dependencies = [ + "bitflags 2.10.0", + "hashbrown 0.15.5", + "indexmap", + "semver", + "serde", +] + [[package]] name = "wasmparser" version = "0.243.0" @@ -3763,6 +3962,17 @@ dependencies = [ "wasmparser 0.236.1", ] +[[package]] +name = "wasmprinter" +version = "0.240.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a84d6e25c198da67d0150ee7c2c62d33d784f0a565d1e670bdf1eeccca8158bc" +dependencies = [ + "anyhow", + "termcolor", + "wasmparser 0.240.0", +] + [[package]] name = "wasmtime" version = "36.0.3" @@ -3785,7 +3995,7 @@ dependencies = [ "object", "once_cell", "postcard", - "pulley-interpreter", + "pulley-interpreter 36.0.3", "rustix", "semver", "serde", @@ -3793,19 +4003,65 @@ dependencies = [ "smallvec", "target-lexicon", "wasmparser 0.236.1", - "wasmtime-environ", + "wasmtime-environ 36.0.3", "wasmtime-internal-asm-macros", - "wasmtime-internal-component-macro", - "wasmtime-internal-component-util", - "wasmtime-internal-cranelift", - "wasmtime-internal-fiber", - "wasmtime-internal-jit-debug", - "wasmtime-internal-jit-icache-coherence", - "wasmtime-internal-math", - "wasmtime-internal-slab", - "wasmtime-internal-unwinder", - "wasmtime-internal-versioned-export-macros", - "wasmtime-internal-winch", + "wasmtime-internal-component-macro 36.0.3", + "wasmtime-internal-component-util 36.0.3", + "wasmtime-internal-cranelift 36.0.3", + "wasmtime-internal-fiber 36.0.3", + "wasmtime-internal-jit-debug 36.0.3", + "wasmtime-internal-jit-icache-coherence 36.0.3", + "wasmtime-internal-math 36.0.3", + "wasmtime-internal-slab 36.0.3", + "wasmtime-internal-unwinder 36.0.3", + "wasmtime-internal-versioned-export-macros 36.0.3", + "wasmtime-internal-winch 36.0.3", + "windows-sys 0.60.2", +] + +[[package]] +name = "wasmtime" +version = "39.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "511bc19c2d48f338007dc941cb40c833c4707023fdaf9ec9b97cf1d5a62d26bb" +dependencies = [ + "addr2line", + "anyhow", + "async-trait", + "bitflags 2.10.0", + "bumpalo", + "cc", + "cfg-if", + "encoding_rs", + "hashbrown 0.15.5", + "indexmap", + "libc", + "log", + "mach2", + "memfd", + "object", + "once_cell", + "postcard", + "pulley-interpreter 39.0.1", + "rustix", + "semver", + "serde", + "serde_derive", + "smallvec", + "target-lexicon", + "wasmparser 0.240.0", + "wasmtime-environ 39.0.1", + "wasmtime-internal-component-macro 39.0.1", + "wasmtime-internal-component-util 39.0.1", + "wasmtime-internal-cranelift 39.0.1", + "wasmtime-internal-fiber 39.0.1", + "wasmtime-internal-jit-debug 39.0.1", + "wasmtime-internal-jit-icache-coherence 39.0.1", + "wasmtime-internal-math 39.0.1", + "wasmtime-internal-slab 39.0.1", + "wasmtime-internal-unwinder 39.0.1", + "wasmtime-internal-versioned-export-macros 39.0.1", + "wasmtime-internal-winch 39.0.1", "windows-sys 0.60.2", ] @@ -3816,8 +4072,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0c7e455d0dc49fad35574e28c110eb23eeda80cfecbe075051892a067298e943" dependencies = [ "anyhow", - "cranelift-bitset", - "cranelift-entity", + "cranelift-bitset 0.123.3", + "cranelift-entity 0.123.3", "gimli", "indexmap", "log", @@ -3828,10 +4084,35 @@ dependencies = [ "serde_derive", "smallvec", "target-lexicon", - "wasm-encoder", + "wasm-encoder 0.236.1", "wasmparser 0.236.1", - "wasmprinter", - "wasmtime-internal-component-util", + "wasmprinter 0.236.1", + "wasmtime-internal-component-util 36.0.3", +] + +[[package]] +name = "wasmtime-environ" +version = "39.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c3b0d53657fea2a8cee8ed1866ad45d2e5bc21be958a626a1dd9b7de589851b3" +dependencies = [ + "anyhow", + "cranelift-bitset 0.126.1", + "cranelift-entity 0.126.1", + "gimli", + "indexmap", + "log", + "object", + "postcard", + "semver", + "serde", + "serde_derive", + "smallvec", + "target-lexicon", + "wasm-encoder 0.240.0", + "wasmparser 0.240.0", + "wasmprinter 0.240.0", + "wasmtime-internal-component-util 39.0.1", ] [[package]] @@ -3853,9 +4134,24 @@ dependencies = [ "proc-macro2", "quote", "syn", - "wasmtime-internal-component-util", - "wasmtime-internal-wit-bindgen", - "wit-parser", + "wasmtime-internal-component-util 36.0.3", + "wasmtime-internal-wit-bindgen 36.0.3", + "wit-parser 0.236.1", +] + +[[package]] +name = "wasmtime-internal-component-macro" +version = "39.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c933104f57d27dd1e6c7bd9ee5df3242bdd1962d9381bc08fa5d4e60e1f5ebdf" +dependencies = [ + "anyhow", + "proc-macro2", + "quote", + "syn", + "wasmtime-internal-component-util 39.0.1", + "wasmtime-internal-wit-bindgen 39.0.1", + "wit-parser 0.240.0", ] [[package]] @@ -3864,6 +4160,12 @@ version = "36.0.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "48ebb886b6c6e7bfe67eb14757f736ed7bbd1b5a034c27070874043c3b90e9ac" +[[package]] +name = "wasmtime-internal-component-util" +version = "39.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "63ef2a95a5dbaa70fc3ef682ea8997e51cdd819b4d157a1100477cf43949d454" + [[package]] name = "wasmtime-internal-cranelift" version = "36.0.3" @@ -3872,23 +4174,51 @@ checksum = "0ec12999113da589f806085a967a5c3d2ac0ca26585842374bf1199dba365f00" dependencies = [ "anyhow", "cfg-if", - "cranelift-codegen", - "cranelift-control", - "cranelift-entity", - "cranelift-frontend", - "cranelift-native", + "cranelift-codegen 0.123.3", + "cranelift-control 0.123.3", + "cranelift-entity 0.123.3", + "cranelift-frontend 0.123.3", + "cranelift-native 0.123.3", "gimli", "itertools 0.14.0", "log", "object", - "pulley-interpreter", + "pulley-interpreter 36.0.3", "smallvec", "target-lexicon", "thiserror 2.0.17", "wasmparser 0.236.1", - "wasmtime-environ", - "wasmtime-internal-math", - "wasmtime-internal-versioned-export-macros", + "wasmtime-environ 36.0.3", + "wasmtime-internal-math 36.0.3", + "wasmtime-internal-versioned-export-macros 36.0.3", +] + +[[package]] +name = "wasmtime-internal-cranelift" +version = "39.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "73122df6a8cf417ce486a94e844d3a60797217ce7ae69653e0ee9e28269e0fa5" +dependencies = [ + "anyhow", + "cfg-if", + "cranelift-codegen 0.126.1", + "cranelift-control 0.126.1", + "cranelift-entity 0.126.1", + "cranelift-frontend 0.126.1", + "cranelift-native 0.126.1", + "gimli", + "itertools 0.14.0", + "log", + "object", + "pulley-interpreter 39.0.1", + "smallvec", + "target-lexicon", + "thiserror 2.0.17", + "wasmparser 0.240.0", + "wasmtime-environ 39.0.1", + "wasmtime-internal-math 39.0.1", + "wasmtime-internal-unwinder 39.0.1", + "wasmtime-internal-versioned-export-macros 39.0.1", ] [[package]] @@ -3903,7 +4233,22 @@ dependencies = [ "libc", "rustix", "wasmtime-internal-asm-macros", - "wasmtime-internal-versioned-export-macros", + "wasmtime-internal-versioned-export-macros 36.0.3", + "windows-sys 0.60.2", +] + +[[package]] +name = "wasmtime-internal-fiber" +version = "39.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "54ead059e58b54a7abbe0bfb9457b3833ebd2ad84326c248a835ff76d64c7c6f" +dependencies = [ + "anyhow", + "cc", + "cfg-if", + "libc", + "rustix", + "wasmtime-internal-versioned-export-macros 39.0.1", "windows-sys 0.60.2", ] @@ -3914,7 +4259,17 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fc4bd73187d8f1accd19d9f10195d0d87c035e6231009ba98bb6d94fefb0ecf1" dependencies = [ "cc", - "wasmtime-internal-versioned-export-macros", + "wasmtime-internal-versioned-export-macros 36.0.3", +] + +[[package]] +name = "wasmtime-internal-jit-debug" +version = "39.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3af620a4ac1623298c90d3736644e12d66974951d1e38d0464798de85c984e17" +dependencies = [ + "cc", + "wasmtime-internal-versioned-export-macros 39.0.1", ] [[package]] @@ -3929,6 +4284,18 @@ dependencies = [ "windows-sys 0.60.2", ] +[[package]] +name = "wasmtime-internal-jit-icache-coherence" +version = "39.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b97ccd36e25390258ce6720add639ffe5a7d81a5c904350aa08f5bbc60433d22" +dependencies = [ + "anyhow", + "cfg-if", + "libc", + "windows-sys 0.60.2", +] + [[package]] name = "wasmtime-internal-math" version = "36.0.3" @@ -3938,12 +4305,27 @@ dependencies = [ "libm", ] +[[package]] +name = "wasmtime-internal-math" +version = "39.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cd1b856e1bbf0230ab560ba4204e944b141971adc4e6cdf3feb6979c1a7b7953" +dependencies = [ + "libm", +] + [[package]] name = "wasmtime-internal-slab" version = "36.0.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cbd2df91a81105cd5e1db81a35e5f3cf8eae871b72c97bd04a3cb5d9e21e8d77" +[[package]] +name = "wasmtime-internal-slab" +version = "39.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8908e71a780b97cbd3d8f3a0c446ac8df963069e0f3f38c9eace4f199d4d3e65" + [[package]] name = "wasmtime-internal-unwinder" version = "36.0.3" @@ -3952,7 +4334,20 @@ checksum = "d425451d62f8075085ebed056341d94f6fefd1cb94b1a7c7d6eb99b0682e399d" dependencies = [ "anyhow", "cfg-if", - "cranelift-codegen", + "cranelift-codegen 0.123.3", + "log", + "object", +] + +[[package]] +name = "wasmtime-internal-unwinder" +version = "39.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fb9c2f8223a0ef96527f0446b80c7d0d9bb0577c7b918e3104bd6d4cdba1d101" +dependencies = [ + "anyhow", + "cfg-if", + "cranelift-codegen 0.126.1", "log", "object", ] @@ -3968,6 +4363,17 @@ dependencies = [ "syn", ] +[[package]] +name = "wasmtime-internal-versioned-export-macros" +version = "39.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2b0fb82cdbffd6cafc812c734a22fa753102888b8760ecf6a08cbb50367a458a" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + [[package]] name = "wasmtime-internal-winch" version = "36.0.3" @@ -3975,14 +4381,32 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f3e8c6bc0c4a68103cf20d831f141be9f56527df0c0830052c6b2409eed18705" dependencies = [ "anyhow", - "cranelift-codegen", + "cranelift-codegen 0.123.3", "gimli", "object", "target-lexicon", "wasmparser 0.236.1", - "wasmtime-environ", - "wasmtime-internal-cranelift", - "winch-codegen", + "wasmtime-environ 36.0.3", + "wasmtime-internal-cranelift 36.0.3", + "winch-codegen 36.0.3", +] + +[[package]] +name = "wasmtime-internal-winch" +version = "39.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f1cfd68149cef86afd9a6c9b51e461266dfa66b37b4c6fdf1201ddbf7f906271" +dependencies = [ + "anyhow", + "cranelift-codegen 0.126.1", + "gimli", + "log", + "object", + "target-lexicon", + "wasmparser 0.240.0", + "wasmtime-environ 39.0.1", + "wasmtime-internal-cranelift 39.0.1", + "winch-codegen 39.0.1", ] [[package]] @@ -3995,7 +4419,20 @@ dependencies = [ "bitflags 2.10.0", "heck", "indexmap", - "wit-parser", + "wit-parser 0.236.1", +] + +[[package]] +name = "wasmtime-internal-wit-bindgen" +version = "39.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a628437073400148f1ba2b55beb60eb376dc5ca538745994c83332b037d1f3fa" +dependencies = [ + "anyhow", + "bitflags 2.10.0", + "heck", + "indexmap", + "wit-parser 0.240.0", ] [[package]] @@ -4068,17 +4505,37 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b69d4fdfcf07cbc0a2d3d585fb0f87d9598fde1efada9d2ac35a11ec09bf4eaa" dependencies = [ "anyhow", - "cranelift-assembler-x64", - "cranelift-codegen", + "cranelift-assembler-x64 0.123.3", + "cranelift-codegen 0.123.3", "gimli", - "regalloc2", + "regalloc2 0.12.2", "smallvec", "target-lexicon", "thiserror 2.0.17", "wasmparser 0.236.1", - "wasmtime-environ", - "wasmtime-internal-cranelift", - "wasmtime-internal-math", + "wasmtime-environ 36.0.3", + "wasmtime-internal-cranelift 36.0.3", + "wasmtime-internal-math 36.0.3", +] + +[[package]] +name = "winch-codegen" +version = "39.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b1de5a648102e39c8e817ed25e3820f4b9772f3c9c930984f32737be60e3156b" +dependencies = [ + "anyhow", + "cranelift-assembler-x64 0.126.1", + "cranelift-codegen 0.126.1", + "gimli", + "regalloc2 0.13.3", + "smallvec", + "target-lexicon", + "thiserror 2.0.17", + "wasmparser 0.240.0", + "wasmtime-environ 39.0.1", + "wasmtime-internal-cranelift 39.0.1", + "wasmtime-internal-math 39.0.1", ] [[package]] @@ -4392,6 +4849,24 @@ dependencies = [ "wasmparser 0.236.1", ] +[[package]] +name = "wit-parser" +version = "0.240.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9875ea3fa272f57cc1fc50f225a7b94021a7878c484b33792bccad0d93223439" +dependencies = [ + "anyhow", + "id-arena", + "indexmap", + "log", + "semver", + "serde", + "serde_derive", + "serde_json", + "unicode-xid", + "wasmparser 0.240.0", +] + [[package]] name = "writeable" version = "0.6.2" diff --git a/Justfile b/Justfile index 4ad33011..48322ff6 100644 --- a/Justfile +++ b/Justfile @@ -41,14 +41,14 @@ build-wasm-examples target=default-target features="": (compile-wit) build-rust-wasm-examples target=default-target features="": (mkdir-redist target) rustup target add wasm32-unknown-unknown cd ./src/rust_wasm_samples && cargo build --target wasm32-unknown-unknown --profile={{ if target == "debug" {"dev"} else { target } }} - cargo run {{ if features =="" {''} else if features=="no-default-features" {"--no-default-features" } else {"--features " + features } }} -p hyperlight-wasm-aot compile {{ if features =~ "gdb" {"--debug"} else {""} }} ./src/rust_wasm_samples/target/wasm32-unknown-unknown/{{ target }}/rust_wasm_samples.wasm ./x64/{{ target }}/rust_wasm_samples.aot + cargo run -p hyperlight-wasm-aot compile {{ if features =~ "gdb" {"--debug"} else {""} }} {{ if features =~ "wasmtime_lts" {"--lts"} else {""} }} ./src/rust_wasm_samples/target/wasm32-unknown-unknown/{{ target }}/rust_wasm_samples.wasm ./x64/{{ target }}/rust_wasm_samples.aot build-rust-component-examples target=default-target features="": (compile-wit) # use cargo component so we don't get all the wasi imports https://github.com/bytecodealliance/cargo-component?tab=readme-ov-file#relationship-with-wasm32-wasip2 # we also explicitly target wasm32-unknown-unknown since cargo component might try to pull in wasi imports https://github.com/bytecodealliance/cargo-component/issues/290 rustup target add wasm32-unknown-unknown cd ./src/component_sample && cargo component build --target wasm32-unknown-unknown --profile={{ if target == "debug" {"dev"} else { target } }} - cargo run {{ if features =="" {''} else if features=="no-default-features" {"--no-default-features" } else {"--features " + features } }} -p hyperlight-wasm-aot compile {{ if features =~ "gdb" {"--debug"} else {""} }} --component ./src/component_sample/target/wasm32-unknown-unknown/{{ target }}/component_sample.wasm ./x64/{{ target }}/component_sample.aot + cargo run -p hyperlight-wasm-aot compile {{ if features =~ "gdb" {"--debug"} else {""} }} {{ if features =~ "wasmtime_lts" {"--lts"} else {""} }} --component ./src/component_sample/target/wasm32-unknown-unknown/{{ target }}/component_sample.wasm ./x64/{{ target }}/component_sample.aot check target=default-target: cargo check --profile={{ if target == "debug" {"dev"} else { target } }} @@ -79,7 +79,9 @@ clippy target=default-target: (check target) cargo clippy --profile={{ if target == "debug" {"dev"} else { target } }} --all-targets --all-features -- -D warnings cd src/rust_wasm_samples && cargo clippy --profile={{ if target == "debug" {"dev"} else { target } }} --all-targets --all-features -- -D warnings cd src/component_sample && cargo clippy --profile={{ if target == "debug" {"dev"} else { target } }} --all-targets --all-features -- -D warnings - cd src/wasm_runtime && cargo hyperlight clippy --profile={{ if target == "debug" {"dev"} else { target } }} --all-targets --all-features -- -D warnings + # wasm_runtime has mutually exclusive wasmtime features, so we run clippy for each separately with all other features + cd src/wasm_runtime && cargo hyperlight clippy --profile={{ if target == "debug" {"dev"} else { target } }} --all-targets --features wasmtime_latest,gdb,trace_guest -- -D warnings + cd src/wasm_runtime && cargo hyperlight clippy --profile={{ if target == "debug" {"dev"} else { target } }} --all-targets --no-default-features --features wasmtime_lts,gdb,trace_guest -- -D warnings cd src/hyperlight_wasm_macro && cargo clippy --profile={{ if target == "debug" {"dev"} else { target } }} --all-targets --all-features -- -D warnings # TESTING @@ -87,11 +89,12 @@ clippy target=default-target: (check target) # There may be tests that we really want to ignore so we cant just use --ignored and run then we have to # specify the test name of the ignored tests that we want to run # Additionally, we have to run the tests with the function_call_metrics feature enabled separately +# We exclude hyperlight-wasm-aot because it has both wasmtime versions as dependencies and no tests so we don't need to build both versions for testing test target=default-target features="": - cargo test {{ if features =="" {''} else if features=="no-default-features" {"--no-default-features" } else {"--no-default-features -F " + features } }} --profile={{ if target == "debug" {"dev"} else { target } }} - cargo test test_metrics {{ if features =="" {''} else if features=="no-default-features" {"--no-default-features" } else {"--no-default-features -F " + features } }} --profile={{ if target == "debug" {"dev"} else { target } }} -- --ignored + cargo test --workspace --exclude hyperlight-wasm-aot {{ if features =="" {''} else if features=="no-default-features" {"--no-default-features" } else {"--no-default-features -F " + features } }} --profile={{ if target == "debug" {"dev"} else { target } }} + cargo test --workspace --exclude hyperlight-wasm-aot test_metrics {{ if features =="" {''} else if features=="no-default-features" {"--no-default-features" } else {"--no-default-features -F " + features } }} --profile={{ if target == "debug" {"dev"} else { target } }} -- --ignored -examples-ci target=default-target features="": (build-rust-wasm-examples target) +examples-ci target=default-target features="": (build-wasm-examples target features) (build-rust-wasm-examples target features) cargo run {{ if features =="" {''} else {"--no-default-features -F " + features } }} --profile={{ if target == "debug" {"dev"} else { target } }} --example helloworld cargo run {{ if features =="" {''} else {"--no-default-features -F " + features } }} --profile={{ if target == "debug" {"dev"} else { target } }} --example hostfuncs cargo run {{ if features =="" {''} else {"--no-default-features -F " + features } }} --profile={{ if target == "debug" {"dev"} else { target } }} --example rust_wasm_examples @@ -99,7 +102,7 @@ examples-ci target=default-target features="": (build-rust-wasm-examples target) cargo run {{ if features =="" {''} else {"--no-default-features -F function_call_metrics," + features } }} --profile={{ if target == "debug" {"dev"} else { target } }} --example metrics cargo run {{ if features =="" {"--no-default-features --features kvm,mshv3"} else {"--no-default-features -F function_call_metrics," + features } }} --profile={{ if target == "debug" {"dev"} else { target } }} --example metrics -examples-components target=default-target features="": (build-rust-component-examples target) +examples-components target=default-target features="": (build-rust-component-examples target features) {{ wit-world }} cargo run {{ if features =="" {''} else {"--no-default-features -F kvm -F " + features } }} --profile={{ if target == "debug" {"dev"} else { target } }} --example component_example {{ wit-world-c }} cargo run {{ if features =="" {''} else {"--no-default-features -F kvm -F " + features } }} --profile={{ if target == "debug" {"dev"} else { target } }} --example c-component diff --git a/src/hyperlight_wasm/Cargo.toml b/src/hyperlight_wasm/Cargo.toml index 5a57f956..c7af9b65 100644 --- a/src/hyperlight_wasm/Cargo.toml +++ b/src/hyperlight_wasm/Cargo.toml @@ -115,6 +115,8 @@ gdb = ["hyperlight-host/gdb"] kvm = ["hyperlight-host/kvm"] mshv3 = ["hyperlight-host/mshv3"] trace_guest = ["hyperlight-host/trace_guest"] +# Use wasmtime LTS version instead of latest in wasm_runtime +wasmtime_lts = [] [[bench]] name = "benchmarks" diff --git a/src/hyperlight_wasm/build.rs b/src/hyperlight_wasm/build.rs index 281cb8be..5f55f9f9 100644 --- a/src/hyperlight_wasm/build.rs +++ b/src/hyperlight_wasm/build.rs @@ -124,6 +124,15 @@ fn build_wasm_runtime() -> PathBuf { .env_clear() .envs(env_vars); + // Use wasmtime LTS version + // This removes wasmtime_latest feature and adds wasmtime_lts + if std::env::var("CARGO_FEATURE_WASMTIME_LTS").is_ok() { + cmd = cmd + .arg("--no-default-features") + .arg("--features") + .arg("wasmtime_lts"); + } + // Add --features gdb if the gdb feature is enabled for this build script if std::env::var("CARGO_FEATURE_GDB").is_ok() { cmd = cmd.arg("--features").arg("gdb"); diff --git a/src/hyperlight_wasm/examples/guest-debugging/main.rs b/src/hyperlight_wasm/examples/guest-debugging/main.rs index c27a88d9..1affaebc 100644 --- a/src/hyperlight_wasm/examples/guest-debugging/main.rs +++ b/src/hyperlight_wasm/examples/guest-debugging/main.rs @@ -24,7 +24,7 @@ limitations under the License. //! # for C modules //! just build-wasm-examples debug gdb //! # for Rust modules -//! just build-rust-wasm-samples debug gdb +//! just build-rust-wasm-examples debug gdb //! ``` //! //! # Running the Example diff --git a/src/hyperlight_wasm/scripts/build-wasm-examples.sh b/src/hyperlight_wasm/scripts/build-wasm-examples.sh index 0d714810..ce35cdbf 100755 --- a/src/hyperlight_wasm/scripts/build-wasm-examples.sh +++ b/src/hyperlight_wasm/scripts/build-wasm-examples.sh @@ -13,12 +13,10 @@ OUTPUT_DIR=$(realpath $OUTPUT_DIR) # Set stripping flags based on whether features are enabled if [ -n "$FEATURES" ]; then - AOT_FEATURES="--features $FEATURES" STRIP_FLAGS="" DEBUG_FLAGS="-g" OPT_FLAGS="-O0" else - AOT_FEATURES="" STRIP_FLAGS="-Wl,--strip-all" DEBUG_FLAGS="" OPT_FLAGS="-O3" @@ -31,6 +29,13 @@ else AOT_DEBUG_FLAGS="" fi +# Set AOT LTS flag if wasmtime_lts feature is enabled +if [[ "$FEATURES" == *"wasmtime_lts"* ]]; then + AOT_LTS_FLAGS="--lts" +else + AOT_LTS_FLAGS="" +fi + if [ -f "/.dockerenv" ] || grep -q docker /proc/1/cgroup; then # running in a container so use the installed wasi-sdk as the devcontainer has this installed for FILENAME in $(find . -name '*.c' -not -path './components/*') @@ -39,7 +44,7 @@ if [ -f "/.dockerenv" ] || grep -q docker /proc/1/cgroup; then # Build the wasm file with wasi-libc for wasmtime /opt/wasi-sdk/bin/clang ${DEBUG_FLAGS} -flto -ffunction-sections -mexec-model=reactor ${OPT_FLAGS} -z stack-size=4096 -Wl,--initial-memory=65536 -Wl,--export=__data_end -Wl,--export=__heap_base,--export=malloc,--export=free,--export=__wasm_call_ctors ${STRIP_FLAGS} -Wl,--no-entry -Wl,--allow-undefined -Wl,--gc-sections -o ${OUTPUT_DIR}/${FILENAME%.*}-wasi-libc.wasm ${FILENAME} - cargo run ${AOT_FEATURES} -p hyperlight-wasm-aot compile ${AOT_DEBUG_FLAGS} ${OUTPUT_DIR}/${FILENAME%.*}-wasi-libc.wasm ${OUTPUT_DIR}/${FILENAME%.*}.aot + cargo run -p hyperlight-wasm-aot compile ${AOT_DEBUG_FLAGS} ${AOT_LTS_FLAGS} ${OUTPUT_DIR}/${FILENAME%.*}-wasi-libc.wasm ${OUTPUT_DIR}/${FILENAME%.*}.aot done for WIT_FILE in ${PWD}/components/*.wit; do @@ -60,7 +65,7 @@ if [ -f "/.dockerenv" ] || grep -q docker /proc/1/cgroup; then ${PWD}/components/bindings/${COMPONENT_NAME}_component_type.o # Build AOT for Wasmtime - cargo run ${AOT_FEATURES} -p hyperlight-wasm-aot compile ${AOT_DEBUG_FLAGS} --component ${OUTPUT_DIR}/${COMPONENT_NAME}-p2.wasm ${OUTPUT_DIR}/${COMPONENT_NAME}.aot + cargo run -p hyperlight-wasm-aot compile ${AOT_DEBUG_FLAGS} ${AOT_LTS_FLAGS} --component ${OUTPUT_DIR}/${COMPONENT_NAME}-p2.wasm ${OUTPUT_DIR}/${COMPONENT_NAME}.aot done else @@ -89,7 +94,7 @@ else -v "${OUTPUT_DIR_REAL}:${OUTPUT_DIR_REAL}" \ wasm-clang-builder:latest /bin/bash -c "/opt/wasi-sdk/bin/clang ${DEBUG_FLAGS} -flto -ffunction-sections -mexec-model=reactor ${OPT_FLAGS} -z stack-size=4096 -Wl,--initial-memory=65536 -Wl,--export=__data_end -Wl,--export=__heap_base,--export=malloc,--export=free,--export=__wasm_call_ctors ${STRIP_FLAGS} -Wl,--no-entry -Wl,--allow-undefined -Wl,--gc-sections -o ${ABS_OUTPUT} ${ABS_INPUT}" - cargo run ${AOT_FEATURES} -p hyperlight-wasm-aot compile ${AOT_DEBUG_FLAGS} ${OUTPUT_WASM} ${OUTPUT_DIR}/${FILENAME%.*}.aot + cargo run -p hyperlight-wasm-aot compile ${AOT_DEBUG_FLAGS} ${AOT_LTS_FLAGS} ${OUTPUT_WASM} ${OUTPUT_DIR}/${FILENAME%.*}.aot done echo Building components @@ -129,7 +134,7 @@ else ${ABS_BINDINGS_TYPE_O}" # Build AOT for Wasmtime - cargo run ${AOT_FEATURES} -p hyperlight-wasm-aot compile ${AOT_DEBUG_FLAGS} --component ${OUTPUT_WASM} ${OUTPUT_DIR}/${COMPONENT_NAME}.aot + cargo run -p hyperlight-wasm-aot compile ${AOT_DEBUG_FLAGS} ${AOT_LTS_FLAGS} --component ${OUTPUT_WASM} ${OUTPUT_DIR}/${COMPONENT_NAME}.aot done fi diff --git a/src/hyperlight_wasm_aot/Cargo.toml b/src/hyperlight_wasm_aot/Cargo.toml index eafdcf9c..cc92d8d2 100644 --- a/src/hyperlight_wasm_aot/Cargo.toml +++ b/src/hyperlight_wasm_aot/Cargo.toml @@ -12,10 +12,12 @@ Application to precompile WebAssembly binaries to for hyperlight-wasm. """ [dependencies] -wasmtime = { version = "36.0.3", default-features = false, features = ["cranelift", "runtime", "component-model" ] } +# Since we can use the library with either the latest bundled wasmtime or the LTS version +# we need to bundle both here as dependencies. +# The default is latest version bundled +# To use LTS version pass the --lts flag when using this tool +wasmtime = { version = "39.0.1", default-features = false, features = ["cranelift", "runtime", "component-model"] } +wasmtime_lts = { package = "wasmtime", version = "36.0.3", default-features = false, features = ["cranelift", "runtime", "component-model"] } clap = "4.5" cargo_metadata = "0.23" cargo-util-schemas = "0.10.1" - -[features] -gdb = ["wasmtime/debug-builtins"] diff --git a/src/hyperlight_wasm_aot/src/main.rs b/src/hyperlight_wasm_aot/src/main.rs index 835e919e..c3fef52f 100644 --- a/src/hyperlight_wasm_aot/src/main.rs +++ b/src/hyperlight_wasm_aot/src/main.rs @@ -16,10 +16,113 @@ limitations under the License. use std::path::Path; -use cargo_metadata::{MetadataCommand, Package}; -use cargo_util_schemas::manifest::PackageName; use clap::{Arg, Command}; -use wasmtime::{Config, Engine, Module, OptLevel, Precompiled}; + +fn precompile_bytes(bytes: &[u8], debug: bool, use_lts: bool, is_component: bool) -> Vec { + if use_lts { + let mut config = wasmtime_lts::Config::new(); + config.target("x86_64-unknown-none").unwrap(); + if debug { + config.debug_info(true); + config.cranelift_opt_level(wasmtime_lts::OptLevel::None); + } + let engine = wasmtime_lts::Engine::new(&config).unwrap(); + if is_component { + engine.precompile_component(bytes).unwrap() + } else { + engine.precompile_module(bytes).unwrap() + } + } else { + let mut config = wasmtime::Config::new(); + config.target("x86_64-unknown-none").unwrap(); + unsafe { config.x86_float_abi_ok(true) }; + if debug { + config.debug_info(true); + config.cranelift_opt_level(wasmtime::OptLevel::None); + } + let engine = wasmtime::Engine::new(&config).unwrap(); + if is_component { + engine.precompile_component(bytes).unwrap() + } else { + engine.precompile_module(bytes).unwrap() + } + } +} + +fn detect_and_deserialize( + bytes: &[u8], + debug: bool, + use_lts: bool, + file: &str, + version_label: &str, +) { + if use_lts { + let mut config = wasmtime_lts::Config::new(); + config.target("x86_64-unknown-none").unwrap(); + if debug { + config.debug_info(true); + config.cranelift_opt_level(wasmtime_lts::OptLevel::None); + } + let engine = wasmtime_lts::Engine::new(&config).unwrap(); + match wasmtime_lts::Engine::detect_precompiled(bytes) { + Some(wasmtime_lts::Precompiled::Module) => { + println!("The file is a valid AOT compiled Wasmtime module"); + match unsafe { wasmtime_lts::Module::deserialize(&engine, bytes) } { + Ok(_) => println!( + "File {} was AOT compiled with a compatible wasmtime version ({})", + file, version_label + ), + Err(e) => eprintln!("{}", e), + } + } + Some(wasmtime_lts::Precompiled::Component) => { + println!("The file is an AOT compiled Wasmtime component") + } + None => { + eprintln!( + "Error - {} is not a valid AOT compiled Wasmtime module or component", + file + ); + } + } + } else { + let mut config = wasmtime::Config::new(); + config.target("x86_64-unknown-none").unwrap(); + // Enable x86_float_abi_ok only for the latest Wasmtime version. + // Safety: + // We are using hyperlight cargo to build the guest which + // sets the Rust target to be compiled with the hard-float ABI manually via + // `-Zbuild-std` and a custom target JSON configuration + // See https://github.com/bytecodealliance/wasmtime/pull/11553 + unsafe { config.x86_float_abi_ok(true) }; + if debug { + config.debug_info(true); + config.cranelift_opt_level(wasmtime::OptLevel::None); + } + let engine = wasmtime::Engine::new(&config).unwrap(); + match wasmtime::Engine::detect_precompiled(bytes) { + Some(wasmtime::Precompiled::Module) => { + println!("The file is a valid AOT compiled Wasmtime module"); + match unsafe { wasmtime::Module::deserialize(&engine, bytes) } { + Ok(_) => println!( + "File {} was AOT compiled with a compatible wasmtime version ({})", + file, version_label + ), + Err(e) => eprintln!("{}", e), + } + } + Some(wasmtime::Precompiled::Component) => { + println!("The file is an AOT compiled Wasmtime component") + } + None => { + eprintln!( + "Error - {} is not a valid AOT compiled Wasmtime module or component", + file + ); + } + } + } +} fn main() { let hyperlight_wasm_aot_version = env!("CARGO_PKG_VERSION"); @@ -54,11 +157,18 @@ fn main() { .required(false) .long("debug") .action(clap::ArgAction::SetTrue), + ) + .arg( + Arg::new("lts") + .help("Use LTS wasmtime version instead of latest") + .required(false) + .long("lts") + .action(clap::ArgAction::SetTrue), ), ) .subcommand( Command::new("check-wasmtime-version") - .about("Check the Wasmtime version use to compile a AOT file") + .about("Check the Wasmtime version used to compile an AOT file") .arg( Arg::new("file") .help("The aot compiled file to check") @@ -71,6 +181,13 @@ fn main() { .required(false) .long("debug") .action(clap::ArgAction::SetTrue), + ) + .arg( + Arg::new("lts") + .help("Use LTS wasmtime version instead of latest") + .required(false) + .long("lts") + .action(clap::ArgAction::SetTrue), ), ) .get_matches(); @@ -88,108 +205,52 @@ fn main() { } }; let debug = args.get_flag("debug"); + let use_lts = args.get_flag("lts"); + let is_component = args.get_flag("component"); + let version_label = if use_lts { "LTS" } else { "latest" }; + if debug { println!( - "Aot Compiling {} to {} with debug info and optimizations off", - infile, outfile + "Aot Compiling {} to {} with debug info and optimizations ({} wasmtime)", + infile, outfile, version_label ); } else { - println!("Aot Compiling {} to {}", infile, outfile); + println!( + "Aot Compiling {} to {} ({} wasmtime)", + infile, outfile, version_label + ); } - let config = get_config(debug); - let engine = Engine::new(&config).unwrap(); + let bytes = std::fs::read(infile).unwrap(); - let serialized = if args.get_flag("component") { - engine.precompile_component(&bytes).unwrap() - } else { - engine.precompile_module(&bytes).unwrap() - }; + let serialized = precompile_bytes(&bytes, debug, use_lts, is_component); std::fs::write(outfile, serialized).unwrap(); } Some("check-wasmtime-version") => { - // get the wasmtime version used by hyperlight-wasm-aot - let metadata = MetadataCommand::new().exec().unwrap(); - let package_name = PackageName::new("wasmtime".to_string()).unwrap(); - let wasmtime_package: Option<&Package> = - metadata.packages.iter().find(|p| p.name == package_name); - let version_number = match wasmtime_package { - Some(pkg) => pkg.version.clone(), - None => panic!("wasmtime dependency not found"), - }; let args = matches .subcommand_matches("check-wasmtime-version") .unwrap(); let debug = args.get_flag("debug"); + let use_lts = args.get_flag("lts"); let file = args.get_one::("file").unwrap(); + let version_label = if use_lts { "LTS" } else { "latest" }; + if debug { println!( - "Checking Wasmtime version used to compile debug info enabled file: {}", - file + "Checking Wasmtime version used to compile with debug info enabled file: {} ({} wasmtime)", + file, version_label ); } else { - println!("Checking Wasmtime version used to compile file: {}", file); + println!( + "Checking Wasmtime version used to compile file: {} ({} wasmtime)", + file, version_label + ); } - // load the file into wasmtime, check that it is aot compiled and extract the version of wasmtime used to compile it from its metadata + let bytes = std::fs::read(file).unwrap(); - let config = get_config(debug); - let engine = Engine::new(&config).unwrap(); - match Engine::detect_precompiled(&bytes) { - Some(pre_compiled) => { - match pre_compiled { - Precompiled::Module => { - println!("The file is a valid AOT compiled Wasmtime module"); - // It doesnt seem like the functions or data needed to extract the version of wasmtime used to compile the module are exposed in the wasmtime crate - // so we will try and load it and then catch the error and parse the version from the error message :-( - match unsafe { Module::deserialize(&engine, bytes) } { - Ok(_) => println!( - "File {} was AOT compiled with wasmtime version: {}", - file, version_number - ), - Err(e) => { - let error_message = e.to_string(); - if !error_message.starts_with( - "Module was compiled with incompatible Wasmtime version", - ) { - eprintln!("{}", error_message); - return; - } - let version = error_message.trim_start_matches("Module was compiled with incompatible Wasmtime version ").trim(); - println!( - "File {} was AOT compiled with wasmtime version: {}", - file, version - ); - } - }; - } - Precompiled::Component => { - eprintln!("The file is an AOT compiled Wasmtime component") - } - } - } - None => { - eprintln!( - "Error - {} is not a valid AOT compiled Wasmtime module or component", - file - ); - } - } + detect_and_deserialize(&bytes, debug, use_lts, file, version_label); } _ => { println!("No subcommand specified"); } } } - -/// Returns a new `Config` for the Wasmtime engine with additional settings for AOT compilation. -fn get_config(debug: bool) -> Config { - let mut config = Config::new(); - config.target("x86_64-unknown-none").unwrap(); - - // Enable the default features for the Wasmtime engine. - if debug { - config.debug_info(true); - config.cranelift_opt_level(OptLevel::None); - } - - config -} diff --git a/src/wasm_runtime/Cargo.lock b/src/wasm_runtime/Cargo.lock index e0f6ddf8..4680c976 100644 --- a/src/wasm_runtime/Cargo.lock +++ b/src/wasm_runtime/Cargo.lock @@ -20,6 +20,17 @@ version = "1.4.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c3d036a3c4ab069c7b410a2ce876bd74808d2d0888a82667669f8e783a898bf1" +[[package]] +name = "async-trait" +version = "0.1.89" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9035ad2d096bed7955a320ee7e2230574d28fd3c3a0f186cbea1ff3c7eed5dbb" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + [[package]] name = "atomic-waker" version = "1.1.2" @@ -132,7 +143,16 @@ version = "0.123.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "90431884c6dd00d473229135f69cb43a2257c12f05ca478f994f4778c0607f28" dependencies = [ - "cranelift-assembler-x64-meta", + "cranelift-assembler-x64-meta 0.123.3", +] + +[[package]] +name = "cranelift-assembler-x64" +version = "0.126.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "30054f4aef4d614d37f27d5b77e36e165f0b27a71563be348e7c9fcfac41eed8" +dependencies = [ + "cranelift-assembler-x64-meta 0.126.1", ] [[package]] @@ -141,7 +161,16 @@ version = "0.123.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7e023ca3e629d01bb1215a0846099dfd9065060c07e4727b2e4d49060c2a6e4b" dependencies = [ - "cranelift-srcgen", + "cranelift-srcgen 0.123.3", +] + +[[package]] +name = "cranelift-assembler-x64-meta" +version = "0.126.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0beab56413879d4f515e08bcf118b1cb85f294129bb117057f573d37bfbb925a" +dependencies = [ + "cranelift-srcgen 0.126.1", ] [[package]] @@ -150,7 +179,16 @@ version = "0.123.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a61a409e5403fe1b7d4f49fecde2a950790c8dfed897c60da0dfb30af7689011" dependencies = [ - "cranelift-entity", + "cranelift-entity 0.123.3", +] + +[[package]] +name = "cranelift-bforest" +version = "0.126.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6d054747549a69b264d5299c8ca1b0dd45dc6bd0ee43f1edfcc42a8b12952c7a" +dependencies = [ + "cranelift-entity 0.126.1", ] [[package]] @@ -163,6 +201,16 @@ dependencies = [ "serde_derive", ] +[[package]] +name = "cranelift-bitset" +version = "0.126.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "98b92d481b77a7dc9d07c96e24a16f29e0c9c27d042828fdf7e49e54ee9819bf" +dependencies = [ + "serde", + "serde_derive", +] + [[package]] name = "cranelift-codegen" version = "0.123.3" @@ -170,24 +218,51 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "134d091c729077b82b14cfad1ed9df542901175c70eefa453c26a375bd1de1c8" dependencies = [ "bumpalo", - "cranelift-assembler-x64", - "cranelift-bforest", - "cranelift-bitset", - "cranelift-codegen-meta", - "cranelift-codegen-shared", - "cranelift-control", - "cranelift-entity", - "cranelift-isle", + "cranelift-assembler-x64 0.123.3", + "cranelift-bforest 0.123.3", + "cranelift-bitset 0.123.3", + "cranelift-codegen-meta 0.123.3", + "cranelift-codegen-shared 0.123.3", + "cranelift-control 0.123.3", + "cranelift-entity 0.123.3", + "cranelift-isle 0.123.3", + "gimli", + "hashbrown 0.15.5", + "log", + "pulley-interpreter 36.0.3", + "regalloc2 0.12.2", + "rustc-hash", + "serde", + "smallvec", + "target-lexicon", + "wasmtime-internal-math 36.0.3", +] + +[[package]] +name = "cranelift-codegen" +version = "0.126.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6eeccfc043d599b0ef1806942707fc51cdd1c3965c343956dc975a55d82a920f" +dependencies = [ + "bumpalo", + "cranelift-assembler-x64 0.126.1", + "cranelift-bforest 0.126.1", + "cranelift-bitset 0.126.1", + "cranelift-codegen-meta 0.126.1", + "cranelift-codegen-shared 0.126.1", + "cranelift-control 0.126.1", + "cranelift-entity 0.126.1", + "cranelift-isle 0.126.1", "gimli", "hashbrown 0.15.5", "log", - "pulley-interpreter", - "regalloc2", + "pulley-interpreter 39.0.1", + "regalloc2 0.13.3", "rustc-hash", "serde", "smallvec", "target-lexicon", - "wasmtime-internal-math", + "wasmtime-internal-math 39.0.1", ] [[package]] @@ -196,11 +271,24 @@ version = "0.123.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9c1529f8643e11f6c5d3954295f3b3923ab251cd3220d0eb034115345e0c953e" dependencies = [ - "cranelift-assembler-x64-meta", - "cranelift-codegen-shared", - "cranelift-srcgen", + "cranelift-assembler-x64-meta 0.123.3", + "cranelift-codegen-shared 0.123.3", + "cranelift-srcgen 0.123.3", + "heck", + "pulley-interpreter 36.0.3", +] + +[[package]] +name = "cranelift-codegen-meta" +version = "0.126.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1174cdb9d9d43b2bdaa612a07ed82af13db9b95526bc2c286c2aec4689bcc038" +dependencies = [ + "cranelift-assembler-x64-meta 0.126.1", + "cranelift-codegen-shared 0.126.1", + "cranelift-srcgen 0.126.1", "heck", - "pulley-interpreter", + "pulley-interpreter 39.0.1", ] [[package]] @@ -209,6 +297,12 @@ version = "0.123.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3a17d7ff63eb0ef851174f4c31a073bcc5886664327e00416dc4fd01aa0d00a8" +[[package]] +name = "cranelift-codegen-shared" +version = "0.126.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7d572be73fae802eb115f45e7e67a9ed16acb4ee683b67c4086768786545419a" + [[package]] name = "cranelift-control" version = "0.123.3" @@ -218,13 +312,33 @@ dependencies = [ "arbitrary", ] +[[package]] +name = "cranelift-control" +version = "0.126.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e1587465cc84c5cc793b44add928771945f3132bbf6b3621ee9473c631a87156" +dependencies = [ + "arbitrary", +] + [[package]] name = "cranelift-entity" version = "0.123.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b48f2b24fc3eec954a1d17e5a9c04957ba24f6202dbaa8df52472ba7624e854a" dependencies = [ - "cranelift-bitset", + "cranelift-bitset 0.123.3", + "serde", + "serde_derive", +] + +[[package]] +name = "cranelift-entity" +version = "0.126.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "063b83448b1343e79282c3c7cbda7ed5f0816f0b763a4c15f7cecb0a17d87ea6" +dependencies = [ + "cranelift-bitset 0.126.1", "serde", "serde_derive", ] @@ -235,7 +349,19 @@ version = "0.123.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ca8aea478d61a71f7f56d19ee2642359c00fc2fa54bc0db0d6c5edd52f1d3efd" dependencies = [ - "cranelift-codegen", + "cranelift-codegen 0.123.3", + "log", + "smallvec", + "target-lexicon", +] + +[[package]] +name = "cranelift-frontend" +version = "0.126.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "aa4461c2d2ca48bc72883f5f5c3129d9aefac832df1db824af9db8db3efee109" +dependencies = [ + "cranelift-codegen 0.126.1", "log", "smallvec", "target-lexicon", @@ -247,13 +373,30 @@ version = "0.123.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "da142f3cc42beaa44bf2558567751816c6adf776f2cfc40ba79ff9e5c232d808" +[[package]] +name = "cranelift-isle" +version = "0.126.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "acd811b25e18f14810d09c504e06098acc1d9dbfa24879bf0d6b6fb44415fc66" + [[package]] name = "cranelift-native" version = "0.123.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "be7b57410e388de0828fa9178e8693abe996bf2356a7f55be35719ee5b162755" dependencies = [ - "cranelift-codegen", + "cranelift-codegen 0.123.3", + "libc", + "target-lexicon", +] + +[[package]] +name = "cranelift-native" +version = "0.126.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2417046989d8d6367a55bbab2e406a9195d176f4779be4aa484d645887217d37" +dependencies = [ + "cranelift-codegen 0.126.1", "libc", "target-lexicon", ] @@ -264,6 +407,12 @@ version = "0.123.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bd9641751da85481f0e04033228403eca2becd2a3d9aff56f6c8bed8b9147bfc" +[[package]] +name = "cranelift-srcgen" +version = "0.126.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8d039de901c8d928222b8128e1b9a9ab27b82a7445cb749a871c75d9cb25c57d" + [[package]] name = "crc32fast" version = "1.5.0" @@ -1047,10 +1196,22 @@ version = "36.0.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0f18b4e1b955bf4d6077dbc9d1d43a3a16f8c8b011a67dbafbd671ab4335c48b" dependencies = [ - "cranelift-bitset", + "cranelift-bitset 0.123.3", + "log", + "pulley-macros 36.0.3", + "wasmtime-internal-math 36.0.3", +] + +[[package]] +name = "pulley-interpreter" +version = "39.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0a09eb45f768f3a0396e85822790d867000c8b5f11551e7268c279e991457b16" +dependencies = [ + "cranelift-bitset 0.126.1", "log", - "pulley-macros", - "wasmtime-internal-math", + "pulley-macros 39.0.1", + "wasmtime-internal-math 39.0.1", ] [[package]] @@ -1064,6 +1225,17 @@ dependencies = [ "syn", ] +[[package]] +name = "pulley-macros" +version = "39.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e29368432b8b7a8a343b75a6914621fad905c95d5c5297449a6546c127224f7a" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + [[package]] name = "quinn" version = "0.11.9" @@ -1177,6 +1349,20 @@ dependencies = [ "smallvec", ] +[[package]] +name = "regalloc2" +version = "0.13.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4e249c660440317032a71ddac302f25f1d5dff387667bcc3978d1f77aa31ac34" +dependencies = [ + "allocator-api2", + "bumpalo", + "hashbrown 0.15.5", + "log", + "rustc-hash", + "smallvec", +] + [[package]] name = "reqwest" version = "0.12.25" @@ -1794,6 +1980,16 @@ dependencies = [ "wasmparser 0.236.1", ] +[[package]] +name = "wasm-encoder" +version = "0.240.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "06d642d8c5ecc083aafe9ceb32809276a304547a3a6eeecceb5d8152598bc71f" +dependencies = [ + "leb128fmt", + "wasmparser 0.240.0", +] + [[package]] name = "wasm-runtime" version = "0.12.0" @@ -1809,7 +2005,8 @@ dependencies = [ "reqwest", "spin 0.10.0", "tracing", - "wasmtime", + "wasmtime 36.0.3", + "wasmtime 39.0.1", ] [[package]] @@ -1825,6 +2022,19 @@ dependencies = [ "serde", ] +[[package]] +name = "wasmparser" +version = "0.240.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b722dcf61e0ea47440b53ff83ccb5df8efec57a69d150e4f24882e4eba7e24a4" +dependencies = [ + "bitflags", + "hashbrown 0.15.5", + "indexmap", + "semver", + "serde", +] + [[package]] name = "wasmparser" version = "0.243.0" @@ -1849,6 +2059,17 @@ dependencies = [ "wasmparser 0.236.1", ] +[[package]] +name = "wasmprinter" +version = "0.240.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a84d6e25c198da67d0150ee7c2c62d33d784f0a565d1e670bdf1eeccca8158bc" +dependencies = [ + "anyhow", + "termcolor", + "wasmparser 0.240.0", +] + [[package]] name = "wasmtime" version = "36.0.3" @@ -1869,24 +2090,65 @@ dependencies = [ "memfd", "object", "postcard", - "pulley-interpreter", + "pulley-interpreter 36.0.3", "semver", "serde", "serde_derive", "smallvec", "target-lexicon", "wasmparser 0.236.1", - "wasmtime-environ", + "wasmtime-environ 36.0.3", "wasmtime-internal-asm-macros", - "wasmtime-internal-component-macro", - "wasmtime-internal-component-util", - "wasmtime-internal-cranelift", - "wasmtime-internal-jit-debug", - "wasmtime-internal-math", - "wasmtime-internal-slab", - "wasmtime-internal-unwinder", - "wasmtime-internal-versioned-export-macros", - "wasmtime-internal-winch", + "wasmtime-internal-component-macro 36.0.3", + "wasmtime-internal-component-util 36.0.3", + "wasmtime-internal-cranelift 36.0.3", + "wasmtime-internal-jit-debug 36.0.3", + "wasmtime-internal-math 36.0.3", + "wasmtime-internal-slab 36.0.3", + "wasmtime-internal-unwinder 36.0.3", + "wasmtime-internal-versioned-export-macros 36.0.3", + "wasmtime-internal-winch 36.0.3", + "windows-sys 0.60.2", +] + +[[package]] +name = "wasmtime" +version = "39.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "511bc19c2d48f338007dc941cb40c833c4707023fdaf9ec9b97cf1d5a62d26bb" +dependencies = [ + "anyhow", + "async-trait", + "bitflags", + "bumpalo", + "cc", + "cfg-if", + "encoding_rs", + "hashbrown 0.15.5", + "indexmap", + "libc", + "log", + "mach2", + "memfd", + "object", + "postcard", + "pulley-interpreter 39.0.1", + "semver", + "serde", + "serde_derive", + "smallvec", + "target-lexicon", + "wasmparser 0.240.0", + "wasmtime-environ 39.0.1", + "wasmtime-internal-component-macro 39.0.1", + "wasmtime-internal-component-util 39.0.1", + "wasmtime-internal-cranelift 39.0.1", + "wasmtime-internal-jit-debug 39.0.1", + "wasmtime-internal-math 39.0.1", + "wasmtime-internal-slab 39.0.1", + "wasmtime-internal-unwinder 39.0.1", + "wasmtime-internal-versioned-export-macros 39.0.1", + "wasmtime-internal-winch 39.0.1", "windows-sys 0.60.2", ] @@ -1897,8 +2159,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0c7e455d0dc49fad35574e28c110eb23eeda80cfecbe075051892a067298e943" dependencies = [ "anyhow", - "cranelift-bitset", - "cranelift-entity", + "cranelift-bitset 0.123.3", + "cranelift-entity 0.123.3", "gimli", "indexmap", "log", @@ -1909,10 +2171,35 @@ dependencies = [ "serde_derive", "smallvec", "target-lexicon", - "wasm-encoder", + "wasm-encoder 0.236.1", "wasmparser 0.236.1", - "wasmprinter", - "wasmtime-internal-component-util", + "wasmprinter 0.236.1", + "wasmtime-internal-component-util 36.0.3", +] + +[[package]] +name = "wasmtime-environ" +version = "39.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c3b0d53657fea2a8cee8ed1866ad45d2e5bc21be958a626a1dd9b7de589851b3" +dependencies = [ + "anyhow", + "cranelift-bitset 0.126.1", + "cranelift-entity 0.126.1", + "gimli", + "indexmap", + "log", + "object", + "postcard", + "semver", + "serde", + "serde_derive", + "smallvec", + "target-lexicon", + "wasm-encoder 0.240.0", + "wasmparser 0.240.0", + "wasmprinter 0.240.0", + "wasmtime-internal-component-util 39.0.1", ] [[package]] @@ -1934,9 +2221,24 @@ dependencies = [ "proc-macro2", "quote", "syn", - "wasmtime-internal-component-util", - "wasmtime-internal-wit-bindgen", - "wit-parser", + "wasmtime-internal-component-util 36.0.3", + "wasmtime-internal-wit-bindgen 36.0.3", + "wit-parser 0.236.1", +] + +[[package]] +name = "wasmtime-internal-component-macro" +version = "39.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c933104f57d27dd1e6c7bd9ee5df3242bdd1962d9381bc08fa5d4e60e1f5ebdf" +dependencies = [ + "anyhow", + "proc-macro2", + "quote", + "syn", + "wasmtime-internal-component-util 39.0.1", + "wasmtime-internal-wit-bindgen 39.0.1", + "wit-parser 0.240.0", ] [[package]] @@ -1945,6 +2247,12 @@ version = "36.0.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "48ebb886b6c6e7bfe67eb14757f736ed7bbd1b5a034c27070874043c3b90e9ac" +[[package]] +name = "wasmtime-internal-component-util" +version = "39.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "63ef2a95a5dbaa70fc3ef682ea8997e51cdd819b4d157a1100477cf43949d454" + [[package]] name = "wasmtime-internal-cranelift" version = "36.0.3" @@ -1953,23 +2261,51 @@ checksum = "0ec12999113da589f806085a967a5c3d2ac0ca26585842374bf1199dba365f00" dependencies = [ "anyhow", "cfg-if", - "cranelift-codegen", - "cranelift-control", - "cranelift-entity", - "cranelift-frontend", - "cranelift-native", + "cranelift-codegen 0.123.3", + "cranelift-control 0.123.3", + "cranelift-entity 0.123.3", + "cranelift-frontend 0.123.3", + "cranelift-native 0.123.3", "gimli", "itertools", "log", "object", - "pulley-interpreter", + "pulley-interpreter 36.0.3", "smallvec", "target-lexicon", "thiserror", "wasmparser 0.236.1", - "wasmtime-environ", - "wasmtime-internal-math", - "wasmtime-internal-versioned-export-macros", + "wasmtime-environ 36.0.3", + "wasmtime-internal-math 36.0.3", + "wasmtime-internal-versioned-export-macros 36.0.3", +] + +[[package]] +name = "wasmtime-internal-cranelift" +version = "39.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "73122df6a8cf417ce486a94e844d3a60797217ce7ae69653e0ee9e28269e0fa5" +dependencies = [ + "anyhow", + "cfg-if", + "cranelift-codegen 0.126.1", + "cranelift-control 0.126.1", + "cranelift-entity 0.126.1", + "cranelift-frontend 0.126.1", + "cranelift-native 0.126.1", + "gimli", + "itertools", + "log", + "object", + "pulley-interpreter 39.0.1", + "smallvec", + "target-lexicon", + "thiserror", + "wasmparser 0.240.0", + "wasmtime-environ 39.0.1", + "wasmtime-internal-math 39.0.1", + "wasmtime-internal-unwinder 39.0.1", + "wasmtime-internal-versioned-export-macros 39.0.1", ] [[package]] @@ -1979,7 +2315,17 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fc4bd73187d8f1accd19d9f10195d0d87c035e6231009ba98bb6d94fefb0ecf1" dependencies = [ "cc", - "wasmtime-internal-versioned-export-macros", + "wasmtime-internal-versioned-export-macros 36.0.3", +] + +[[package]] +name = "wasmtime-internal-jit-debug" +version = "39.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3af620a4ac1623298c90d3736644e12d66974951d1e38d0464798de85c984e17" +dependencies = [ + "cc", + "wasmtime-internal-versioned-export-macros 39.0.1", ] [[package]] @@ -1991,12 +2337,27 @@ dependencies = [ "libm", ] +[[package]] +name = "wasmtime-internal-math" +version = "39.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cd1b856e1bbf0230ab560ba4204e944b141971adc4e6cdf3feb6979c1a7b7953" +dependencies = [ + "libm", +] + [[package]] name = "wasmtime-internal-slab" version = "36.0.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cbd2df91a81105cd5e1db81a35e5f3cf8eae871b72c97bd04a3cb5d9e21e8d77" +[[package]] +name = "wasmtime-internal-slab" +version = "39.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8908e71a780b97cbd3d8f3a0c446ac8df963069e0f3f38c9eace4f199d4d3e65" + [[package]] name = "wasmtime-internal-unwinder" version = "36.0.3" @@ -2009,6 +2370,19 @@ dependencies = [ "object", ] +[[package]] +name = "wasmtime-internal-unwinder" +version = "39.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fb9c2f8223a0ef96527f0446b80c7d0d9bb0577c7b918e3104bd6d4cdba1d101" +dependencies = [ + "anyhow", + "cfg-if", + "cranelift-codegen 0.126.1", + "log", + "object", +] + [[package]] name = "wasmtime-internal-versioned-export-macros" version = "36.0.3" @@ -2020,6 +2394,17 @@ dependencies = [ "syn", ] +[[package]] +name = "wasmtime-internal-versioned-export-macros" +version = "39.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2b0fb82cdbffd6cafc812c734a22fa753102888b8760ecf6a08cbb50367a458a" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + [[package]] name = "wasmtime-internal-winch" version = "36.0.3" @@ -2027,14 +2412,32 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f3e8c6bc0c4a68103cf20d831f141be9f56527df0c0830052c6b2409eed18705" dependencies = [ "anyhow", - "cranelift-codegen", + "cranelift-codegen 0.123.3", "gimli", "object", "target-lexicon", "wasmparser 0.236.1", - "wasmtime-environ", - "wasmtime-internal-cranelift", - "winch-codegen", + "wasmtime-environ 36.0.3", + "wasmtime-internal-cranelift 36.0.3", + "winch-codegen 36.0.3", +] + +[[package]] +name = "wasmtime-internal-winch" +version = "39.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f1cfd68149cef86afd9a6c9b51e461266dfa66b37b4c6fdf1201ddbf7f906271" +dependencies = [ + "anyhow", + "cranelift-codegen 0.126.1", + "gimli", + "log", + "object", + "target-lexicon", + "wasmparser 0.240.0", + "wasmtime-environ 39.0.1", + "wasmtime-internal-cranelift 39.0.1", + "winch-codegen 39.0.1", ] [[package]] @@ -2047,7 +2450,20 @@ dependencies = [ "bitflags", "heck", "indexmap", - "wit-parser", + "wit-parser 0.236.1", +] + +[[package]] +name = "wasmtime-internal-wit-bindgen" +version = "39.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a628437073400148f1ba2b55beb60eb376dc5ca538745994c83332b037d1f3fa" +dependencies = [ + "anyhow", + "bitflags", + "heck", + "indexmap", + "wit-parser 0.240.0", ] [[package]] @@ -2095,17 +2511,37 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b69d4fdfcf07cbc0a2d3d585fb0f87d9598fde1efada9d2ac35a11ec09bf4eaa" dependencies = [ "anyhow", - "cranelift-assembler-x64", - "cranelift-codegen", + "cranelift-assembler-x64 0.123.3", + "cranelift-codegen 0.123.3", "gimli", - "regalloc2", + "regalloc2 0.12.2", "smallvec", "target-lexicon", "thiserror", "wasmparser 0.236.1", - "wasmtime-environ", - "wasmtime-internal-cranelift", - "wasmtime-internal-math", + "wasmtime-environ 36.0.3", + "wasmtime-internal-cranelift 36.0.3", + "wasmtime-internal-math 36.0.3", +] + +[[package]] +name = "winch-codegen" +version = "39.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b1de5a648102e39c8e817ed25e3820f4b9772f3c9c930984f32737be60e3156b" +dependencies = [ + "anyhow", + "cranelift-assembler-x64 0.126.1", + "cranelift-codegen 0.126.1", + "gimli", + "regalloc2 0.13.3", + "smallvec", + "target-lexicon", + "thiserror", + "wasmparser 0.240.0", + "wasmtime-environ 39.0.1", + "wasmtime-internal-cranelift 39.0.1", + "wasmtime-internal-math 39.0.1", ] [[package]] @@ -2303,6 +2739,24 @@ dependencies = [ "wasmparser 0.236.1", ] +[[package]] +name = "wit-parser" +version = "0.240.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9875ea3fa272f57cc1fc50f225a7b94021a7878c484b33792bccad0d93223439" +dependencies = [ + "anyhow", + "id-arena", + "indexmap", + "log", + "semver", + "serde", + "serde_derive", + "serde_json", + "unicode-xid", + "wasmparser 0.240.0", +] + [[package]] name = "writeable" version = "0.6.2" diff --git a/src/wasm_runtime/Cargo.toml b/src/wasm_runtime/Cargo.toml index c0e00ad3..df92b7d3 100644 --- a/src/wasm_runtime/Cargo.toml +++ b/src/wasm_runtime/Cargo.toml @@ -14,7 +14,10 @@ bench = false hyperlight-common = { version = "0.12.0", default-features = false } hyperlight-guest-bin = { version = "0.12.0", features = [ "printf" ] } hyperlight-guest = { version = "0.12.0" } -wasmtime = { version = "36.0.3", default-features = false, features = [ "runtime", "custom-virtual-memory", "custom-native-signals", "component-model" ] } +# Default to latest wasmtime, use wasmtime_lts feature for LTS version +# These are marked optional to avoid pulling them both in. The should be mutually exclusive. +wasmtime = { version = "39.0.1", default-features = false, features = [ "runtime", "custom-virtual-memory", "custom-native-signals", "component-model" ], optional = true } +wasmtime_lts = { package = "wasmtime", version = "36.0.3", default-features = false, features = [ "runtime", "custom-virtual-memory", "custom-native-signals", "component-model" ], optional = true } hyperlight-wasm-macro = { path = "../hyperlight_wasm_macro" } spin = "0.10.0" tracing = { version = "0.1.43", default-features = false, features = ["attributes", "log"] } @@ -29,6 +32,8 @@ reqwest = {version = "0.12", default-features = false, features = ["blocking"," [workspace] # indicate that this crate is not part of any workspace [features] -default = [] -gdb = ["wasmtime/debug-builtins"] +default = ["wasmtime_latest"] +wasmtime_latest = ["dep:wasmtime"] +wasmtime_lts = ["dep:wasmtime_lts"] +gdb = ["wasmtime?/debug-builtins", "wasmtime_lts?/debug-builtins"] trace_guest = ["hyperlight-common/trace_guest", "hyperlight-guest/trace_guest", "hyperlight-guest-bin/trace_guest"] diff --git a/src/wasm_runtime/src/component.rs b/src/wasm_runtime/src/component.rs index ea43d033..253cbaae 100644 --- a/src/wasm_runtime/src/component.rs +++ b/src/wasm_runtime/src/component.rs @@ -108,6 +108,16 @@ pub extern "C" fn hyperlight_main() { platform::register_page_fault_handler(); let mut config = Config::new(); + // Enable x86_float_abi_ok only for the latest Wasmtime version. + // Safety: + // We are using hyperlight cargo to build the guest which + // sets the Rust target to be compiled with the hard-float ABI manually via + // `-Zbuild-std` and a custom target JSON configuration + // See https://github.com/bytecodealliance/wasmtime/pull/11553 + #[cfg(not(feature = "wasmtime_lts"))] + unsafe { + config.x86_float_abi_ok(true) + }; config.with_custom_code_memory(Some(alloc::sync::Arc::new(platform::WasmtimeCodeMemory {}))); #[cfg(gdb)] config.debug_info(true); diff --git a/src/wasm_runtime/src/main.rs b/src/wasm_runtime/src/main.rs index 23afd9f4..d26fb618 100644 --- a/src/wasm_runtime/src/main.rs +++ b/src/wasm_runtime/src/main.rs @@ -19,6 +19,20 @@ limitations under the License. extern crate alloc; +// Re-export wasmtime based on expected version +#[cfg(all(feature = "wasmtime_latest", feature = "wasmtime_lts"))] +compile_error!( + "Features 'wasmtime_latest' and 'wasmtime_lts' are mutually exclusive. Please enable only one." +); + +#[cfg(not(any(feature = "wasmtime_latest", feature = "wasmtime_lts")))] +compile_error!("Either 'wasmtime_latest' or 'wasmtime_lts' feature must be enabled."); + +#[cfg(not(feature = "wasmtime_lts"))] +extern crate wasmtime; +#[cfg(feature = "wasmtime_lts")] +extern crate wasmtime_lts as wasmtime; + mod platform; #[cfg(not(component))] diff --git a/src/wasm_runtime/src/module.rs b/src/wasm_runtime/src/module.rs index 14e2d64a..c0b6f119 100644 --- a/src/wasm_runtime/src/module.rs +++ b/src/wasm_runtime/src/module.rs @@ -98,6 +98,17 @@ pub fn guest_dispatch_function(function_call: FunctionCall) -> Result> { #[instrument(skip_all, level = "Info")] fn init_wasm_runtime() -> Result> { let mut config = Config::new(); + // Enable x86_float_abi_ok only for the latest Wasmtime version. + // Safety: + // We are using hyperlight cargo to build the guest which + // sets the Rust target to be compiled with the hard-float ABI manually via + // `-Zbuild-std` and a custom target JSON configuration + // See https://github.com/bytecodealliance/wasmtime/pull/11553 + #[cfg(not(feature = "wasmtime_lts"))] + unsafe { + config.x86_float_abi_ok(true) + }; + config.with_custom_code_memory(Some(alloc::sync::Arc::new(platform::WasmtimeCodeMemory {}))); #[cfg(gdb)] config.debug_info(true);