From 0a2193379530bf977092a61a01ad4e54733cc6f4 Mon Sep 17 00:00:00 2001 From: Michael Zhang Date: Fri, 21 Jun 2024 17:59:41 -0500 Subject: [PATCH] wasm wip --- Cargo.lock | 348 ++++++++++++++++++++++++- Cargo.toml | 2 +- apps/journal/Cargo.toml | 10 + apps/journal/asconfig.json | 22 -- apps/journal/assembly/index.ts | 4 - apps/journal/assembly/tsconfig.json | 6 - apps/journal/build/.gitignore | 2 - apps/journal/index.html | 10 - apps/journal/manifest.yml | 2 +- apps/journal/package-lock.json | 54 ---- apps/journal/package.json | 26 -- apps/journal/register.rn | 3 - apps/journal/src/lib.rs | 23 ++ apps/journal/tests/index.js | 4 - crates/panorama-core/Cargo.toml | 1 + crates/panorama-core/src/state/apps.rs | 30 ++- 16 files changed, 408 insertions(+), 139 deletions(-) create mode 100644 apps/journal/Cargo.toml delete mode 100644 apps/journal/asconfig.json delete mode 100644 apps/journal/assembly/index.ts delete mode 100644 apps/journal/assembly/tsconfig.json delete mode 100644 apps/journal/build/.gitignore delete mode 100644 apps/journal/index.html delete mode 100644 apps/journal/package-lock.json delete mode 100644 apps/journal/package.json delete mode 100644 apps/journal/register.rn create mode 100644 apps/journal/src/lib.rs delete mode 100644 apps/journal/tests/index.js diff --git a/Cargo.lock b/Cargo.lock index d9d43d9..a930b37 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -60,6 +60,12 @@ version = "0.2.18" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5c6cb57a04249c6480766f7f7cef5467412af1490f8d1e243141daddada3264f" +[[package]] +name = "ambient-authority" +version = "0.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e9d4ee0d472d1cd2e28c97dfa124b3d8d992e10eb0a035f33f5d12e3a177ba3b" + [[package]] name = "android-tzdata" version = "0.1.1" @@ -623,6 +629,83 @@ dependencies = [ "serde", ] +[[package]] +name = "cap-fs-ext" +version = "3.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2fc2d2954524be4866aaa720f008fba9995de54784957a1b0e0119992d6d5e52" +dependencies = [ + "cap-primitives", + "cap-std", + "io-lifetimes", + "windows-sys 0.52.0", +] + +[[package]] +name = "cap-net-ext" +version = "3.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "799c81d79ea9c71a1438efd417c788214bc9e7986046d3710b6bbe60da4d8275" +dependencies = [ + "cap-primitives", + "cap-std", + "rustix", + "smallvec", +] + +[[package]] +name = "cap-primitives" +version = "3.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "00172660727e2d7f808e7cc2bfffd093fdb3ea2ff2ef819289418a3c3ffab5ac" +dependencies = [ + "ambient-authority", + "fs-set-times", + "io-extras", + "io-lifetimes", + "ipnet", + "maybe-owned", + "rustix", + "windows-sys 0.52.0", + "winx", +] + +[[package]] +name = "cap-rand" +version = "3.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "270f1d341a2afc62604f8f688bee4e444d052b7a74c1458dd3aa7efb47d4077f" +dependencies = [ + "ambient-authority", + "rand 0.8.5", +] + +[[package]] +name = "cap-std" +version = "3.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8cd9187bb3f7478a4c135ea10473a41a5f029d2ac800c1adf64f35ec7d4c8603" +dependencies = [ + "cap-primitives", + "io-extras", + "io-lifetimes", + "rustix", +] + +[[package]] +name = "cap-time-ext" +version = "3.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "91666f31e30c85b1d2ee8432c90987f752c45f5821f5638027b41e73e16a395b" +dependencies = [ + "ambient-authority", + "cap-primitives", + "iana-time-zone", + "once_cell", + "rustix", + "winx", +] + [[package]] name = "cargo-platform" version = "0.1.8" @@ -1266,13 +1349,22 @@ dependencies = [ "subtle", ] +[[package]] +name = "dirs" +version = "4.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ca3aa72a6f96ea37bbc5aa912f6788242832f75369bdfdadcb0e38423f100059" +dependencies = [ + "dirs-sys 0.3.7", +] + [[package]] name = "dirs" version = "5.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "44c45a9d03d6676652bcb5e724c7e988de1acad23a711b5217ab9cbecbec2225" dependencies = [ - "dirs-sys", + "dirs-sys 0.4.1", ] [[package]] @@ -1285,6 +1377,17 @@ dependencies = [ "dirs-sys-next", ] +[[package]] +name = "dirs-sys" +version = "0.3.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1b1d1d91c932ef41c0f2663aa8b0ca0342d444d842c06914aa0a7e352d0bada6" +dependencies = [ + "libc", + "redox_users", + "winapi", +] + [[package]] name = "dirs-sys" version = "0.4.1" @@ -1537,6 +1640,17 @@ version = "2.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9fc0510504f03c51ada170672ac806f1f105a88aa97a5281117e1ddc3368e51a" +[[package]] +name = "fd-lock" +version = "4.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7e5768da2206272c81ef0b5e951a41862938a6070da63bcea197899942d3b947" +dependencies = [ + "cfg-if", + "rustix", + "windows-sys 0.52.0", +] + [[package]] name = "fdeflate" version = "0.3.4" @@ -1619,6 +1733,17 @@ dependencies = [ "percent-encoding", ] +[[package]] +name = "fs-set-times" +version = "0.20.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "033b337d725b97690d86893f9de22b67b80dcc4e9ad815f348254c38119db8fb" +dependencies = [ + "io-lifetimes", + "rustix", + "windows-sys 0.52.0", +] + [[package]] name = "fs4" version = "0.8.4" @@ -2426,6 +2551,22 @@ dependencies = [ "web-sys", ] +[[package]] +name = "io-extras" +version = "0.18.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c9f046b9af244f13b3bd939f55d16830ac3a201e8a9ba9661bfcb03e2be72b9b" +dependencies = [ + "io-lifetimes", + "windows-sys 0.52.0", +] + +[[package]] +name = "io-lifetimes" +version = "2.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5a611371471e98973dbcab4e0ec66c31a10bc356eeb4d54a0e05eac8158fe38c" + [[package]] name = "ipnet" version = "2.9.0" @@ -2541,6 +2682,13 @@ dependencies = [ "libc", ] +[[package]] +name = "journal" +version = "0.1.0" +dependencies = [ + "wasm-bindgen", +] + [[package]] name = "js-sys" version = "0.3.69" @@ -2800,6 +2948,12 @@ version = "0.7.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0e7465ac9959cc2b1404e8e2367b43684a6d13790fe23056cc8c6c5a6b7bcb94" +[[package]] +name = "maybe-owned" +version = "0.3.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4facc753ae494aeb6e3c22f839b158aebd4f9270f55cd3c79906c45476c47ab4" + [[package]] name = "md-5" version = "0.10.6" @@ -3336,6 +3490,7 @@ dependencies = [ "uuid", "walkdir", "wasmtime", + "wasmtime-wasi", ] [[package]] @@ -3347,7 +3502,7 @@ dependencies = [ "axum", "chrono", "csv", - "dirs", + "dirs 5.0.1", "futures", "itertools 0.13.0", "panorama-core", @@ -4180,8 +4335,10 @@ checksum = "70dc5ec042f7a43c4a73241207cecc9873a06d45debb38b329f8541d85c2730f" dependencies = [ "bitflags 2.5.0", "errno", + "itoa 1.0.11", "libc", "linux-raw-sys", + "once_cell", "windows-sys 0.52.0", ] @@ -4560,6 +4717,15 @@ dependencies = [ "winapi", ] +[[package]] +name = "shellexpand" +version = "2.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7ccc8076840c4da029af4f87e4e8daeb0fca6b87bbb02e10cb60b791450e11e4" +dependencies = [ + "dirs 4.0.0", +] + [[package]] name = "signal-hook-registry" version = "1.4.2" @@ -5098,6 +5264,22 @@ dependencies = [ "version-compare", ] +[[package]] +name = "system-interface" +version = "0.27.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b858526d22750088a9b3cf2e3c2aacebd5377f13adeec02860c30d09113010a6" +dependencies = [ + "bitflags 2.5.0", + "cap-fs-ext", + "cap-std", + "fd-lock", + "io-lifetimes", + "rustix", + "windows-sys 0.52.0", + "winx", +] + [[package]] name = "tantivy" version = "0.22.0" @@ -5948,7 +6130,7 @@ dependencies = [ "cocoa", "core-graphics", "crossbeam-channel", - "dirs", + "dirs 5.0.1", "libappindicator", "muda", "objc", @@ -6375,9 +6557,11 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "786d8b5e7a4d54917c5ebe555b9667337e5f93383f49bddaaeec2eba68093b45" dependencies = [ "anyhow", + "async-trait", "bumpalo", "cc", "cfg-if", + "encoding_rs", "hashbrown 0.14.5", "indexmap 2.2.6", "libc", @@ -6392,6 +6576,7 @@ dependencies = [ "postcard", "psm", "rustix", + "semver", "serde", "serde_derive", "smallvec", @@ -6400,11 +6585,14 @@ dependencies = [ "wasmparser", "wasmtime-asm-macros", "wasmtime-component-macro", + "wasmtime-component-util", "wasmtime-cranelift", "wasmtime-environ", + "wasmtime-fiber", "wasmtime-jit-icache-coherence", "wasmtime-slab", "wasmtime-versioned-export-macros", + "wasmtime-winch", "windows-sys 0.52.0", ] @@ -6481,9 +6669,25 @@ dependencies = [ "wasm-encoder", "wasmparser", "wasmprinter", + "wasmtime-component-util", "wasmtime-types", ] +[[package]] +name = "wasmtime-fiber" +version = "22.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4ded58eb2d1bf0dcd2182d0ccd7055c4b10b50d711514f1d73f61515d0fa829d" +dependencies = [ + "anyhow", + "cc", + "cfg-if", + "rustix", + "wasmtime-asm-macros", + "wasmtime-versioned-export-macros", + "windows-sys 0.52.0", +] + [[package]] name = "wasmtime-jit-icache-coherence" version = "22.0.0" @@ -6526,6 +6730,54 @@ dependencies = [ "syn 2.0.67", ] +[[package]] +name = "wasmtime-wasi" +version = "22.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8abb1301089ed8e0b4840f539cba316a73ac382090f1b25d22d8c8eed8df49c7" +dependencies = [ + "anyhow", + "async-trait", + "bitflags 2.5.0", + "bytes", + "cap-fs-ext", + "cap-net-ext", + "cap-rand", + "cap-std", + "cap-time-ext", + "fs-set-times", + "futures", + "io-extras", + "io-lifetimes", + "once_cell", + "rustix", + "system-interface", + "thiserror", + "tokio", + "tracing", + "url", + "wasmtime", + "wiggle", + "windows-sys 0.52.0", +] + +[[package]] +name = "wasmtime-winch" +version = "22.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ed4db238a0241df2d15f79ad17b3a37a27f2ea6cb885894d81b42ae107544466" +dependencies = [ + "anyhow", + "cranelift-codegen", + "gimli 0.28.1", + "object", + "target-lexicon", + "wasmparser", + "wasmtime-cranelift", + "wasmtime-environ", + "winch-codegen", +] + [[package]] name = "wasmtime-wit-bindgen" version = "22.0.0" @@ -6538,6 +6790,15 @@ dependencies = [ "wit-parser", ] +[[package]] +name = "wast" +version = "35.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2ef140f1b49946586078353a453a1d28ba90adfc54dde75710bc1931de204d68" +dependencies = [ + "leb128", +] + [[package]] name = "wayland-sys" version = "0.31.2" @@ -6664,6 +6925,48 @@ dependencies = [ "wasite", ] +[[package]] +name = "wiggle" +version = "22.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "29830e5d01c182d24b94092c697aa7ab0ee97d22e78a2bf40ca91eae6ebca5c2" +dependencies = [ + "anyhow", + "async-trait", + "bitflags 2.5.0", + "thiserror", + "tracing", + "wasmtime", + "wiggle-macro", +] + +[[package]] +name = "wiggle-generate" +version = "22.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "557567f2793508760cd855f7659b7a0b9dc4dbc451f53f1415d6943a15311ade" +dependencies = [ + "anyhow", + "heck 0.4.1", + "proc-macro2", + "quote", + "shellexpand", + "syn 2.0.67", + "witx", +] + +[[package]] +name = "wiggle-macro" +version = "22.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cc26129a8aea20b62c961d1b9ab4a3c3b56b10042ed85d004f8678af0f21ba6e" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.67", + "wiggle-generate", +] + [[package]] name = "winapi" version = "0.3.9" @@ -6695,6 +6998,23 @@ version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" +[[package]] +name = "winch-codegen" +version = "0.20.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "85c6915884e731b2db0d8cf08cb64474cb69221a161675fd3c135f91febc3daa" +dependencies = [ + "anyhow", + "cranelift-codegen", + "gimli 0.28.1", + "regalloc2", + "smallvec", + "target-lexicon", + "wasmparser", + "wasmtime-cranelift", + "wasmtime-environ", +] + [[package]] name = "window-vibrancy" version = "0.5.0" @@ -7056,6 +7376,16 @@ dependencies = [ "windows-sys 0.48.0", ] +[[package]] +name = "winx" +version = "0.36.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f9643b83820c0cd246ecabe5fa454dd04ba4fa67996369466d0747472d337346" +dependencies = [ + "bitflags 2.5.0", + "windows-sys 0.52.0", +] + [[package]] name = "wit-parser" version = "0.209.1" @@ -7074,6 +7404,18 @@ dependencies = [ "wasmparser", ] +[[package]] +name = "witx" +version = "0.9.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e366f27a5cabcddb2706a78296a40b8fcc451e1a6aba2fc1d94b4a01bdaaef4b" +dependencies = [ + "anyhow", + "log", + "thiserror", + "wast", +] + [[package]] name = "wry" version = "0.40.1" diff --git a/Cargo.toml b/Cargo.toml index 174ac6a..fc3d318 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,2 +1,2 @@ workspace.resolver = "2" -workspace.members = ["crates/*", "ui/src-tauri"] +workspace.members = [ "apps/journal","crates/*", "ui/src-tauri"] diff --git a/apps/journal/Cargo.toml b/apps/journal/Cargo.toml new file mode 100644 index 0000000..b9801fb --- /dev/null +++ b/apps/journal/Cargo.toml @@ -0,0 +1,10 @@ +[package] +name = "journal" +version = "0.1.0" +edition = "2021" + +[lib] +crate-type = ["cdylib", "rlib"] + +[dependencies] +wasm-bindgen = "0.2.92" diff --git a/apps/journal/asconfig.json b/apps/journal/asconfig.json deleted file mode 100644 index 8776597..0000000 --- a/apps/journal/asconfig.json +++ /dev/null @@ -1,22 +0,0 @@ -{ - "targets": { - "debug": { - "outFile": "build/debug.wasm", - "textFile": "build/debug.wat", - "sourceMap": true, - "debug": true - }, - "release": { - "outFile": "build/release.wasm", - "textFile": "build/release.wat", - "sourceMap": true, - "optimizeLevel": 3, - "shrinkLevel": 0, - "converge": false, - "noAssert": false - } - }, - "options": { - "bindings": "esm" - } -} \ No newline at end of file diff --git a/apps/journal/assembly/index.ts b/apps/journal/assembly/index.ts deleted file mode 100644 index b3662cf..0000000 --- a/apps/journal/assembly/index.ts +++ /dev/null @@ -1,4 +0,0 @@ -export function install(): i32 { - console.log("Hellosu!"); - return 0; -} diff --git a/apps/journal/assembly/tsconfig.json b/apps/journal/assembly/tsconfig.json deleted file mode 100644 index e28fcf2..0000000 --- a/apps/journal/assembly/tsconfig.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "extends": "assemblyscript/std/assembly.json", - "include": [ - "./**/*.ts" - ] -} \ No newline at end of file diff --git a/apps/journal/build/.gitignore b/apps/journal/build/.gitignore deleted file mode 100644 index d6b7ef3..0000000 --- a/apps/journal/build/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -* -!.gitignore diff --git a/apps/journal/index.html b/apps/journal/index.html deleted file mode 100644 index c170dde..0000000 --- a/apps/journal/index.html +++ /dev/null @@ -1,10 +0,0 @@ - - - - - - - diff --git a/apps/journal/manifest.yml b/apps/journal/manifest.yml index 0f4c027..b4c5d5a 100644 --- a/apps/journal/manifest.yml +++ b/apps/journal/manifest.yml @@ -3,4 +3,4 @@ version: 0.1.0 panorama_version: 0.1.0 description: Note taking app -installer_path: build/release.wasm \ No newline at end of file +installer_path: pkg/journal_bg.wasm \ No newline at end of file diff --git a/apps/journal/package-lock.json b/apps/journal/package-lock.json deleted file mode 100644 index 9c71fd8..0000000 --- a/apps/journal/package-lock.json +++ /dev/null @@ -1,54 +0,0 @@ -{ - "name": "journal", - "version": "0.1.0", - "lockfileVersion": 3, - "requires": true, - "packages": { - "": { - "name": "journal", - "version": "0.1.0", - "license": "ISC", - "devDependencies": { - "assemblyscript": "^0.27.27" - } - }, - "node_modules/assemblyscript": { - "version": "0.27.27", - "resolved": "https://registry.npmjs.org/assemblyscript/-/assemblyscript-0.27.27.tgz", - "integrity": "sha512-z4ijXsjjk3uespEeCWpO1K2GQySc6bn+LL5dL0tsC2VXNYKFnKDmAh3wefcKazxXHFVhYlxqNfyv96ajaQyINQ==", - "dev": true, - "dependencies": { - "binaryen": "116.0.0-nightly.20240114", - "long": "^5.2.1" - }, - "bin": { - "asc": "bin/asc.js", - "asinit": "bin/asinit.js" - }, - "engines": { - "node": ">=16", - "npm": ">=7" - }, - "funding": { - "type": "opencollective", - "url": "https://opencollective.com/assemblyscript" - } - }, - "node_modules/binaryen": { - "version": "116.0.0-nightly.20240114", - "resolved": "https://registry.npmjs.org/binaryen/-/binaryen-116.0.0-nightly.20240114.tgz", - "integrity": "sha512-0GZrojJnuhoe+hiwji7QFaL3tBlJoA+KFUN7ouYSDGZLSo9CKM8swQX8n/UcbR0d1VuZKU+nhogNzv423JEu5A==", - "dev": true, - "bin": { - "wasm-opt": "bin/wasm-opt", - "wasm2js": "bin/wasm2js" - } - }, - "node_modules/long": { - "version": "5.2.3", - "resolved": "https://registry.npmjs.org/long/-/long-5.2.3.tgz", - "integrity": "sha512-lcHwpNoggQTObv5apGNCTdJrO69eHOZMi4BNC+rTLER8iHAqGrUVeLh/irVIM7zTw2bOXA8T6uNPeujwOLg/2Q==", - "dev": true - } - } -} diff --git a/apps/journal/package.json b/apps/journal/package.json deleted file mode 100644 index 154d5a1..0000000 --- a/apps/journal/package.json +++ /dev/null @@ -1,26 +0,0 @@ -{ - "name": "journal", - "version": "0.1.0", - "description": "", - "main": "index.js", - "scripts": { - "test": "node tests", - "asbuild:debug": "asc assembly/index.ts --target debug", - "asbuild:release": "asc assembly/index.ts --target release", - "asbuild": "npm run asbuild:debug && npm run asbuild:release", - "start": "npx serve ." - }, - "keywords": [], - "author": "", - "license": "ISC", - "devDependencies": { - "assemblyscript": "^0.27.27" - }, - "type": "module", - "exports": { - ".": { - "import": "./build/release.js", - "types": "./build/release.d.ts" - } - } -} \ No newline at end of file diff --git a/apps/journal/register.rn b/apps/journal/register.rn deleted file mode 100644 index fc1028a..0000000 --- a/apps/journal/register.rn +++ /dev/null @@ -1,3 +0,0 @@ -pub fn main() { - let y = 1 + 2; -} \ No newline at end of file diff --git a/apps/journal/src/lib.rs b/apps/journal/src/lib.rs new file mode 100644 index 0000000..ba72875 --- /dev/null +++ b/apps/journal/src/lib.rs @@ -0,0 +1,23 @@ +use std::ffi::CString; + +use wasm_bindgen::prelude::wasm_bindgen; + +mod sys { + use std::ffi::c_char; + + extern "C" { + pub fn register_endpoint(url: *const c_char); + } +} + +pub fn register_endpoint(url: impl AsRef) { + let url = CString::new(url.as_ref()).unwrap(); + let result = unsafe { sys::register_endpoint(url.into_raw()) }; + println!("Result: {:?}", result); +} + +#[wasm_bindgen] +pub fn install() -> i32 { + register_endpoint("/hello"); + 123 +} diff --git a/apps/journal/tests/index.js b/apps/journal/tests/index.js deleted file mode 100644 index 769a0b0..0000000 --- a/apps/journal/tests/index.js +++ /dev/null @@ -1,4 +0,0 @@ -import assert from "assert"; -import { add } from "../build/debug.js"; -assert.strictEqual(add(1, 2), 3); -console.log("ok"); diff --git a/crates/panorama-core/Cargo.toml b/crates/panorama-core/Cargo.toml index ec41771..8a46c6d 100644 --- a/crates/panorama-core/Cargo.toml +++ b/crates/panorama-core/Cargo.toml @@ -31,6 +31,7 @@ wasmtime = { version = "22.0.0", default-features = false, features = [ "runtime", "cranelift", ] } +wasmtime-wasi = "22.0.0" [dependencies.async-imap] version = "0.9.7" diff --git a/crates/panorama-core/src/state/apps.rs b/crates/panorama-core/src/state/apps.rs index d03e1ca..17ab004 100644 --- a/crates/panorama-core/src/state/apps.rs +++ b/crates/panorama-core/src/state/apps.rs @@ -8,7 +8,10 @@ use std::{ use anyhow::{Context as _, Result}; use serde_yaml::Value; -use wasmtime::{Config, Engine, Linker, Module, Store}; +use wasmtime::{ + Caller, Config, Engine, Linker, Memory, MemoryType, Module, Store, +}; +use wasmtime_wasi::WasiCtxBuilder; use crate::AppState; @@ -101,8 +104,29 @@ impl AppState { let config = Config::new(); let engine = Engine::new(&config)?; let module = Module::new(&engine, &installer_program)?; - let linker = Linker::new(&engine); - let mut store: Store = Store::new(&engine, 4); + + let wasi = WasiCtxBuilder::new().inherit_stdio().inherit_args().build(); + let mut store: Store<_> = Store::new(&engine, wasi); + let ty = MemoryType::new64(0, None); + let memory = Memory::new(&mut store, ty)?; + + let mut linker = Linker::new(&engine); + linker.func_wrap( + "env", + "register_endpoint", + |caller: Caller<'_, _>, param: i32| { + println!("Got {} , from WebAssembly", param); + // println!("my host state is: {}", caller.data()); + }, + )?; + linker.func_wrap( + "env", + "abort", + |caller: Caller<'_, _>, param: i32, _: i32, _: i32, _: i32| { + println!("Oops, aborted."); + }, + )?; + let instance = linker.instantiate(&mut store, &module)?; let hello = instance.get_typed_func::<(), i32>(&mut store, "install")?; hello.call(&mut store, ())?;