From ee7fb990c3184ae1e5bfde3e917e72b8619679e9 Mon Sep 17 00:00:00 2001 From: ccgauche Date: Sat, 12 Dec 2020 00:37:22 +0100 Subject: [PATCH] Added plugin system Added a plugin system based on wasmer-runtime - Support Action (Print handled) - Support Events (PluginLoadEvent handled) --- Cargo.lock | 504 ++++++-- Cargo.toml | 1 + common/Cargo.toml | 5 + common/common-api/Cargo.toml | 10 + common/common-api/src/lib.rs | 57 + common/src/lib.rs | 3 + common/src/plugin/errors.rs | 21 + common/src/{plugin.rs => plugin/mod.rs} | 39 +- common/src/plugin/module.rs | 150 +++ common/sys/src/state.rs | 12 +- plugin-api/Cargo.toml | 7 +- plugin-api/hello/Cargo.lock | 1566 +---------------------- plugin-api/hello/src/lib.rs | 21 +- plugin-api/plugin_proc/Cargo.toml | 15 + plugin-api/plugin_proc/src/lib.rs | 27 + plugin-api/src/api/mod.rs | 7 - plugin-api/src/lib.rs | 58 +- plugin-api/src/raw_api/mod.rs | 3 - plugin-api/src/raw_hooks/mod.rs | 4 - 19 files changed, 817 insertions(+), 1693 deletions(-) create mode 100644 common/common-api/Cargo.toml create mode 100644 common/common-api/src/lib.rs create mode 100644 common/src/plugin/errors.rs rename common/src/{plugin.rs => plugin/mod.rs} (74%) create mode 100644 common/src/plugin/module.rs create mode 100644 plugin-api/plugin_proc/Cargo.toml create mode 100644 plugin-api/plugin_proc/src/lib.rs delete mode 100644 plugin-api/src/api/mod.rs delete mode 100644 plugin-api/src/raw_api/mod.rs delete mode 100644 plugin-api/src/raw_hooks/mod.rs diff --git a/Cargo.lock b/Cargo.lock index 4c33e79f3a..f83a4e1759 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -22,7 +22,7 @@ version = "0.13.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1b6a2d3371669ab3ca9797670853d61402b03d0b4b9ebf33d677dfa720203072" dependencies = [ - "gimli", + "gimli 0.22.0", ] [[package]] @@ -172,7 +172,7 @@ checksum = "0609c78bd572f4edc74310dfb63a01f5609d53fa8b4dd7c4d98aef3b3e8d72d1" dependencies = [ "proc-macro-hack", "quote 1.0.7", - "syn 1.0.42", + "syn 1.0.54", ] [[package]] @@ -182,9 +182,9 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5a1ae06b5f52588295bfd019b837b6fb1a6914d58ece30b0c43ae439ef08e562" dependencies = [ "proc-macro-error", - "proc-macro2 1.0.23", + "proc-macro2 1.0.24", "quote 1.0.7", - "syn 1.0.42", + "syn 1.0.54", ] [[package]] @@ -290,7 +290,7 @@ source = "git+https://gitlab.com/veloren/auth.git?rev=b943c85e4a38f5ec60cd18c34c dependencies = [ "auth-common", "fxhash", - "hex", + "hex 0.3.2", "rust-argon2", "serde_json", "ureq 1.4.1", @@ -373,7 +373,7 @@ dependencies = [ "lazy_static", "lazycell", "peeking_take_while", - "proc-macro2 1.0.23", + "proc-macro2 1.0.24", "quote 1.0.7", "regex", "rustc-hash", @@ -407,6 +407,21 @@ dependencies = [ "constant_time_eq", ] +[[package]] +name = "blake3" +version = "0.3.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e9ff35b701f3914bdb8fad3368d822c766ef2858b2583198e41639b936f09d3f" +dependencies = [ + "arrayref", + "arrayvec 0.5.1", + "cc", + "cfg-if 0.1.10", + "constant_time_eq", + "crypto-mac", + "digest 0.9.0", +] + [[package]] name = "block" version = "0.1.6" @@ -712,6 +727,13 @@ dependencies = [ "pin-project-lite", ] +[[package]] +name = "common-api" +version = "0.1.0" +dependencies = [ + "serde", +] + [[package]] name = "conrod_core" version = "0.63.0" @@ -785,9 +807,9 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2d709e38f0f6100c0c8c0b3aefb0aa1f83af865d7b6b267e8402820513a0c0d8" dependencies = [ "darling", - "proc-macro2 1.0.23", + "proc-macro2 1.0.24", "quote 1.0.7", - "syn 1.0.42", + "syn 1.0.54", ] [[package]] @@ -977,6 +999,66 @@ dependencies = [ "winapi 0.3.9", ] +[[package]] +name = "cranelift-bforest" +version = "0.59.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "45a9c21f8042b9857bda93f6c1910b9f9f24100187a3d3d52f214a34e3dc5818" +dependencies = [ + "cranelift-entity", +] + +[[package]] +name = "cranelift-codegen" +version = "0.59.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7853f77a6e4a33c67a69c40f5e1bb982bd2dc5c4a22e17e67b65bbccf9b33b2e" +dependencies = [ + "byteorder", + "cranelift-bforest", + "cranelift-codegen-meta", + "cranelift-codegen-shared", + "cranelift-entity", + "gimli 0.20.0", + "log", + "smallvec 1.4.2", + "target-lexicon", + "thiserror", +] + +[[package]] +name = "cranelift-codegen-meta" +version = "0.59.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "084cd6d5fb0d1da28acd72c199471bfb09acc703ec8f3bf07b1699584272a3b9" +dependencies = [ + "cranelift-codegen-shared", + "cranelift-entity", +] + +[[package]] +name = "cranelift-codegen-shared" +version = "0.59.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "701b599783305a58c25027a4d73f2d6b599b2d8ef3f26677275f480b4d51e05d" + +[[package]] +name = "cranelift-entity" +version = "0.59.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b88e792b28e1ebbc0187b72ba5ba880dad083abe9231a99d19604d10c9e73f38" + +[[package]] +name = "cranelift-native" +version = "0.59.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "32daf082da21c0c05d93394ff4842c2ab7c4991b1f3186a1d952f8ac660edd0b" +dependencies = [ + "cranelift-codegen", + "raw-cpuid", + "target-lexicon", +] + [[package]] name = "crc32fast" version = "1.2.0" @@ -1208,6 +1290,16 @@ dependencies = [ "winapi 0.3.9", ] +[[package]] +name = "crypto-mac" +version = "0.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b584a330336237c1eecd3e94266efb216c56ed91225d634cb2991c5f3fd1aeab" +dependencies = [ + "generic-array 0.14.4", + "subtle", +] + [[package]] name = "csv" version = "1.1.3" @@ -1237,7 +1329,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7fbaabec2c953050352311293be5c6aba8e141ba19d6811862b232d6fd020484" dependencies = [ "quote 1.0.7", - "syn 1.0.42", + "syn 1.0.54", ] [[package]] @@ -1267,10 +1359,10 @@ checksum = "f0c960ae2da4de88a91b2d920c2a7233b400bc33cb28453a2987822d8392519b" dependencies = [ "fnv", "ident_case", - "proc-macro2 1.0.23", + "proc-macro2 1.0.24", "quote 1.0.7", "strsim 0.9.3", - "syn 1.0.42", + "syn 1.0.54", ] [[package]] @@ -1281,7 +1373,7 @@ checksum = "d9b5a2f4ac4969822c62224815d069952656cadc7084fdca9751e6d959189b72" dependencies = [ "darling_core", "quote 1.0.7", - "syn 1.0.42", + "syn 1.0.54", ] [[package]] @@ -1317,9 +1409,9 @@ version = "2.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cb582b60359da160a9477ee80f15c8d784c477e69c217ef2cdd4169c24ea380f" dependencies = [ - "proc-macro2 1.0.23", + "proc-macro2 1.0.24", "quote 1.0.7", - "syn 1.0.42", + "syn 1.0.54", ] [[package]] @@ -1345,9 +1437,9 @@ version = "1.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "45f5098f628d02a7a0f68ddba586fb61e80edec3bdc1be3b921f4ceec60858d3" dependencies = [ - "proc-macro2 1.0.23", + "proc-macro2 1.0.24", "quote 1.0.7", - "syn 1.0.42", + "syn 1.0.54", ] [[package]] @@ -1360,6 +1452,24 @@ dependencies = [ "migrations_macros", ] +[[package]] +name = "digest" +version = "0.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f3d0c8c8752312f9713efd397ff63acb9f85585afbf179282e720e7704954dd5" +dependencies = [ + "generic-array 0.12.3", +] + +[[package]] +name = "digest" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d3dd60d1080a57a05ab032377049e0591415d2b31afd7028356dbf3cc6dcb066" +dependencies = [ + "generic-array 0.14.4", +] + [[package]] name = "directories-next" version = "2.0.0" @@ -1483,9 +1593,30 @@ version = "0.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1e94aa31f7c0dc764f57896dc615ddd76fc13b0d5dca7eb6cc5e018a5a09ec06" dependencies = [ - "proc-macro2 1.0.23", + "proc-macro2 1.0.24", "quote 1.0.7", - "syn 1.0.42", + "syn 1.0.54", +] + +[[package]] +name = "errno" +version = "0.2.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fa68f2fb9cae9d37c9b2b3584aba698a2e97f72d7aef7b9f7aa71d8b54ce46fe" +dependencies = [ + "errno-dragonfly", + "libc", + "winapi 0.3.9", +] + +[[package]] +name = "errno-dragonfly" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "14ca354e36190500e1e1fb267c647932382b54053c50b14970856c0b00a35067" +dependencies = [ + "gcc", + "libc", ] [[package]] @@ -1540,9 +1671,9 @@ version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ccb5acb1045ebbfa222e2c50679e392a71dd77030b78fb0189f2d9c5974400f9" dependencies = [ - "proc-macro2 1.0.23", + "proc-macro2 1.0.24", "quote 1.0.7", - "syn 1.0.42", + "syn 1.0.54", ] [[package]] @@ -1714,9 +1845,9 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d0b5a30a4328ab5473878237c447333c093297bded83a4983d10f4deea240d39" dependencies = [ "proc-macro-hack", - "proc-macro2 1.0.23", + "proc-macro2 1.0.24", "quote 1.0.7", - "syn 1.0.42", + "syn 1.0.54", ] [[package]] @@ -1777,6 +1908,31 @@ dependencies = [ "byteorder", ] +[[package]] +name = "gcc" +version = "0.3.55" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f5f3913fa0bfe7ee1fd8248b6b9f42a5af4b9d65ec2dd2c3c26132b950ecfc2" + +[[package]] +name = "generic-array" +version = "0.12.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c68f0274ae0e023facc3c97b2e00f076be70e254bc851d972503b328db79b2ec" +dependencies = [ + "typenum", +] + +[[package]] +name = "generic-array" +version = "0.14.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "501466ecc8a30d1d3b7fc9229b122b2ce8ed6e9d9223f1138d4babb253e51817" +dependencies = [ + "typenum", + "version_check 0.9.2", +] + [[package]] name = "getrandom" version = "0.1.15" @@ -1864,6 +2020,16 @@ dependencies = [ "winapi 0.3.9", ] +[[package]] +name = "gimli" +version = "0.20.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "81dd6190aad0f05ddbbf3245c54ed14ca4aa6dd32f22312b70d8f168c3e3e633" +dependencies = [ + "byteorder", + "indexmap", +] + [[package]] name = "gimli" version = "0.22.0" @@ -2105,6 +2271,12 @@ version = "0.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "805026a5d0141ffc30abb3be3173848ad46a1b1664fe632428479619a3644d77" +[[package]] +name = "hex" +version = "0.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "644f9158b2f133fd50f5fb3242878846d9eb792e445c893805ff0e3824006e35" + [[package]] name = "hibitset" version = "0.6.3" @@ -2324,6 +2496,7 @@ checksum = "55e2e4c765aa53a0424761bf9f41aa7a6ac1efa87238f59560640e27fca028f2" dependencies = [ "autocfg 1.0.1", "hashbrown 0.9.1", + "serde", ] [[package]] @@ -2753,9 +2926,9 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9753f12909fd8d923f75ae5c3258cae1ed3c8ec052e1b38c93c21a6d157f789c" dependencies = [ "migrations_internals", - "proc-macro2 1.0.23", + "proc-macro2 1.0.24", "quote 1.0.7", - "syn 1.0.42", + "syn 1.0.54", ] [[package]] @@ -2930,9 +3103,9 @@ checksum = "05d1c6307dc424d0f65b9b06e94f88248e6305726b14729fd67a5e47b2dc481d" dependencies = [ "darling", "proc-macro-crate", - "proc-macro2 1.0.23", + "proc-macro2 1.0.24", "quote 1.0.7", - "syn 1.0.42", + "syn 1.0.54", ] [[package]] @@ -3106,9 +3279,9 @@ version = "0.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6f09b9841adb6b5e1f89ef7087ea636e0fd94b2851f887c1e3eb5d5f8228fab3" dependencies = [ - "proc-macro2 1.0.23", + "proc-macro2 1.0.24", "quote 1.0.7", - "syn 1.0.42", + "syn 1.0.54", ] [[package]] @@ -3200,9 +3373,9 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ffa5a33ddddfee04c0283a7653987d634e880347e96b5b2ed64de07efb59db9d" dependencies = [ "proc-macro-crate", - "proc-macro2 1.0.23", + "proc-macro2 1.0.24", "quote 1.0.7", - "syn 1.0.42", + "syn 1.0.54", ] [[package]] @@ -3390,6 +3563,16 @@ dependencies = [ "libm", ] +[[package]] +name = "page_size" +version = "0.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "eebde548fbbf1ea81a99b128872779c437752fb99f217c45245e1a61dcd9edcd" +dependencies = [ + "libc", + "winapi 0.3.9", +] + [[package]] name = "parking_lot" version = "0.9.0" @@ -3508,9 +3691,9 @@ version = "0.4.24" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "24c6d293bdd3ca5a1697997854c6cf7855e43fb6a0ba1c47af57a5bcafd158ae" dependencies = [ - "proc-macro2 1.0.23", + "proc-macro2 1.0.24", "quote 1.0.7", - "syn 1.0.42", + "syn 1.0.54", ] [[package]] @@ -3570,6 +3753,15 @@ dependencies = [ "web-sys", ] +[[package]] +name = "plugin_proc" +version = "0.1.0" +dependencies = [ + "proc-macro2 1.0.24", + "quote 1.0.7", + "syn 1.0.54", +] + [[package]] name = "png" version = "0.16.7" @@ -3612,9 +3804,9 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "da25490ff9892aab3fcf7c36f08cfb902dd3e71ca0f9f9517bea02a73a5ce38c" dependencies = [ "proc-macro-error-attr", - "proc-macro2 1.0.23", + "proc-macro2 1.0.24", "quote 1.0.7", - "syn 1.0.42", + "syn 1.0.54", "version_check 0.9.2", ] @@ -3624,7 +3816,7 @@ version = "1.0.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a1be40180e52ecc98ad80b184934baf3d0d29f979574e439af5a55274b35f869" dependencies = [ - "proc-macro2 1.0.23", + "proc-macro2 1.0.24", "quote 1.0.7", "version_check 0.9.2", ] @@ -3652,9 +3844,9 @@ dependencies = [ [[package]] name = "proc-macro2" -version = "1.0.23" +version = "1.0.24" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "51ef7cd2518ead700af67bf9d1a658d90b6037d77110fd9c0445429d0ba1c6c9" +checksum = "1e0704ee1a7e00d7bb417d0770ea303c1bccbabf0ef1667dae92b5967f5f8a71" dependencies = [ "unicode-xid 0.2.1", ] @@ -3697,7 +3889,7 @@ version = "1.0.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "aa563d17ecb180e500da1cfd2b028310ac758de548efdd203e18f283af693f37" dependencies = [ - "proc-macro2 1.0.23", + "proc-macro2 1.0.24", ] [[package]] @@ -3876,6 +4068,17 @@ dependencies = [ "rand_core 0.3.1", ] +[[package]] +name = "raw-cpuid" +version = "7.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b4a349ca83373cfa5d6dbb66fd76e58b2cca08da71a5f6400de0a0a6a9bceeaf" +dependencies = [ + "bitflags", + "cc", + "rustc_version", +] + [[package]] name = "raw-window-handle" version = "0.3.3" @@ -3973,7 +4176,7 @@ dependencies = [ "cc", "libc", "once_cell", - "spin 0.5.2", + "spin", "untrusted", "web-sys", "winapi 0.3.9", @@ -4210,13 +4413,32 @@ checksum = "388a1df253eca08550bef6c72392cfe7c30914bf41df5269b68cbd6ff8f570a3" [[package]] name = "serde" -version = "1.0.116" +version = "1.0.118" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "96fe57af81d28386a513cbc6858332abc6117cfdb5999647c6444b8f43a370a5" +checksum = "06c64263859d87aa2eb554587e2d23183398d617427327cf2b3d0ed8c69e4800" dependencies = [ "serde_derive", ] +[[package]] +name = "serde-bench" +version = "0.0.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d733da87e79faaac25616e33d26299a41143fd4cd42746cbb0e91d8feea243fd" +dependencies = [ + "byteorder", + "serde", +] + +[[package]] +name = "serde_bytes" +version = "0.11.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "16ae07dd2f88a366f15bd0632ba725227018c69a1c8550a927324f8eb8368bb9" +dependencies = [ + "serde", +] + [[package]] name = "serde_cbor" version = "0.11.1" @@ -4229,13 +4451,13 @@ dependencies = [ [[package]] name = "serde_derive" -version = "1.0.116" +version = "1.0.118" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f630a6370fd8e457873b4bd2ffdae75408bc291ba72be773772a4c2a065d9ae8" +checksum = "c84d3526699cd55261af4b941e4e725444df67aa4f9e6a3564f18030d12672df" dependencies = [ - "proc-macro2 1.0.23", + "proc-macro2 1.0.24", "quote 1.0.7", - "syn 1.0.42", + "syn 1.0.54", ] [[package]] @@ -4267,9 +4489,9 @@ version = "0.1.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2dc6b7951b17b051f3210b063f12cc17320e2fe30ae05b0fe2a3abb068551c76" dependencies = [ - "proc-macro2 1.0.23", + "proc-macro2 1.0.24", "quote 1.0.7", - "syn 1.0.42", + "syn 1.0.54", ] [[package]] @@ -4333,9 +4555,9 @@ version = "0.6.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a1f37080f2751fbf091dbdebaa95bd6cf9dbf74ad1d50396b1908518a1747fdf" dependencies = [ - "proc-macro2 1.0.23", + "proc-macro2 1.0.24", "quote 1.0.7", - "syn 1.0.42", + "syn 1.0.54", ] [[package]] @@ -4495,12 +4717,6 @@ version = "0.5.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6e63cff320ae2c57904679ba7cb63280a3dc4613885beafb148ee7bf9aa9042d" -[[package]] -name = "spin" -version = "0.7.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "652ac3743312871a5fb703f0337e68ffa3cdc28c863efad0b8dc858fa10c991b" - [[package]] name = "spin_sleep" version = "1.0.0" @@ -4554,11 +4770,11 @@ version = "0.5.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c87a60a40fccc84bef0652345bbbbbe20a605bf5d0ce81719fc476f5c03b50ef" dependencies = [ - "proc-macro2 1.0.23", + "proc-macro2 1.0.24", "quote 1.0.7", "serde", "serde_derive", - "syn 1.0.42", + "syn 1.0.54", ] [[package]] @@ -4568,13 +4784,13 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "58fa5ff6ad0d98d1ffa8cb115892b6e69d67799f6763e162a1c9db421dc22e11" dependencies = [ "base-x", - "proc-macro2 1.0.23", + "proc-macro2 1.0.24", "quote 1.0.7", "serde", "serde_derive", "serde_json", "sha1", - "syn 1.0.42", + "syn 1.0.54", ] [[package]] @@ -4629,11 +4845,17 @@ checksum = "c92e775028122a4b3dd55d58f14fc5120289c69bee99df1d117ae30f84b225c9" dependencies = [ "heck", "proc-macro-error", - "proc-macro2 1.0.23", + "proc-macro2 1.0.24", "quote 1.0.7", - "syn 1.0.42", + "syn 1.0.54", ] +[[package]] +name = "subtle" +version = "2.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "343f3f510c2915908f155e94f17220b19ccfacf2a64a2a5d8004f2c3e311e7fd" + [[package]] name = "sum_type" version = "0.2.0" @@ -4659,11 +4881,11 @@ dependencies = [ [[package]] name = "syn" -version = "1.0.42" +version = "1.0.54" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9c51d92969d209b54a98397e1b91c8ae82d8c87a7bb87df0b29aa2ad81454228" +checksum = "9a2af957a63d6bd42255c359c93d9bfdb97076bd3b820897ce55ffbfbf107f44" dependencies = [ - "proc-macro2 1.0.23", + "proc-macro2 1.0.24", "quote 1.0.7", "unicode-xid 0.2.1", ] @@ -4686,6 +4908,12 @@ dependencies = [ "xattr", ] +[[package]] +name = "target-lexicon" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ab0e7238dcc7b40a7be719a25365910f6807bd864f4cce6b2e6b873658e2b19d" + [[package]] name = "termcolor" version = "1.1.2" @@ -4719,9 +4947,9 @@ version = "1.0.20" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bd80fc12f73063ac132ac92aceea36734f04a1d93c1240c6944e23a3b8841793" dependencies = [ - "proc-macro2 1.0.23", + "proc-macro2 1.0.24", "quote 1.0.7", - "syn 1.0.42", + "syn 1.0.54", ] [[package]] @@ -4964,9 +5192,9 @@ version = "0.1.11" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "80e0ccfc3378da0cce270c946b676a376943f5cd16aeba64568e7939806f4ada" dependencies = [ - "proc-macro2 1.0.23", + "proc-macro2 1.0.24", "quote 1.0.7", - "syn 1.0.42", + "syn 1.0.54", ] [[package]] @@ -5110,6 +5338,12 @@ dependencies = [ "nom 5.1.2", ] +[[package]] +name = "typenum" +version = "1.12.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "373c8a200f9e67a0c95e62a4f52fbf80c23b4381c05a17845531982fa99e6b33" + [[package]] name = "unicode-bidi" version = "0.3.4" @@ -5323,6 +5557,8 @@ version = "0.8.0" dependencies = [ "arraygen", "authc", + "bincode", + "common-api", "criterion", "crossbeam", "csv", @@ -5357,14 +5593,17 @@ dependencies = [ "tracing", "tracy-client", "vek 0.12.0", + "wasmer-runtime", ] [[package]] name = "veloren-plugin-api" version = "0.1.0" dependencies = [ - "spin 0.7.0", - "veloren-common", + "bincode", + "common-api", + "plugin_proc", + "serde", ] [[package]] @@ -5654,9 +5893,9 @@ dependencies = [ "bumpalo", "lazy_static", "log", - "proc-macro2 1.0.23", + "proc-macro2 1.0.24", "quote 1.0.7", - "syn 1.0.42", + "syn 1.0.54", "wasm-bindgen-shared", ] @@ -5688,9 +5927,9 @@ version = "0.2.68" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f249f06ef7ee334cc3b8ff031bfc11ec99d00f34d86da7498396dc1e3b1498fe" dependencies = [ - "proc-macro2 1.0.23", + "proc-macro2 1.0.24", "quote 1.0.7", - "syn 1.0.42", + "syn 1.0.54", "wasm-bindgen-backend", "wasm-bindgen-shared", ] @@ -5701,6 +5940,119 @@ version = "0.2.68" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1d649a3145108d7d3fbcde896a468d1bd636791823c9921135218ad89be08307" +[[package]] +name = "wasmer-clif-backend" +version = "0.17.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5a2fae69b1c7429316cad6743f3d2ca83cf8957924c477c5a4eff036ec0097a9" +dependencies = [ + "byteorder", + "cranelift-codegen", + "cranelift-entity", + "cranelift-native", + "libc", + "nix 0.15.0", + "rayon", + "serde", + "serde-bench", + "serde_bytes", + "serde_derive", + "target-lexicon", + "wasmer-clif-fork-frontend", + "wasmer-clif-fork-wasm", + "wasmer-runtime-core", + "wasmer-win-exception-handler", + "wasmparser", + "winapi 0.3.9", +] + +[[package]] +name = "wasmer-clif-fork-frontend" +version = "0.59.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c23f2824f354a00a77e4b040eef6e1d4c595a8a3e9013bad65199cc8dade9a5a" +dependencies = [ + "cranelift-codegen", + "log", + "smallvec 1.4.2", + "target-lexicon", +] + +[[package]] +name = "wasmer-clif-fork-wasm" +version = "0.59.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a35e21d3aebc51cc6ebc0e830cf8458a9891c3482fb3c65ad18d408102929ae5" +dependencies = [ + "cranelift-codegen", + "cranelift-entity", + "log", + "thiserror", + "wasmer-clif-fork-frontend", + "wasmparser", +] + +[[package]] +name = "wasmer-runtime" +version = "0.17.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c92a9ae96b193c35c47fc829265198322cf980edc353a9de32bc87a1545d44f3" +dependencies = [ + "lazy_static", + "memmap", + "serde", + "serde_derive", + "wasmer-clif-backend", + "wasmer-runtime-core", +] + +[[package]] +name = "wasmer-runtime-core" +version = "0.17.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "740161245998752cf1a567e860fd6355df0336fedca6be1940ec7aaa59643220" +dependencies = [ + "bincode", + "blake3", + "cc", + "digest 0.8.1", + "errno", + "hex 0.4.2", + "indexmap", + "lazy_static", + "libc", + "nix 0.15.0", + "page_size", + "parking_lot 0.10.2", + "rustc_version", + "serde", + "serde-bench", + "serde_bytes", + "serde_derive", + "smallvec 1.4.2", + "target-lexicon", + "wasmparser", + "winapi 0.3.9", +] + +[[package]] +name = "wasmer-win-exception-handler" +version = "0.17.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1cd39f3b2bd7964b28ea6f944a7eaa445cfbc91c4f2695d188103f2689bb37d9" +dependencies = [ + "cc", + "libc", + "wasmer-runtime-core", + "winapi 0.3.9", +] + +[[package]] +name = "wasmparser" +version = "0.51.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "aeb1956b19469d1c5e63e459d29e7b5aa0f558d9f16fcef09736f8a265e6c10a" + [[package]] name = "wayland-client" version = "0.27.0" @@ -5819,7 +6171,7 @@ version = "0.27.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "030f56009d932bd9400bb472764fea8109be1b0fc482d9cd75496c943ac30328" dependencies = [ - "proc-macro2 1.0.23", + "proc-macro2 1.0.24", "quote 1.0.7", "xml-rs", ] @@ -5830,7 +6182,7 @@ version = "0.28.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e1cc091af4b05a435312f7cefe3a26824d2017966a58362ca913f72c3d68e5e2" dependencies = [ - "proc-macro2 1.0.23", + "proc-macro2 1.0.24", "quote 1.0.7", "xml-rs", ] diff --git a/Cargo.toml b/Cargo.toml index 63832b4a96..ce8d132762 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -4,6 +4,7 @@ cargo-features = ["named-profiles","profile-overrides"] members = [ "common", "common/sys", + "common/common-api", "client", "plugin-api", "server", diff --git a/common/Cargo.toml b/common/Cargo.toml index 8a2da17983..556b1271c0 100644 --- a/common/Cargo.toml +++ b/common/Cargo.toml @@ -63,6 +63,11 @@ structopt = { version = "0.3.13", optional = true } # Tracy tracy-client = { version = "0.9.0", optional = true } +# Plugins +wasmer-runtime = "0.17.1" +bincode = "1.3.1" +common-api = {path = "./common-api"} + [dev-dependencies] #bench criterion = "0.3" diff --git a/common/common-api/Cargo.toml b/common/common-api/Cargo.toml new file mode 100644 index 0000000000..27baec7453 --- /dev/null +++ b/common/common-api/Cargo.toml @@ -0,0 +1,10 @@ +[package] +name = "common-api" +version = "0.1.0" +authors = ["ccgauche "] +edition = "2018" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +serde = {version = "1.0.118", features = ["derive"]} \ No newline at end of file diff --git a/common/common-api/src/lib.rs b/common/common-api/src/lib.rs new file mode 100644 index 0000000000..9218fb62f8 --- /dev/null +++ b/common/common-api/src/lib.rs @@ -0,0 +1,57 @@ +use serde::{Serialize, de::DeserializeOwned, Deserialize}; + + +#[derive(Deserialize,Serialize,Debug)] +pub enum Action { + ServerClose, + Print(String), + PlayerSendMessage(usize,String), + KillEntity(usize) +} + +pub trait Event: Serialize + DeserializeOwned{ + type Response: Serialize + DeserializeOwned; +} + +pub mod events { + + use super::Event; + use serde::{Serialize,Deserialize}; + #[derive(Serialize, Deserialize, Debug)] + pub struct PlayerJoinEvent { + pub player_name: String, + pub player_id: usize + } + + impl Event for PlayerJoinEvent { + type Response = PlayerJoinResult; + } + + #[derive(Serialize, Deserialize, Debug)] + pub enum PlayerJoinResult { + CloseConnection, + None + } + + impl Default for PlayerJoinResult { + fn default() -> Self { + Self::None + } + } + + #[derive(Serialize, Deserialize, Debug)] + pub struct PluginLoadEvent; + + impl Event for PluginLoadEvent { + type Response = (); + } + + // #[derive(Serialize, Deserialize, Debug)] + // pub struct EmptyResult; + + // impl Default for PlayerJoinResult { + // fn default() -> Self { + // Self::None + // } + // } +} \ No newline at end of file diff --git a/common/src/lib.rs b/common/src/lib.rs index 2b410155f4..4de06ca912 100644 --- a/common/src/lib.rs +++ b/common/src/lib.rs @@ -17,6 +17,8 @@ option_zip )] +pub extern crate common_api; + pub mod assets; pub mod astar; pub mod character; @@ -55,6 +57,7 @@ pub mod util; pub mod vol; pub mod volumes; + pub use combat::{Damage, DamageSource, GroupTarget, Knockback}; pub use explosion::{Explosion, RadiusEffect}; pub use loadout_builder::LoadoutBuilder; diff --git a/common/src/plugin/errors.rs b/common/src/plugin/errors.rs new file mode 100644 index 0000000000..ad6bfef789 --- /dev/null +++ b/common/src/plugin/errors.rs @@ -0,0 +1,21 @@ +use bincode::ErrorKind; +use wasmer_runtime::error::{ResolveError, RuntimeError}; + +#[derive(Debug)] +pub enum PluginError { + Io(std::io::Error), + Toml(toml::de::Error), + NoConfig, + NoSuchModule, + PluginModuleError(PluginModuleError) +} + +#[derive(Debug)] +pub enum PluginModuleError { + FindFunction(String), + FunctionGet(ResolveError), + Compile(wasmer_runtime::error::CompileError), + Instantiate(wasmer_runtime::error::Error), + RunFunction(RuntimeError), + Encoding(Box), +} \ No newline at end of file diff --git a/common/src/plugin.rs b/common/src/plugin/mod.rs similarity index 74% rename from common/src/plugin.rs rename to common/src/plugin/mod.rs index e90c15641b..193776a155 100644 --- a/common/src/plugin.rs +++ b/common/src/plugin/mod.rs @@ -1,20 +1,20 @@ + +pub mod errors; +pub mod module; + use crate::assets::ASSETS_PATH; use serde::{Deserialize, Serialize}; use std::{ collections::HashMap, fs, - io::{self, Read}, + io::Read, path::{Path, PathBuf}, }; use tracing::{error, info}; -#[derive(Debug)] -pub enum PluginError { - Io(io::Error), - Toml(toml::de::Error), - NoConfig, - NoSuchModule, -} +use common_api::Event; + +use self::{ errors::PluginError, module::{PluginModule, PreparedEventQuery}}; #[derive(Clone, Debug, Serialize, Deserialize)] pub struct PluginData { @@ -23,11 +23,6 @@ pub struct PluginData { dependencies: Vec, } -#[derive(Clone)] -pub struct PluginModule { - wasm_data: Vec, -} - #[derive(Clone)] pub struct Plugin { data: PluginData, @@ -66,7 +61,7 @@ impl Plugin { .iter() .map(|path| { let wasm_data = files.remove(path).ok_or(PluginError::NoSuchModule)?; - Ok(PluginModule { wasm_data }) + PluginModule::new(&wasm_data).map_err(|e| PluginError::PluginModuleError(e)) }) .collect::>()?; @@ -76,6 +71,12 @@ impl Plugin { files, }) } + + pub fn execute_prepared(&self, event_name: &str, event: &PreparedEventQuery) -> Result, PluginError> where T: Event { + self.modules.iter().flat_map(|module| { + module.try_execute(event_name, event).map(|x| x.map_err(|e| PluginError::PluginModuleError(e))) + }).collect::,_>>() + } } #[derive(Clone, Default)] @@ -91,6 +92,16 @@ impl PluginMgr { Self::from_dir(assets_path) } + pub fn execute_prepared(&self, event_name: &str,event: &PreparedEventQuery) -> Result, PluginError> where T: Event { + Ok(self.plugins.iter().map(|plugin| { + plugin.execute_prepared(event_name, event) + }).collect::>, _>>()?.into_iter().flatten().collect::>()) + } + + pub fn execute_event(&self, event_name: &str,event: &T) -> Result, PluginError> where T: Event { + self.execute_prepared(event_name, &PreparedEventQuery::new(event)?) + } + pub fn from_dir>(path: P) -> Result { let plugins = fs::read_dir(path) .map_err(PluginError::Io)? diff --git a/common/src/plugin/module.rs b/common/src/plugin/module.rs new file mode 100644 index 0000000000..e025da71be --- /dev/null +++ b/common/src/plugin/module.rs @@ -0,0 +1,150 @@ +use std::{marker::PhantomData, sync::Arc}; + +use error::RuntimeError; +use parking_lot::Mutex; +use wasmer_runtime::*; + +use super::errors::{PluginError, PluginModuleError}; +use common_api::{Action, Event}; + +// This represent a WASM function interface +pub type Function<'a> = Func<'a, (i32, u32), i32>; + +#[derive(Clone)] +// This tructure represent the WASM State of the plugin. +pub struct PluginModule { + wasm_instance: Arc>, + events: Vec, +} + +impl PluginModule { + + // This function take bytes from a WASM File and compile them + pub fn new(wasm_data: &Vec) -> Result { + let module = compile(&wasm_data).map_err(|e| PluginModuleError::Compile(e))?; + let instance = module + .instantiate(&imports! {"env" => { + "send_action" => func!(read_action), + }}).map_err(|e| PluginModuleError::Instantiate(e))?; + + Ok(Self { + events: instance.exports.into_iter().map(|(name, _)| name).collect(), + wasm_instance: Arc::new(Mutex::new(instance)), + }) + } + + // This function try to execute an event for the current module will return None if the event doesn't exists + pub fn try_execute( + &self, + event_name: &str, + request: &PreparedEventQuery, + ) -> Option> + where + T: Event, + { + if !self.events.iter().any(|x| x == event_name) { + return None; + } + let bytes = { + let instance = self.wasm_instance.lock(); + let func = match instance.exports.get(event_name).map_err(|e| PluginModuleError::FunctionGet(e)) { + Ok(e) => e, + Err(e) => return Some(Err(e)) + }; + let mem = instance.context().memory(0); + match execute_raw(&mem, &func, &request.bytes).map_err(|e| PluginModuleError::RunFunction(e)) { + Ok(e) => e, + Err(e) => return Some(Err(e)) + } + }; + Some(bincode::deserialize(&bytes).map_err(|e| PluginModuleError::Encoding(e))) + } +} + +// This structure represent a Pre-encoded event object (Usefull to avoid reencoding for each module in every plugin) +pub struct PreparedEventQuery { + bytes: Vec, + _phantom: PhantomData, +} + +impl PreparedEventQuery { + // Create a prepared query from a event reference (Encode to bytes the struct) + // This Prepared Query is used by the `try_execute` method in `PluginModule` + pub fn new(event: &T) -> Result + where + T: Event, + { + Ok(Self { + bytes: bincode::serialize(&event).map_err(|e| PluginError::PluginModuleError(PluginModuleError::Encoding(e)))?, + _phantom: PhantomData::default(), + }) + } +} + +const MEMORY_POS: usize = 100000; + +// This function is not public because this function should not be used without an interface to limit unsafe behaviours +#[allow(unsafe_code)] +fn execute_raw( + memory: &Memory, + function: &Function, + bytes: &[u8], +) -> Result, RuntimeError> { + let view = memory.view::(); + let len = bytes.len(); + for (cell, byte) in view[MEMORY_POS..len + MEMORY_POS].iter().zip(bytes.iter()) { + cell.set(*byte) + } + let start = function + .call(MEMORY_POS as i32, len as u32)? as usize; + let view = memory.view::(); + let mut new_len_bytes = [0u8; 4]; + // TODO: It is probably better to dirrectly make the new_len_bytes + for i in 0..4 { + // Since memory view is a more than 11500 elements array we can get the [1;4] without any bound checks + unsafe { + new_len_bytes[i] = view.get_unchecked(i + 1).get(); + } + } + let new_len = u32::from_ne_bytes(new_len_bytes) as usize; + Ok(view[start..start + new_len] + .iter() + .map(|c| c.get()) + .collect()) +} + +pub fn read_action(ctx: &mut Ctx, ptr: u32, len: u32) { + let memory = ctx.memory(0); + + let memory = memory.view::(); + + let str_slice = &memory[ptr as usize..(ptr + len) as usize]; + + let bytes: Vec = str_slice.iter().map(|x| x.get()).collect(); + + let e: Vec = match bincode::deserialize(&bytes) { + Ok(e) => e, + Err(e) => { + tracing::error!(?e, "Can't decode action"); + return; + } + }; + + for action in e { + match action { + Action::ServerClose => { + tracing::info!("Server closed by plugin"); + std::process::exit(-1); + } + Action::Print(e) => { + tracing::info!("{}",e); + } + Action::PlayerSendMessage(a, b) => { + tracing::info!("SendMessage {} -> {}",a,b); + } + Action::KillEntity(e) => { + tracing::info!("Kill Entity {}",e); + } + } + } +} \ No newline at end of file diff --git a/common/sys/src/state.rs b/common/sys/src/state.rs index e8fadcdc0a..6860d4eb5d 100644 --- a/common/sys/src/state.rs +++ b/common/sys/src/state.rs @@ -180,13 +180,23 @@ impl State { // Load plugins from asset directory ecs.insert(match PluginMgr::from_assets() { - Ok(plugin_mgr) => plugin_mgr, + Ok(plugin_mgr) => { + if let Err(e) = plugin_mgr.execute_event("on_load", &common::common_api::events::PluginLoadEvent {}) { + tracing::error!(?e, "Failed to run plugin init"); + info!("Error occurred when loading plugins. Running without plugins instead."); + PluginMgr::default() + } else { + plugin_mgr + } + }, Err(_) => { info!("Error occurred when loading plugins. Running without plugins instead."); PluginMgr::default() }, }); + //manager.execute_event("on_load", &); + ecs } diff --git a/plugin-api/Cargo.toml b/plugin-api/Cargo.toml index b8291db26a..3e50ed0f76 100644 --- a/plugin-api/Cargo.toml +++ b/plugin-api/Cargo.toml @@ -5,6 +5,9 @@ authors = ["Joshua Barretto "] edition = "2018" [dependencies] -common = { package = "veloren-common", path = "../common" } +common-api = { path = "../common/common-api" } +plugin_proc = { path = "./plugin_proc"} +serde = {version = "1.0.118", features = ["derive"]} +bincode = "1.3.1" -spin = "0.7" +# spin = "0.7" diff --git a/plugin-api/hello/Cargo.lock b/plugin-api/hello/Cargo.lock index 5cb1e5f6b7..e2fb998e8c 100644 --- a/plugin-api/hello/Cargo.lock +++ b/plugin-api/hello/Cargo.lock @@ -1,133 +1,15 @@ # This file is automatically @generated by Cargo. # It is not intended for manual editing. [[package]] -name = "adler32" -version = "1.2.0" +name = "bincode" +version = "1.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "aae1277d39aeec15cb388266ecc24b11c80469deae6067e17a1a7aa9e5c1f234" - -[[package]] -name = "ahash" -version = "0.3.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e8fd72866655d1904d6b0997d0b07ba561047d070fbe29de039031c641b61217" - -[[package]] -name = "anymap" -version = "0.12.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "33954243bd79057c2de7338850b85983a44588021f8a5fee574a8888c6de4344" - -[[package]] -name = "approx" -version = "0.3.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f0e60b75072ecd4168020818c0107f2857bb6c4e64252d8d3983f6263b40a5c3" +checksum = "f30d3a39baa26f9651f17b375061f3233dde33424a8b72b0dbe93a68a0bc896d" dependencies = [ - "num-traits", -] - -[[package]] -name = "arraygen" -version = "0.1.14" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5a1ae06b5f52588295bfd019b837b6fb1a6914d58ece30b0c43ae439ef08e562" -dependencies = [ - "proc-macro-error", - "proc-macro2", - "quote", - "syn", -] - -[[package]] -name = "arrayref" -version = "0.3.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a4c527152e37cf757a3f78aae5a06fbeefdb07ccc535c980a3208ee3060dd544" - -[[package]] -name = "arrayvec" -version = "0.5.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "23b62fc65de8e4e7f52534fb52b0f3ed04746ae267519eef2a83941e8085068b" - -[[package]] -name = "atom" -version = "0.3.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c9ff149ed9780025acfdb36862d35b28856bb693ceb451259a7164442f22fdc3" - -[[package]] -name = "auth-common" -version = "0.1.0" -source = "git+https://gitlab.com/veloren/auth.git?rev=b943c85e4a38f5ec60cd18c34c73097640162bfe#b943c85e4a38f5ec60cd18c34c73097640162bfe" -dependencies = [ - "rand", + "byteorder", "serde", - "uuid", ] -[[package]] -name = "authc" -version = "1.0.0" -source = "git+https://gitlab.com/veloren/auth.git?rev=b943c85e4a38f5ec60cd18c34c73097640162bfe#b943c85e4a38f5ec60cd18c34c73097640162bfe" -dependencies = [ - "auth-common", - "fxhash", - "hex", - "rust-argon2", - "serde_json", - "ureq", - "uuid", -] - -[[package]] -name = "autocfg" -version = "1.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cdb031dd78e28731d87d56cc8ffef4a8f36ca26c38fe2de700543e627f8a464a" - -[[package]] -name = "base64" -version = "0.12.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3441f0f7b02788e948e47f457ca01f1d7e6d92c693bc132c22b087d3141c03ff" - -[[package]] -name = "base64" -version = "0.13.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "904dfeac50f3cdaba28fc6f57fdcddb75f49ed61346676a78c4ffe55877802fd" - -[[package]] -name = "bitflags" -version = "1.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cf1de2fe8c75bc145a2f577add951f8134889b4795d47466a54a5c846d691693" - -[[package]] -name = "blake2b_simd" -version = "0.5.11" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "afa748e348ad3be8263be728124b24a24f268266f6f5d58af9d75f6a40b5c587" -dependencies = [ - "arrayref", - "arrayvec", - "constant_time_eq", -] - -[[package]] -name = "bumpalo" -version = "3.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2e8c087f005730276d1096a652e92a8bacee2e2472bcc9715a74d2bec38b5820" - -[[package]] -name = "bytemuck" -version = "1.4.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "41aa2ec95ca3b5c54cf73c91acf06d24f4495d5f1b1c12506ae3483d646177ac" - [[package]] name = "byteorder" version = "1.3.4" @@ -135,338 +17,12 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "08c48aae112d48ed9f069b33538ea9e3e90aa263cfa3d1c24309612b1f7472de" [[package]] -name = "cc" -version = "1.0.66" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4c0496836a84f8d0495758516b8621a622beb77c0fed418570e50764093ced48" - -[[package]] -name = "cfg-if" -version = "0.1.10" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4785bdd1c96b2a846b2bd7cc02e86b6b3dbf14e7e53446c4f54c92a361040822" - -[[package]] -name = "cfg-if" -version = "1.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" - -[[package]] -name = "chunked_transfer" -version = "1.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7477065d45a8fe57167bf3cf8bcd3729b54cfcb81cca49bda2d038ea89ae82ca" - -[[package]] -name = "color_quant" -version = "1.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3d7b894f5411737b7867f4827955924d7c254fc9f4d91a6aad6b097804b1018b" - -[[package]] -name = "const_fn" -version = "0.4.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cd51eab21ab4fd6a3bf889e2d0958c0a6e3a61ad04260325e919e652a2a62826" - -[[package]] -name = "constant_time_eq" -version = "0.1.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "245097e9a4535ee1e3e3931fcfcd55a796a44c643e8596ff6566d68f09b87bbc" - -[[package]] -name = "crc32fast" -version = "1.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "81156fece84ab6a9f2afdb109ce3ae577e42b1228441eded99bd77f627953b1a" +name = "common-api" +version = "0.1.0" dependencies = [ - "cfg-if 1.0.0", -] - -[[package]] -name = "crossbeam" -version = "0.7.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "69323bff1fb41c635347b8ead484a5ca6c3f11914d784170b158d8449ab07f8e" -dependencies = [ - "cfg-if 0.1.10", - "crossbeam-channel 0.4.4", - "crossbeam-deque 0.7.3", - "crossbeam-epoch 0.8.2", - "crossbeam-queue", - "crossbeam-utils 0.7.2", -] - -[[package]] -name = "crossbeam-channel" -version = "0.4.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b153fe7cbef478c567df0f972e02e6d736db11affe43dfc9c56a9374d1adfb87" -dependencies = [ - "crossbeam-utils 0.7.2", - "maybe-uninit", -] - -[[package]] -name = "crossbeam-channel" -version = "0.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dca26ee1f8d361640700bde38b2c37d8c22b3ce2d360e1fc1c74ea4b0aa7d775" -dependencies = [ - "cfg-if 1.0.0", - "crossbeam-utils 0.8.1", -] - -[[package]] -name = "crossbeam-deque" -version = "0.7.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9f02af974daeee82218205558e51ec8768b48cf524bd01d550abe5573a608285" -dependencies = [ - "crossbeam-epoch 0.8.2", - "crossbeam-utils 0.7.2", - "maybe-uninit", -] - -[[package]] -name = "crossbeam-deque" -version = "0.8.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "94af6efb46fef72616855b036a624cf27ba656ffc9be1b9a3c931cfc7749a9a9" -dependencies = [ - "cfg-if 1.0.0", - "crossbeam-epoch 0.9.1", - "crossbeam-utils 0.8.1", -] - -[[package]] -name = "crossbeam-epoch" -version = "0.8.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "058ed274caafc1f60c4997b5fc07bf7dc7cca454af7c6e81edffe5f33f70dace" -dependencies = [ - "autocfg", - "cfg-if 0.1.10", - "crossbeam-utils 0.7.2", - "lazy_static", - "maybe-uninit", - "memoffset 0.5.6", - "scopeguard", -] - -[[package]] -name = "crossbeam-epoch" -version = "0.9.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a1aaa739f95311c2c7887a76863f500026092fb1dce0161dab577e559ef3569d" -dependencies = [ - "cfg-if 1.0.0", - "const_fn", - "crossbeam-utils 0.8.1", - "lazy_static", - "memoffset 0.6.1", - "scopeguard", -] - -[[package]] -name = "crossbeam-queue" -version = "0.2.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "774ba60a54c213d409d5353bda12d49cd68d14e45036a285234c8d6f91f92570" -dependencies = [ - "cfg-if 0.1.10", - "crossbeam-utils 0.7.2", - "maybe-uninit", -] - -[[package]] -name = "crossbeam-utils" -version = "0.7.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c3c7c73a2d1e9fc0886a08b93e98eb643461230d5f1925e4036204d5f2e261a8" -dependencies = [ - "autocfg", - "cfg-if 0.1.10", - "lazy_static", -] - -[[package]] -name = "crossbeam-utils" -version = "0.8.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "02d96d1e189ef58269ebe5b97953da3274d83a93af647c2ddd6f9dab28cedb8d" -dependencies = [ - "autocfg", - "cfg-if 1.0.0", - "lazy_static", -] - -[[package]] -name = "deflate" -version = "0.8.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "73770f8e1fe7d64df17ca66ad28994a0a623ea497fa69486e14984e715c5d174" -dependencies = [ - "adler32", - "byteorder", -] - -[[package]] -name = "directories-next" -version = "2.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "339ee130d97a610ea5a5872d2bbb130fdf68884ff09d3028b81bec8a1ac23bbc" -dependencies = [ - "cfg-if 1.0.0", - "dirs-sys-next", -] - -[[package]] -name = "dirs-sys-next" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "99de365f605554ae33f115102a02057d4fc18b01f3284d6870be0938743cfe7d" -dependencies = [ - "libc", - "redox_users", - "winapi 0.3.9", -] - -[[package]] -name = "dot_vox" -version = "4.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "83c18405ef54de0398b77a3ec8394d3a1639e7bf060e1385201e8db40c44ab41" -dependencies = [ - "byteorder", - "lazy_static", - "log", - "nom 4.2.3", -] - -[[package]] -name = "either" -version = "1.6.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e78d4f1cc4ae33bbfc157ed5d5a5ef3bc29227303d595861deb238fcec4e9457" - -[[package]] -name = "enum-iterator" -version = "0.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c79a6321a1197d7730510c7e3f6cb80432dfefecb32426de8cea0aa19b4bb8d7" -dependencies = [ - "enum-iterator-derive", -] - -[[package]] -name = "enum-iterator-derive" -version = "0.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1e94aa31f7c0dc764f57896dc615ddd76fc13b0d5dca7eb6cc5e018a5a09ec06" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - -[[package]] -name = "filetime" -version = "0.2.13" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0c122a393ea57648015bf06fbd3d372378992e86b9ff5a7a497b076a28c79efe" -dependencies = [ - "cfg-if 1.0.0", - "libc", - "redox_syscall", - "winapi 0.3.9", -] - -[[package]] -name = "form_urlencoded" -version = "1.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ece68d15c92e84fa4f19d3780f1294e5ca82a78a6d515f1efaabcc144688be00" -dependencies = [ - "matches", - "percent-encoding", -] - -[[package]] -name = "fsevent" -version = "2.0.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "97f347202c95c98805c216f9e1df210e8ebaec9fdb2365700a43c10797a35e63" -dependencies = [ - "bitflags", - "fsevent-sys", -] - -[[package]] -name = "fsevent-sys" -version = "3.0.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "77a29c77f1ca394c3e73a9a5d24cfcabb734682d9634fc398f2204a63c994120" -dependencies = [ - "libc", -] - -[[package]] -name = "fuchsia-zircon" -version = "0.3.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2e9763c69ebaae630ba35f74888db465e49e259ba1bc0eda7d06f4a067615d82" -dependencies = [ - "bitflags", - "fuchsia-zircon-sys", -] - -[[package]] -name = "fuchsia-zircon-sys" -version = "0.3.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3dcaa9ae7725d12cdb85b3ad99a434db70b468c09ded17e012d86b5c1010f7a7" - -[[package]] -name = "fxhash" -version = "0.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c31b6d751ae2c7f11320402d34e41349dd1016f8d5d45e48c4312bc8625af50c" -dependencies = [ - "byteorder", -] - -[[package]] -name = "getrandom" -version = "0.1.15" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fc587bc0ec293155d5bfa6b9891ec18a1e330c234f896ea47fbada4cadbe47e6" -dependencies = [ - "cfg-if 0.1.10", - "libc", - "wasi", -] - -[[package]] -name = "hashbrown" -version = "0.7.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "96282e96bfcd3da0d3aa9938bedf1e50df3269b6db08b4876d2da0bb1a0841cf" -dependencies = [ - "ahash", - "autocfg", - "rayon", "serde", ] -[[package]] -name = "hashbrown" -version = "0.9.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d7afe4a420e3fe79967a00898cc1f4db7c8a49a9333a29f8a4bd76a253d5cd04" - [[package]] name = "hello" version = "0.1.0" @@ -475,466 +31,14 @@ dependencies = [ ] [[package]] -name = "hermit-abi" -version = "0.1.17" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5aca5565f760fb5b220e499d72710ed156fdb74e631659e99377d9ebfbd13ae8" -dependencies = [ - "libc", -] - -[[package]] -name = "hex" -version = "0.3.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "805026a5d0141ffc30abb3be3173848ad46a1b1664fe632428479619a3644d77" - -[[package]] -name = "hibitset" -version = "0.6.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "93a1bb8316a44459a7d14253c4d28dd7395cbd23cc04a68c46e851b8e46d64b1" -dependencies = [ - "atom", - "rayon", -] - -[[package]] -name = "idna" -version = "0.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "02e2673c30ee86b5b96a9cb52ad15718aa1f966f5ab9ad54a8b95d5ca33120a9" -dependencies = [ - "matches", - "unicode-bidi", - "unicode-normalization", -] - -[[package]] -name = "image" -version = "0.23.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7ce04077ead78e39ae8610ad26216aed811996b043d47beed5090db674f9e9b5" -dependencies = [ - "bytemuck", - "byteorder", - "color_quant", - "num-iter", - "num-rational", - "num-traits", - "png", -] - -[[package]] -name = "indexmap" -version = "1.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "55e2e4c765aa53a0424761bf9f41aa7a6ac1efa87238f59560640e27fca028f2" -dependencies = [ - "autocfg", - "hashbrown 0.9.1", -] - -[[package]] -name = "inotify" -version = "0.8.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "46dd0a94b393c730779ccfd2a872b67b1eb67be3fc33082e733bdb38b5fde4d4" -dependencies = [ - "bitflags", - "inotify-sys", - "libc", -] - -[[package]] -name = "inotify-sys" -version = "0.1.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c4563555856585ab3180a5bf0b2f9f8d301a728462afffc8195b3f5394229c55" -dependencies = [ - "libc", -] - -[[package]] -name = "instant" -version = "0.1.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "61124eeebbd69b8190558df225adf7e4caafce0d743919e5d6b19652314ec5ec" -dependencies = [ - "cfg-if 1.0.0", -] - -[[package]] -name = "iovec" -version = "0.1.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b2b3ea6ff95e175473f8ffe6a7eb7c00d054240321b84c57051175fe3c1e075e" -dependencies = [ - "libc", -] - -[[package]] -name = "itoa" -version = "0.4.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dc6f3ad7b9d11a0c00842ff8de1b60ee58661048eb8049ed33c73594f359d7e6" - -[[package]] -name = "js-sys" -version = "0.3.46" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cf3d7383929f7c9c7c2d0fa596f325832df98c3704f2c60553080f7127a58175" -dependencies = [ - "wasm-bindgen", -] - -[[package]] -name = "kernel32-sys" -version = "0.2.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7507624b29483431c0ba2d82aece8ca6cdba9382bff4ddd0f7490560c056098d" -dependencies = [ - "winapi 0.2.8", - "winapi-build", -] - -[[package]] -name = "lazy_static" -version = "1.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" - -[[package]] -name = "lazycell" -version = "1.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "830d08ce1d1d941e6b30645f1a0eb5643013d835ce3779a5fc208261dbe10f55" - -[[package]] -name = "libc" -version = "0.2.81" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1482821306169ec4d07f6aca392a4681f66c75c9918aa49641a2595db64053cb" - -[[package]] -name = "lock_api" -version = "0.4.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dd96ffd135b2fd7b973ac026d28085defbe8983df057ced3eb4f2130b0831312" -dependencies = [ - "scopeguard", -] - -[[package]] -name = "log" -version = "0.4.11" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4fabed175da42fed1fa0746b0ea71f412aa9d35e76e95e59b192c64b9dc2bf8b" -dependencies = [ - "cfg-if 0.1.10", -] - -[[package]] -name = "matches" -version = "0.1.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7ffc5c5338469d4d3ea17d269fa8ea3512ad247247c30bd2df69e68309ed0a08" - -[[package]] -name = "maybe-uninit" -version = "2.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "60302e4db3a61da70c0cb7991976248362f30319e88850c487b9b95bbf059e00" - -[[package]] -name = "memchr" -version = "2.3.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0ee1c47aaa256ecabcaea351eae4a9b01ef39ed810004e298d2511ed284b1525" - -[[package]] -name = "memoffset" -version = "0.5.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "043175f069eda7b85febe4a74abbaeff828d9f8b448515d3151a14a3542811aa" -dependencies = [ - "autocfg", -] - -[[package]] -name = "memoffset" -version = "0.6.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "157b4208e3059a8f9e78d559edc658e13df41410cb3ae03979c83130067fdd87" -dependencies = [ - "autocfg", -] - -[[package]] -name = "miniz_oxide" -version = "0.3.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "791daaae1ed6889560f8c4359194f56648355540573244a5448a83ba1ecc7435" -dependencies = [ - "adler32", -] - -[[package]] -name = "mio" -version = "0.6.23" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4afd66f5b91bf2a3bc13fad0e21caedac168ca4c707504e75585648ae80e4cc4" -dependencies = [ - "cfg-if 0.1.10", - "fuchsia-zircon", - "fuchsia-zircon-sys", - "iovec", - "kernel32-sys", - "libc", - "log", - "miow", - "net2", - "slab", - "winapi 0.2.8", -] - -[[package]] -name = "mio-extras" -version = "2.0.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "52403fe290012ce777c4626790c8951324a2b9e3316b3143779c72b029742f19" -dependencies = [ - "lazycell", - "log", - "mio", - "slab", -] - -[[package]] -name = "miow" -version = "0.2.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ebd808424166322d4a38da87083bfddd3ac4c131334ed55856112eb06d46944d" -dependencies = [ - "kernel32-sys", - "net2", - "winapi 0.2.8", - "ws2_32-sys", -] - -[[package]] -name = "mopa" -version = "0.2.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a785740271256c230f57462d3b83e52f998433a7062fc18f96d5999474a9f915" - -[[package]] -name = "net2" -version = "0.2.36" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d7cf75f38f16cb05ea017784dc6dbfd354f76c223dba37701734c4f5a9337d02" -dependencies = [ - "cfg-if 0.1.10", - "libc", - "winapi 0.3.9", -] - -[[package]] -name = "nom" -version = "4.2.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2ad2a91a8e869eeb30b9cb3119ae87773a8f4ae617f41b1eb9c154b2905f7bd6" -dependencies = [ - "memchr", - "version_check 0.1.5", -] - -[[package]] -name = "nom" -version = "5.1.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ffb4262d26ed83a1c0a33a38fe2bb15797329c85770da05e6b828ddb782627af" -dependencies = [ - "memchr", - "version_check 0.9.2", -] - -[[package]] -name = "notify" -version = "5.0.0-pre.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a8b946889dfdad884379cd56367d93b6d0ce8889cc027d26a69a3a31c0a03bb5" -dependencies = [ - "anymap", - "bitflags", - "crossbeam-channel 0.4.4", - "filetime", - "fsevent", - "fsevent-sys", - "inotify", - "libc", - "mio", - "mio-extras", - "walkdir", - "winapi 0.3.9", -] - -[[package]] -name = "num-derive" -version = "0.3.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "876a53fff98e03a936a674b29568b0e605f06b29372c2489ff4de23f1949743d" +name = "plugin_proc" +version = "0.1.0" dependencies = [ "proc-macro2", "quote", "syn", ] -[[package]] -name = "num-integer" -version = "0.1.44" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d2cc698a63b549a70bc047073d2949cce27cd1c7b0a4a862d08a8031bc2801db" -dependencies = [ - "autocfg", - "num-traits", -] - -[[package]] -name = "num-iter" -version = "0.1.42" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b2021c8337a54d21aca0d59a92577a029af9431cb59b909b03252b9c164fad59" -dependencies = [ - "autocfg", - "num-integer", - "num-traits", -] - -[[package]] -name = "num-rational" -version = "0.3.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "12ac428b1cb17fce6f731001d307d351ec70a6d202fc2e60f7d4c5e42d8f4f07" -dependencies = [ - "autocfg", - "num-integer", - "num-traits", -] - -[[package]] -name = "num-traits" -version = "0.2.14" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9a64b1ec5cda2586e284722486d802acf1f7dbdc623e2bfc57e65ca1cd099290" -dependencies = [ - "autocfg", -] - -[[package]] -name = "num_cpus" -version = "1.13.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "05499f3756671c15885fee9034446956fff3f243d6077b91e5767df161f766b3" -dependencies = [ - "hermit-abi", - "libc", -] - -[[package]] -name = "once_cell" -version = "1.5.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "13bd41f508810a131401606d54ac32a467c97172d74ba7662562ebba5ad07fa0" - -[[package]] -name = "ordered-float" -version = "2.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dacdec97876ef3ede8c50efc429220641a0b11ba0048b4b0c357bccbc47c5204" -dependencies = [ - "num-traits", -] - -[[package]] -name = "parking_lot" -version = "0.11.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6d7744ac029df22dca6284efe4e898991d28e3085c706c972bcd7da4a27a15eb" -dependencies = [ - "instant", - "lock_api", - "parking_lot_core", -] - -[[package]] -name = "parking_lot_core" -version = "0.8.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d7c6d9b8427445284a09c55be860a15855ab580a417ccad9da88f5a06787ced0" -dependencies = [ - "cfg-if 1.0.0", - "instant", - "libc", - "redox_syscall", - "smallvec", - "winapi 0.3.9", -] - -[[package]] -name = "percent-encoding" -version = "2.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d4fd5641d01c8f18a23da7b6fe29298ff4b55afcccdf78973b24cf3175fee32e" - -[[package]] -name = "pin-project-lite" -version = "0.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6b063f57ec186e6140e2b8b6921e5f1bd89c7356dda5b33acc5401203ca6131c" - -[[package]] -name = "png" -version = "0.16.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3c3287920cb847dee3de33d301c463fba14dda99db24214ddf93f83d3021f4c6" -dependencies = [ - "bitflags", - "crc32fast", - "deflate", - "miniz_oxide", -] - -[[package]] -name = "ppv-lite86" -version = "0.2.10" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ac74c624d6b2d21f425f752262f42188365d7b8ff1aff74c82e45136510a4857" - -[[package]] -name = "proc-macro-error" -version = "1.0.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "da25490ff9892aab3fcf7c36f08cfb902dd3e71ca0f9f9517bea02a73a5ce38c" -dependencies = [ - "proc-macro-error-attr", - "proc-macro2", - "quote", - "syn", - "version_check 0.9.2", -] - -[[package]] -name = "proc-macro-error-attr" -version = "1.0.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a1be40180e52ecc98ad80b184934baf3d0d29f979574e439af5a55274b35f869" -dependencies = [ - "proc-macro2", - "quote", - "version_check 0.9.2", -] - [[package]] name = "proc-macro2" version = "1.0.24" @@ -944,15 +48,6 @@ dependencies = [ "unicode-xid", ] -[[package]] -name = "qstring" -version = "0.7.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d464fae65fff2680baf48019211ce37aaec0c78e9264c84a3e484717f965104e" -dependencies = [ - "percent-encoding", -] - [[package]] name = "quote" version = "1.0.7" @@ -962,199 +57,6 @@ dependencies = [ "proc-macro2", ] -[[package]] -name = "rand" -version = "0.7.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6a6b1679d49b24bbfe0c803429aa1874472f50d9b363131f0e89fc356b544d03" -dependencies = [ - "getrandom", - "libc", - "rand_chacha", - "rand_core", - "rand_hc", -] - -[[package]] -name = "rand_chacha" -version = "0.2.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f4c8ed856279c9737206bf725bf36935d8666ead7aa69b52be55af369d193402" -dependencies = [ - "ppv-lite86", - "rand_core", -] - -[[package]] -name = "rand_core" -version = "0.5.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "90bde5296fc891b0cef12a6d03ddccc162ce7b2aff54160af9338f8d40df6d19" -dependencies = [ - "getrandom", -] - -[[package]] -name = "rand_hc" -version = "0.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ca3129af7b92a17112d59ad498c6f81eaf463253766b90396d39ea7a39d6613c" -dependencies = [ - "rand_core", -] - -[[package]] -name = "rayon" -version = "1.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8b0d8e0819fadc20c74ea8373106ead0600e3a67ef1fe8da56e39b9ae7275674" -dependencies = [ - "autocfg", - "crossbeam-deque 0.8.0", - "either", - "rayon-core", -] - -[[package]] -name = "rayon-core" -version = "1.9.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9ab346ac5921dc62ffa9f89b7a773907511cdfa5490c572ae9be1be33e8afa4a" -dependencies = [ - "crossbeam-channel 0.5.0", - "crossbeam-deque 0.8.0", - "crossbeam-utils 0.8.1", - "lazy_static", - "num_cpus", -] - -[[package]] -name = "redox_syscall" -version = "0.1.57" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "41cc0f7e4d5d4544e8861606a285bb08d3e70712ccc7d2b84d7c0ccfaf4b05ce" - -[[package]] -name = "redox_users" -version = "0.3.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "de0737333e7a9502c789a36d7c7fa6092a49895d4faa31ca5df163857ded2e9d" -dependencies = [ - "getrandom", - "redox_syscall", -] - -[[package]] -name = "ring" -version = "0.16.19" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "024a1e66fea74c66c66624ee5622a7ff0e4b73a13b4f5c326ddb50c708944226" -dependencies = [ - "cc", - "libc", - "once_cell", - "spin 0.5.2", - "untrusted", - "web-sys", - "winapi 0.3.9", -] - -[[package]] -name = "ron" -version = "0.6.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f8a58080b7bb83b2ea28c3b7a9a994fd5e310330b7c8ca5258d99b98128ecfe4" -dependencies = [ - "base64 0.12.3", - "bitflags", - "serde", -] - -[[package]] -name = "roots" -version = "0.0.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "84348444bd7ad45729d0c49a4240d7cdc11c9d512c06c5ad1835c1ad4acda6db" - -[[package]] -name = "rust-argon2" -version = "0.8.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4b18820d944b33caa75a71378964ac46f58517c92b6ae5f762636247c09e78fb" -dependencies = [ - "base64 0.13.0", - "blake2b_simd", - "constant_time_eq", -] - -[[package]] -name = "rustc_version" -version = "0.2.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "138e3e0acb6c9fb258b19b67cb8abd63c00679d2851805ea151465464fe9030a" -dependencies = [ - "semver", -] - -[[package]] -name = "rustls" -version = "0.19.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "064fd21ff87c6e87ed4506e68beb42459caa4a0e2eb144932e6776768556980b" -dependencies = [ - "base64 0.13.0", - "log", - "ring", - "sct", - "webpki", -] - -[[package]] -name = "ryu" -version = "1.0.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "71d301d4193d031abdd79ff7e3dd721168a9572ef3fe51a1517aba235bd8f86e" - -[[package]] -name = "same-file" -version = "1.0.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "93fc1dc3aaa9bfed95e02e6eadabb4baf7e3078b0bd1b4d7b6b0b68378900502" -dependencies = [ - "winapi-util", -] - -[[package]] -name = "scopeguard" -version = "1.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d29ab0c6d3fc0ee92fe66e2d99f700eab17a8d57d1c1d3b748380fb20baa78cd" - -[[package]] -name = "sct" -version = "0.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e3042af939fca8c3453b7af0f1c66e533a15a86169e39de2657310ade8f98d3c" -dependencies = [ - "ring", - "untrusted", -] - -[[package]] -name = "semver" -version = "0.9.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1d7eb9ef2c18661902cc47e535f9bc51b78acd254da71d375c2f6720d9a40403" -dependencies = [ - "semver-parser", -] - -[[package]] -name = "semver-parser" -version = "0.7.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "388a1df253eca08550bef6c72392cfe7c30914bf41df5269b68cbd6ff8f570a3" - [[package]] name = "serde" version = "1.0.118" @@ -1175,127 +77,6 @@ dependencies = [ "syn", ] -[[package]] -name = "serde_json" -version = "1.0.60" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1500e84d27fe482ed1dc791a56eddc2f230046a040fa908c08bda1d9fb615779" -dependencies = [ - "itoa", - "ryu", - "serde", -] - -[[package]] -name = "serde_repr" -version = "0.1.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2dc6b7951b17b051f3210b063f12cc17320e2fe30ae05b0fe2a3abb068551c76" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - -[[package]] -name = "shred" -version = "0.10.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c5f08237e667ac94ad20f8878b5943d91a93ccb231428446c57c21c57779016d" -dependencies = [ - "arrayvec", - "hashbrown 0.7.2", - "mopa", - "rayon", - "smallvec", - "tynm", -] - -[[package]] -name = "shrev" -version = "1.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b5752e017e03af9d735b4b069f53b7a7fd90fefafa04d8bd0c25581b0bff437f" - -[[package]] -name = "slab" -version = "0.4.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c111b5bd5695e56cffe5129854aa230b39c93a305372fdbb2668ca2394eea9f8" - -[[package]] -name = "slotmap" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c46a3482db8f247956e464d783693ece164ca056e6e67563ee5505bdb86452cd" -dependencies = [ - "serde", -] - -[[package]] -name = "smallvec" -version = "1.5.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ae524f056d7d770e174287294f562e95044c68e88dec909a00d2094805db9d75" - -[[package]] -name = "specs" -version = "0.16.1" -source = "git+https://github.com/amethyst/specs.git?rev=7a2e348ab2223818bad487695c66c43db88050a5#7a2e348ab2223818bad487695c66c43db88050a5" -dependencies = [ - "crossbeam-queue", - "hashbrown 0.7.2", - "hibitset", - "log", - "rayon", - "serde", - "shred", - "shrev", - "tuple_utils", -] - -[[package]] -name = "specs-idvs" -version = "0.1.0" -source = "git+https://gitlab.com/veloren/specs-idvs.git?branch=specs-git#fcb0b2306b571f62f9f85d89e79e087454d95efd" -dependencies = [ - "specs", -] - -[[package]] -name = "spin" -version = "0.5.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6e63cff320ae2c57904679ba7cb63280a3dc4613885beafb148ee7bf9aa9042d" - -[[package]] -name = "spin" -version = "0.7.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "652ac3743312871a5fb703f0337e68ffa3cdc28c863efad0b8dc858fa10c991b" - -[[package]] -name = "spin_sleep" -version = "1.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2a98101bdc3833e192713c2af0b0dd2614f50d1cf1f7a97c5221b7aac052acc7" -dependencies = [ - "once_cell", - "winapi 0.3.9", -] - -[[package]] -name = "static_assertions" -version = "1.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a2eb9349b6444b326872e140eb1cf5e7c522154d69e7a0ffb0fb81c06b37543f" - -[[package]] -name = "sum_type" -version = "0.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "da5b4a0c9f3c7c8e891e445a7c776627e208e8bba23ab680798066dd283e6a15" - [[package]] name = "syn" version = "1.0.54" @@ -1307,341 +88,18 @@ dependencies = [ "unicode-xid", ] -[[package]] -name = "tinyvec" -version = "1.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ccf8dbc19eb42fba10e8feaaec282fb50e2c14b2726d6301dbfeed0f73306a6f" -dependencies = [ - "tinyvec_macros", -] - -[[package]] -name = "tinyvec_macros" -version = "0.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cda74da7e1a664f795bb1f8a87ec406fb89a02522cf6e50620d016add6dbbf5c" - -[[package]] -name = "tracing" -version = "0.1.22" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9f47026cdc4080c07e49b37087de021820269d996f581aac150ef9e5583eefe3" -dependencies = [ - "cfg-if 1.0.0", - "pin-project-lite", - "tracing-core", -] - -[[package]] -name = "tracing-core" -version = "0.1.17" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f50de3927f93d202783f4513cda820ab47ef17f624b03c096e86ef00c67e6b5f" - -[[package]] -name = "tuple_utils" -version = "0.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "44834418e2c5b16f47bedf35c28e148db099187dd5feee6367fb2525863af4f1" - -[[package]] -name = "tynm" -version = "0.1.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a4df2caa2dc9c3d1f7641ba981f4cd40ab229775aa7aeb834c9ab2850d50623d" -dependencies = [ - "nom 5.1.2", -] - -[[package]] -name = "unicode-bidi" -version = "0.3.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "49f2bd0c6468a8230e1db229cff8029217cf623c767ea5d60bfbd42729ea54d5" -dependencies = [ - "matches", -] - -[[package]] -name = "unicode-normalization" -version = "0.1.16" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a13e63ab62dbe32aeee58d1c5408d35c36c392bba5d9d3142287219721afe606" -dependencies = [ - "tinyvec", -] - [[package]] name = "unicode-xid" version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f7fe0bb3479651439c9112f72b6c505038574c9fbb575ed1bf3b797fa39dd564" -[[package]] -name = "untrusted" -version = "0.7.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a156c684c91ea7d62626509bce3cb4e1d9ed5c4d978f7b4352658f96a4c26b4a" - -[[package]] -name = "ureq" -version = "1.5.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "294b85ef5dbc3670a72e82a89971608a1fcc4ed5c7c5a2895230d31a95f0569b" -dependencies = [ - "base64 0.13.0", - "chunked_transfer", - "log", - "once_cell", - "qstring", - "rustls", - "url", - "webpki", - "webpki-roots", -] - -[[package]] -name = "url" -version = "2.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5909f2b0817350449ed73e8bcd81c8c3c8d9a7a5d8acba4b27db277f1868976e" -dependencies = [ - "form_urlencoded", - "idna", - "matches", - "percent-encoding", -] - -[[package]] -name = "uuid" -version = "0.8.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9fde2f6a4bea1d6e007c4ad38c6839fa71cbb63b6dbf5b595aa38dc9b1093c11" -dependencies = [ - "rand", - "serde", -] - -[[package]] -name = "vek" -version = "0.12.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2b5ec6f1e1336c875817faba09752eeac76aa0c51c304b9030cbfcd0daf5e217" -dependencies = [ - "approx", - "num-integer", - "num-traits", - "rustc_version", - "serde", - "static_assertions", -] - -[[package]] -name = "veloren-common" -version = "0.8.0" -dependencies = [ - "arraygen", - "authc", - "crossbeam", - "directories-next", - "dot_vox", - "enum-iterator", - "hashbrown 0.7.2", - "image", - "indexmap", - "lazy_static", - "notify", - "num-derive", - "num-traits", - "ordered-float", - "parking_lot", - "rand", - "rayon", - "ron", - "roots", - "serde", - "serde_json", - "serde_repr", - "slab", - "slotmap", - "specs", - "specs-idvs", - "spin_sleep", - "sum_type", - "tracing", - "vek", -] - [[package]] name = "veloren-plugin-api" version = "0.1.0" dependencies = [ - "spin 0.7.0", - "veloren-common", -] - -[[package]] -name = "version_check" -version = "0.1.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "914b1a6776c4c929a602fafd8bc742e06365d4bcbe48c30f9cca5824f70dc9dd" - -[[package]] -name = "version_check" -version = "0.9.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b5a972e5669d67ba988ce3dc826706fb0a8b01471c088cb0b6110b805cc36aed" - -[[package]] -name = "walkdir" -version = "2.3.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "777182bc735b6424e1a57516d35ed72cb8019d85c8c9bf536dccb3445c1a2f7d" -dependencies = [ - "same-file", - "winapi 0.3.9", - "winapi-util", -] - -[[package]] -name = "wasi" -version = "0.9.0+wasi-snapshot-preview1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cccddf32554fecc6acb585f82a32a72e28b48f8c4c1883ddfeeeaa96f7d8e519" - -[[package]] -name = "wasm-bindgen" -version = "0.2.69" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3cd364751395ca0f68cafb17666eee36b63077fb5ecd972bbcd74c90c4bf736e" -dependencies = [ - "cfg-if 1.0.0", - "wasm-bindgen-macro", -] - -[[package]] -name = "wasm-bindgen-backend" -version = "0.2.69" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1114f89ab1f4106e5b55e688b828c0ab0ea593a1ea7c094b141b14cbaaec2d62" -dependencies = [ - "bumpalo", - "lazy_static", - "log", - "proc-macro2", - "quote", - "syn", - "wasm-bindgen-shared", -] - -[[package]] -name = "wasm-bindgen-macro" -version = "0.2.69" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7a6ac8995ead1f084a8dea1e65f194d0973800c7f571f6edd70adf06ecf77084" -dependencies = [ - "quote", - "wasm-bindgen-macro-support", -] - -[[package]] -name = "wasm-bindgen-macro-support" -version = "0.2.69" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b5a48c72f299d80557c7c62e37e7225369ecc0c963964059509fbafe917c7549" -dependencies = [ - "proc-macro2", - "quote", - "syn", - "wasm-bindgen-backend", - "wasm-bindgen-shared", -] - -[[package]] -name = "wasm-bindgen-shared" -version = "0.2.69" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7e7811dd7f9398f14cc76efd356f98f03aa30419dea46aa810d71e819fc97158" - -[[package]] -name = "web-sys" -version = "0.3.46" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "222b1ef9334f92a21d3fb53dc3fd80f30836959a90f9274a626d7e06315ba3c3" -dependencies = [ - "js-sys", - "wasm-bindgen", -] - -[[package]] -name = "webpki" -version = "0.21.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b8e38c0608262c46d4a56202ebabdeb094cef7e560ca7a226c6bf055188aa4ea" -dependencies = [ - "ring", - "untrusted", -] - -[[package]] -name = "webpki-roots" -version = "0.21.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "82015b7e0b8bad8185994674a13a93306bea76cf5a16c5a181382fd3a5ec2376" -dependencies = [ - "webpki", -] - -[[package]] -name = "winapi" -version = "0.2.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "167dc9d6949a9b857f3451275e911c3f44255842c1f7a76f33c55103a909087a" - -[[package]] -name = "winapi" -version = "0.3.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419" -dependencies = [ - "winapi-i686-pc-windows-gnu", - "winapi-x86_64-pc-windows-gnu", -] - -[[package]] -name = "winapi-build" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2d315eee3b34aca4797b2da6b13ed88266e6d612562a0c46390af8299fc699bc" - -[[package]] -name = "winapi-i686-pc-windows-gnu" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" - -[[package]] -name = "winapi-util" -version = "0.1.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "70ec6ce85bb158151cae5e5c87f95a8e97d2c0c4b001223f33a334e3ce5de178" -dependencies = [ - "winapi 0.3.9", -] - -[[package]] -name = "winapi-x86_64-pc-windows-gnu" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" - -[[package]] -name = "ws2_32-sys" -version = "0.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d59cefebd0c892fa2dd6de581e937301d8552cb44489cdff035c6187cb63fa5e" -dependencies = [ - "winapi 0.2.8", - "winapi-build", + "bincode", + "common-api", + "plugin_proc", + "serde", ] diff --git a/plugin-api/hello/src/lib.rs b/plugin-api/hello/src/lib.rs index f6c53cf8a6..1bb679a2a8 100644 --- a/plugin-api/hello/src/lib.rs +++ b/plugin-api/hello/src/lib.rs @@ -1,7 +1,18 @@ -use plugin_api::{PLUGIN, api}; +use plugin_api::{*,events::*}; -pub extern fn main() { - PLUGIN.on_start(|| { - api::print("Hello from my plugin!"); - }); +#[export_function] +pub fn on_load(load: PluginLoadEvent) -> () { + send_actions(vec![Action::Print("This is a test".to_owned())]); + println!("Hello world"); + +} + +#[export_function] +pub fn on_player_join(input: PlayerJoinEvent) -> PlayerJoinResult { + send_actions(vec![Action::PlayerSendMessage(input.player_id,format!("Welcome {} on our server",input.player_name))]); + if input.player_name == "Cheater123" { + PlayerJoinResult::CloseConnection + } else { + PlayerJoinResult::None + } } diff --git a/plugin-api/plugin_proc/Cargo.toml b/plugin-api/plugin_proc/Cargo.toml new file mode 100644 index 0000000000..44709430b5 --- /dev/null +++ b/plugin-api/plugin_proc/Cargo.toml @@ -0,0 +1,15 @@ +[package] +name = "plugin_proc" +version = "0.1.0" +authors = ["ccgauche "] +edition = "2018" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[lib] +proc-macro = true + +[dependencies] +proc-macro2 = "1.0.24" +syn = { version = "1.0.54", features = ["full","extra-traits"]} +quote = "1.0.7" \ No newline at end of file diff --git a/plugin-api/plugin_proc/src/lib.rs b/plugin-api/plugin_proc/src/lib.rs new file mode 100644 index 0000000000..023e89a19f --- /dev/null +++ b/plugin-api/plugin_proc/src/lib.rs @@ -0,0 +1,27 @@ +extern crate proc_macro; + +use proc_macro::TokenStream; +use quote::quote; +use syn::{parse_macro_input, ItemFn}; + +#[proc_macro_attribute] +pub fn export_function(_args: TokenStream, item: TokenStream) -> TokenStream { + let parsed = parse_macro_input!(item as ItemFn); + let fn_body = parsed.block; // function body + let sig = parsed.sig; // function signature + let fn_name = sig.ident; // function name/identifier + let fn_args = sig.inputs; // comma separated args + let fn_return = sig.output; // comma separated args + + let out: proc_macro2::TokenStream = quote! { + #[no_mangle] + pub fn #fn_name(intern__ptr: i32, intern__len: u32) -> i32 { + let input = plugin_api::read_input(intern__ptr,intern__len).unwrap(); + fn inner(#fn_args) #fn_return { + #fn_body + } + plugin_api::write_output(&inner(input)) + } + }; + out.into() +} \ No newline at end of file diff --git a/plugin-api/src/api/mod.rs b/plugin-api/src/api/mod.rs deleted file mode 100644 index 48d40d36d9..0000000000 --- a/plugin-api/src/api/mod.rs +++ /dev/null @@ -1,7 +0,0 @@ -use crate::raw_api; - -pub fn print(s: &str) { - unsafe { - raw_api::print(s.as_bytes().as_ptr(), s.len()); - } -} diff --git a/plugin-api/src/lib.rs b/plugin-api/src/lib.rs index b3d6fb1e1a..c2d72a9773 100644 --- a/plugin-api/src/lib.rs +++ b/plugin-api/src/lib.rs @@ -1,36 +1,40 @@ #![feature(const_fn)] -pub mod api; -pub mod raw_api; -pub mod raw_hooks; -use spin::Mutex; +pub extern crate plugin_proc; +pub extern crate common_api; -#[derive(Copy, Clone, Debug)] -pub enum Hook { - OnStart, - OnTick, - OnStop, +pub use common_api::*; + + +pub use plugin_proc::*; + +use serde::de::DeserializeOwned; +use serde::Serialize; + +extern "C" { + fn send_action(ptr: *const u8, len: usize); } -pub struct Plugin { - pub on_start: Mutex>>, - pub on_tick: Mutex>>, - pub on_stop: Mutex>>, -} - -impl Plugin { - pub const fn new() -> Self { - Self { - on_start: Mutex::new(Vec::new()), - on_tick: Mutex::new(Vec::new()), - on_stop: Mutex::new(Vec::new()), - } - } - - pub fn on_start(&self, f: impl Fn() + Send + Sync + 'static) { - self.on_start.lock().push(Box::new(f)); +pub fn send_actions(action: Vec) { + let ret = bincode::serialize(&action).unwrap(); + unsafe { + send_action(ret.as_ptr(), ret.len()); } } -pub static PLUGIN: Plugin = Plugin::new(); +pub fn read_input(ptr: i32, len: u32) -> Result where T: DeserializeOwned{ + let slice = unsafe { + ::std::slice::from_raw_parts(ptr as _, len as _) + }; + bincode::deserialize(slice).map_err(|_|"Failed to deserialize function input") +} + +pub fn write_output(value: impl Serialize) -> i32 { + let ret = bincode::serialize(&value).unwrap(); + let len = ret.len() as u32; + unsafe { + ::std::ptr::write(1 as _, len); + } + ret.as_ptr() as _ +} \ No newline at end of file diff --git a/plugin-api/src/raw_api/mod.rs b/plugin-api/src/raw_api/mod.rs deleted file mode 100644 index cfb11dd86e..0000000000 --- a/plugin-api/src/raw_api/mod.rs +++ /dev/null @@ -1,3 +0,0 @@ -extern "C" { - pub fn print(s: *const u8, len: usize); -} diff --git a/plugin-api/src/raw_hooks/mod.rs b/plugin-api/src/raw_hooks/mod.rs deleted file mode 100644 index 875e86902f..0000000000 --- a/plugin-api/src/raw_hooks/mod.rs +++ /dev/null @@ -1,4 +0,0 @@ -use super::*; - -// API -pub extern "C" fn on_tick() { PLUGIN.on_tick.lock().iter().for_each(|f| f()); }