feat: some shit
This commit is contained in:
8
packages/node_registry_rust/Cargo.toml
Normal file
8
packages/node_registry_rust/Cargo.toml
Normal file
@@ -0,0 +1,8 @@
|
||||
[package]
|
||||
name = "node_registry_rust"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
3
packages/node_registry_rust/src/lib.rs
Normal file
3
packages/node_registry_rust/src/lib.rs
Normal file
@@ -0,0 +1,3 @@
|
||||
pub fn add(left: usize, right: usize) -> usize {
|
||||
left + right
|
||||
}
|
9
packages/runtime_exec/Cargo.toml
Normal file
9
packages/runtime_exec/Cargo.toml
Normal file
@@ -0,0 +1,9 @@
|
||||
[package]
|
||||
name = "runtime_executor_rust"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
wasmtime = "18.0.1"
|
63
packages/runtime_exec/src/lib.rs
Normal file
63
packages/runtime_exec/src/lib.rs
Normal file
@@ -0,0 +1,63 @@
|
||||
use std::env;
|
||||
use std::path::PathBuf;
|
||||
|
||||
use wasmtime::*;
|
||||
|
||||
fn get_current_working_dir() -> std::io::Result<PathBuf> {
|
||||
env::current_dir()
|
||||
}
|
||||
|
||||
pub fn run_nodes() -> Result<i32, String> {
|
||||
// An engine stores and configures global compilation settings like
|
||||
// optimization level, enabled wasm features, etc.
|
||||
let engine = Engine::default();
|
||||
|
||||
let pwd = get_current_working_dir().expect("Cant get wkring dir");
|
||||
println!(
|
||||
"{}",
|
||||
pwd.into_os_string().into_string().expect("cant unwrap")
|
||||
);
|
||||
|
||||
// We start off by creating a `Module` which represents a compiled form
|
||||
// of our input wasm module. In this case it'll be JIT-compiled after
|
||||
// we parse the text format.
|
||||
let module =
|
||||
Module::from_file(&engine, "src/hello.wat").expect("Could not instatiate hello.wat");
|
||||
|
||||
// A `Store` is what will own instances, functions, globals, etc. All wasm
|
||||
// items are stored within a `Store`, and it's what we'll always be using to
|
||||
// interact with the wasm world. Custom data can be stored in stores but for
|
||||
// now we just use `()`.
|
||||
let mut store = Store::new(&engine, ());
|
||||
|
||||
// With a compiled `Module` we can then instantiate it, creating
|
||||
// an `Instance` which we can actually poke at functions on.
|
||||
let instance = Instance::new(&mut store, &module, &[]).expect("Could not instatiate module");
|
||||
|
||||
// The `Instance` gives us access to various exported functions and items,
|
||||
// which we access here to pull out our `answer` exported function and
|
||||
// run it.
|
||||
let answer = instance
|
||||
.get_func(&mut store, "answer")
|
||||
.expect("`answer` was not an exported function");
|
||||
|
||||
// There's a few ways we can call the `answer` `Func` value. The easiest
|
||||
// is to statically assert its signature with `typed` (in this case
|
||||
// asserting it takes no arguments and returns one i32) and then call it.
|
||||
let answer = answer
|
||||
.typed::<(), i32>(&store)
|
||||
.expect("Can't access answer function");
|
||||
|
||||
// And finally we can call our function! Note that the error propagation
|
||||
// with `?` is done to handle the case where the wasm function traps.
|
||||
let result = answer
|
||||
.call(&mut store, ())
|
||||
.expect("Could not call function");
|
||||
println!("Answer: {:?}", result);
|
||||
|
||||
Ok(result)
|
||||
}
|
||||
|
||||
fn main() {
|
||||
println!("Duude");
|
||||
}
|
7
packages/runtime_executor_rust/Cargo.toml
Normal file
7
packages/runtime_executor_rust/Cargo.toml
Normal file
@@ -0,0 +1,7 @@
|
||||
[package]
|
||||
name = "runtime_executor_rust"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
[dependencies]
|
||||
wasmtime = "18.0.1"
|
37
packages/runtime_executor_rust/src/main.rs
Normal file
37
packages/runtime_executor_rust/src/main.rs
Normal file
@@ -0,0 +1,37 @@
|
||||
use wasmtime::{Config, Engine, component::Component, component::Instance};
|
||||
|
||||
use std::env;
|
||||
use std::path::PathBuf;
|
||||
|
||||
fn get_current_working_dir() -> std::io::Result<PathBuf> {
|
||||
env::current_dir()
|
||||
}
|
||||
|
||||
pub fn run_nodes() -> Result<i32, String> {
|
||||
|
||||
let mut config = Config::new();
|
||||
config.wasm_multi_memory(true);
|
||||
config.wasm_component_model(true);
|
||||
|
||||
// An engine stores and configures global compilation settings like
|
||||
// optimization level, enabled wasm features, etc.
|
||||
let engine = Engine::new(&config).expect("Could not create engine");
|
||||
|
||||
|
||||
let component = Component::from_file(&engine, "../../target/wasm32-unknown-unknown/release/add.wasm").expect("Could not load add.wasm");
|
||||
|
||||
let resources = component.resources_required()
|
||||
.expect("this component does not import any core modules or instances");
|
||||
|
||||
println!("{}", resources.num_memories);
|
||||
|
||||
let instance = Instance::new(&engine, component);
|
||||
|
||||
|
||||
Ok(12)
|
||||
}
|
||||
|
||||
|
||||
fn main() {
|
||||
let _ = run_nodes();
|
||||
}
|
3
packages/types/index.ts
Normal file
3
packages/types/index.ts
Normal file
@@ -0,0 +1,3 @@
|
||||
interface Node {
|
||||
|
||||
}
|
12
packages/types/package.json
Normal file
12
packages/types/package.json
Normal file
@@ -0,0 +1,12 @@
|
||||
{
|
||||
"name": "types",
|
||||
"version": "1.0.0",
|
||||
"description": "",
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
"test": "echo \"Error: no test specified\" && exit 1"
|
||||
},
|
||||
"keywords": [],
|
||||
"author": "",
|
||||
"license": "ISC"
|
||||
}
|
Reference in New Issue
Block a user