Repository navigation
Add stdout and stderr callbacks to WasiConfiguration - #391
Merged
Merged
Conversation
martindevans
force-pushed
the
wasi-custom-output
branch
from
October 25, 2026 13:42
2b0e4d5 to
2a31d44
Compare
Member
|
Thanks for putting this together, just waiting for CI to finish before merging it :) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
A guest's stdout and stderr could only be discarded, inherited or written to a file, so a host that wants guest output in its own logs (a Rust panic message, for instance) had to go through a temporary file.
wasi_config_set_stdout_customandwasi_config_set_stderr_customtake a callback instead, but were unbound.WasiConfiguration.WithStandardOutputCallbackandWithStandardErrorCallbackbind them with aWasiOutputCallback(ReadOnlySpan<byte>). The trampoline is rooted by aGCHandlethat Wasmtime frees through the finalizer when the WASI context is dropped. Like the existing stdio setters, each replaces any file or inheritance previously set for that stream.Two behaviours come from Wasmtime rather than the binding, and are documented on the delegate:
Covered by tests for both streams (with a forced GC between configuration and the guest's write), a throwing callback failing the write, and a later file setter replacing the callback.