-
Notifications
You must be signed in to change notification settings - Fork 905
fix: compilation on wasip2 #5368
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: compilation on wasip2 #5368
Conversation
d65bd04 to
1c31705
Compare
|
I think we can make this work on stable. As OsStr coming from the wasip2 is guaranteed to be valid utf8. So |
|
Good point. I think this should work, but can you check that this makes sense to you? OS => byteslet bytes = std::os::wasi::ffi::OsStrExt::as_bytes(self);in WASI should just be let bytes = self.as_encoded_bytes(); // WASI strings are UTF8? bytes => OSlet os_str: &OsStr =
std::os::wasi::ffi::OsStrExt::from_bytes(fs_encoded_bytes.as_bytes(ob.py()));should be let os_str: &OsStr = OsStr::new(
str::from_utf8(fs_encoded_bytes.as_bytes(ob.py()))?
);(using this error conversion) |
|
Using Maybe an other maintainer has some more insight in possible failure cases. |
|
If we expect utf8 to always be the case, perhaps it's good enough to panic in this instance for now? I.e. to OS => bytes conversion can be let bytes = self.to_str().expect("wasi strings are UTF8").as_bytes(); |
1c31705 to
1c5f96e
Compare
1c5f96e to
0882789
Compare
WASI strings are UTF8, so we don't need the nightly-only APIs. See rust-lang/rust#130323 as well.
0882789 to
c68b395
Compare
|
This now uses the proposed stable-Rust conversation routines and is ready for another round of reviews. |
davidhewitt
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for reporting and fixing!
WASI strings are UTF8, so we don't need the nightly-only APIs. See rust-lang/rust#130323 as well.
Before this change, pyo3 cannot be compiled for wasip2:
(you can also use a nightly compiler and/or add
--features=nightly, this won't change anything)Now it can be compiled with:
It's a bit sad that this requires nightly, but until rust-lang/rust#130323 is fixed, we cannot do much about it. A similar workaround was chosen by
tempfile.