feat: track images with git lfs
This commit is contained in:
5
app/src-tauri/src/hello.wat
Normal file
5
app/src-tauri/src/hello.wat
Normal file
@ -0,0 +1,5 @@
|
||||
(module
|
||||
(func (export "answer") (result i32)
|
||||
i32.const 42
|
||||
)
|
||||
)
|
80
app/src-tauri/src/lib.rs
Normal file
80
app/src-tauri/src/lib.rs
Normal file
@ -0,0 +1,80 @@
|
||||
use std::env;
|
||||
use std::path::PathBuf;
|
||||
|
||||
use wasmtime::*;
|
||||
|
||||
// Learn more about Tauri commands at https://tauri.app/v1/guides/features/command
|
||||
#[tauri::command]
|
||||
fn greet(name: &str) -> String {
|
||||
format!("Hello, {}! You've been greeted from Rust!", name)
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
fn insult(name: &str) -> String {
|
||||
format!("Hello, {}! Fuck you from Rust!", name)
|
||||
}
|
||||
|
||||
fn get_current_working_dir() -> std::io::Result<PathBuf> {
|
||||
env::current_dir()
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
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)
|
||||
}
|
||||
|
||||
#[cfg_attr(mobile, tauri::mobile_entry_point)]
|
||||
pub fn run() {
|
||||
tauri::Builder::default()
|
||||
.plugin(tauri_plugin_shell::init())
|
||||
.invoke_handler(tauri::generate_handler![greet, run_nodes, insult])
|
||||
.run(tauri::generate_context!())
|
||||
.expect("error while running tauri application");
|
||||
}
|
6
app/src-tauri/src/main.rs
Normal file
6
app/src-tauri/src/main.rs
Normal file
@ -0,0 +1,6 @@
|
||||
// Prevents additional console window on Windows in release, DO NOT REMOVE!!
|
||||
#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")]
|
||||
|
||||
fn main() {
|
||||
tauri_app_lib::run()
|
||||
}
|
Reference in New Issue
Block a user