mirror of
https://gitlab.com/veloren/veloren.git
synced 2024-08-30 18:12:32 +00:00
Reorganised plugin crates
This commit is contained in:
parent
05aee7df18
commit
780f54ac90
41
Cargo.lock
generated
41
Cargo.lock
generated
@ -727,13 +727,6 @@ dependencies = [
|
||||
"pin-project-lite",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "common-api"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"serde",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "conrod_core"
|
||||
version = "0.63.0"
|
||||
@ -3753,15 +3746,6 @@ dependencies = [
|
||||
"web-sys",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "plugin-api-derive"
|
||||
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"
|
||||
@ -5558,7 +5542,6 @@ dependencies = [
|
||||
"arraygen",
|
||||
"authc",
|
||||
"bincode",
|
||||
"common-api",
|
||||
"criterion",
|
||||
"crossbeam",
|
||||
"csv",
|
||||
@ -5593,6 +5576,7 @@ dependencies = [
|
||||
"tracing",
|
||||
"tracy-client",
|
||||
"vek 0.12.0",
|
||||
"veloren-plugin-api",
|
||||
"wasmer-runtime",
|
||||
]
|
||||
|
||||
@ -5600,12 +5584,28 @@ dependencies = [
|
||||
name = "veloren-plugin-api"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"bincode",
|
||||
"common-api",
|
||||
"plugin-api-derive",
|
||||
"serde",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "veloren-plugin-derive"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"proc-macro2 1.0.24",
|
||||
"quote 1.0.7",
|
||||
"syn 1.0.54",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "veloren-plugin-rt"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"bincode",
|
||||
"serde",
|
||||
"veloren-plugin-api",
|
||||
"veloren-plugin-derive",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "veloren-server"
|
||||
version = "0.8.0"
|
||||
@ -5787,6 +5787,7 @@ dependencies = [
|
||||
"tracy-client",
|
||||
"vek 0.12.0",
|
||||
"veloren-common",
|
||||
"veloren-plugin-api",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
@ -4,7 +4,9 @@ cargo-features = ["named-profiles","profile-overrides"]
|
||||
members = [
|
||||
"common",
|
||||
"common/sys",
|
||||
"common/common-api",
|
||||
"plugin/rt",
|
||||
"plugin/api",
|
||||
"plugin/derive",
|
||||
"client",
|
||||
"plugin-api",
|
||||
"server",
|
||||
|
@ -66,7 +66,7 @@ tracy-client = { version = "0.9.0", optional = true }
|
||||
# Plugins
|
||||
wasmer-runtime = "0.17.1"
|
||||
bincode = "1.3.1"
|
||||
common-api = {path = "./common-api"}
|
||||
plugin-api = { package = "veloren-plugin-api", path = "../plugin/api"}
|
||||
|
||||
[dev-dependencies]
|
||||
#bench
|
||||
|
@ -17,8 +17,6 @@
|
||||
option_zip
|
||||
)]
|
||||
|
||||
pub extern crate common_api;
|
||||
|
||||
pub mod assets;
|
||||
pub mod astar;
|
||||
pub mod character;
|
||||
|
@ -7,7 +7,7 @@ use serde::{Deserialize, Serialize};
|
||||
use std::{collections::{HashMap, HashSet}, fs, io::Read, path::{Path, PathBuf}};
|
||||
use tracing::{error, info};
|
||||
|
||||
use common_api::Event;
|
||||
use plugin_api::Event;
|
||||
|
||||
use self::{ errors::PluginError, module::{PluginModule, PreparedEventQuery}};
|
||||
|
||||
|
@ -5,7 +5,7 @@ use parking_lot::Mutex;
|
||||
use wasmer_runtime::*;
|
||||
|
||||
use super::errors::{PluginError, PluginModuleError};
|
||||
use common_api::{Action, Event};
|
||||
use plugin_api::{Action, Event};
|
||||
|
||||
// This represent a WASM function interface
|
||||
pub type Function<'a> = Func<'a, (i32, u32), i32>;
|
||||
|
@ -34,3 +34,6 @@ serde = { version = "1.0.110", features = ["derive"] }
|
||||
|
||||
# Tracy
|
||||
tracy-client = { version = "0.9.0", optional = true }
|
||||
|
||||
# Plugins
|
||||
plugin-api = { package = "veloren-plugin-api", path = "../../plugin/api"}
|
||||
|
@ -181,7 +181,7 @@ impl State {
|
||||
// Load plugins from asset directory
|
||||
ecs.insert(match PluginMgr::from_assets() {
|
||||
Ok(plugin_mgr) => {
|
||||
if let Err(e) = plugin_mgr.execute_event("on_load", &common::common_api::events::PluginLoadEvent {}) {
|
||||
if let Err(e) = plugin_mgr.execute_event("on_load", &plugin_api::events::PluginLoadEvent {}) {
|
||||
tracing::error!(?e, "Failed to run plugin init");
|
||||
info!("Error occurred when loading plugins. Running without plugins instead.");
|
||||
PluginMgr::default()
|
||||
|
@ -1,5 +1,5 @@
|
||||
[package]
|
||||
name = "common-api"
|
||||
name = "veloren-plugin-api"
|
||||
version = "0.1.0"
|
||||
authors = ["ccgauche <gaucheron.laurent@gmail.com>"]
|
||||
edition = "2018"
|
@ -1,6 +1,5 @@
|
||||
use serde::{Serialize, de::DeserializeOwned, Deserialize};
|
||||
|
||||
|
||||
#[derive(Deserialize,Serialize,Debug)]
|
||||
pub enum Action {
|
||||
ServerClose,
|
||||
@ -14,9 +13,9 @@ pub trait Event: Serialize + DeserializeOwned{
|
||||
}
|
||||
|
||||
pub mod events {
|
||||
|
||||
use super::Event;
|
||||
use serde::{Serialize,Deserialize};
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug)]
|
||||
pub struct PlayerJoinEvent {
|
||||
pub player_name: String,
|
@ -1,5 +1,5 @@
|
||||
[package]
|
||||
name = "plugin-api-derive"
|
||||
name = "veloren-plugin-derive"
|
||||
version = "0.1.0"
|
||||
authors = ["ccgauche <gaucheron.laurent@gmail.com>"]
|
||||
edition = "2018"
|
@ -16,11 +16,11 @@ pub fn export_function(_args: TokenStream, item: TokenStream) -> TokenStream {
|
||||
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();
|
||||
let input = plugin_rt::read_input(intern__ptr,intern__len).unwrap();
|
||||
fn inner(#fn_args) #fn_return {
|
||||
#fn_body
|
||||
}
|
||||
plugin_api::write_output(&inner(input))
|
||||
plugin_rt::write_output(&inner(input))
|
||||
}
|
||||
};
|
||||
out.into()
|
@ -16,27 +16,12 @@ version = "1.3.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "08c48aae112d48ed9f069b33538ea9e3e90aa263cfa3d1c24309612b1f7472de"
|
||||
|
||||
[[package]]
|
||||
name = "common-api"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"serde",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "hello"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"veloren-plugin-api",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "plugin_proc"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn",
|
||||
"veloren-plugin-rt",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@ -98,8 +83,24 @@ checksum = "f7fe0bb3479651439c9112f72b6c505038574c9fbb575ed1bf3b797fa39dd564"
|
||||
name = "veloren-plugin-api"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"bincode",
|
||||
"common-api",
|
||||
"plugin_proc",
|
||||
"serde",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "veloren-plugin-derive"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "veloren-plugin-rt"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"bincode",
|
||||
"serde",
|
||||
"veloren-plugin-api",
|
||||
"veloren-plugin-derive",
|
||||
]
|
@ -8,6 +8,7 @@ edition = "2018"
|
||||
crate-type = ["cdylib"]
|
||||
|
||||
[dependencies]
|
||||
plugin-api = { package = "veloren-plugin-api", path = ".." }
|
||||
plugin-rt = { package = "veloren-plugin-rt", path = "../rt" }
|
||||
plugin-api = { package = "veloren-plugin-api", path = "../api" }
|
||||
|
||||
[workspace]
|
@ -1,10 +1,12 @@
|
||||
use plugin_api::{*,events::*};
|
||||
pub extern crate plugin_rt;
|
||||
|
||||
use plugin_rt::*;
|
||||
use plugin_api::{Action, events::*};
|
||||
|
||||
#[export_function]
|
||||
pub fn on_load(load: PluginLoadEvent) -> () {
|
||||
send_actions(vec![Action::Print("This is a test".to_owned())]);
|
||||
println!("Hello world");
|
||||
|
||||
}
|
||||
|
||||
#[export_function]
|
@ -1,13 +1,11 @@
|
||||
[package]
|
||||
name = "veloren-plugin-api"
|
||||
name = "veloren-plugin-rt"
|
||||
version = "0.1.0"
|
||||
authors = ["Joshua Barretto <joshua.s.barretto@gmail.com>"]
|
||||
edition = "2018"
|
||||
|
||||
[dependencies]
|
||||
common-api = { path = "../common/common-api" }
|
||||
plugin-api-derive = { path = "./plugin-api-derive"}
|
||||
plugin-api = { package = "veloren-plugin-api", path = "../api" }
|
||||
plugin-derive = { package = "veloren-plugin-derive", path = "../derive"}
|
||||
serde = {version = "1.0.118", features = ["derive"]}
|
||||
bincode = "1.3.1"
|
||||
|
||||
# spin = "0.7"
|
@ -1,12 +1,7 @@
|
||||
#![feature(const_fn)]
|
||||
|
||||
|
||||
pub extern crate plugin_api_derive;
|
||||
pub extern crate common_api;
|
||||
|
||||
pub use common_api::*;
|
||||
|
||||
pub use plugin_api_derive::*;
|
||||
pub use plugin_api as api;
|
||||
pub use plugin_derive::*;
|
||||
|
||||
use serde::de::DeserializeOwned;
|
||||
use serde::Serialize;
|
||||
@ -15,7 +10,7 @@ extern "C" {
|
||||
fn send_action(ptr: *const u8, len: usize);
|
||||
}
|
||||
|
||||
pub fn send_actions(action: Vec<Action>) {
|
||||
pub fn send_actions(action: Vec<api::Action>) {
|
||||
let ret = bincode::serialize(&action).unwrap();
|
||||
unsafe {
|
||||
send_action(ret.as_ptr(), ret.len());
|
Loading…
Reference in New Issue
Block a user