Skip to content

Commit fc447cc

Browse files
fix: support wasm32-wasip2 on stable channel
Signed-off-by: Brooks Townsend <[email protected]>
1 parent ebd5cfb commit fc447cc

File tree

1 file changed

+13
-9
lines changed

1 file changed

+13
-9
lines changed

url/src/lib.rs

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -148,9 +148,6 @@ url = { version = "2", features = ["debugger_visualizer"] }
148148
feature = "debugger_visualizer",
149149
debugger_visualizer(natvis_file = "../../debug_metadata/url.natvis")
150150
)]
151-
// We use std::os::wasi::prelude::OsStrExt, and that is conditionally feature gated
152-
// to be unstable on wasm32-wasip2. https://github.com/rust-lang/rust/issues/130323
153-
#![cfg_attr(all(target_os = "wasi", target_env = "p2"), feature(wasip2))]
154151

155152
pub use form_urlencoded;
156153

@@ -2892,8 +2889,6 @@ fn path_to_file_url_segments(
28922889
use percent_encoding::percent_encode;
28932890
#[cfg(any(unix, target_os = "redox"))]
28942891
use std::os::unix::prelude::OsStrExt;
2895-
#[cfg(target_os = "wasi")]
2896-
use std::os::wasi::prelude::OsStrExt;
28972892
if !path.is_absolute() {
28982893
return Err(());
28992894
}
@@ -2903,10 +2898,16 @@ fn path_to_file_url_segments(
29032898
for component in path.components().skip(1) {
29042899
empty = false;
29052900
serialization.push('/');
2901+
#[cfg(not(target_os = "wasi"))]
29062902
serialization.extend(percent_encode(
29072903
component.as_os_str().as_bytes(),
29082904
SPECIAL_PATH_SEGMENT,
29092905
));
2906+
#[cfg(target_os = "wasi")]
2907+
serialization.extend(percent_encode(
2908+
component.as_os_str().to_string_lossy().as_bytes(),
2909+
SPECIAL_PATH_SEGMENT,
2910+
));
29102911
}
29112912
if empty {
29122913
// An URL’s path must not be empty.
@@ -2997,11 +2998,10 @@ fn file_url_segments_to_pathbuf(
29972998
) -> Result<PathBuf, ()> {
29982999
use alloc::vec::Vec;
29993000
use percent_encoding::percent_decode;
3001+
#[cfg(not(target_os = "wasi"))]
30003002
use std::ffi::OsStr;
30013003
#[cfg(any(unix, target_os = "redox"))]
30023004
use std::os::unix::prelude::OsStrExt;
3003-
#[cfg(target_os = "wasi")]
3004-
use std::os::wasi::prelude::OsStrExt;
30053005
use std::path::PathBuf;
30063006

30073007
if host.is_some() {
@@ -3027,8 +3027,12 @@ fn file_url_segments_to_pathbuf(
30273027
bytes.push(b'/');
30283028
}
30293029

3030-
let os_str = OsStr::from_bytes(&bytes);
3031-
let path = PathBuf::from(os_str);
3030+
#[cfg(not(target_os = "wasi"))]
3031+
let path = PathBuf::from(OsStr::from_bytes(&bytes));
3032+
#[cfg(target_os = "wasi")]
3033+
let path = String::from_utf8(bytes)
3034+
.map(|path| PathBuf::from(path))
3035+
.map_err(|_| ())?;
30323036

30333037
debug_assert!(
30343038
path.is_absolute(),

0 commit comments

Comments
 (0)