Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: support wasm32-wasip2 on the stable channel #983

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 13 additions & 9 deletions url/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -148,9 +148,6 @@ url = { version = "2", features = ["debugger_visualizer"] }
feature = "debugger_visualizer",
debugger_visualizer(natvis_file = "../../debug_metadata/url.natvis")
)]
// We use std::os::wasi::prelude::OsStrExt, and that is conditionally feature gated
// to be unstable on wasm32-wasip2. https://github.com/rust-lang/rust/issues/130323
#![cfg_attr(all(target_os = "wasi", target_env = "p2"), feature(wasip2))]

pub use form_urlencoded;

Expand Down Expand Up @@ -2892,8 +2889,6 @@ fn path_to_file_url_segments(
use percent_encoding::percent_encode;
#[cfg(any(unix, target_os = "redox"))]
use std::os::unix::prelude::OsStrExt;
#[cfg(target_os = "wasi")]
use std::os::wasi::prelude::OsStrExt;
if !path.is_absolute() {
return Err(());
}
Expand All @@ -2903,10 +2898,16 @@ fn path_to_file_url_segments(
for component in path.components().skip(1) {
empty = false;
serialization.push('/');
#[cfg(not(target_os = "wasi"))]
serialization.extend(percent_encode(
component.as_os_str().as_bytes(),
SPECIAL_PATH_SEGMENT,
));
#[cfg(target_os = "wasi")]
serialization.extend(percent_encode(
component.as_os_str().to_string_lossy().as_bytes(),
SPECIAL_PATH_SEGMENT,
));
}
if empty {
// An URL’s path must not be empty.
Expand Down Expand Up @@ -2997,11 +2998,10 @@ fn file_url_segments_to_pathbuf(
) -> Result<PathBuf, ()> {
use alloc::vec::Vec;
use percent_encoding::percent_decode;
#[cfg(not(target_os = "wasi"))]
use std::ffi::OsStr;
#[cfg(any(unix, target_os = "redox"))]
use std::os::unix::prelude::OsStrExt;
#[cfg(target_os = "wasi")]
use std::os::wasi::prelude::OsStrExt;
use std::path::PathBuf;

if host.is_some() {
Expand All @@ -3027,8 +3027,12 @@ fn file_url_segments_to_pathbuf(
bytes.push(b'/');
}

let os_str = OsStr::from_bytes(&bytes);
let path = PathBuf::from(os_str);
#[cfg(not(target_os = "wasi"))]
let path = PathBuf::from(OsStr::from_bytes(&bytes));
#[cfg(target_os = "wasi")]
let path = String::from_utf8(bytes)
.map(|path| PathBuf::from(path))
.map_err(|_| ())?;

debug_assert!(
path.is_absolute(),
Expand Down
Loading