Skip to content
Merged
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions newsfragments/5368.fixed.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix compilation on `wasm32-wasip2`.
6 changes: 4 additions & 2 deletions src/conversions/std/osstr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ impl<'py> IntoPyObject<'py> for &OsStr {
#[cfg(not(windows))]
{
#[cfg(target_os = "wasi")]
let bytes = std::os::wasi::ffi::OsStrExt::as_bytes(self);
let bytes = self.to_str().expect("wasi strings are UTF8").as_bytes();
#[cfg(not(target_os = "wasi"))]
let bytes = std::os::unix::ffi::OsStrExt::as_bytes(self);

Expand Down Expand Up @@ -87,9 +87,11 @@ impl FromPyObject<'_, '_> for OsString {
};

// Create an OsStr view into the raw bytes from Python
//
// For WASI: OS strings are UTF-8 by definition.
#[cfg(target_os = "wasi")]
let os_str: &OsStr =
std::os::wasi::ffi::OsStrExt::from_bytes(fs_encoded_bytes.as_bytes(ob.py()));
OsStr::new(std::str::from_utf8(fs_encoded_bytes.as_bytes(ob.py()))?);
#[cfg(not(target_os = "wasi"))]
let os_str: &OsStr =
std::os::unix::ffi::OsStrExt::from_bytes(fs_encoded_bytes.as_bytes(ob.py()));
Expand Down
Loading