Skip to content

Commit c68b395

Browse files
committed
fix: compilation on wasip2
WASI strings are UTF8, so we don't need the nightly-only APIs. See rust-lang/rust#130323 as well.
1 parent 6a6ed99 commit c68b395

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-2
lines changed

newsfragments/5368.fixed.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fix compilation on `wasm32-wasip2`.

src/conversions/std/osstr.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ impl<'py> IntoPyObject<'py> for &OsStr {
2323
#[cfg(not(windows))]
2424
{
2525
#[cfg(target_os = "wasi")]
26-
let bytes = std::os::wasi::ffi::OsStrExt::as_bytes(self);
26+
let bytes = self.to_str().expect("wasi strings are UTF8").as_bytes();
2727
#[cfg(not(target_os = "wasi"))]
2828
let bytes = std::os::unix::ffi::OsStrExt::as_bytes(self);
2929

@@ -87,9 +87,11 @@ impl FromPyObject<'_, '_> for OsString {
8787
};
8888

8989
// Create an OsStr view into the raw bytes from Python
90+
//
91+
// For WASI: OS strings are UTF-8 by definition.
9092
#[cfg(target_os = "wasi")]
9193
let os_str: &OsStr =
92-
std::os::wasi::ffi::OsStrExt::from_bytes(fs_encoded_bytes.as_bytes(ob.py()));
94+
OsStr::new(std::str::from_utf8(fs_encoded_bytes.as_bytes(ob.py()))?);
9395
#[cfg(not(target_os = "wasi"))]
9496
let os_str: &OsStr =
9597
std::os::unix::ffi::OsStrExt::from_bytes(fs_encoded_bytes.as_bytes(ob.py()));

0 commit comments

Comments
 (0)