salmans opened PR #11152 from salmans:win-unix-no-std to bytecodealliance:main:
This PR fixes feature flag handling to properly respect the std feature when targeting Windows/Unix platforms.
Breaking Change: This fix will disable standard library features for dependents that use wasmtime with
default-features = false.Changes:
- Updated feature dependencies in
Cargo.tomlfiles to conditionally enable std-dependent features
- Added proper feature gating in runtime modules forno_stdcompatibility
- Modified VM system module to respect the std feature flag on Windows/Unix targetsThe fix ensures that when wasmtime is used without default features, it properly builds in
no_stdon all supported platforms.
salmans submitted PR review.
salmans created PR review comment:
It's not clear what the dependency on
rustixdoes here. The code compiles and passes all tests without it. Should we remove these lines?
salmans submitted PR review.
salmans created PR review comment:
We could implement and provide
no_stdvariations ofmod unixandmod windowsinstead of leaving it up to the user (These are the existing implementations: https://github.com/bytecodealliance/wasmtime/tree/main/crates/wasmtime/src/runtime/vm/sys).
salmans updated PR #11152.
salmans updated PR #11152.
salmans updated PR #11152.
alexcrichton commented on PR #11152:
Thanks for the PR! Could you elaborate on the motivation for this change as well? For example I'm not aware of a target that's
cfg(unix)orcfg(windows)and doesn't havestd.
salmans submitted PR review.
salmans created PR review comment:
I made this change to fix
cargo check -p wasmtime --no-default-features --features async,std(previouslycargo check -p wasmtime --no-default-features --features async) but I'm not sure if that's an expected behavior change.
salmans commented on PR #11152:
@alexcrichton I’m experimenting with running Wasmtime (with Pulley) in the Windows kernel. The goal is to use WebAssembly to enable limited changes to kernel logic without requiring a full software update or system restart. I’m exploring Wasm as a potential alternative to eBPF for Windows.
salmans has marked PR #11152 as ready for review.
salmans requested wasmtime-core-reviewers for a review on PR #11152.
salmans requested fitzgen for a review on PR #11152.
salmans requested wasmtime-default-reviewers for a review on PR #11152.
alexcrichton commented on PR #11152:
Oh nice! Do you know if there's a
#[cfg]specific to the target that you're working with that this could be keyed on instead offeature = "std"? While the breakage here isn't the end of the world and something we could document, I'd prefer to shape the change a bit differently. For example there's no testing on CI that a no_std build works on Linux/Windows so this is something that will likely easily regress over time.
bjorn3 submitted PR review.
bjorn3 created PR review comment:
mmap and the like is put behind the
mmfeature. It likely passes without because of the[target.'cfg(unix)'.dependencies] rustix = { workspace = true, optional = true, features = ["mm", "param"] }elsewhere in this file.
salmans commented on PR #11152:
No, I don't think there's any specific target for (windows/unix) kernel. But just to clarify, are you suggesting that turning off
stdshould still pull in standard library to avoid issues like the ones with CI? If so, an alternative solution that I can think of is to guard no_std with a new flag likeoverride-stdorforce-no-std.
alexcrichton submitted PR review:
Sorry I can be more clear, my concern was a big vague there. I originally had the gut reaction of "this feels weird" but I'm effectively getting over that gut reaction. There's still changes I'd like to see in this PR, but I can try to be more clear about them. I've left various review comments below.
alexcrichton created PR review comment:
One change I'd like to see in this PR is that the
stdfeature should not be necessary to just build the crate, even on Linux/Windows targets. In essence these CI changes shouldn't be necessary.I tested locally and sketched out https://github.com/salmans/wasmtime/pull/1 which I believe would enable backing out these CI changes and would ensure that
stdis not a necessary feature even on Linux/Windows targets.
alexcrichton created PR review comment:
Can you clarify why this change was necessary? I believe the
stdfeature here is off-by-default and never enabled by Wasmtime?
alexcrichton created PR review comment:
Mind applying this diff:
diff --git a/crates/wasmtime/src/runtime/fiber.rs b/crates/wasmtime/src/runtime/fiber.rs index 4dcd59e532..8aa0033c4f 100644 --- a/crates/wasmtime/src/runtime/fiber.rs +++ b/crates/wasmtime/src/runtime/fiber.rs @@ -343,9 +343,7 @@ impl<T> StoreContextMut<'_, T> { self, f: impl FnOnce(StoreContextMut<'_, T>) -> Pin<Box<dyn Future<Output = R> + Send + '_>>, ) -> Result<R> { - BlockingContext::with(self.0, |store, cx| { - cx.block_on(f(StoreContextMut(store)).as_mut()) - }) + self.with_blocking(|store, cx| cx.block_on(f(store).as_mut())) } /// Creates a `BlockingContext` suitable for blocking on futures or @@ -354,7 +352,6 @@ impl<T> StoreContextMut<'_, T> { /// # Panics /// /// Panics if this is invoked outside the context of a fiber. - #[allow(dead_code)] pub(crate) fn with_blocking<R>( self, f: impl FnOnce(StoreContextMut<'_, T>, &mut BlockingContext<'_, '_>) -> R,to work around the need for the annotation? A bit of a hack but hopefully not too bad.
alexcrichton created PR review comment:
Yeah it's fine to drop
rustix/mmhere due to our preexisting dep directive and ifdep:rustixcan be dropped that also seems reasonable. It's perhaps already included elsewhere.
alexcrichton created PR review comment:
While theoretically possible this would primarily require an implementation of TLS in a no_std context which, as far as I know, isn't available?
salmans updated PR #11152.
salmans submitted PR review.
salmans created PR review comment:
Thanks you!
salmans submitted PR review.
salmans created PR review comment:
You're right, we don't need that change. My bad!
alexcrichton requested alexcrichton for a review on PR #11152.
salmans updated PR #11152.
salmans updated PR #11152.
salmans submitted PR review.
salmans created PR review comment:
The change resolves almost all CI issues except for stack switching checks: https://github.com/bytecodealliance/wasmtime/actions/runs/15983572956/job/45083266148?pr=11152
salmans updated PR #11152.
salmans commented on PR #11152:
@alexcrichton after more experimentation on Windows, I realized
win.rsinjit-icache-coherencepullsstd. I'm happy to explore a no_std implementation for it in a separate PR but for now, I just pushed a new commit to disable icache coherence in Windows no_std. If that change makes sense, I'm going to address the remaining CI issues before finalizing the PR. Thanks again for your help!
alexcrichton commented on PR #11152:
For the stack switching issues can you update the
stack-switchingcargo feature to requirestd?
salmans updated PR #11152.
salmans updated PR #11152.
salmans updated PR #11152.
alexcrichton created PR review comment:
For this it's a pretty critical operation here to manage the icache so we'll want to avoid this
#[cfg]which makes it difficult to see when it's used and when it isn't. I think the best solution here might be to sidestep the problem entirely and update this line to take thestdfeature into account. For example that could be(unix || windows) && cfg!(feature = "std")or something like that. A comment there would be good to explain that ifstdis disabled then it's not supported in Wasmtime right now to interact with the OS which means that it's no longer supported.
alexcrichton submitted PR review.
salmans submitted PR review.
salmans created PR review comment:
I tried that change but it doesn't solve the problem: Wasmtime still pulls
stdthroughjit-icache-coherenceinno_stdWindows.
Another possible solution is to uselibcinjit-icache-coherenceforno_stdWindows at this line. For that, we could add a newstdfeature flag tojit-icache-coherenceand enable it ifstdinwasmtimeis enabled.
salmans updated PR #11152.
salmans submitted PR review.
salmans created PR review comment:
I just pushed a new commit that implements the change suggested above but happy to implement a different solution if this is problematic.
alexcrichton updated PR #11152.
alexcrichton submitted PR review.
alexcrichton created PR review comment:
Your commit looks reasonable, thanks for doing that! I'll apologize again though about how this is a bit messy. I'd prefer to avoid having the crate be sort of half-std/half-not, so I think I've come up with an idea to sidestep this entirely which is to include the icache crate only if
stdis enabled in Wasmtime itself. That solves the concerns I have about things getting a bit weird sometimes and the only remaining issue is various CI bits and how well this works out. I've pushed up a commit to this PR which implements what I was thinking of and I'll watch CI to see if my strategy won't work due to something I haven't thought of
alexcrichton updated PR #11152.
alexcrichton updated PR #11152.
alexcrichton updated PR #11152.
salmans submitted PR review.
salmans created PR review comment:
Not at all! I appreciate your help and the time you've put into this. Okay, I'll wait for CI and merge the changes into the branch as soon as I see green. Thanks again!
salmans edited PR review comment.
salmans submitted PR review.
salmans created PR review comment:
Yes, that's right. I'm resolving this for now but will explore that space for a potential future PR.
alexcrichton submitted PR review.
alexcrichton has enabled auto merge for PR #11152.
alexcrichton merged PR #11152.
Last updated: Dec 06 2025 at 06:05 UTC