Эх сурвалжийг харах

fix: support wasm32-wasip2 on stable channel (#983)

Signed-off-by: Brooks Townsend <brooksmtownsend@gmail.com>
Brooks Townsend 1 жил өмнө
parent
commit
30e62589c7
1 өөрчлөгдсөн 13 нэмэгдсэн , 9 устгасан
  1. 13 9
      url/src/lib.rs

+ 13 - 9
url/src/lib.rs

@@ -148,9 +148,6 @@ url = { version = "2", features = ["debugger_visualizer"] }
     feature = "debugger_visualizer",
     feature = "debugger_visualizer",
     debugger_visualizer(natvis_file = "../../debug_metadata/url.natvis")
     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;
 pub use form_urlencoded;
 
 
@@ -2985,8 +2982,6 @@ fn path_to_file_url_segments(
     use std::os::hermit::ffi::OsStrExt;
     use std::os::hermit::ffi::OsStrExt;
     #[cfg(any(unix, target_os = "redox"))]
     #[cfg(any(unix, target_os = "redox"))]
     use std::os::unix::prelude::OsStrExt;
     use std::os::unix::prelude::OsStrExt;
-    #[cfg(target_os = "wasi")]
-    use std::os::wasi::prelude::OsStrExt;
     if !path.is_absolute() {
     if !path.is_absolute() {
         return Err(());
         return Err(());
     }
     }
@@ -2996,10 +2991,16 @@ fn path_to_file_url_segments(
     for component in path.components().skip(1) {
     for component in path.components().skip(1) {
         empty = false;
         empty = false;
         serialization.push('/');
         serialization.push('/');
+        #[cfg(not(target_os = "wasi"))]
         serialization.extend(percent_encode(
         serialization.extend(percent_encode(
             component.as_os_str().as_bytes(),
             component.as_os_str().as_bytes(),
             SPECIAL_PATH_SEGMENT,
             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 {
     if empty {
         // An URL’s path must not be empty.
         // An URL’s path must not be empty.
@@ -3093,13 +3094,12 @@ fn file_url_segments_to_pathbuf(
 ) -> Result<PathBuf, ()> {
 ) -> Result<PathBuf, ()> {
     use alloc::vec::Vec;
     use alloc::vec::Vec;
     use percent_encoding::percent_decode;
     use percent_encoding::percent_decode;
+    #[cfg(not(target_os = "wasi"))]
     use std::ffi::OsStr;
     use std::ffi::OsStr;
     #[cfg(target_os = "hermit")]
     #[cfg(target_os = "hermit")]
     use std::os::hermit::ffi::OsStrExt;
     use std::os::hermit::ffi::OsStrExt;
     #[cfg(any(unix, target_os = "redox"))]
     #[cfg(any(unix, target_os = "redox"))]
     use std::os::unix::prelude::OsStrExt;
     use std::os::unix::prelude::OsStrExt;
-    #[cfg(target_os = "wasi")]
-    use std::os::wasi::prelude::OsStrExt;
     use std::path::PathBuf;
     use std::path::PathBuf;
 
 
     if host.is_some() {
     if host.is_some() {
@@ -3125,8 +3125,12 @@ fn file_url_segments_to_pathbuf(
         bytes.push(b'/');
         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!(
     debug_assert!(
         path.is_absolute(),
         path.is_absolute(),