From 512ff873ecba7b03648bc96053ac298b7bfa3743 Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Tue, 4 Feb 2025 14:47:35 -0600 Subject: [PATCH 1/2] Fix tests on nightly (#1999) Ensure that `PartialOrd` and `Ord` implementations for `Alignment` are the same instead of having one be manual and one be derived. This is required to account for a small behavior change in nightly Rust. --- crates/wit-parser/src/sizealign.rs | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/crates/wit-parser/src/sizealign.rs b/crates/wit-parser/src/sizealign.rs index 294ad8d6a0..bbe0f0d7ae 100644 --- a/crates/wit-parser/src/sizealign.rs +++ b/crates/wit-parser/src/sizealign.rs @@ -1,4 +1,5 @@ use std::{ + cmp::Ordering, num::NonZeroUsize, ops::{Add, AddAssign}, }; @@ -6,7 +7,7 @@ use std::{ use crate::{FlagsRepr, Int, Resolve, Type, TypeDef, TypeDefKind}; /// Architecture specific alignment -#[derive(Eq, PartialEq, PartialOrd, Clone, Copy)] +#[derive(Eq, PartialEq, Clone, Copy)] pub enum Alignment { /// This represents 4 byte alignment on 32bit and 8 byte alignment on 64bit architectures Pointer, @@ -29,11 +30,17 @@ impl std::fmt::Debug for Alignment { } } +impl PartialOrd for Alignment { + fn partial_cmp(&self, other: &Self) -> Option { + Some(self.cmp(other)) + } +} + impl Ord for Alignment { /// Needed for determining the max alignment of an object from its parts. /// The ordering is: Bytes(1) < Bytes(2) < Bytes(4) < Pointer < Bytes(8) /// as a Pointer is either four or eight byte aligned, depending on the architecture - fn cmp(&self, other: &Self) -> std::cmp::Ordering { + fn cmp(&self, other: &Self) -> Ordering { match (self, other) { (Alignment::Pointer, Alignment::Pointer) => std::cmp::Ordering::Equal, (Alignment::Pointer, Alignment::Bytes(b)) => { From 977143cf94951dc561f4e37bfe7e4b9ee5be91fd Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Tue, 4 Feb 2025 19:24:52 -0800 Subject: [PATCH 2/2] Vendor wasmtime's install-rust action --- .github/actions/install-rust/action.yml | 63 +++++++++++++++++++++++++ .github/workflows/main.yml | 24 +++++----- 2 files changed, 75 insertions(+), 12 deletions(-) create mode 100644 .github/actions/install-rust/action.yml diff --git a/.github/actions/install-rust/action.yml b/.github/actions/install-rust/action.yml new file mode 100644 index 0000000000..a308348811 --- /dev/null +++ b/.github/actions/install-rust/action.yml @@ -0,0 +1,63 @@ +name: 'Install Rust toolchain' +description: 'Install a rust toolchain' + +inputs: + toolchain: + description: 'Default toolchan to install' + required: false + default: 'default' + msrv_range: + description: 'Versions later-than-latest-Rust the MSRV supports' + required: false + default: '2' + +runs: + using: composite + steps: + - name: Install Rust + shell: bash + id: select + run: | + # Determine MSRV as N in `1.N.0` by looking at the `rust-version` + # located in the root `Cargo.toml`. + msrv=$(grep 'rust-version.*1' Cargo.toml | sed 's/.*\.\([0-9]*\)\..*/\1/') + range=${{ inputs.msrv_range }} + + if [ "${{ inputs.toolchain }}" = "default" ]; then + echo "version=1.$((msrv+range)).0" >> "$GITHUB_OUTPUT" + elif [ "${{ inputs.toolchain }}" = "msrv" ]; then + echo "version=1.$msrv.0" >> "$GITHUB_OUTPUT" + elif [ "${{ inputs.toolchain }}" = "wasmtime-ci-pinned-nightly" ]; then + echo "version=nightly-2025-01-09" >> "$GITHUB_OUTPUT" + else + echo "version=${{ inputs.toolchain }}" >> "$GITHUB_OUTPUT" + fi + + - name: Install Rust + shell: bash + run: | + rustup set profile minimal + rustup update "${{ steps.select.outputs.version }}" --no-self-update + rustup default "${{ steps.select.outputs.version }}" + + # Save disk space by avoiding incremental compilation. Also turn down + # debuginfo from 2 to 0 to help save disk space. + cat >> "$GITHUB_ENV" <> "$GITHUB_ENV" + + if [[ "${{ runner.os }}" = "macOS" ]]; then + cat >> "$GITHUB_ENV" <> "$GITHUB_ENV" diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 40377ba2e2..33a856d8fc 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -40,7 +40,7 @@ jobs: - uses: actions/checkout@v4 with: submodules: true - - uses: bytecodealliance/wasmtime/.github/actions/install-rust@v20.0.0 + - uses: ./.github/actions/install-rust - uses: bytecodealliance/wasmtime/.github/actions/binary-compatible-builds@v20.0.0 with: name: ${{ matrix.build }} @@ -63,7 +63,7 @@ jobs: - uses: actions/checkout@v4 with: submodules: true - - uses: bytecodealliance/wasmtime/.github/actions/install-rust@v20.0.0 + - uses: ./.github/actions/install-rust - name: Test (no-hash-maps) run: cargo test --workspace --locked --features no-hash-maps @@ -103,7 +103,7 @@ jobs: - uses: actions/checkout@v4 with: submodules: true - - uses: bytecodealliance/wasmtime/.github/actions/install-rust@v20.0.0 + - uses: ./.github/actions/install-rust with: toolchain: ${{ matrix.rust }} - run: cargo test --locked --all ${{ matrix.flags }} @@ -115,7 +115,7 @@ jobs: - uses: actions/checkout@v4 with: submodules: true - - uses: bytecodealliance/wasmtime/.github/actions/install-rust@v20.0.0 + - uses: ./.github/actions/install-rust - run: cargo test --locked -p wasmparser --benches - run: cargo test --locked -p wasm-encoder --all-features - run: cargo test -p wasm-smith --features wasmparser @@ -134,7 +134,7 @@ jobs: - uses: actions/checkout@v4 with: submodules: true - - uses: bytecodealliance/wasmtime/.github/actions/install-rust@v20.0.0 + - uses: ./.github/actions/install-rust - run: cmake -S examples -B examples/build -DCMAKE_BUILD_TYPE=Release - run: cmake --build examples/build --config Release @@ -145,7 +145,7 @@ jobs: - uses: actions/checkout@v4 with: submodules: true - - uses: bytecodealliance/wasmtime/.github/actions/install-rust@v20.0.0 + - uses: ./.github/actions/install-rust with: toolchain: 1.79.0 - run: rustup target add wasm32-wasip1 @@ -162,7 +162,7 @@ jobs: - uses: actions/checkout@v4 with: submodules: true - - uses: bytecodealliance/wasmtime/.github/actions/install-rust@v20.0.0 + - uses: ./.github/actions/install-rust - run: rustup target add wasm32-wasip1 - run: | tag=v10.0.1 @@ -183,7 +183,7 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - - uses: bytecodealliance/wasmtime/.github/actions/install-rust@v20.0.0 + - uses: ./.github/actions/install-rust - run: rustup component add rustfmt - run: printf "\n" > playground/component/src/bindings.rs # Note that this doesn't use `cargo fmt` because that doesn't format @@ -198,7 +198,7 @@ jobs: - uses: actions/checkout@v4 with: submodules: true - - uses: bytecodealliance/wasmtime/.github/actions/install-rust@v20.0.0 + - uses: ./.github/actions/install-rust with: toolchain: nightly - run: cargo install cargo-fuzz @@ -209,7 +209,7 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - - uses: bytecodealliance/wasmtime/.github/actions/install-rust@v20.0.0 + - uses: ./.github/actions/install-rust - run: rustup target add x86_64-unknown-none - run: cargo check --benches -p wasm-smith - run: cargo check --no-default-features @@ -281,7 +281,7 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - - uses: bytecodealliance/wasmtime/.github/actions/install-rust@v20.0.0 + - uses: ./.github/actions/install-rust - run: rustup component add clippy - run: cargo clippy --workspace --all-targets --exclude dl --exclude component @@ -292,7 +292,7 @@ jobs: - uses: actions/checkout@v4 with: submodules: true - - uses: bytecodealliance/wasmtime/.github/actions/install-rust@v20.0.0 + - uses: ./.github/actions/install-rust - run: rustc ci/publish.rs # Make sure we can bump version numbers for the next release - run: ./publish bump