Skip to content

Commit

Permalink
[217] Fix tests on nightly (#2008)
Browse files Browse the repository at this point in the history
* 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.

* Vendor wasmtime's install-rust action
  • Loading branch information
alexcrichton authored Feb 5, 2025
1 parent 46cb2e8 commit 32368cd
Show file tree
Hide file tree
Showing 3 changed files with 84 additions and 14 deletions.
63 changes: 63 additions & 0 deletions .github/actions/install-rust/action.yml
Original file line number Diff line number Diff line change
@@ -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" <<EOF
CARGO_INCREMENTAL=0
CARGO_PROFILE_DEV_DEBUG=0
CARGO_PROFILE_TEST_DEBUG=0
EOF
# Deny warnings on CI to keep our code warning-free as it lands in-tree.
echo RUSTFLAGS="-D warnings" >> "$GITHUB_ENV"
if [[ "${{ runner.os }}" = "macOS" ]]; then
cat >> "$GITHUB_ENV" <<EOF
CARGO_PROFILE_DEV_SPLIT_DEBUGINFO=unpacked
CARGO_PROFILE_TEST_SPLIT_DEBUGINFO=unpacked
EOF
fi
- name: Require semicolons in WIT
shell: bash
run: echo WIT_REQUIRE_SEMICOLONS=1 >> "$GITHUB_ENV"
24 changes: 12 additions & 12 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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/[email protected]
with:
name: ${{ matrix.build }}
Expand All @@ -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

Expand Down Expand Up @@ -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 }}
Expand All @@ -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
Expand All @@ -133,7 +133,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

Expand All @@ -144,7 +144,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
Expand All @@ -161,7 +161,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
Expand All @@ -182,7 +182,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
Expand All @@ -197,7 +197,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
Expand All @@ -208,7 +208,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
Expand Down Expand Up @@ -263,7 +263,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 --exclude dl --exclude component

Expand All @@ -274,7 +274,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
Expand Down
11 changes: 9 additions & 2 deletions crates/wit-parser/src/sizealign.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
use std::{
cmp::Ordering,
num::NonZeroUsize,
ops::{Add, AddAssign},
};

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,
Expand All @@ -29,11 +30,17 @@ impl std::fmt::Debug for Alignment {
}
}

impl PartialOrd for Alignment {
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
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)) => {
Expand Down

0 comments on commit 32368cd

Please sign in to comment.