Skip to content
Merged
Show file tree
Hide file tree
Changes from 13 commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
706d650
feat: Progress reporting and abort for module compilation
theduke Nov 18, 2025
9d8e664
feat(wasix): Module load/compile progress reporting
theduke Nov 18, 2025
43027f2
feat(cli): run command: Show compilation progress
theduke Nov 18, 2025
17ae0ce
Fix clippy warnings
theduke Nov 18, 2025
3aab1ac
Rename CompileError::User to CompileError::Aborted
theduke Nov 18, 2025
965e038
Refactor Module::new_with_progress to ProgressEngineExt::new_module_w…
theduke Nov 18, 2025
a861985
tests: Add module compile progress/abort tests
theduke Nov 18, 2025
5fe730d
chore(cli): Improve module compilation progress status
theduke Nov 18, 2025
a9a070b
Lift ProgressContext to wasmer-compiler crate
theduke Nov 18, 2025
9b1f8a9
Extend singlepass compiler with progress reporting.
theduke Nov 18, 2025
26507da
Include trampolines in compilation progress.
theduke Nov 18, 2025
327b3b9
Add singlepass progress tests
theduke Nov 18, 2025
4571262
chore: Docs improvements and small clippy fixes
theduke Nov 18, 2025
4aadf39
tmp
theduke Nov 20, 2025
c44c3b0
Merge remote-tracking branch 'origin/main' into compiler-progress
theduke Dec 1, 2025
6fac680
Merge branch 'main' into compiler-progress
marxin Jan 14, 2026
b6b5290
Merge branch 'main' into compiler-progress
marxin Jan 14, 2026
c0ec682
fix cranelift testse
marxin Jan 14, 2026
27398f1
remove dbg output
marxin Jan 14, 2026
f4f4575
use correct runtime
marxin Jan 14, 2026
0c84047
refactor
marxin Jan 14, 2026
085f23a
remove from_binary_with_progress from BackendModule trait
marxin Jan 14, 2026
84ef34d
simplify
marxin Jan 14, 2026
0c0f0e4
drop progress_ext
marxin Jan 14, 2026
810bf6d
use thiserror for UserAbort
marxin Jan 14, 2026
6d69f89
move tests to tests/compilers
marxin Jan 14, 2026
f4c1a40
fix singlepass progress bar
marxin Jan 14, 2026
6e28543
run progress tests for all compilers
marxin Jan 14, 2026
ca9ad0e
fix compilation error based on configuration
marxin Jan 14, 2026
9a93a1b
fix conditional build
marxin Jan 14, 2026
c33b214
fix cargo fmt
marxin Jan 14, 2026
c2bc7dc
Merge branch 'main' into compiler-progress
marxin Jan 16, 2026
4a9516f
remove unused imports
marxin Jan 16, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions lib/api/src/backend/js/entities/module.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ use js_sys::{Reflect, Uint8Array, WebAssembly};
use tracing::{debug, warn};
use wasm_bindgen::{JsValue, prelude::*};
use wasmer_types::{
CompileError, DeserializeError, ExportType, ExportsIterator, ExternType, FunctionType,
GlobalType, ImportType, ImportsIterator, MemoryType, ModuleInfo, Mutability, Pages,
SerializeError, TableType, Type,
CompilationProgressCallback, CompileError, DeserializeError, ExportType, ExportsIterator,
ExternType, FunctionType, GlobalType, ImportType, ImportsIterator, MemoryType, ModuleInfo,
Mutability, Pages, SerializeError, TableType, Type,
};

use crate::{
Expand Down Expand Up @@ -67,6 +67,14 @@ impl Module {
unsafe { Self::from_binary_unchecked(_engine, binary) }
}

pub(crate) fn from_binary_with_progress(
engine: &impl AsEngineRef,
binary: &[u8],
_callback: CompilationProgressCallback,
) -> Result<Self, CompileError> {
Self::from_binary(engine, binary)
}

pub(crate) unsafe fn from_binary_unchecked(
_engine: &impl AsEngineRef,
binary: &[u8],
Expand Down
12 changes: 10 additions & 2 deletions lib/api/src/backend/jsc/entities/module.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ use bytes::Bytes;
use rusty_jsc::{JSObject, JSValue};
use tracing::warn;
use wasmer_types::{
CompileError, DeserializeError, ExportType, ExportsIterator, ImportType, ImportsIterator,
ModuleInfo, SerializeError,
CompilationProgressCallback, CompileError, DeserializeError, ExportType, ExportsIterator,
ImportType, ImportsIterator, ModuleInfo, SerializeError,
};

use crate::{
Expand Down Expand Up @@ -43,6 +43,14 @@ impl Module {
unsafe { Self::from_binary_unchecked(_engine, binary) }
}

pub(crate) fn from_binary_with_progress(
engine: &impl AsEngineRef,
binary: &[u8],
_callback: CompilationProgressCallback,
) -> Result<Self, CompileError> {
Self::from_binary(engine, binary)
}

pub(crate) unsafe fn from_binary_unchecked(
engine: &impl AsEngineRef,
binary: &[u8],
Expand Down
4 changes: 3 additions & 1 deletion lib/api/src/backend/sys/entities/engine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ use std::{path::Path, sync::Arc};

use shared_buffer::OwnedBuffer;
pub use wasmer_compiler::{Artifact, BaseTunables, Engine, EngineBuilder, Tunables};
use wasmer_types::{DeserializeError, Features, HashAlgorithm, target::Target};
use wasmer_types::{
CompilationProgressCallback, DeserializeError, Features, HashAlgorithm, target::Target,
};

use crate::{BackendEngine, BackendModule};

Expand Down
48 changes: 44 additions & 4 deletions lib/api/src/backend/sys/entities/module.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ use std::sync::Arc;
use bytes::Bytes;
use wasmer_compiler::{Artifact, ArtifactCreate, Engine};
use wasmer_types::{
CompileError, DeserializeError, ExportType, ExportsIterator, ImportType, ImportsIterator,
ModuleInfo, SerializeError,
CompilationProgressCallback, CompileError, DeserializeError, ExportType, ExportsIterator,
ImportType, ImportsIterator, ModuleInfo, SerializeError,
};

use crate::{
Expand Down Expand Up @@ -45,12 +45,38 @@ impl Module {
unsafe { Self::from_binary_unchecked(engine, binary) }
}

pub(crate) fn from_binary_with_progress(
engine: &impl AsEngineRef,
binary: &[u8],
callback: CompilationProgressCallback,
) -> Result<Self, CompileError> {
Self::validate(engine, binary)?;
unsafe { Self::from_binary_unchecked_with_progress(engine, binary, Some(callback)) }
}

pub(crate) unsafe fn from_binary_unchecked(
engine: &impl AsEngineRef,
binary: &[u8],
) -> Result<Self, CompileError> {
let module = Self::compile(engine, binary)?;
Ok(module)
Self::compile(engine, binary)
}

pub(crate) unsafe fn from_binary_unchecked_with_progress(
engine: &impl AsEngineRef,
binary: &[u8],
callback: Option<CompilationProgressCallback>,
) -> Result<Self, CompileError> {
#[cfg(feature = "compiler")]
{
let module = Self::compile_with_progress(engine, binary, callback)?;
Ok(module)
}

#[cfg(not(feature = "compiler"))]
{
let _ = callback;
Self::compile(engine, binary)
}
}

#[cfg(feature = "compiler")]
Expand All @@ -72,6 +98,20 @@ impl Module {
Ok(Self::from_artifact(artifact))
}

#[cfg(feature = "compiler")]
fn compile_with_progress(
engine: &impl AsEngineRef,
binary: &[u8],
callback: Option<CompilationProgressCallback>,
) -> Result<Self, CompileError> {
let artifact = engine
.as_engine_ref()
.engine()
.as_sys()
.compile_with_progress(binary, callback)?;
Ok(Self::from_artifact(artifact))
}

#[cfg(not(feature = "compiler"))]
fn compile(_engine: &impl AsEngineRef, _binary: &[u8]) -> Result<Self, CompileError> {
Err(CompileError::UnsupportedTarget(
Expand Down
14 changes: 11 additions & 3 deletions lib/api/src/backend/v8/entities/module.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ use crate::{

use bytes::Bytes;
use wasmer_types::{
CompileError, DeserializeError, ExportType, ExportsIterator, ExternType, FunctionType,
GlobalType, ImportType, ImportsIterator, MemoryType, ModuleInfo, Mutability, Pages,
SerializeError, TableType, Type,
CompilationProgressCallback, CompileError, DeserializeError, ExportType, ExportsIterator,
ExternType, FunctionType, GlobalType, ImportType, ImportsIterator, MemoryType, ModuleInfo,
Mutability, Pages, SerializeError, TableType, Type,
};

#[derive(Debug)]
Expand Down Expand Up @@ -152,6 +152,14 @@ impl Module {
unsafe { Self::from_binary_unchecked(engine, binary) }
}

pub(crate) fn from_binary_with_progress(
engine: &impl AsEngineRef,
binary: &[u8],
_callback: CompilationProgressCallback,
) -> Result<Self, CompileError> {
Self::from_binary(engine, binary)
}

#[allow(clippy::arc_with_non_send_sync)]
#[tracing::instrument(skip(engine, binary))]
pub(crate) unsafe fn from_binary_unchecked(
Expand Down
14 changes: 11 additions & 3 deletions lib/api/src/backend/wamr/entities/module.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ use crate::{AsEngineRef, BackendModule, IntoBytes, backend::wamr::bindings::*};

use bytes::Bytes;
use wasmer_types::{
CompileError, DeserializeError, ExportType, ExportsIterator, ExternType, FunctionType,
GlobalType, ImportType, ImportsIterator, MemoryType, ModuleInfo, Mutability, Pages,
SerializeError, TableType, Type,
CompilationProgressCallback, CompileError, DeserializeError, ExportType, ExportsIterator,
ExternType, FunctionType, GlobalType, ImportType, ImportsIterator, MemoryType, ModuleInfo,
Mutability, Pages, SerializeError, TableType, Type,
};
pub(crate) struct ModuleHandle {
pub(crate) inner: *mut wasm_module_t,
Expand Down Expand Up @@ -75,6 +75,14 @@ impl Module {
unsafe { Self::from_binary_unchecked(_engine, binary) }
}

pub(crate) fn from_binary_with_progress(
engine: &impl AsEngineRef,
binary: &[u8],
_callback: CompilationProgressCallback,
) -> Result<Self, CompileError> {
Self::from_binary(engine, binary)
}

pub(crate) unsafe fn from_binary_unchecked(
engine: &impl AsEngineRef,
binary: &[u8],
Expand Down
14 changes: 11 additions & 3 deletions lib/api/src/backend/wasmi/entities/module.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ use crate::{

use bytes::Bytes;
use wasmer_types::{
CompileError, DeserializeError, ExportType, ExportsIterator, ExternType, FunctionType,
GlobalType, ImportType, ImportsIterator, MemoryType, ModuleInfo, Mutability, Pages,
SerializeError, TableType, Type,
CompilationProgressCallback, CompileError, DeserializeError, ExportType, ExportsIterator,
ExternType, FunctionType, GlobalType, ImportType, ImportsIterator, MemoryType, ModuleInfo,
Mutability, Pages, SerializeError, TableType, Type,
};
pub(crate) struct ModuleHandle {
pub(crate) inner: *mut wasm_module_t,
Expand Down Expand Up @@ -74,6 +74,14 @@ impl Module {
unsafe { Self::from_binary_unchecked(_engine, binary) }
}

pub(crate) fn from_binary_with_progress(
engine: &impl AsEngineRef,
binary: &[u8],
_callback: CompilationProgressCallback,
) -> Result<Self, CompileError> {
Self::from_binary(engine, binary)
}

#[allow(clippy::arc_with_non_send_sync)]
pub(crate) unsafe fn from_binary_unchecked(
engine: &impl AsEngineRef,
Expand Down
3 changes: 3 additions & 0 deletions lib/api/src/entities/engine/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ use crate::{BackendKind, IntoBytes, Store};
/// Create temporary handles to engines.
mod engine_ref;

mod progress_ext;
pub use progress_ext::ProgressEngineExt;

/// The actual (private) definition of the engines.
mod inner;
pub(crate) use inner::BackendEngine;
Expand Down
35 changes: 35 additions & 0 deletions lib/api/src/entities/engine/progress_ext.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
use wasmer_types::CompilationProgressCallback;

/// Provides progress-related extensions to the `Engine` trait.
pub trait ProgressEngineExt {
/// Compile a module from bytes with a progress callback.
///
/// The callback is invoked with progress updates during the compilation process.
/// The callback also may return an error to abort the compilation.
///
/// Signature of the callback function: `Fn(CompilationProgress) -> Result<(), UserAbort> + Send + Sync + 'static`
///
/// # Aborting compilation
///
/// The callback has to return a `Result<(), UserAbort>`.
///
/// If the callback returns an error, the compilation will fail with a `CompileError::Aborted`.
///
/// See [`CompilationProgressCallback::new`] for more details.
fn new_module_with_progress(
&self,
bytes: &[u8],
on_progress: CompilationProgressCallback,
) -> Result<crate::Module, wasmer_types::CompileError>;
}

impl ProgressEngineExt for crate::Engine {
/// See [`ProgressEngineExt::new_module_with_progress`].
fn new_module_with_progress(
&self,
bytes: &[u8],
on_progress: CompilationProgressCallback,
) -> Result<crate::Module, wasmer_types::CompileError> {
crate::BackendModule::new_with_progress(self, bytes, on_progress).map(crate::Module)
}
}
80 changes: 78 additions & 2 deletions lib/api/src/entities/module/inner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ use thiserror::Error;
#[cfg(feature = "wat")]
use wasmer_types::WasmError;
use wasmer_types::{
CompileError, DeserializeError, ExportType, ExportsIterator, ImportType, ImportsIterator,
ModuleInfo, SerializeError,
CompilationProgressCallback, CompileError, DeserializeError, ExportType, ExportsIterator,
ImportType, ImportsIterator, ModuleInfo, SerializeError,
};

use crate::{
Expand Down Expand Up @@ -43,6 +43,21 @@ impl BackendModule {
Self::from_binary(engine, bytes.as_ref())
}

#[inline]
pub fn new_with_progress(
engine: &impl AsEngineRef,
bytes: impl AsRef<[u8]>,
callback: CompilationProgressCallback,
) -> Result<Self, CompileError> {
#[cfg(feature = "wat")]
let bytes = wat::parse_bytes(bytes.as_ref()).map_err(|e| {
CompileError::Wasm(WasmError::Generic(format!(
"Error when converting wat: {e}",
)))
})?;
Self::from_binary_with_progress(engine, bytes.as_ref(), callback)
}

/// Creates a new WebAssembly module from a file path.
#[inline]
pub fn from_file(
Expand Down Expand Up @@ -100,6 +115,67 @@ impl BackendModule {
}
}

#[inline]
pub fn from_binary_with_progress(
engine: &impl AsEngineRef,
binary: &[u8],
callback: CompilationProgressCallback,
) -> Result<Self, CompileError> {
match engine.as_engine_ref().inner.be {
#[cfg(feature = "sys")]
crate::BackendEngine::Sys(_) => Ok(Self::Sys(
crate::backend::sys::entities::module::Module::from_binary_with_progress(
engine,
binary,
callback.clone(),
)?,
)),

#[cfg(feature = "wamr")]
crate::BackendEngine::Wamr(_) => Ok(Self::Wamr(
crate::backend::wamr::entities::module::Module::from_binary_with_progress(
engine,
binary,
callback.clone(),
)?,
)),

#[cfg(feature = "wasmi")]
crate::BackendEngine::Wasmi(_) => Ok(Self::Wasmi(
crate::backend::wasmi::entities::module::Module::from_binary_with_progress(
engine,
binary,
callback.clone(),
)?,
)),

#[cfg(feature = "v8")]
crate::BackendEngine::V8(_) => Ok(Self::V8(
crate::backend::v8::entities::module::Module::from_binary_with_progress(
engine,
binary,
callback.clone(),
)?,
)),

#[cfg(feature = "js")]
crate::BackendEngine::Js(_) => Ok(Self::Js(
crate::backend::js::entities::module::Module::from_binary_with_progress(
engine,
binary,
callback.clone(),
)?,
)),

#[cfg(feature = "jsc")]
crate::BackendEngine::Jsc(_) => Ok(Self::Jsc(
crate::backend::jsc::entities::module::Module::from_binary_with_progress(
engine, binary, callback,
)?,
)),
}
}

/// Creates a new WebAssembly module from a Wasm binary,
/// skipping any kind of validation on the WebAssembly file.
///
Expand Down
4 changes: 2 additions & 2 deletions lib/api/src/entities/module/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ use thiserror::Error;
#[cfg(feature = "wat")]
use wasmer_types::WasmError;
use wasmer_types::{
CompileError, DeserializeError, ExportType, ExportsIterator, ImportType, ImportsIterator,
ModuleInfo, SerializeError,
CompilationProgress, CompilationProgressCallback, CompileError, DeserializeError, ExportType,
ExportsIterator, ImportType, ImportsIterator, ModuleInfo, SerializeError, UserAbort,
};

use crate::{AsEngineRef, macros::backend::match_rt, utils::IntoBytes};
Expand Down
Loading
Loading