component_manager, strict_eval.js
This commit is contained in:
parent
ae4c76ed41
commit
3778469de9
11 changed files with 119 additions and 14 deletions
54
src-tauri/src/component_manager.rs
Normal file
54
src-tauri/src/component_manager.rs
Normal file
|
@ -0,0 +1,54 @@
|
|||
use crate::{AddedDecodersCount, DecoderPath};
|
||||
use wasmtime::*;
|
||||
|
||||
pub fn add_decoders(decoder_paths: Vec<DecoderPath>) -> AddedDecodersCount {
|
||||
println!("decoders in Tauri: {decoder_paths:#?}");
|
||||
|
||||
wasmtime_test().unwrap();
|
||||
|
||||
decoder_paths.len()
|
||||
}
|
||||
|
||||
fn wasmtime_test() -> wasmtime::Result<()> {
|
||||
let engine = Engine::default();
|
||||
|
||||
// Modules can be compiled through either the text or binary format
|
||||
let wat = r#"
|
||||
(module
|
||||
(import "host" "host_func" (func $host_hello (param i32)))
|
||||
|
||||
(func (export "hello")
|
||||
i32.const 3
|
||||
call $host_hello)
|
||||
)
|
||||
"#;
|
||||
let module = Module::new(&engine, wat)?;
|
||||
|
||||
// Host functionality can be arbitrary Rust functions and is provided
|
||||
// to guests through a `Linker`.
|
||||
let mut linker = Linker::new(&engine);
|
||||
linker.func_wrap(
|
||||
"host",
|
||||
"host_func",
|
||||
|caller: Caller<'_, u32>, param: i32| {
|
||||
println!("Got {} from WebAssembly", param);
|
||||
println!("my host state is: {}", caller.data());
|
||||
},
|
||||
)?;
|
||||
|
||||
// All wasm objects operate within the context of a "store". Each
|
||||
// `Store` has a type parameter to store host-specific data, which in
|
||||
// this case we're using `4` for.
|
||||
let mut store: Store<u32> = Store::new(&engine, 4);
|
||||
|
||||
// Instantiation of a module requires specifying its imports and then
|
||||
// afterwards we can fetch exports by name, as well as asserting the
|
||||
// type signature of the function with `get_typed_func`.
|
||||
let instance = linker.instantiate(&mut store, &module)?;
|
||||
let hello = instance.get_typed_func::<(), ()>(&mut store, "hello")?;
|
||||
|
||||
// And finally we can call the wasm!
|
||||
hello.call(&mut store, ())?;
|
||||
|
||||
Ok(())
|
||||
}
|
|
@ -5,6 +5,10 @@ use wellen::simple::Waveform;
|
|||
|
||||
type Filename = String;
|
||||
type JavascriptCode = String;
|
||||
type AddedDecodersCount = usize;
|
||||
type DecoderPath = String;
|
||||
|
||||
mod component_manager;
|
||||
|
||||
#[derive(Default)]
|
||||
struct Store {
|
||||
|
@ -91,6 +95,11 @@ async fn unload_signal(signal_ref_index: usize, store: tauri::State<'_, Store>)
|
|||
Ok(())
|
||||
}
|
||||
|
||||
#[tauri::command(rename_all = "snake_case")]
|
||||
async fn add_decoders(decoder_paths: Vec<DecoderPath>) -> Result<AddedDecodersCount, ()> {
|
||||
Ok(component_manager::add_decoders(decoder_paths))
|
||||
}
|
||||
|
||||
#[cfg_attr(mobile, tauri::mobile_entry_point)]
|
||||
pub fn run() {
|
||||
// https://github.com/tauri-apps/tauri/issues/8462
|
||||
|
@ -109,6 +118,7 @@ pub fn run() {
|
|||
get_hierarchy,
|
||||
load_signal_and_get_timeline,
|
||||
unload_signal,
|
||||
add_decoders,
|
||||
])
|
||||
.run(tauri::generate_context!())
|
||||
.expect("error while running tauri application");
|
||||
|
|
Reference in a new issue