Added plugin system

Added a plugin system based on wasmer-runtime
 - Support Action (Print handled)
 - Support Events (PluginLoadEvent handled)
This commit is contained in:
ccgauche 2020-12-12 00:37:22 +01:00 committed by Joshua Barretto
parent 12b29ea174
commit ee7fb990c3
19 changed files with 817 additions and 1693 deletions

504
Cargo.lock generated
View File

@ -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",
]

View File

@ -4,6 +4,7 @@ cargo-features = ["named-profiles","profile-overrides"]
members = [
"common",
"common/sys",
"common/common-api",
"client",
"plugin-api",
"server",

View File

@ -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"

View File

@ -0,0 +1,10 @@
[package]
name = "common-api"
version = "0.1.0"
authors = ["ccgauche <gaucheron.laurent@gmail.com>"]
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"]}

View File

@ -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
// }
// }
}

View File

@ -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;

View File

@ -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<ErrorKind>),
}

View File

@ -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<String>,
}
#[derive(Clone)]
pub struct PluginModule {
wasm_data: Vec<u8>,
}
#[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::<Result<_, _>>()?;
@ -76,6 +71,12 @@ impl Plugin {
files,
})
}
pub fn execute_prepared<T>(&self, event_name: &str, event: &PreparedEventQuery<T>) -> Result<Vec<T::Response>, 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::<Result<Vec<_>,_>>()
}
}
#[derive(Clone, Default)]
@ -91,6 +92,16 @@ impl PluginMgr {
Self::from_dir(assets_path)
}
pub fn execute_prepared<T>(&self, event_name: &str,event: &PreparedEventQuery<T>) -> Result<Vec<T::Response>, PluginError> where T: Event {
Ok(self.plugins.iter().map(|plugin| {
plugin.execute_prepared(event_name, event)
}).collect::<Result<Vec<Vec<T::Response>>, _>>()?.into_iter().flatten().collect::<Vec<T::Response>>())
}
pub fn execute_event<T>(&self, event_name: &str,event: &T) -> Result<Vec<T::Response>, PluginError> where T: Event {
self.execute_prepared(event_name, &PreparedEventQuery::new(event)?)
}
pub fn from_dir<P: AsRef<Path>>(path: P) -> Result<Self, PluginError> {
let plugins = fs::read_dir(path)
.map_err(PluginError::Io)?

150
common/src/plugin/module.rs Normal file
View File

@ -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<Mutex<Instance>>,
events: Vec<String>,
}
impl PluginModule {
// This function take bytes from a WASM File and compile them
pub fn new(wasm_data: &Vec<u8>) -> Result<Self,PluginModuleError> {
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<T>(
&self,
event_name: &str,
request: &PreparedEventQuery<T>,
) -> Option<Result<T::Response,PluginModuleError>>
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<T> {
bytes: Vec<u8>,
_phantom: PhantomData<T>,
}
impl<T: Event> PreparedEventQuery<T> {
// 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<Self, PluginError>
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<Vec<u8>, RuntimeError> {
let view = memory.view::<u8>();
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::<u8>();
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::<u8>();
let str_slice = &memory[ptr as usize..(ptr + len) as usize];
let bytes: Vec<u8> = str_slice.iter().map(|x| x.get()).collect();
let e: Vec<Action> = 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);
}
}
}
}

View File

@ -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
}

View File

@ -5,6 +5,9 @@ authors = ["Joshua Barretto <joshua.s.barretto@gmail.com>"]
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"

File diff suppressed because it is too large Load Diff

View File

@ -1,7 +1,18 @@
use plugin_api::{PLUGIN, api};
use plugin_api::{*,events::*};
#[export_function]
pub fn on_load(load: PluginLoadEvent) -> () {
send_actions(vec![Action::Print("This is a test".to_owned())]);
println!("Hello world");
pub extern fn main() {
PLUGIN.on_start(|| {
api::print("Hello from my plugin!");
});
}
#[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
}
}

View File

@ -0,0 +1,15 @@
[package]
name = "plugin_proc"
version = "0.1.0"
authors = ["ccgauche <gaucheron.laurent@gmail.com>"]
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"

View File

@ -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()
}

View File

@ -1,7 +0,0 @@
use crate::raw_api;
pub fn print(s: &str) {
unsafe {
raw_api::print(s.as_bytes().as_ptr(), s.len());
}
}

View File

@ -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<Vec<Box<dyn Fn() + Send + Sync>>>,
pub on_tick: Mutex<Vec<Box<dyn Fn() + Send + Sync>>>,
pub on_stop: Mutex<Vec<Box<dyn Fn() + Send + Sync>>>,
}
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<Action>) {
let ret = bincode::serialize(&action).unwrap();
unsafe {
send_action(ret.as_ptr(), ret.len());
}
}
pub static PLUGIN: Plugin = Plugin::new();
pub fn read_input<T>(ptr: i32, len: u32) -> Result<T, &'static str> 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 _
}

View File

@ -1,3 +0,0 @@
extern "C" {
pub fn print(s: *const u8, len: usize);
}

View File

@ -1,4 +0,0 @@
use super::*;
// API
pub extern "C" fn on_tick() { PLUGIN.on_tick.lock().iter().for_each(|f| f()); }