Skip to content

Commit 53d5b0c

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

File tree

1 file changed

+12
-10
lines changed

1 file changed

+12
-10
lines changed

url/src/lib.rs

Lines changed: 12 additions & 10 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,8 @@ fn file_url_segments_to_pathbuf(
29972998
) -> Result<PathBuf, ()> {
29982999
use alloc::vec::Vec;
29993000
use percent_encoding::percent_decode;
3000-
use std::ffi::OsStr;
30013001
#[cfg(any(unix, target_os = "redox"))]
30023002
use std::os::unix::prelude::OsStrExt;
3003-
#[cfg(target_os = "wasi")]
3004-
use std::os::wasi::prelude::OsStrExt;
30053003
use std::path::PathBuf;
30063004

30073005
if host.is_some() {
@@ -3027,8 +3025,12 @@ fn file_url_segments_to_pathbuf(
30273025
bytes.push(b'/');
30283026
}
30293027

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

30333035
debug_assert!(
30343036
path.is_absolute(),

0 commit comments

Comments
 (0)