-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2193 from demergent-labs/rquickjs_move_crates
Rquickjs move crates
- Loading branch information
Showing
210 changed files
with
2,402 additions
and
314 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,6 @@ | ||
[workspace] | ||
members = ["src/build/rust/canister", "src/build/rust/open_value_sharing"] | ||
members = [ | ||
"src/build/experimental/commands/compile/wasm_binary/rust/experimental_canister_template", | ||
"src/build/experimental/commands/compile/wasm_binary/rust/open_value_sharing", | ||
"src/build/stable/commands/compile/wasm_binary/rust/stable_canister_template", | ||
] |
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
src/build/rust/canister/Cargo.toml → ...experimental_canister_template/Cargo.toml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
[package] | ||
name = "canister" | ||
name = "experimental_canister_template" | ||
version = "0.0.0" | ||
edition = "2018" | ||
|
||
|
File renamed without changes.
1 change: 0 additions & 1 deletion
1
src/build/rust/canister/src/benchmarking.rs → ...tal_canister_template/src/benchmarking.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 0 additions & 14 deletions
14
src/build/stable/commands/compile/wasm_binary/generate_cargo_toml_files.ts
This file was deleted.
Oops, something went wrong.
20 changes: 20 additions & 0 deletions
20
src/build/stable/commands/compile/wasm_binary/rust/stable_canister_template/Cargo.toml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
[package] | ||
name = "stable_canister_template" | ||
version = "0.0.0" | ||
edition = "2018" | ||
|
||
[lib] | ||
crate-type = ["cdylib"] | ||
|
||
[dependencies] | ||
candid = "0.10.2" | ||
candid_parser = "0.1.2" | ||
ic-cdk = "0.12.2" | ||
ic-cdk-macros = "0.8.4" | ||
ic-cdk-timers = "0.6.0" | ||
ic-stable-structures = "0.6.5" | ||
ic-wasi-polyfill = "0.6.1" | ||
rquickjs = { version = "0.6.2", features = ["array-buffer"] } | ||
serde = "1.0.202" | ||
serde_json = "1.0.107" | ||
slotmap = "=1.0.6" |
38 changes: 38 additions & 0 deletions
38
...ild/stable/commands/compile/wasm_binary/rust/stable_canister_template/src/benchmarking.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
use std::{cell::RefCell, error::Error}; | ||
|
||
use candid::CandidType; | ||
|
||
use crate::quickjs_with_ctx; | ||
|
||
#[derive(CandidType, Debug, Clone)] | ||
pub struct BenchmarkEntry { | ||
pub method_name: String, | ||
pub instructions: u64, | ||
pub timestamp: u64, | ||
} | ||
|
||
thread_local! { | ||
pub static BENCHMARKS_REF_CELL: RefCell<Vec<BenchmarkEntry>> = RefCell::new(Vec::new()); | ||
} | ||
|
||
pub fn record_benchmark(function_name: &str, instructions: u64) -> Result<(), Box<dyn Error>> { | ||
quickjs_with_ctx(|ctx| { | ||
let timestamp = ic_cdk::api::time(); | ||
|
||
let method_names: rquickjs::Object = | ||
ctx.clone().globals().get("_azleCanisterMethodNames")?; | ||
|
||
let method_name: String = method_names.get(function_name)?; | ||
|
||
BENCHMARKS_REF_CELL.with(|benchmarks_ref_cell| { | ||
let mut benchmarks = benchmarks_ref_cell.borrow_mut(); | ||
benchmarks.push(BenchmarkEntry { | ||
method_name, | ||
instructions, | ||
timestamp, | ||
}); | ||
}); | ||
|
||
Ok(()) | ||
}) | ||
} |
66 changes: 66 additions & 0 deletions
66
src/build/stable/commands/compile/wasm_binary/rust/stable_canister_template/src/candid.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
use crate::{ | ||
ic, quickjs_with_ctx, wasm_binary_manipulation::get_js_code, CONTEXT_REF_CELL, MODULE_NAME, | ||
}; | ||
|
||
// TODO we might not need any of these panic hooks | ||
|
||
// Heavily inspired by https://stackoverflow.com/a/47676844 | ||
#[no_mangle] | ||
pub fn get_candid_and_method_meta_pointer() -> *mut std::os::raw::c_char { | ||
std::panic::set_hook(Box::new(|panic_info| { | ||
let msg = match panic_info.payload().downcast_ref::<&str>() { | ||
Some(s) => *s, | ||
None => "Unknown panic message", | ||
}; | ||
let location = if let Some(location) = panic_info.location() { | ||
format!(" at {}:{}", location.file(), location.line()) | ||
} else { | ||
" (unknown location)".to_string() | ||
}; | ||
|
||
let message = &format!("Panic occurred: {}{}", msg, location); | ||
|
||
ic_cdk::println!("{}", message); | ||
})); | ||
|
||
let runtime = rquickjs::Runtime::new().unwrap(); | ||
let context = rquickjs::Context::full(&runtime).unwrap(); | ||
|
||
CONTEXT_REF_CELL.with(|context_ref_cell| { | ||
*context_ref_cell.borrow_mut() = Some(context); | ||
}); | ||
|
||
quickjs_with_ctx(|ctx| { | ||
ctx.clone() | ||
.globals() | ||
.set("_azleNodeWasmEnvironment", true) | ||
.unwrap(); | ||
|
||
ic::register(ctx.clone()); | ||
|
||
ctx.clone() | ||
.globals() | ||
.set("exports", rquickjs::Object::new(ctx.clone()).unwrap()) | ||
.unwrap(); | ||
|
||
ctx.clone() | ||
.globals() | ||
.set("_azleExperimental", false) | ||
.unwrap(); | ||
|
||
let js = get_js_code(); | ||
|
||
// TODO is there a better name for this main module? | ||
// TODO this returns a promise...make sure we handle it appropriately | ||
rquickjs::Module::evaluate(ctx.clone(), MODULE_NAME, js).unwrap(); | ||
|
||
let get_candid_and_method_meta: rquickjs::Function = | ||
ctx.globals().get("_azleGetCandidAndMethodMeta").unwrap(); | ||
|
||
let candid_and_method_meta: String = get_candid_and_method_meta.call(()).unwrap(); | ||
|
||
let c_string = std::ffi::CString::new(candid_and_method_meta).unwrap(); | ||
|
||
c_string.into_raw() | ||
}) | ||
} |
7 changes: 7 additions & 0 deletions
7
src/build/stable/commands/compile/wasm_binary/rust/stable_canister_template/src/chunk.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
#[allow(unused)] | ||
pub async fn chunk() { | ||
let id = ic_cdk::id(); | ||
let method = "_azle_chunk"; | ||
let args_raw = [68, 73, 68, 76, 0, 0]; // '()' pre encoded | ||
let _ = ic_cdk::api::call::call_raw128(id, method, args_raw, 0).await; | ||
} |
Oops, something went wrong.