From 4d31f046415614e077cbddb2473d105bdcc8e8be Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Fri, 20 Dec 2024 09:24:23 -0800 Subject: [PATCH] Fix build on 32-bit Windows; consolidate CI platform checks This commit fixes the build of the `wasmtime` crate and CLI on 32-bit Windows. This required adding some extra bits for trap handling and a stub for "unimplemented" for unwind information registration. This then additionally refactored our CI configuration to place all of the cross-compile checks in one matrix instead of spread out across a few jobs. Closes #9882 prtest:platform-checks --- .github/workflows/main.yml | 113 ++++++++---------- .../src/runtime/vm/sys/windows/mod.rs | 10 +- .../runtime/vm/sys/windows/traphandlers.rs | 5 + .../src/runtime/vm/sys/windows/unwind32.rs | 23 ++++ .../vm/sys/windows/{unwind.rs => unwind64.rs} | 0 5 files changed, 86 insertions(+), 65 deletions(-) create mode 100644 crates/wasmtime/src/runtime/vm/sys/windows/unwind32.rs rename crates/wasmtime/src/runtime/vm/sys/windows/{unwind.rs => unwind64.rs} (100%) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index f9c2be3e8efe..8f380913285a 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -193,6 +193,7 @@ jobs: audit: ${{ steps.calculate.outputs.audit }} preview1-adapter: ${{ steps.calculate.outputs.preview1-adapter }} run-dwarf: ${{ steps.calculate.outputs.run-dwarf }} + platform-checks: ${{ steps.calculate.outputs.platform-checks }} steps: - uses: actions/checkout@v4 - id: calculate @@ -215,6 +216,8 @@ jobs: run_full=true elif grep -q 'prtest:debug' commits.log; then echo run-dwarf=true >> $GITHUB_OUTPUT + elif grep -q 'prtest:platform-checks' commits.log; then + echo platform-checks=true >> $GITHUB_OUTPUT fi if grep -q crates.c-api names.log; then echo test-capi=true >> $GITHUB_OUTPUT @@ -256,6 +259,7 @@ jobs: echo audit=true >> $GITHUB_OUTPUT echo preview1-adapter=true >> $GITHUB_OUTPUT echo run-dwarf=true >> $GITHUB_OUTPUT + echo platform-checks=true >> $GITHUB_OUTPUT fi # Build all documentation of Wasmtime, including the C API documentation, @@ -452,13 +456,6 @@ jobs: submodules: true - uses: ./.github/actions/install-rust - - run: rustup target add x86_64-unknown-none - - run: cargo check --target x86_64-unknown-none -p wasmtime --no-default-features --features runtime,component-model - - run: cargo check --target x86_64-unknown-none -p wasmtime --no-default-features --features runtime,gc,component-model - - run: cargo check --target x86_64-unknown-none -p wasmtime --no-default-features --features runtime,gc,component-model,signals-based-traps - - run: cargo check --target x86_64-unknown-none -p cranelift-control --no-default-features - - run: cargo check --target x86_64-unknown-none -p pulley-interpreter --features encode,decode,disas,interp - # common logic to cancel the entire run if this job fails - uses: ./.github/actions/cancel-on-failure if: failure() @@ -512,10 +509,6 @@ jobs: env: CARGO_PROFILE_DEV_DEBUG_ASSERTIONS: false - # Check whether `wasmtime` cross-compiles to x86_64-unknown-freebsd - - run: rustup target add x86_64-unknown-freebsd - - run: cargo check --target x86_64-unknown-freebsd - # Re-vendor all WIT files and ensure that they're all up-to-date by ensuring # that there's no git changes. - name: Re-vendor WIT @@ -531,44 +524,60 @@ jobs: - uses: ./.github/actions/cancel-on-failure if: failure() - checks_illumos: - name: Check illumos - runs-on: ubuntu-latest + # Various checks that Wasmtime builds for a variety of platforms. Each + # platform may not include the entire dependency tree and maybe just a few + # features here and there, see the `include` matrix for more details. + platform_checks: + needs: determine + if: needs.determine.outputs.platform-checks + name: Platform: ${{ matrix.target }} + runs-on: ${{ matrix.os }} + strategy: + fail-fast: true + matrix: + include: + - target: x86_64-unknown-freebsd + os: ubuntu-latest + test: cargo check + - target: aarch64-pc-windows-msvc + os: windows-latest + test: cargo check + - target: i686-pc-windows-msvc + os: windows-latest + test: cargo check + # This is used for general compatibility with `#![no_std]` targets and a + # variety of crates are tested here. + - target: x86_64-unknown-none + os: ubuntu-latest + test: > + cargo check -p wasmtime --no-default-features --features runtime,component-model && + cargo check -p wasmtime --no-default-features --features runtime,gc,component-model && + cargo check -p wasmtime --no-default-features --features runtime,gc,component-model,signals-based-traps && + cargo check -p wasmtime --no-default-features --features runtime,gc,component-model,signals-based-traps && + cargo check -p cranelift-control --no-default-features && + cargo check -p pulley-interpreter --features encode,decode,disas,interp + # Use `cross` for illumos to have a C compiler/linker available. + - target: x86_64-unknown-illumos + os: ubuntu-latest + cross: true + test: cross build + - target: wasm32-wasip1 + os: ubuntu-latest + test: cargo build --no-default-features --features compile,cranelift,all-arch steps: - uses: actions/checkout@v4 with: submodules: true - uses: ./.github/actions/install-rust - - # Check whether `wasmtime` cross-compiles to illumos. We need to use `cross` for this (even for - # cargo check) because of non-Rust dependencies. + - run: rustup target add ${{ matrix.target }} - name: Install cross run: | curl -L --proto '=https' --tlsv1.2 -sSf https://raw.githubusercontent.com/cargo-bins/cargo-binstall/main/install-from-binstall-release.sh | bash cargo binstall --no-confirm cross - - name: Cross-compile to illumos - run: - cross build --target x86_64-unknown-illumos - - # common logic to cancel the entire run if this job fails - - uses: ./.github/actions/cancel-on-failure - if: failure() - - # Check whether `wasmtime` cross-compiles to aarch64-pc-windows-msvc - # We don't build nor test it because it lacks trap handling. - # Tracking issue: https://github.com/bytecodealliance/wasmtime/issues/4992 - checks_winarm64: - needs: determine - if: needs.determine.outputs.run-full - name: Check Windows ARM64 - runs-on: windows-latest - steps: - - uses: actions/checkout@v4 - with: - submodules: true - - uses: ./.github/actions/install-rust - - run: rustup target add aarch64-pc-windows-msvc - - run: cargo check -p wasmtime --target aarch64-pc-windows-msvc + if: ${{ matrix.cross }} + - run: ${{ matrix.test }} + env: + CARGO_BUILD_TARGET: ${{ matrix.target }} # common logic to cancel the entire run if this job fails - uses: ./.github/actions/cancel-on-failure @@ -956,27 +965,6 @@ jobs: - uses: ./.github/actions/cancel-on-failure if: failure() - - build-wasmtime-target-wasm32: - name: Build wasmtime-target-wasm32 - if: needs.determine.outputs.run-full - needs: determine - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v4 - with: - submodules: true - - uses: ./.github/actions/install-rust - - run: rustup target add wasm32-wasip1 wasm32-unknown-unknown - - run: cargo build --target wasm32-wasip1 --no-default-features --features compile,cranelift,all-arch - env: - VERSION: ${{ github.sha }} - - # common logic to cancel the entire run if this job fails - - uses: ./.github/actions/cancel-on-failure - if: failure() - - bench: needs: determine if: needs.determine.outputs.run-full @@ -1174,8 +1162,6 @@ jobs: - no_std_checks - clippy - monolith_checks - - checks_illumos - - checks_winarm64 - bench - meta_deterministic_check - verify-publish @@ -1183,7 +1169,6 @@ jobs: - miri - build-preview1-component-adapter - build-preview1-component-adapter-provider - - build-wasmtime-target-wasm32 - test-min-platform-example - check_js if: always() diff --git a/crates/wasmtime/src/runtime/vm/sys/windows/mod.rs b/crates/wasmtime/src/runtime/vm/sys/windows/mod.rs index 0ecc7295c99b..332b56d229e0 100644 --- a/crates/wasmtime/src/runtime/vm/sys/windows/mod.rs +++ b/crates/wasmtime/src/runtime/vm/sys/windows/mod.rs @@ -4,9 +4,17 @@ use std::cell::Cell; pub mod mmap; pub mod traphandlers; -pub mod unwind; pub mod vm; +#[cfg(target_pointer_width = "32")] +pub mod unwind32; +#[cfg(target_pointer_width = "32")] +pub use unwind32 as unwind; +#[cfg(target_pointer_width = "64")] +pub mod unwind64; +#[cfg(target_pointer_width = "64")] +pub use unwind64 as unwind; + std::thread_local!(static TLS: Cell<*mut u8> = const { Cell::new(std::ptr::null_mut()) }); #[inline] diff --git a/crates/wasmtime/src/runtime/vm/sys/windows/traphandlers.rs b/crates/wasmtime/src/runtime/vm/sys/windows/traphandlers.rs index e107763a45b9..6af1a6369402 100644 --- a/crates/wasmtime/src/runtime/vm/sys/windows/traphandlers.rs +++ b/crates/wasmtime/src/runtime/vm/sys/windows/traphandlers.rs @@ -109,6 +109,11 @@ unsafe extern "system" fn exception_handler(exception_info: *mut EXCEPTION_POINT pc: context.Pc as usize, fp: context.Anonymous.Anonymous.Fp as usize, }; + } else if #[cfg(target_arch = "x86")] { + let regs = TrapRegisters { + pc: context.Eip as usize, + fp: context.Ebp as usize, + }; } else { compile_error!("unsupported platform"); } diff --git a/crates/wasmtime/src/runtime/vm/sys/windows/unwind32.rs b/crates/wasmtime/src/runtime/vm/sys/windows/unwind32.rs new file mode 100644 index 000000000000..041bbfded32a --- /dev/null +++ b/crates/wasmtime/src/runtime/vm/sys/windows/unwind32.rs @@ -0,0 +1,23 @@ +//! Module for Windows x86 ABI unwind registry. +//! +//! Note that this is not implemented at this time because there is no Cranelift +//! backend foR windows. + +use crate::prelude::*; +use std::mem; + +pub enum UnwindRegistration {} + +impl UnwindRegistration { + #[allow(missing_docs)] + pub const SECTION_NAME: &'static str = ".pdata"; + + #[allow(missing_docs)] + pub unsafe fn new( + _base_address: *const u8, + _unwind_info: *const u8, + _unwind_len: usize, + ) -> Result { + bail!("unwind registration unimplemented on i686 windows") + } +} diff --git a/crates/wasmtime/src/runtime/vm/sys/windows/unwind.rs b/crates/wasmtime/src/runtime/vm/sys/windows/unwind64.rs similarity index 100% rename from crates/wasmtime/src/runtime/vm/sys/windows/unwind.rs rename to crates/wasmtime/src/runtime/vm/sys/windows/unwind64.rs