From 0af3f6da9d3eff1727c69d6096710381d18185ec Mon Sep 17 00:00:00 2001 From: Jordan Last Date: Fri, 9 Dec 2022 12:13:12 -0600 Subject: [PATCH 1/5] make the vm public --- vm/src/vm/interpreter.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/vm/src/vm/interpreter.rs b/vm/src/vm/interpreter.rs index 8d0d85ea5c..75f4d4eb31 100644 --- a/vm/src/vm/interpreter.rs +++ b/vm/src/vm/interpreter.rs @@ -22,7 +22,7 @@ use std::sync::atomic::Ordering; /// }); /// ``` pub struct Interpreter { - vm: VirtualMachine, + pub vm: VirtualMachine, } impl Interpreter { From 491a3a6d79eb00c8979fff45ab5f33c39b900f8d Mon Sep 17 00:00:00 2001 From: Jordan Last Date: Fri, 9 Dec 2022 12:21:43 -0600 Subject: [PATCH 2/5] attempt to update dependencies --- vm/Cargo.toml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/vm/Cargo.toml b/vm/Cargo.toml index e84739db3a..98148f02f4 100644 --- a/vm/Cargo.toml +++ b/vm/Cargo.toml @@ -38,11 +38,11 @@ num-traits = "0.2.14" num-integer = "0.1.44" num-rational = "0.4.0" rand = "0.8.5" -getrandom = { version = "0.2.6", features = ["js"] } +getrandom = { version = "0.2.6", features = ["custom"] } log = "0.4.16" serde = { version = "1.0.136", features = ["derive"] } caseless = "0.2.1" -chrono = { version = "0.4.19", features = ["wasmbind"] } +chrono = { version = "0.4.19" } itertools = "0.10.3" hex = "0.4.3" hexf-parse = "0.2.1" From 948bc67b386f223076d8d8ee35deac0853d81cf2 Mon Sep 17 00:00:00 2001 From: Jordan Last Date: Fri, 9 Dec 2022 12:46:08 -0600 Subject: [PATCH 3/5] get rid of RustPython --- vm/Cargo.toml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/vm/Cargo.toml b/vm/Cargo.toml index 98148f02f4..7d79e44af9 100644 --- a/vm/Cargo.toml +++ b/vm/Cargo.toml @@ -126,8 +126,8 @@ features = [ "impl-default", "vcruntime", "ifdef", "netioapi", "memoryapi", ] -[target.'cfg(target_arch = "wasm32")'.dependencies] -wasm-bindgen = "0.2.80" +# [target.'cfg(target_arch = "wasm32")'.dependencies] +# wasm-bindgen = "0.2.80" [build-dependencies] itertools = "0.10.3" From ba523faea148b82e37eb3028e56f32c91186c56a Mon Sep 17 00:00:00 2001 From: Jordan Last Date: Fri, 9 Dec 2022 12:54:27 -0600 Subject: [PATCH 4/5] attempt to get everything to compile and deploy --- vm/Cargo.toml | 3 ++- vm/src/stdlib/time.rs | 35 +++++++++++++++++++++++------------ vm/src/vm/vm_object.rs | 21 +++++++++++---------- 3 files changed, 36 insertions(+), 23 deletions(-) diff --git a/vm/Cargo.toml b/vm/Cargo.toml index 7d79e44af9..299807cacc 100644 --- a/vm/Cargo.toml +++ b/vm/Cargo.toml @@ -42,7 +42,7 @@ getrandom = { version = "0.2.6", features = ["custom"] } log = "0.4.16" serde = { version = "1.0.136", features = ["derive"] } caseless = "0.2.1" -chrono = { version = "0.4.19" } +chrono = { version = "=0.4.19" } itertools = "0.10.3" hex = "0.4.3" hexf-parse = "0.2.1" @@ -71,6 +71,7 @@ flate2 = "1.0.23" once_cell = "1.10.0" memoffset = "0.6.5" optional = "0.5.0" +ic-cdk = "0.6.8" # RustPython crates implementing functionality based on CPython sre-engine = "0.4.1" diff --git a/vm/src/stdlib/time.rs b/vm/src/stdlib/time.rs index ce1f4d88a0..bb40baa3b9 100644 --- a/vm/src/stdlib/time.rs +++ b/vm/src/stdlib/time.rs @@ -91,15 +91,17 @@ mod time { #[cfg(all(target_arch = "wasm32", not(target_os = "wasi")))] fn _time(_vm: &VirtualMachine) -> PyResult { - use wasm_bindgen::prelude::*; - #[wasm_bindgen] - extern "C" { - type Date; - #[wasm_bindgen(static_method_of = Date)] - fn now() -> f64; - } - // Date.now returns unix time in milliseconds, we want it in seconds - Ok(Date::now() / 1000.0) + // use wasm_bindgen::prelude::*; + // #[wasm_bindgen] + // extern "C" { + // type Date; + // #[wasm_bindgen(static_method_of = Date)] + // fn now() -> f64; + // } + // // Date.now returns unix time in milliseconds, we want it in seconds + // Ok(Date::now() / 1000.0) + + Ok(ic_cdk::api::time() as f64 / 1_000_000_000 as f64) } #[pyfunction] @@ -144,14 +146,20 @@ mod time { fn naive_or_local(self, vm: &VirtualMachine) -> PyResult { Ok(match self { OptionalArg::Present(secs) => pyobj_to_naive_date_time(secs, vm)?, - OptionalArg::Missing => chrono::offset::Local::now().naive_local(), + OptionalArg::Missing => chrono::NaiveDateTime::from_timestamp( + (ic_cdk::api::time() / 1_000_000_000) as i64, + 0, + ), }) } fn naive_or_utc(self, vm: &VirtualMachine) -> PyResult { Ok(match self { OptionalArg::Present(secs) => pyobj_to_naive_date_time(secs, vm)?, - OptionalArg::Missing => chrono::offset::Utc::now().naive_utc(), + OptionalArg::Missing => chrono::NaiveDateTime::from_timestamp( + (ic_cdk::api::time() / 1_000_000_000) as i64, + 0, + ), }) } } @@ -160,7 +168,10 @@ mod time { fn naive_or_local(self, vm: &VirtualMachine) -> PyResult { Ok(match self { OptionalArg::Present(t) => t.to_date_time(vm)?, - OptionalArg::Missing => chrono::offset::Local::now().naive_local(), + OptionalArg::Missing => chrono::NaiveDateTime::from_timestamp( + (ic_cdk::api::time() / 1_000_000_000) as i64, + 0, + ), }) } } diff --git a/vm/src/vm/vm_object.rs b/vm/src/vm/vm_object.rs index b20c446b96..2a948abed2 100644 --- a/vm/src/vm/vm_object.rs +++ b/vm/src/vm/vm_object.rs @@ -42,16 +42,17 @@ impl VirtualMachine { } #[cfg(all(target_arch = "wasm32", not(target_os = "wasi")))] { - use wasm_bindgen::prelude::*; - #[wasm_bindgen] - extern "C" { - #[wasm_bindgen(js_namespace = console)] - fn error(s: &str); - } - let mut s = String::new(); - self.write_exception(&mut s, &exc).unwrap(); - error(&s); - panic!("{}; exception backtrace above", msg) + // use wasm_bindgen::prelude::*; + // #[wasm_bindgen] + // extern "C" { + // #[wasm_bindgen(js_namespace = console)] + // fn error(s: &str); + // } + // let mut s = String::new(); + // self.write_exception(&mut s, &exc).unwrap(); + // error(&s); + // panic!("{}; exception backtrace above", msg) + panic!("{}", msg) } } From 9ca024b30446249cc2a584543bbc658ab4b65c6f Mon Sep 17 00:00:00 2001 From: Jordan Last Date: Fri, 9 Dec 2022 12:58:13 -0600 Subject: [PATCH 5/5] update types --- stdlib/src/resource.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/stdlib/src/resource.rs b/stdlib/src/resource.rs index 1d3513f47d..37247196bd 100644 --- a/stdlib/src/resource.rs +++ b/stdlib/src/resource.rs @@ -149,7 +149,7 @@ mod resource { #[pyfunction] fn getrlimit(resource: i32, vm: &VirtualMachine) -> PyResult { - if resource < 0 || resource >= RLIM_NLIMITS as _ { + if resource < 0 || resource >= RLIM_NLIMITS as i32 { return Err(vm.new_value_error("invalid resource specified".to_owned())); } let rlimit = unsafe { @@ -164,7 +164,7 @@ mod resource { #[pyfunction] fn setrlimit(resource: i32, limits: Limits, vm: &VirtualMachine) -> PyResult<()> { - if resource < 0 || resource >= RLIM_NLIMITS as _ { + if resource < 0 || resource >= RLIM_NLIMITS as i32 { return Err(vm.new_value_error("invalid resource specified".to_owned())); } let res = unsafe {