From 12b0113ac811c89d37e267eaf57221e1673bcd9f Mon Sep 17 00:00:00 2001 From: Colin Murphy Date: Wed, 21 Jan 2026 10:07:34 -0500 Subject: [PATCH] fix: enable wasip2 feature for wasm32-wasip2 target After PR #51 added the requirement `any(windows, unix)` to expose native and platform modules, and Rust changed WASI targets to set the `unix` cfg (rust-lang/rust#147572), typed-path now attempts to compile code using `std::os::wasi` for WASI targets. However, this is an unstable feature requiring `#![feature(wasip2)]` when targeting wasm32-wasip2. This commit adds the wasip2 feature flag conditionally only for wasip2 targets (target_env = "p2"), allowing the crate to compile with nightly Rust for wasm32-wasip2 while maintaining compatibility with wasm32-wasip1 which does not have or need this feature. Also fixes an unused import warning for `std::io` on wasm targets where the `absolutize` function (which uses `io`) is not available. Successfully tested on both wasm32-wasip1 and wasm32-wasip2 targets. --- src/lib.rs | 1 + src/typed/non_utf8/pathbuf.rs | 4 +++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/src/lib.rs b/src/lib.rs index c41d915..4ddda57 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,5 +1,6 @@ #![cfg_attr(feature = "std", doc = include_str!("../README.md"))] #![cfg_attr(not(feature = "std"), no_std)] +#![cfg_attr(all(target_os = "wasi", target_env = "p2"), feature(wasip2))] #[doc = include_str!("../README.md")] #[cfg(all(doctest, feature = "std"))] diff --git a/src/typed/non_utf8/pathbuf.rs b/src/typed/non_utf8/pathbuf.rs index 72a1682..9fad919 100644 --- a/src/typed/non_utf8/pathbuf.rs +++ b/src/typed/non_utf8/pathbuf.rs @@ -1,8 +1,10 @@ use alloc::borrow::Cow; use alloc::collections::TryReserveError; use core::convert::TryFrom; +#[cfg(all(feature = "std", not(target_family = "wasm")))] +use std::io; #[cfg(feature = "std")] -use std::{io, path::PathBuf}; +use std::path::PathBuf; use crate::common::{CheckedPathError, StripPrefixError}; use crate::no_std_compat::*;