feat: add abi stable crates
This commit is contained in:
366
__ffi/abi_stable_crates/plugin_1/Cargo.lock
generated
Normal file
366
__ffi/abi_stable_crates/plugin_1/Cargo.lock
generated
Normal file
@@ -0,0 +1,366 @@
|
||||
# This file is automatically @generated by Cargo.
|
||||
# It is not intended for manual editing.
|
||||
[[package]]
|
||||
name = "abi_stable"
|
||||
version = "0.9.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "112fbc83f18cf0f12358975cac27eb4556cc5d777bde72312e0cec7a294e1699"
|
||||
dependencies = [
|
||||
"abi_stable_derive",
|
||||
"abi_stable_shared",
|
||||
"core_extensions",
|
||||
"crossbeam-channel",
|
||||
"generational-arena",
|
||||
"libloading",
|
||||
"lock_api",
|
||||
"parking_lot",
|
||||
"repr_offset",
|
||||
"rustc_version",
|
||||
"serde",
|
||||
"serde_derive",
|
||||
"serde_json",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "abi_stable_derive"
|
||||
version = "0.9.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "1be19f4da4a4a1f2537f1f14d8f0917c07758acb7419d3bad9e9d62a11f6b5b0"
|
||||
dependencies = [
|
||||
"abi_stable_shared",
|
||||
"as_derive_utils",
|
||||
"core_extensions",
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"rustc_version",
|
||||
"syn",
|
||||
"typed-arena",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "abi_stable_shared"
|
||||
version = "0.9.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a96112d6a13f37dd1cc2a2f07f7f12b7c3d176b6eec36e7987432a70fece8b48"
|
||||
dependencies = [
|
||||
"core_extensions",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "arrayvec"
|
||||
version = "0.5.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "23b62fc65de8e4e7f52534fb52b0f3ed04746ae267519eef2a83941e8085068b"
|
||||
|
||||
[[package]]
|
||||
name = "as_derive_utils"
|
||||
version = "0.9.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ffc3613a62c7b739739a2cb1ee166ac275f16c5b86caf454ba21a2f79f04b025"
|
||||
dependencies = [
|
||||
"core_extensions",
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "autocfg"
|
||||
version = "1.0.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "cdb031dd78e28731d87d56cc8ffef4a8f36ca26c38fe2de700543e627f8a464a"
|
||||
|
||||
[[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 = "core_extensions"
|
||||
version = "0.1.18"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ff55d62b113b98e0b0a55112741376c4cfe36f1290d18392c2c5727e09629a7f"
|
||||
dependencies = [
|
||||
"rustc_version",
|
||||
]
|
||||
|
||||
[[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",
|
||||
]
|
||||
|
||||
[[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 = "example_interface"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"abi_stable",
|
||||
"arrayvec",
|
||||
"core_extensions",
|
||||
"serde",
|
||||
"serde_json",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "example_plugin_utils"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"abi_stable",
|
||||
"core_extensions",
|
||||
"example_interface",
|
||||
"serde",
|
||||
"serde_json",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "generational-arena"
|
||||
version = "0.2.8"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "8e1d3b771574f62d0548cee0ad9057857e9fc25d7a3335f140c84f6acd0bf601"
|
||||
dependencies = [
|
||||
"cfg-if 0.1.10",
|
||||
]
|
||||
|
||||
[[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 = "itoa"
|
||||
version = "0.4.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "dc6f3ad7b9d11a0c00842ff8de1b60ee58661048eb8049ed33c73594f359d7e6"
|
||||
|
||||
[[package]]
|
||||
name = "lazy_static"
|
||||
version = "1.4.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646"
|
||||
|
||||
[[package]]
|
||||
name = "libc"
|
||||
version = "0.2.81"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "1482821306169ec4d07f6aca392a4681f66c75c9918aa49641a2595db64053cb"
|
||||
|
||||
[[package]]
|
||||
name = "libloading"
|
||||
version = "0.6.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e9367bdfa836b7e3cf895867f7a570283444da90562980ec2263d6e1569b16bc"
|
||||
dependencies = [
|
||||
"cfg-if 1.0.0",
|
||||
"winapi",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "lock_api"
|
||||
version = "0.4.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "dd96ffd135b2fd7b973ac026d28085defbe8983df057ced3eb4f2130b0831312"
|
||||
dependencies = [
|
||||
"scopeguard",
|
||||
]
|
||||
|
||||
[[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.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "9ccb628cad4f84851442432c60ad8e1f607e29752d0bf072cbd0baf28aa34272"
|
||||
dependencies = [
|
||||
"cfg-if 1.0.0",
|
||||
"instant",
|
||||
"libc",
|
||||
"redox_syscall",
|
||||
"smallvec",
|
||||
"winapi",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "proc-macro2"
|
||||
version = "1.0.24"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "1e0704ee1a7e00d7bb417d0770ea303c1bccbabf0ef1667dae92b5967f5f8a71"
|
||||
dependencies = [
|
||||
"unicode-xid",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "quote"
|
||||
version = "1.0.8"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "991431c3519a3f36861882da93630ce66b52918dcf1b8e2fd66b397fc96f28df"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "redox_syscall"
|
||||
version = "0.1.57"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "41cc0f7e4d5d4544e8861606a285bb08d3e70712ccc7d2b84d7c0ccfaf4b05ce"
|
||||
|
||||
[[package]]
|
||||
name = "repr_offset"
|
||||
version = "0.1.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a68e33940e1f1e7ab77493ad7d983dba544ce72185c61d4b1b23e6c32dd2a165"
|
||||
dependencies = [
|
||||
"rustc_version",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rustc_version"
|
||||
version = "0.2.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "138e3e0acb6c9fb258b19b67cb8abd63c00679d2851805ea151465464fe9030a"
|
||||
dependencies = [
|
||||
"semver",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "ryu"
|
||||
version = "1.0.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "71d301d4193d031abdd79ff7e3dd721168a9572ef3fe51a1517aba235bd8f86e"
|
||||
|
||||
[[package]]
|
||||
name = "scopeguard"
|
||||
version = "1.1.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d29ab0c6d3fc0ee92fe66e2d99f700eab17a8d57d1c1d3b748380fb20baa78cd"
|
||||
|
||||
[[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"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "06c64263859d87aa2eb554587e2d23183398d617427327cf2b3d0ed8c69e4800"
|
||||
dependencies = [
|
||||
"serde_derive",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "serde_derive"
|
||||
version = "1.0.118"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "c84d3526699cd55261af4b941e4e725444df67aa4f9e6a3564f18030d12672df"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"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 = "smallvec"
|
||||
version = "1.5.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ae524f056d7d770e174287294f562e95044c68e88dec909a00d2094805db9d75"
|
||||
|
||||
[[package]]
|
||||
name = "syn"
|
||||
version = "1.0.56"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a9802ddde94170d186eeee5005b798d9c159fa970403f1be19976d0cfb939b72"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"unicode-xid",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "typed-arena"
|
||||
version = "2.0.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "0685c84d5d54d1c26f7d3eb96cd41550adb97baed141a761cf335d3d33bcd0ae"
|
||||
|
||||
[[package]]
|
||||
name = "unicode-xid"
|
||||
version = "0.2.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f7fe0bb3479651439c9112f72b6c505038574c9fbb575ed1bf3b797fa39dd564"
|
||||
|
||||
[[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-i686-pc-windows-gnu"
|
||||
version = "0.4.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6"
|
||||
|
||||
[[package]]
|
||||
name = "winapi-x86_64-pc-windows-gnu"
|
||||
version = "0.4.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f"
|
||||
16
__ffi/abi_stable_crates/plugin_1/Cargo.toml
Normal file
16
__ffi/abi_stable_crates/plugin_1/Cargo.toml
Normal file
@@ -0,0 +1,16 @@
|
||||
[package]
|
||||
name = "example_plugin_utils"
|
||||
version = "0.1.0"
|
||||
authors = ["rodrimati1992 <rodrimatt1985@gmail.com>"]
|
||||
edition = "2018"
|
||||
|
||||
[dependencies]
|
||||
abi_stable = "0.9.1"
|
||||
core_extensions={ version = "0.1.18", default_features = false, features = ["std"] }
|
||||
serde={ version = "1.0.117", features = ["derive"] }
|
||||
serde_json = { version = "1.0.59", features = ["raw_value"] }
|
||||
example_interface={ version="0.1", path="../interface"}
|
||||
|
||||
[lib]
|
||||
name = "example_plugin_utils"
|
||||
crate-type = ["cdylib",'rlib']
|
||||
174
__ffi/abi_stable_crates/plugin_1/src/lib.rs
Normal file
174
__ffi/abi_stable_crates/plugin_1/src/lib.rs
Normal file
@@ -0,0 +1,174 @@
|
||||
/*!
|
||||
This is an `implementation crate`,
|
||||
It exports the root module(a struct of function pointers) required by the
|
||||
`example_0_interface`(the `interface crate`).
|
||||
*/
|
||||
|
||||
use abi_stable::{
|
||||
export_root_module,
|
||||
sabi_extern_fn,
|
||||
external_types::crossbeam_channel::RSender,
|
||||
prefix_type::PrefixTypeTrait,
|
||||
sabi_trait::prelude::TU_Opaque,
|
||||
std_types::{RStr,RVec, RString,RResult,ROk},
|
||||
};
|
||||
use example_interface::{
|
||||
AsyncCommand,
|
||||
ApplicationMut,
|
||||
CommandDescription,
|
||||
Error as AppError,
|
||||
Plugin,PluginType,PluginId,PluginMod,PluginMod_Ref,
|
||||
Plugin_TO,
|
||||
utils::process_command,
|
||||
WhichPlugin,
|
||||
};
|
||||
use core_extensions::SelfOps;
|
||||
use serde::{Serialize, Deserialize};
|
||||
use serde_json::value::Value;
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
/// Exports the root module of this library.
|
||||
///
|
||||
/// This code isn't run until the layout of the type it returns is checked.
|
||||
#[export_root_module]
|
||||
fn instantiate_root_module()->PluginMod_Ref{
|
||||
PluginMod {
|
||||
new,
|
||||
}.leak_into_prefix()
|
||||
}
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
#[sabi_extern_fn]
|
||||
pub fn new(_sender:RSender<AsyncCommand>,plugin_id:PluginId) -> RResult<PluginType,AppError> {
|
||||
let this=CommandUtils{
|
||||
plugin_id,
|
||||
};
|
||||
ROk(Plugin_TO::from_value(this,TU_Opaque))
|
||||
}
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
|
||||
#[derive(Debug,Serialize,Deserialize)]
|
||||
pub enum UtilCmd{
|
||||
Repeat{
|
||||
how_much:usize,
|
||||
plugin:WhichPlugin,
|
||||
command:Value,
|
||||
},
|
||||
Batch{
|
||||
plugin:WhichPlugin,
|
||||
commands:Vec<Value>,
|
||||
},
|
||||
}
|
||||
|
||||
#[derive(Debug,Serialize,Deserialize)]
|
||||
pub enum ReturnValue{
|
||||
Repeat,
|
||||
Batch,
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
fn run_command_inner(
|
||||
this:&mut CommandUtils,
|
||||
command:UtilCmd,
|
||||
mut app:ApplicationMut<'_>,
|
||||
)->Result<ReturnValue,AppError>{
|
||||
match command {
|
||||
UtilCmd::Repeat{how_much,plugin,command}=>{
|
||||
let s=serde_json::to_string(&command).unwrap();
|
||||
for _ in 0..how_much {
|
||||
app.send_command_to_plugin(
|
||||
this.plugin_id(),
|
||||
plugin.clone(),
|
||||
s.clone().into(),
|
||||
).into_result()?;
|
||||
}
|
||||
ReturnValue::Repeat
|
||||
}
|
||||
UtilCmd::Batch{plugin,commands}=>{
|
||||
for command in commands {
|
||||
let s=serde_json::to_string(&command).unwrap();
|
||||
app.send_command_to_plugin(
|
||||
this.plugin_id(),
|
||||
plugin.clone(),
|
||||
s.into(),
|
||||
).into_result()?;
|
||||
}
|
||||
ReturnValue::Batch
|
||||
}
|
||||
}.piped(Ok)
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
struct CommandUtils{
|
||||
plugin_id:PluginId,
|
||||
}
|
||||
|
||||
|
||||
impl Plugin for CommandUtils {
|
||||
fn json_command(
|
||||
&mut self,
|
||||
command: RStr<'_>,
|
||||
app:ApplicationMut<'_>,
|
||||
)->RResult<RString,AppError>{
|
||||
process_command(self,command,|this,command|{
|
||||
run_command_inner(this,command,app)
|
||||
})
|
||||
}
|
||||
|
||||
fn plugin_id(&self)->&PluginId{
|
||||
&self.plugin_id
|
||||
}
|
||||
|
||||
fn list_commands(&self)->RVec<CommandDescription>{
|
||||
vec![
|
||||
CommandDescription::from_literals(
|
||||
"Repeat",
|
||||
"\
|
||||
Sends a command to a plugin N times.
|
||||
|
||||
Command params:
|
||||
{
|
||||
\"how_much\":10,
|
||||
\"plugin\":\"plugin:last\",
|
||||
\"command\":{ ... some command ... }
|
||||
}
|
||||
"
|
||||
),
|
||||
CommandDescription::from_literals(
|
||||
"Batch",
|
||||
"\
|
||||
Sends a sequence of commands to a plugin.
|
||||
|
||||
Command params:
|
||||
{
|
||||
\"plugin\":\"plugin_name\",
|
||||
\"commands\":[
|
||||
{ ... some command ... },
|
||||
{ ... some command ... },
|
||||
{ ... some command ... }
|
||||
]
|
||||
}",
|
||||
),
|
||||
].into()
|
||||
}
|
||||
|
||||
fn close(self,_app:ApplicationMut<'_>){}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user