A lightweight WebAssembly runtime that is fast, secure, and standards-compliant
cranelift-module: fix the no_std build and cover it in CI (#14151)
WissssleyLe6b33de5139d
diff --git a/.github/workflows/main.yml b/.github/workflows/main.ymlindex 8c2e196b31..6bbc0afab6 100644--- a/.github/workflows/main.yml+++ b/.github/workflows/main.yml@@ -417,6 +417,10 @@ jobs:-p cranelift-entity --no-default-features-p cranelift-entity --no-default-features --features enable-serde+ - name: cranelift-module+ checks: |+ -p cranelift-module --no-default-features+- name: wasmtime-bench-apichecks: |-p wasmtime-bench-apidiff --git a/cranelift/module/Cargo.toml b/cranelift/module/Cargo.tomlindex 624d5db209..1bf9062f7c 100644--- a/cranelift/module/Cargo.toml+++ b/cranelift/module/Cargo.toml@@ -17,7 +17,7 @@ workspace = true[dependencies]cranelift-codegen = { workspace = true }cranelift-control = { workspace = true }-hashbrown = { workspace = true, optional = true }+hashbrown = { workspace = true }anyhow = { workspace = true, features = ['std'] }serde = { workspace = true, optional = true }serde_derive = { workspace = true, optional = true }@@ -25,7 +25,9 @@ serde_derive = { workspace = true, optional = true }[features]default = ["std"]std = ["cranelift-codegen/std"]-core = ["hashbrown", "cranelift-codegen/core"]+# The "core" feature no longer does anything here either: hashbrown is now an+# unconditional dependency. Kept, empty, for backward compatibility.+core = []# For dependent crates that want to serialize some parts of craneliftenable-serde = ["serde", "serde_derive", "cranelift-codegen/enable-serde"]diff --git a/cranelift/module/src/module.rs b/cranelift/module/src/module.rsindex 526f998561..76972d2129 100644--- a/cranelift/module/src/module.rs+++ b/cranelift/module/src/module.rs@@ -290,6 +290,11 @@ pub enum ModuleError {Compilation(CodegenError),/// Memory allocation failure from a backend+ ///+ /// Only the `std` builds carry this variant: the payload is a+ /// `std::io::Error` and the only producer is `cranelift-jit`, which needs+ /// `std` anyway.+ #[cfg(feature = "std")]Allocation {/// Io error the allocation failed witherr: std::io::Error,@@ -310,8 +315,8 @@ impl<'a> From<CompileError<'a>> for ModuleError {// This is manually implementing Error and Display instead of using thiserror to reduce the amount// of dependencies used by Cranelift.-impl std::error::Error for ModuleError {- fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {+impl core::error::Error for ModuleError {+ fn source(&self) -> Option<&(dyn core::error::Error + 'static)> {match self {Self::Undeclared { .. }| Self::IncompatibleDeclaration { .. }@@ -319,6 +324,7 @@ impl std::error::Error for ModuleError {| Self::DuplicateDefinition { .. }| Self::InvalidImportDefinition { .. } => None,Self::Compilation(source) => Some(source),+ #[cfg(feature = "std")]Self::Allocation { err: source } => Some(source),Self::Backend(source) => Some(&**source),Self::Flag(source) => Some(source),@@ -353,6 +359,7 @@ impl std::fmt::Display for ModuleError {Self::Compilation(err) => {write!(f, "Compilation error: {err}")}+ #[cfg(feature = "std")]Self::Allocation { err } => {write!(f, "Allocation error: {err}")}@@ -362,13 +369,13 @@ impl std::fmt::Display for ModuleError {}}-impl std::convert::From<CodegenError> for ModuleError {+impl From<CodegenError> for ModuleError {fn from(source: CodegenError) -> Self {Self::Compilation { 0: source }}}-impl std::convert::From<SetError> for ModuleError {+impl From<SetError> for ModuleError {fn from(source: SetError) -> Self {Self::Flag { 0: source }}