Skip to content

Commit

Permalink
Rely on core::error::Error (#9702)
Browse files Browse the repository at this point in the history
* Rely on `core::error::Error`

With Wasmtime's new MSRV at 1.81 this means that `core::error::Error` is
available which means that in `no_std` mode the `Error` trait can be
used. This has been integrated into `anyhow::Error` already upstream and
means that we can remove our own local hacks such as the `Err2Anyhow` trait.

This commit removes the `Err2Anyhow` trait and all usage, going back to
idiomatic Rust error propagation and conversion even in the `no_std`
world. This should make code more portable by default and remove some
weird idioms we had for supporting this.

prtest:full

* Add some trusted vets

* Audit object crate update

* Disable backtraces on CI
  • Loading branch information
alexcrichton authored Dec 3, 2024
1 parent 71cb94b commit 9034e10
Show file tree
Hide file tree
Showing 45 changed files with 231 additions and 375 deletions.
11 changes: 0 additions & 11 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -641,12 +641,8 @@ jobs:
- run: cmake -Sexamples -Bexamples/build -DBUILD_SHARED_LIBS=OFF
- run: cmake --build examples/build --config Debug
- run: cmake -E env CTEST_OUTPUT_ON_FAILURE=1 cmake --build examples/build --config Debug --target RUN_TESTS
env:
RUST_BACKTRACE: 1
if: matrix.os == 'windows-latest'
- run: cmake -E env CTEST_OUTPUT_ON_FAILURE=1 cmake --build examples/build --config Debug --target test
env:
RUST_BACKTRACE: 1
if: matrix.os != 'windows-latest'

# Perform all tests (debug mode) for `wasmtime`.
Expand Down Expand Up @@ -771,8 +767,6 @@ jobs:

# Build and test all features
- run: ./ci/run-tests.sh --locked ${{ matrix.bucket }}
env:
RUST_BACKTRACE: 1

# NB: the test job here is explicitly lacking in cancellation of this run if
# something goes wrong. These take the longest anyway and otherwise if
Expand Down Expand Up @@ -817,8 +811,6 @@ jobs:

# Run the tests!
- run: cargo test -p wasmtime-wasi-nn --features ${{ matrix.feature }}
env:
RUST_BACKTRACE: 1

# common logic to cancel the entire run if this job fails
- run: gh run cancel ${{ github.run_id }}
Expand All @@ -843,8 +835,6 @@ jobs:
# Run the tests
- run: |
cargo test -p wasmtime-fuzzing -p wasm-spec-interpreter
env:
RUST_BACKTRACE: 1
# common logic to cancel the entire run if this job fails
- run: gh run cancel ${{ github.run_id }}
Expand All @@ -871,7 +861,6 @@ jobs:
sudo ln -s /usr/lib/llvm-15/lib/python3.10/dist-packages/lldb/* /usr/lib/python3/dist-packages/lldb/
cargo test --test all -- --ignored --test-threads 1 debug::
env:
RUST_BACKTRACE: 1
LLDB: lldb-15 # override default version, 14
# common logic to cancel the entire run if this job fails
Expand Down
72 changes: 36 additions & 36 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -291,10 +291,10 @@ wasm-wave = "0.221.2"
# Non-Bytecode Alliance maintained dependencies:
# --------------------------
cc = "1.0"
object = { version = "0.36", default-features = false, features = ['read_core', 'elf'] }
object = { version = "0.36.5", default-features = false, features = ['read_core', 'elf'] }
gimli = { version = "0.31.0", default-features = false, features = ['read'] }
addr2line = { version = "0.24.1", default-features = false }
anyhow = { version = "1.0.22", default-features = false }
anyhow = { version = "1.0.93", default-features = false }
windows-sys = "0.59.0"
env_logger = "0.11.5"
log = { version = "0.4.8", default-features = false }
Expand All @@ -317,7 +317,7 @@ proptest = "1.0.0"
rand = { version = "0.8.3", features = ["small_rng"] }
sptr = "0.3.2"
# serde and serde_derive must have the same version
serde = { version = "1.0.188", default-features = false, features = ['alloc'] }
serde = { version = "1.0.215", default-features = false, features = ['alloc'] }
serde_derive = "1.0.188"
serde_json = "1.0.80"
glob = "0.3.0"
Expand Down
3 changes: 1 addition & 2 deletions crates/environ/src/compile/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,7 @@ impl From<WasmError> for CompileError {
}
}

#[cfg(feature = "std")]
impl std::error::Error for CompileError {
impl core::error::Error for CompileError {
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
match self {
CompileError::Wasm(e) => Some(e),
Expand Down
20 changes: 20 additions & 0 deletions crates/environ/src/obj.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
//! Utilities for working with object files that operate as Wasmtime's
//! serialization and intermediate format for compiled modules.
use core::fmt;

/// Filler for the `os_abi` field of the ELF header.
///
/// This is just a constant that seems reasonable in the sense it's unlikely to
Expand Down Expand Up @@ -177,3 +179,21 @@ libcalls! {
FmaF64 = "libcall_fmaf64"
X86Pshufb = "libcall_x86_pshufb"
}

/// Workaround to implement `core::error::Error` until
/// gimli-rs/object#747 is settled.
pub struct ObjectCrateErrorWrapper(pub object::Error);

impl fmt::Debug for ObjectCrateErrorWrapper {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
self.0.fmt(f)
}
}

impl fmt::Display for ObjectCrateErrorWrapper {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
self.0.fmt(f)
}
}

impl core::error::Error for ObjectCrateErrorWrapper {}
Loading

0 comments on commit 9034e10

Please sign in to comment.