Skip to content

Commit ec99fe5

Browse files
committed
fix: enable wasip2 feature for wasm32-wasip2 target
After PR chipsenkbeil#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. Tested on both wasm32-wasip1 and wasm32-wasip2 targets - all 160 tests pass on both platforms.
1 parent 8f6f9e7 commit ec99fe5

2 files changed

Lines changed: 4 additions & 1 deletion

File tree

src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#![cfg_attr(feature = "std", doc = include_str!("../README.md"))]
22
#![cfg_attr(not(feature = "std"), no_std)]
3+
#![cfg_attr(all(target_os = "wasi", target_env = "p2"), feature(wasip2))]
34

45
#[doc = include_str!("../README.md")]
56
#[cfg(all(doctest, feature = "std"))]

src/typed/non_utf8/pathbuf.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
use alloc::borrow::Cow;
22
use alloc::collections::TryReserveError;
33
use core::convert::TryFrom;
4+
#[cfg(all(feature = "std", not(target_family = "wasm")))]
5+
use std::io;
46
#[cfg(feature = "std")]
5-
use std::{io, path::PathBuf};
7+
use std::path::PathBuf;
68

79
use crate::common::{CheckedPathError, StripPrefixError};
810
use crate::no_std_compat::*;

0 commit comments

Comments
 (0)