-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Make rustpython-vm compatible with non-js wasm32-unknown & add tests #4211
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,7 +19,7 @@ impl VirtualMachine { | |
self.flush_std(); | ||
panic!("{msg}") | ||
} | ||
#[cfg(all(target_arch = "wasm32", not(target_os = "wasi")))] | ||
#[cfg(all(target_arch = "wasm32", feature = "js", not(target_os = "wasi")))] | ||
{ | ||
use wasm_bindgen::prelude::*; | ||
#[wasm_bindgen] | ||
|
@@ -32,6 +32,11 @@ impl VirtualMachine { | |
error(&s); | ||
panic!("{}; exception backtrace above", msg) | ||
} | ||
#[cfg(all(target_arch = "wasm32", not(feature = "js"), not(target_os = "wasi")))] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Wouldn't it be useful to still see information from the exception? Can't you do something like: let err_string: String = exc.to_pyobject(vm).repr(vm).unwrap().to_string(); Or does the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It will be useful |
||
{ | ||
let _ = exc; | ||
panic!("{}; python exception not available", msg) | ||
} | ||
} | ||
|
||
pub(crate) fn flush_std(&self) { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
[package] | ||
name = "wasm-unknown-test" | ||
version = "0.1.0" | ||
edition = "2021" | ||
|
||
[lib] | ||
crate-type = ["cdylib"] | ||
|
||
[dependencies] | ||
getrandom = { version = "0.2.12", features = ["custom"] } | ||
rustpython-vm = { path = "../../vm", default-features = false, features = ["compiler"] } | ||
|
||
[workspace] |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
A test crate to ensure that `rustpython-vm` compiles on `wasm32-unknown-unknown` without a JS host. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
use rustpython_vm::{eval, Interpreter}; | ||
|
||
pub unsafe extern "C" fn eval(s: *const u8, l: usize) -> u32 { | ||
let src = std::slice::from_raw_parts(s, l); | ||
let src = std::str::from_utf8(src).unwrap(); | ||
Interpreter::without_stdlib(Default::default()).enter(|vm| { | ||
let res = eval::eval(vm, src, vm.new_scope_with_builtins(), "<string>").unwrap(); | ||
res.try_into_value(vm).unwrap() | ||
}) | ||
} | ||
|
||
fn getrandom_always_fail(_buf: &mut [u8]) -> Result<(), getrandom::Error> { | ||
Err(getrandom::Error::UNSUPPORTED) | ||
} | ||
|
||
getrandom::register_custom_getrandom!(getrandom_always_fail); |
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.
I will need a way to implement time, I have the APIs in my environment, but I will need a way to override this