Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
3dc2544
Debugging: add the debug-main world.
cfallin Mar 10, 2026
7f542d3
Review feedback.
cfallin Mar 12, 2026
1caf84f
Review feedback.
cfallin Mar 12, 2026
adec476
Review feedback: update vendor-wit.sh.
cfallin Mar 12, 2026
d2515bb
Review feedback: -Ddebugger-arg= -> -Darg=.
cfallin Mar 12, 2026
18705e2
Review feedback.
cfallin Mar 12, 2026
a15e743
Review feedback.
cfallin Mar 12, 2026
8d5db0d
Review feedback: factor host.rs into several submodules.
cfallin Mar 12, 2026
647853b
Review feedback: rename Debugger to Debuggee on host side.
cfallin Mar 12, 2026
dcf03f9
Review feedback: split inherit_stdin_stdout, and add corresponding op…
cfallin Mar 12, 2026
49ff2fc
Review feedback.
cfallin Mar 12, 2026
eaebb70
Review feedback.
cfallin Mar 12, 2026
c9e59a8
Add simple debug-component tests.
cfallin Mar 12, 2026
55d6bc8
Add wasm32-wasip2 target in a few places in CI
cfallin Mar 12, 2026
d0027a6
Cargo vets for wstd dependency.
cfallin Mar 12, 2026
59be108
Add wasm32-wasip2 in more places
cfallin Mar 12, 2026
329c8d7
fix debug-component test dependence on componentization byte offsets
cfallin Mar 12, 2026
b3fc04d
Review feedback.
cfallin Mar 13, 2026
c39e049
Fix cancel-safety of EventFuture.
cfallin Mar 13, 2026
6252848
Fix: Interrupted events should only occur after interrupt(), not on e…
cfallin Mar 13, 2026
ea1f7a9
Review feedback.
cfallin Mar 13, 2026
2df52d6
Review feedback: strip down WASI imports in debugger world.
cfallin Mar 13, 2026
d7aa6a2
fold debugger test component back into wasip1 + adapter test artifact…
cfallin Mar 13, 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
2 changes: 1 addition & 1 deletion .github/actions/install-rust/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -79,4 +79,4 @@ runs:

- name: Install the WASI target
shell: bash
run: rustup target add wasm32-wasip1 wasm32-unknown-unknown
run: rustup target add wasm32-wasip2 wasm32-wasip1 wasm32-unknown-unknown
10 changes: 5 additions & 5 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -739,7 +739,7 @@ jobs:
toolchain: ${{ matrix.rust }}

# Install targets in order to build various tests throughout the repo
- run: rustup target add wasm32-wasip1 wasm32-unknown-unknown ${{ matrix.target }}
- run: rustup target add wasm32-wasip1 wasm32-unknown-unknown wasm32-wasip2 ${{ matrix.target }}
- run: echo CARGO_BUILD_TARGET=${{ matrix.target }} >> $GITHUB_ENV
if: matrix.target != ''

Expand Down Expand Up @@ -937,7 +937,7 @@ jobs:
if: (runner.os == 'Windows') && (matrix.feature == 'winml')

# Install Rust targets.
- run: rustup target add wasm32-wasip1
- run: rustup target add wasm32-wasip1 wasm32-wasip2

# Run the tests!
- run: cargo test -p wasmtime-wasi-nn --features ${{ matrix.feature }}
Expand Down Expand Up @@ -1009,7 +1009,7 @@ jobs:
submodules: true
- uses: ./.github/actions/install-rust
- run: |
rustup target add wasm32-wasip1 wasm32-unknown-unknown
rustup target add wasm32-wasip2 wasm32-wasip1 wasm32-unknown-unknown
cd /tmp
curl --retry 5 --retry-all-errors -OL https://github.com/WebAssembly/wasi-sdk/releases/download/wasi-sdk-30/wasi-sdk-30.0-x86_64-linux.tar.gz
tar -xzf wasi-sdk-30.0-x86_64-linux.tar.gz
Expand Down Expand Up @@ -1038,7 +1038,7 @@ jobs:
with:
submodules: true
- uses: ./.github/actions/install-rust
- run: rustup target add wasm32-wasip1 wasm32-unknown-unknown
- run: rustup target add wasm32-wasip2 wasm32-wasip1 wasm32-unknown-unknown

- name: Install wasm-tools
run: |
Expand Down Expand Up @@ -1118,7 +1118,7 @@ jobs:
with:
submodules: true
- uses: ./.github/actions/install-rust
- run: rustup target add wasm32-wasip1
- run: rustup target add wasm32-wasip2 wasm32-wasip1
- run: cargo test --benches --release

# Verify that cranelift's code generation is deterministic
Expand Down
4 changes: 4 additions & 0 deletions Cargo.lock

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

4 changes: 3 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ wasmtime-wasi-threads = { workspace = true, optional = true }
wasmtime-wasi-http = { workspace = true, optional = true }
wasmtime-unwinder = { workspace = true }
wasmtime-wizer = { workspace = true, optional = true, features = ['clap', 'wasmtime'] }
wasmtime-debugger = { workspace = true, optional = true }
clap = { workspace = true }
clap_complete = { workspace = true, optional = true }
target-lexicon = { workspace = true }
Expand Down Expand Up @@ -565,7 +566,7 @@ gc-drc = ["gc", "wasmtime/gc-drc", "wasmtime-cli-flags/gc-drc"]
gc-null = ["gc", "wasmtime/gc-null", "wasmtime-cli-flags/gc-null"]
pulley = ["wasmtime-cli-flags/pulley"]
stack-switching = ["wasmtime/stack-switching", "wasmtime-cli-flags/stack-switching"]
debug = ["wasmtime-cli-flags/debug", "wasmtime/debug"]
debug = ["wasmtime-cli-flags/debug", "wasmtime/debug", "component-model"]

# CLI subcommands for the `wasmtime` executable. See `wasmtime $cmd --help`
# for more information on each subcommand.
Expand All @@ -591,6 +592,7 @@ run = [
"dep:tokio",
"wasmtime-cli-flags/async",
"wasmtime-wasi-http?/p2",
"dep:wasmtime-debugger",
]
completion = ["dep:clap_complete"]
objdump = [
Expand Down
9 changes: 9 additions & 0 deletions ci/vendor-wit.sh
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,15 @@ wkg get --format wit --overwrite "wasi:random@$p3" -o "crates/wasi-http/src/p3/w
wkg get --format wit --overwrite "wasi:sockets@$p3" -o "crates/wasi-http/src/p3/wit/deps/sockets.wit"
wkg get --format wit --overwrite "wasi:http@$p3" -o "crates/wasi-http/src/p3/wit/deps/http.wit"

rm -rf crates/debugger/wit/deps
mkdir -p crates/debugger/wit/deps
wkg get --format wit --overwrite "wasi:io@$p2" -o "crates/debugger/wit/deps/io.wit"
wkg get --format wit --overwrite "wasi:clocks@$p2" -o "crates/debugger/wit/deps/clocks.wit"
wkg get --format wit --overwrite "wasi:cli@$p2" -o "crates/debugger/wit/deps/cli.wit"
wkg get --format wit --overwrite "wasi:filesystem@$p2" -o "crates/debugger/wit/deps/filesystem.wit"
wkg get --format wit --overwrite "wasi:random@$p2" -o "crates/debugger/wit/deps/random.wit"
wkg get --format wit --overwrite "wasi:sockets@$p2" -o "crates/debugger/wit/deps/sockets.wit"

# wasi-nn is fetched separately since it's not in the standard WASI registry
repo=https://raw.githubusercontent.com/WebAssembly/wasi-nn
revision=0.2.0-rc-2024-10-28
Expand Down
22 changes: 22 additions & 0 deletions crates/cli-flags/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,22 @@ wasmtime_option_group! {
pub log_to_files: Option<bool>,
/// Enable coredump generation to this file after a WebAssembly trap.
pub coredump: Option<String>,
/// Load the given debugger component and attach it to the
/// main module or component.
pub debugger: Option<PathBuf>,
/// Pass the given command-line arguments to the debugger
/// component. May be specified multiple times.
#[serde(default)]
pub arg: Vec<String>,
/// Allow the debugger component to inherit stdin.Off by
/// default.
pub inherit_stdin: Option<bool>,
/// Allow the debugger component to inherit stdout. Off by
/// default.
pub inherit_stdout: Option<bool>,
/// Allow the debugger component to inherit stderr. Off by
/// default.
pub inherit_stderr: Option<bool>,
}

enum Debug {
Expand Down Expand Up @@ -491,6 +507,12 @@ wasmtime_option_group! {
///
/// This option can be further overwritten with `--env` flags.
pub inherit_env: Option<bool>,
/// Inherit stdin from the parent process. On by default.
pub inherit_stdin: Option<bool>,
/// Inherit stdout from the parent process. On by default.
pub inherit_stdout: Option<bool>,
/// Inherit stderr from the parent process. On by default.
pub inherit_stderr: Option<bool>,
/// Pass a wasi config variable to the program.
#[serde(skip)]
pub config_var: Vec<KeyValuePair>,
Expand Down
16 changes: 16 additions & 0 deletions crates/cli-flags/src/opt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ use crate::{KeyValuePair, WasiNnGraph};
use clap::builder::{StringValueParser, TypedValueParser, ValueParserFactory};
use clap::error::{Error, ErrorKind};
use serde::de::{self, Visitor};
use std::path::PathBuf;
use std::str::FromStr;
use std::time::Duration;
use std::{fmt, marker};
use wasmtime::{Result, bail};
Expand Down Expand Up @@ -344,6 +346,20 @@ impl WasmtimeOptionValue for String {
}
}

impl WasmtimeOptionValue for PathBuf {
const VAL_HELP: &'static str = "=path";
fn parse(val: Option<&str>) -> Result<Self> {
match val {
Some(val) => Ok(PathBuf::from_str(val)?),
None => bail!("value must be specified with key=val syntax"),
}
}

fn display(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "{self:?}")
}
}

impl WasmtimeOptionValue for u32 {
const VAL_HELP: &'static str = "=N";
fn parse(val: Option<&str>) -> Result<Self> {
Expand Down
5 changes: 4 additions & 1 deletion crates/debugger/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,12 @@ rust-version.workspace = true
workspace = true

[dependencies]
wasmtime = { workspace = true, features = ["debug", "std", "async"] }
wasmtime = { workspace = true, features = ["debug", "std", "async", "component-model", "gc", "gc-drc"] }
wasmtime-wasi = { workspace = true }
wasmtime-wasi-io = { workspace = true }
tokio = { workspace = true, features = ["rt", "sync", "macros"] }
log = { workspace = true }
async-trait = { workspace = true }

[dev-dependencies]
# Depend on `wasmtime` again to get `cranelift` and `wat` so we can
Expand Down
38 changes: 38 additions & 0 deletions crates/debugger/src/host.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
//! Host implementation for the debugger world.

use wasmtime::{
Result,
component::{Resource, ResourceTable},
};

mod api;
mod bindings;
mod opaque;

pub use api::Debuggee;
pub use bindings::DebugMain as DebuggerComponent;
pub use bindings::bytecodealliance::wasmtime::debuggee as wit;
use opaque::OpaqueDebugger;

/// Register a debuggee in a resource table.
pub fn add_debuggee<T: Send + 'static>(
table: &mut ResourceTable,
debuggee: crate::Debuggee<T>,
) -> Result<Resource<Debuggee>> {
let engine = debuggee.engine().clone();
let interrupt_pending = debuggee.interrupt_pending().clone();
let inner: Option<Box<dyn OpaqueDebugger + Send + 'static>> = Some(Box::new(debuggee));
Ok(table.push(Debuggee {
inner,
engine,
interrupt_pending,
})?)
}

/// Add the debugger world's host functions to a [`wasmtime::component::Linker`].
pub fn add_to_linker<T: Send + 'static>(
linker: &mut wasmtime::component::Linker<T>,
f: fn(&mut T) -> &mut ResourceTable,
) -> wasmtime::Result<()> {
wit::add_to_linker::<_, wasmtime::component::HasSelf<ResourceTable>>(linker, f)
}
Loading
Loading