diff --git a/Cargo.lock b/Cargo.lock index b0dc9ab4..8e08f931 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -233,6 +233,12 @@ dependencies = [ "pkg-config", ] +[[package]] +name = "ambient-authority" +version = "0.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e9d4ee0d472d1cd2e28c97dfa124b3d8d992e10eb0a035f33f5d12e3a177ba3b" + [[package]] name = "android-activity" version = "0.5.2" @@ -490,7 +496,7 @@ dependencies = [ "futures-lite 2.2.0", "parking", "polling 3.5.0", - "rustix 0.38.31", + "rustix 0.38.34", "slab", "tracing", "windows-sys 0.52.0", @@ -546,7 +552,7 @@ dependencies = [ "cfg-if", "event-listener 3.1.0", "futures-lite 1.13.0", - "rustix 0.38.31", + "rustix 0.38.34", "windows-sys 0.48.0", ] @@ -565,7 +571,7 @@ dependencies = [ "cfg-if", "event-listener 5.1.0", "futures-lite 2.2.0", - "rustix 0.38.31", + "rustix 0.38.34", "tracing", "windows-sys 0.52.0", ] @@ -593,7 +599,7 @@ dependencies = [ "cfg-if", "futures-core", "futures-io", - "rustix 0.38.31", + "rustix 0.38.34", "signal-hook-registry", "slab", "windows-sys 0.48.0", @@ -976,7 +982,7 @@ dependencies = [ "bitflags 2.6.0", "log", "polling 3.5.0", - "rustix 0.38.31", + "rustix 0.38.34", "slab", "thiserror", ] @@ -988,7 +994,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0f0ea9b9476c7fad82841a8dbb380e2eae480c21910feba80725b46931ed8f02" dependencies = [ "calloop", - "rustix 0.38.31", + "rustix 0.38.34", "wayland-backend", "wayland-client", ] @@ -999,6 +1005,83 @@ version = "1.1.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c59e92b5a388f549b863a7bea62612c09f24c8393560709a54558a9abdfb3b9c" +[[package]] +name = "cap-fs-ext" +version = "3.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "eb23061fc1c4ead4e45ca713080fe768e6234e959f5a5c399c39eb41aa34e56e" +dependencies = [ + "cap-primitives", + "cap-std", + "io-lifetimes 2.0.3", + "windows-sys 0.52.0", +] + +[[package]] +name = "cap-net-ext" +version = "3.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f83ae11f116bcbafc5327c6af250341db96b5930046732e1905f7dc65887e0e1" +dependencies = [ + "cap-primitives", + "cap-std", + "rustix 0.38.34", + "smallvec", +] + +[[package]] +name = "cap-primitives" +version = "3.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6d00bd8d26c4270d950eaaa837387964a2089a1c3c349a690a1fa03221d29531" +dependencies = [ + "ambient-authority", + "fs-set-times", + "io-extras", + "io-lifetimes 2.0.3", + "ipnet", + "maybe-owned", + "rustix 0.38.34", + "windows-sys 0.52.0", + "winx", +] + +[[package]] +name = "cap-rand" +version = "3.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dbcb16a619d8b8211ed61f42bd290d2a1ac71277a69cf8417ec0996fa92f5211" +dependencies = [ + "ambient-authority", + "rand", +] + +[[package]] +name = "cap-std" +version = "3.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "19eb8e3d71996828751c1ed3908a439639752ac6bdc874e41469ef7fc15fbd7f" +dependencies = [ + "cap-primitives", + "io-extras", + "io-lifetimes 2.0.3", + "rustix 0.38.34", +] + +[[package]] +name = "cap-time-ext" +version = "3.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "61142dc51e25b7acc970ca578ce2c3695eac22bbba46c1073f5f583e78957725" +dependencies = [ + "ambient-authority", + "cap-primitives", + "iana-time-zone", + "once_cell", + "rustix 0.38.34", + "winx", +] + [[package]] name = "cc" version = "1.0.88" @@ -1633,7 +1716,27 @@ version = "5.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9a49173b84e034382284f27f1af4dcbbd231ffa358c0fe316541a7337f376a35" dependencies = [ - "dirs-sys", + "dirs-sys 0.4.1", +] + +[[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-sys" +version = "0.3.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1b1d1d91c932ef41c0f2663aa8b0ca0342d444d842c06914aa0a7e352d0bada6" +dependencies = [ + "libc", + "redox_users", + "winapi", ] [[package]] @@ -2060,6 +2163,17 @@ version = "2.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "25cbce373ec4653f1a01a31e8a5e5ec0c622dc27ff9c4e6606eefef5cbbed4a5" +[[package]] +name = "fd-lock" +version = "4.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7e5768da2206272c81ef0b5e951a41862938a6070da63bcea197899942d3b947" +dependencies = [ + "cfg-if", + "rustix 0.38.34", + "windows-sys 0.52.0", +] + [[package]] name = "fdeflate" version = "0.3.4" @@ -2165,6 +2279,17 @@ version = "2.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6c2141d6d6c8512188a7891b4b01590a45f6dac67afb4f255c4124dbb86d4eaa" +[[package]] +name = "fs-set-times" +version = "0.20.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "033b337d725b97690d86893f9de22b67b80dcc4e9ad815f348254c38119db8fb" +dependencies = [ + "io-lifetimes 2.0.3", + "rustix 0.38.34", + "windows-sys 0.52.0", +] + [[package]] name = "futures" version = "0.3.30" @@ -2726,6 +2851,29 @@ dependencies = [ "tokio-native-tls", ] +[[package]] +name = "iana-time-zone" +version = "0.1.60" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e7ffbb5a1b541ea2561f8c41c087286cc091e21e556a4f09a8f6cbf17b69b141" +dependencies = [ + "android_system_properties", + "core-foundation-sys", + "iana-time-zone-haiku", + "js-sys", + "wasm-bindgen", + "windows-core 0.52.0", +] + +[[package]] +name = "iana-time-zone-haiku" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f31827a206f56af32e590ba56d5d2d085f558508192593743f16b2306495269f" +dependencies = [ + "cc", +] + [[package]] name = "icrate" version = "0.0.4" @@ -2882,6 +3030,16 @@ dependencies = [ "syn 2.0.72", ] +[[package]] +name = "io-extras" +version = "0.18.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c9f046b9af244f13b3bd939f55d16830ac3a201e8a9ba9661bfcb03e2be72b9b" +dependencies = [ + "io-lifetimes 2.0.3", + "windows-sys 0.52.0", +] + [[package]] name = "io-lifetimes" version = "1.0.11" @@ -2893,6 +3051,12 @@ dependencies = [ "windows-sys 0.48.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" @@ -3235,6 +3399,7 @@ dependencies = [ "luminol-filesystem", "luminol-graphics", "luminol-macros", + "luminol-plugins", "luminol-term", "luminol-ui", "luminol-web", @@ -3521,6 +3686,7 @@ dependencies = [ "color-eyre", "slab", "wasm-bridge", + "wasmtime-wasi", ] [[package]] @@ -3682,6 +3848,12 @@ dependencies = [ "regex-automata 0.1.10", ] +[[package]] +name = "maybe-owned" +version = "0.3.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4facc753ae494aeb6e3c22f839b158aebd4f9270f55cd3c79906c45476c47ab4" + [[package]] name = "maybe-rayon" version = "0.1.1" @@ -3704,7 +3876,7 @@ version = "0.6.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b2cffa4ad52c6f791f4f8b15f0c05f9824b2ced1160e88cc393d64fff9a8ac64" dependencies = [ - "rustix 0.38.31", + "rustix 0.38.34", ] [[package]] @@ -4597,7 +4769,7 @@ dependencies = [ "cfg-if", "concurrent-queue", "pin-project-lite", - "rustix 0.38.31", + "rustix 0.38.34", "tracing", "windows-sys 0.52.0", ] @@ -5220,7 +5392,7 @@ checksum = "fea8ca367a3a01fe35e6943c400addf443c0f57670e6ec51196f71a4b8762dd2" dependencies = [ "bitflags 1.3.2", "errno", - "io-lifetimes", + "io-lifetimes 1.0.11", "libc", "linux-raw-sys 0.3.8", "windows-sys 0.48.0", @@ -5228,15 +5400,16 @@ dependencies = [ [[package]] name = "rustix" -version = "0.38.31" +version = "0.38.34" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6ea3e1a662af26cd7a3ba09c0297a31af215563ecf42817c98df621387f4e949" +checksum = "70dc5ec042f7a43c4a73241207cecc9873a06d45debb38b329f8541d85c2730f" dependencies = [ "bitflags 2.6.0", "errno", "itoa", "libc", "linux-raw-sys 0.4.13", + "once_cell", "windows-sys 0.52.0", ] @@ -5248,7 +5421,7 @@ checksum = "a25c3aad9fc1424eb82c88087789a7d938e1829724f3e4043163baf0d13cfc12" dependencies = [ "errno", "libc", - "rustix 0.38.31", + "rustix 0.38.34", ] [[package]] @@ -5381,11 +5554,12 @@ dependencies = [ [[package]] name = "serde_json" -version = "1.0.120" +version = "1.0.122" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4e0d21c9a8cae1235ad58a00c11cb40d4b1e5c784f1ef2c537876ed6ffd8b7c5" +checksum = "784b6203951c57ff748476b126ccb5e8e2959a5c19e5c617ab1956be3dbc68da" dependencies = [ "itoa", + "memchr", "ryu", "serde", ] @@ -5469,6 +5643,15 @@ dependencies = [ "lazy_static", ] +[[package]] +name = "shellexpand" +version = "2.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7ccc8076840c4da029af4f87e4e8daeb0fca6b87bbb02e10cb60b791450e11e4" +dependencies = [ + "dirs", +] + [[package]] name = "shlex" version = "1.3.0" @@ -5571,7 +5754,7 @@ dependencies = [ "libc", "log", "memmap2", - "rustix 0.38.31", + "rustix 0.38.34", "thiserror", "wayland-backend", "wayland-client", @@ -5875,6 +6058,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.6.0", + "cap-fs-ext", + "cap-std", + "fd-lock", + "io-lifetimes 2.0.3", + "rustix 0.38.34", + "windows-sys 0.52.0", + "winx", +] + [[package]] name = "target-lexicon" version = "0.12.14" @@ -5895,7 +6094,7 @@ checksum = "85b77fafb263dd9d05cbeac119526425676db3784113aa9295c88498cbf8bff1" dependencies = [ "cfg-if", "fastrand 2.0.1", - "rustix 0.38.31", + "rustix 0.38.34", "windows-sys 0.52.0", ] @@ -6780,6 +6979,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4e300c0e3f19dc9064e3b17ce661088646c70dbdde36aab46470ed68ba58db7d" dependencies = [ "anyhow", + "async-trait", "bincode", "bumpalo", "cfg-if", @@ -6791,7 +6991,7 @@ dependencies = [ "object 0.32.2", "once_cell", "paste", - "rustix 0.38.31", + "rustix 0.38.34", "semver", "serde", "serde_derive", @@ -6802,6 +7002,7 @@ dependencies = [ "wasmtime-component-util 19.0.2", "wasmtime-cranelift", "wasmtime-environ 19.0.2", + "wasmtime-fiber", "wasmtime-jit-icache-coherence", "wasmtime-runtime", "wasmtime-slab", @@ -6936,6 +7137,21 @@ dependencies = [ "wasmtime-types 23.0.1", ] +[[package]] +name = "wasmtime-fiber" +version = "19.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9235b643527bcbac808216ed342e1fba324c95f14a62762acfa6f2e6ca5edbd6" +dependencies = [ + "anyhow", + "cc", + "cfg-if", + "rustix 0.38.34", + "wasmtime-asm-macros", + "wasmtime-versioned-export-macros", + "windows-sys 0.52.0", +] + [[package]] name = "wasmtime-jit-icache-coherence" version = "19.0.2" @@ -6965,11 +7181,12 @@ dependencies = [ "memoffset 0.9.0", "paste", "psm", - "rustix 0.38.31", + "rustix 0.38.34", "sptr", "wasm-encoder 0.201.0", "wasmtime-asm-macros", "wasmtime-environ 19.0.2", + "wasmtime-fiber", "wasmtime-versioned-export-macros", "wasmtime-wmemcheck", "windows-sys 0.52.0", @@ -7019,6 +7236,37 @@ dependencies = [ "syn 2.0.72", ] +[[package]] +name = "wasmtime-wasi" +version = "19.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b95961546319d4019625920756967a929879d1d46c4e5f89a74e9f4405655b0c" +dependencies = [ + "anyhow", + "async-trait", + "bitflags 2.6.0", + "bytes", + "cap-fs-ext", + "cap-net-ext", + "cap-rand", + "cap-std", + "cap-time-ext", + "fs-set-times", + "futures", + "io-extras", + "io-lifetimes 2.0.3", + "once_cell", + "rustix 0.38.34", + "system-interface", + "thiserror", + "tokio", + "tracing", + "url", + "wasmtime", + "wiggle", + "windows-sys 0.52.0", +] + [[package]] name = "wasmtime-winch" version = "19.0.2" @@ -7054,6 +7302,15 @@ version = "19.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c9a8c62e9df8322b2166d2a6f096fbec195ddb093748fd74170dcf25ef596769" +[[package]] +name = "wast" +version = "35.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2ef140f1b49946586078353a453a1d28ba90adfc54dde75710bc1931de204d68" +dependencies = [ + "leb128", +] + [[package]] name = "wast" version = "215.0.0" @@ -7073,7 +7330,7 @@ version = "1.215.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "670bf4d9c8cf76ae242d70ded47c546525b6dafaa6871f9bcb065344bf2b4e3d" dependencies = [ - "wast", + "wast 215.0.0", ] [[package]] @@ -7084,7 +7341,7 @@ checksum = "9d50fa61ce90d76474c87f5fc002828d81b32677340112b4ef08079a9d459a40" dependencies = [ "cc", "downcast-rs", - "rustix 0.38.31", + "rustix 0.38.34", "scoped-tls", "smallvec", "wayland-sys", @@ -7097,7 +7354,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "82fb96ee935c2cea6668ccb470fb7771f6215d1691746c2d896b447a00ad3f1f" dependencies = [ "bitflags 2.6.0", - "rustix 0.38.31", + "rustix 0.38.34", "wayland-backend", "wayland-scanner", ] @@ -7119,7 +7376,7 @@ version = "0.31.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "71ce5fa868dd13d11a0d04c5e2e65726d0897be8de247c0c5a65886e283231ba" dependencies = [ - "rustix 0.38.31", + "rustix 0.38.34", "wayland-client", "xcursor", ] @@ -7344,6 +7601,48 @@ version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "653f141f39ec16bba3c5abe400a0c60da7468261cc2cbf36805022876bc721a8" +[[package]] +name = "wiggle" +version = "19.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "899d3fe5fbacd02f114cacdaa1cca9040280c4153c71833a77b9609c60ccf72b" +dependencies = [ + "anyhow", + "async-trait", + "bitflags 2.6.0", + "thiserror", + "tracing", + "wasmtime", + "wiggle-macro", +] + +[[package]] +name = "wiggle-generate" +version = "19.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2df5887f452cff44ffe1e1aba69b7fafe812deed38498446fa7a46b55e962cd5" +dependencies = [ + "anyhow", + "heck 0.4.1", + "proc-macro2", + "quote", + "shellexpand", + "syn 2.0.72", + "witx", +] + +[[package]] +name = "wiggle-macro" +version = "19.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "acdb12de36507498abaa3a042f895a43ee00a2f6125b6901b9a27edf72bfdbe7" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.72", + "wiggle-generate", +] + [[package]] name = "winapi" version = "0.3.9" @@ -7720,7 +8019,7 @@ dependencies = [ "raw-window-handle 0.5.2", "raw-window-handle 0.6.0", "redox_syscall 0.3.5", - "rustix 0.38.31", + "rustix 0.38.34", "sctk-adwaita", "smithay-client-toolkit", "smol_str", @@ -7786,6 +8085,16 @@ dependencies = [ "toml 0.5.11", ] +[[package]] +name = "winx" +version = "0.36.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f9643b83820c0cd246ecabe5fa454dd04ba4fa67996369466d0747472d337346" +dependencies = [ + "bitflags 2.6.0", + "windows-sys 0.52.0", +] + [[package]] name = "wit-bindgen" version = "0.28.0" @@ -7951,6 +8260,18 @@ dependencies = [ "wasmparser 0.214.0", ] +[[package]] +name = "witx" +version = "0.9.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e366f27a5cabcddb2706a78296a40b8fcc451e1a6aba2fc1d94b4a01bdaaef4b" +dependencies = [ + "anyhow", + "log", + "thiserror", + "wast 35.0.2", +] + [[package]] name = "x11-dl" version = "2.21.0" @@ -7973,7 +8294,7 @@ dependencies = [ "libc", "libloading 0.8.1", "once_cell", - "rustix 0.38.31", + "rustix 0.38.34", "x11rb-protocol", ] diff --git a/Cargo.toml b/Cargo.toml index d94952a3..fe58c5db 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -174,6 +174,7 @@ luminol-plugins = { version = "0.4.0", path = "crates/plugins/" } luminol-eframe.workspace = true luminol-egui-wgpu.workspace = true luminol-macros.workspace = true +luminol-plugins.workspace = true egui.workspace = true egui_extras.workspace = true diff --git a/crates/plugins/Cargo.toml b/crates/plugins/Cargo.toml index 0e5d558f..60b25a96 100644 --- a/crates/plugins/Cargo.toml +++ b/crates/plugins/Cargo.toml @@ -12,6 +12,7 @@ categories.workspace = true [dependencies] wasm-bridge = { version = "0.4.0", features = ["component-model"] } +wasmtime-wasi = "19.0.2" slab.workspace = true color-eyre.workspace = true diff --git a/crates/plugins/src/lib.rs b/crates/plugins/src/lib.rs index c1dabdb8..5c0ec809 100644 --- a/crates/plugins/src/lib.rs +++ b/crates/plugins/src/lib.rs @@ -4,8 +4,23 @@ pub struct Plugins { } pub struct Plugin { - instance: wasm_bridge::Instance, - store: wasm_bridge::Store<()>, + instance: wasm_bridge::component::Instance, + store: wasm_bridge::Store, +} + +struct WasiCtx { + wasi_ctx: wasmtime_wasi::WasiCtx, + table: wasmtime_wasi::ResourceTable, +} + +impl wasmtime_wasi::WasiView for WasiCtx { + fn table(&mut self) -> &mut wasmtime_wasi::ResourceTable { + &mut self.table + } + + fn ctx(&mut self) -> &mut wasmtime_wasi::WasiCtx { + &mut self.wasi_ctx + } } impl Default for Plugins { @@ -14,6 +29,10 @@ impl Default for Plugins { } } +fn get(v: &mut WasiCtx) -> &mut WasiCtx { + v +} + impl Plugins { pub fn new() -> Self { let engine = wasm_bridge::Engine::default(); @@ -26,16 +45,37 @@ impl Plugins { #[allow(deprecated)] pub fn load_plugin(&mut self, plugin_bytes: &[u8]) -> wasm_bridge::Result { - let module = wasm_bridge::Module::new(&self.engine, plugin_bytes)?; - let mut linker = wasm_bridge::Linker::new(&self.engine); + let component = wasm_bridge::component::Component::new(&self.engine, plugin_bytes)?; + let mut linker = wasm_bridge::component::Linker::new(&self.engine); + + let wasi_ctx = wasmtime_wasi::WasiCtxBuilder::new().build(); + let table = wasmtime_wasi::ResourceTable::default(); + let ctx = WasiCtx { wasi_ctx, table }; + + wasmtime_wasi::bindings::cli::environment::add_to_linker(&mut linker.0, get)?; + wasmtime_wasi::bindings::cli::stdin::add_to_linker(&mut linker.0, get)?; + wasmtime_wasi::bindings::cli::stdout::add_to_linker(&mut linker.0, get)?; + wasmtime_wasi::bindings::cli::stderr::add_to_linker(&mut linker.0, get)?; + wasmtime_wasi::bindings::cli::exit::add_to_linker(&mut linker.0, get)?; + wasmtime_wasi::bindings::io::error::add_to_linker(&mut linker.0, get)?; + wasmtime_wasi::bindings::sync_io::io::streams::add_to_linker(&mut linker.0, get)?; + wasmtime_wasi::bindings::sync_io::filesystem::types::add_to_linker(&mut linker.0, get)?; + wasmtime_wasi::bindings::filesystem::preopens::add_to_linker(&mut linker.0, get)?; + + linker.root().func_wrap("print", |_, (param,): (String,)| { + println!("{param}",); + Ok(()) + })?; - let mut store = wasm_bridge::Store::new(&self.engine, ()); + let mut store = wasm_bridge::Store::new(&self.engine, ctx); + let instance = linker.instantiate(&mut store, &component)?; - let instance = linker.instantiate(&mut store, &module)?; + let func = instance.get_typed_func::<(), ()>(&mut store, "run")?; + func.call(&mut store, ())?; let plugin = Plugin { instance, store }; let key = self.loaded_plugins.insert(plugin); - todo!(); + Ok(key) } } diff --git a/crates/plugins/wit b/crates/plugins/wit new file mode 120000 index 00000000..8d499a7c --- /dev/null +++ b/crates/plugins/wit @@ -0,0 +1 @@ +../../plugins/wit \ No newline at end of file diff --git a/plugins/rust_example/src/lib.rs b/plugins/rust_example/src/lib.rs index af086aff..c1215b70 100644 --- a/plugins/rust_example/src/lib.rs +++ b/plugins/rust_example/src/lib.rs @@ -9,7 +9,7 @@ struct TheGuest; impl Guest for TheGuest { fn run() { - print("Hello from Rust!"); + print("Hello from a plugin!"); } } diff --git a/src/main.rs b/src/main.rs index 2f656a76..b98540f7 100644 --- a/src/main.rs +++ b/src/main.rs @@ -60,6 +60,10 @@ pub fn git_revision() -> &'static str { #[cfg(not(target_arch = "wasm32"))] fn main() { + let plugin_bytes = include_bytes!("../plugins/rust_example/rust_example.wasm"); + let mut plugins = luminol_plugins::Plugins::new(); + plugins.load_plugin(plugin_bytes).unwrap(); + // Load the panic report from the previous run if it exists let mut report = None; if let Some(path) = std::env::var_os("LUMINOL_PANIC_REPORT_FILE") {