Skip to content

Commit f2ac717

Browse files
committed
Plugins: Apply changes for shared types in host.
* Make the need adjustments after separating the plugins to different packages unifying the implementation for the shared types. * Generating the shared types doesn't generate not referenced types with `bindgen!()` macro. The current workaround is to generate the types from parser package inside the shared module. * State `generate_used_types` explicitly to true in `generat!()` macro for plugins_api because this macro supports this option
1 parent 2eac9b0 commit f2ac717

File tree

15 files changed

+316
-319
lines changed

15 files changed

+316
-319
lines changed

application/apps/indexer/Cargo.lock

+87-63
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

application/apps/indexer/plugins_api/src/shared/mod.rs

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ pub mod plugin_logger;
66
wit_bindgen::generate!({
77
path: "wit/v0.1.0",
88
world: "chipmunk:shared/bindings",
9+
generate_unused_types: true,
910
});
1011

1112
use crate::shared_types::{ConfigSchemaItem, ConfigSchemaType, Version};

application/apps/indexer/plugins_host/Cargo.toml

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ log.workspace = true
1313
dirs.workspace = true
1414
toml.workspace = true
1515

16-
wasmtime = "28.0"
17-
wasmtime-wasi = "28.0"
16+
wasmtime = "29.0"
17+
wasmtime-wasi = "29.0"
1818

1919
parsers = { path = "../parsers" }
2020
sources = { path = "../sources" }

application/apps/indexer/plugins_host/src/bytesource_shared/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use crate::{
1111
PluginHostInitError, WasmPlugin,
1212
};
1313

14-
const BYTESOURCE_INTERFACE_NAME: &str = "chipmunk:plugin/byte-source";
14+
const BYTESOURCE_INTERFACE_NAME: &str = "chipmunk:bytesource/byte-source";
1515

1616
/// The maximum number of consecutive returns with empty bytes allowed from a plugin.
1717
/// If a plugin exceeds this number, it may be considered harmful to the system.

application/apps/indexer/plugins_host/src/parser_shared/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use crate::{
1010

1111
pub mod plugin_parse_message;
1212

13-
const PARSER_INTERFACE_NAME: &str = "chipmunk:plugin/parser";
13+
const PARSER_INTERFACE_NAME: &str = "chipmunk:parser/parser";
1414

1515
/// Marker for a column separator in the output string.
1616
pub const COLUMN_SEP: &str = "\u{0004}";
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
11
use std::io;
22

3-
use crate::PluginGuestInitError;
4-
5-
pub use self::chipmunk::plugin::{bytesource_types, shared_types};
6-
use self::shared_types::{ConfigItem, ConfigSchemaItem, ConfigSchemaType, ConfigValue, Version};
3+
pub use self::chipmunk::bytesource::bytesource_types;
74

85
wasmtime::component::bindgen!({
9-
path: "../plugins_api/wit/v_0.1.0/",
10-
world: "bytesource-plugin",
6+
path: "../plugins_api/wit/v0.1.0",
7+
world: "chipmunk:bytesource/bytesource",
118
async: {
129
only_imports: [],
1310
},
11+
with: {
12+
"chipmunk:shared/[email protected]": crate::v0_1_0::shared::logging,
13+
"chipmunk:shared/[email protected]": crate::v0_1_0::shared::shared_types,
14+
}
1415
});
1516

1617
impl From<&stypes::PluginByteSourceGeneralSettings> for bytesource_types::SourceConfig {
@@ -19,7 +20,7 @@ impl From<&stypes::PluginByteSourceGeneralSettings> for bytesource_types::Source
1920
// functionality to log the message from the plugins.
2021
let current_log_level = log::max_level().to_level().unwrap_or(log::Level::Error);
2122

22-
use chipmunk::plugin::logging::Level as PlugLevel;
23+
use crate::v0_1_0::shared::logging::Level as PlugLevel;
2324
let level = match current_log_level {
2425
log::Level::Error => PlugLevel::Error,
2526
log::Level::Warn => PlugLevel::Warn,
@@ -32,93 +33,15 @@ impl From<&stypes::PluginByteSourceGeneralSettings> for bytesource_types::Source
3233
}
3334
}
3435

35-
impl From<shared_types::InitError> for PluginGuestInitError {
36-
fn from(value: shared_types::InitError) -> Self {
37-
use shared_types::InitError as E;
38-
use PluginGuestInitError as GuestE;
39-
match value {
40-
E::Config(msg) => GuestE::Config(msg),
41-
E::Io(msg) => GuestE::IO(msg),
42-
E::Unsupported(msg) => GuestE::Unsupported(msg),
43-
E::Other(msg) => GuestE::Other(msg),
44-
}
45-
}
46-
}
47-
4836
impl From<bytesource_types::SourceError> for io::Error {
4937
fn from(value: bytesource_types::SourceError) -> Self {
5038
use bytesource_types::SourceError as E;
5139
let msg = match value {
5240
E::Io(msg) => format!("IO Error from bytesoruce plugin. Error: {msg}"),
53-
E::Unsupported => String::from("Unsupported Error from bytesource plugin"),
41+
E::Unsupported(msg) => format!("Unsupported Error from bytesource plugin: {msg}"),
5442
E::Other(msg) => format!("Unknown Error from bytesoruce plugin. Error: {msg}"),
5543
};
5644

5745
io::Error::new(io::ErrorKind::Other, msg)
5846
}
5947
}
60-
61-
use stypes::PluginConfigValue as HostConfValue;
62-
impl From<HostConfValue> for ConfigValue {
63-
fn from(value: HostConfValue) -> Self {
64-
match value {
65-
HostConfValue::Boolean(val) => ConfigValue::Boolean(val),
66-
HostConfValue::Integer(val) => ConfigValue::Integer(val),
67-
HostConfValue::Float(val) => ConfigValue::Float(val),
68-
HostConfValue::Text(val) => ConfigValue::Text(val),
69-
HostConfValue::Files(val) => ConfigValue::Files(
70-
val.into_iter()
71-
.map(|p| p.to_string_lossy().to_string())
72-
.collect(),
73-
),
74-
HostConfValue::Directories(val) => ConfigValue::Directories(
75-
val.into_iter()
76-
.map(|p| p.to_string_lossy().to_string())
77-
.collect(),
78-
),
79-
HostConfValue::Dropdown(val) => ConfigValue::Dropdown(val),
80-
}
81-
}
82-
}
83-
84-
impl From<stypes::PluginConfigItem> for ConfigItem {
85-
fn from(item: stypes::PluginConfigItem) -> Self {
86-
Self {
87-
id: item.id,
88-
value: item.value.into(),
89-
}
90-
}
91-
}
92-
93-
use stypes::PluginConfigSchemaType as HostSchemaType;
94-
use stypes::SemanticVersion;
95-
impl From<ConfigSchemaType> for HostSchemaType {
96-
fn from(value: ConfigSchemaType) -> Self {
97-
match value {
98-
ConfigSchemaType::Boolean => HostSchemaType::Boolean,
99-
ConfigSchemaType::Integer => HostSchemaType::Integer,
100-
ConfigSchemaType::Float => HostSchemaType::Float,
101-
ConfigSchemaType::Text => HostSchemaType::Text,
102-
ConfigSchemaType::Directories => HostSchemaType::Directories,
103-
ConfigSchemaType::Files(exts) => HostSchemaType::Files(exts),
104-
ConfigSchemaType::Dropdown(items) => HostSchemaType::Dropdown(items),
105-
}
106-
}
107-
}
108-
109-
impl From<ConfigSchemaItem> for stypes::PluginConfigSchemaItem {
110-
fn from(item: ConfigSchemaItem) -> Self {
111-
Self {
112-
id: item.id,
113-
title: item.title,
114-
description: item.description,
115-
input_type: item.input_type.into(),
116-
}
117-
}
118-
}
119-
120-
impl From<Version> for SemanticVersion {
121-
fn from(value: Version) -> Self {
122-
Self::new(value.major, value.minor, value.patch)
123-
}
124-
}

application/apps/indexer/plugins_host/src/v0_1_0/bytesource/bytesource_plugin_state.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@ use wasmtime_wasi::{ResourceTable, WasiCtx, WasiView};
22

33
use super::bindings::{
44
bytesource_types::{self, Level},
5-
chipmunk::plugin::logging,
6-
shared_types,
5+
chipmunk::shared::{logging, shared_types},
76
};
87

98
pub struct ByteSourcePluginState {

application/apps/indexer/plugins_host/src/v0_1_0/bytesource/mod.rs

+8-8
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ mod bytesource_plugin_state;
33

44
use std::io;
55

6-
use bindings::BytesourcePlugin;
6+
use bindings::Bytesource;
77
use bytesource_plugin_state::ByteSourcePluginState;
88
use stypes::{RenderOptions, SemanticVersion};
99
use wasmtime::{
@@ -20,7 +20,7 @@ use crate::{
2020

2121
pub struct PluginByteSource {
2222
store: Store<ByteSourcePluginState>,
23-
plugin_bindings: BytesourcePlugin,
23+
plugin_bindings: Bytesource,
2424
}
2525

2626
impl PluginByteSource {
@@ -51,14 +51,14 @@ impl PluginByteSource {
5151
let mut linker: Linker<ByteSourcePluginState> = Linker::new(engine);
5252
wasmtime_wasi::add_to_linker_async(&mut linker)?;
5353

54-
BytesourcePlugin::add_to_linker(&mut linker, |state| state)?;
54+
Bytesource::add_to_linker(&mut linker, |state| state)?;
5555

5656
let resource_table = ResourceTable::new();
5757

5858
let mut store = Store::new(engine, ByteSourcePluginState::new(ctx, resource_table));
5959

6060
let plugin_bindings =
61-
BytesourcePlugin::instantiate_async(&mut store, &component, &linker).await?;
61+
Bytesource::instantiate_async(&mut store, &component, &linker).await?;
6262

6363
Ok(Self {
6464
store,
@@ -81,7 +81,7 @@ impl PluginByteSource {
8181

8282
byte_source
8383
.plugin_bindings
84-
.chipmunk_plugin_byte_source()
84+
.chipmunk_bytesource_byte_source()
8585
.call_init(
8686
&mut byte_source.store,
8787
general_config.into(),
@@ -100,7 +100,7 @@ impl PluginByteSource {
100100
) -> Result<Vec<stypes::PluginConfigSchemaItem>, PluginError> {
101101
let schemas = self
102102
.plugin_bindings
103-
.chipmunk_plugin_byte_source()
103+
.chipmunk_bytesource_byte_source()
104104
.call_get_config_schemas(&mut self.store)
105105
.await?;
106106

@@ -110,7 +110,7 @@ impl PluginByteSource {
110110
pub async fn plugin_version(&mut self) -> Result<SemanticVersion, PluginError> {
111111
let version = self
112112
.plugin_bindings
113-
.chipmunk_plugin_byte_source()
113+
.chipmunk_bytesource_byte_source()
114114
.call_get_version(&mut self.store)
115115
.await?;
116116

@@ -120,7 +120,7 @@ impl PluginByteSource {
120120
pub async fn read_next(&mut self, len: usize) -> io::Result<Vec<u8>> {
121121
let bytes_result = self
122122
.plugin_bindings
123-
.chipmunk_plugin_byte_source()
123+
.chipmunk_bytesource_byte_source()
124124
.call_read(&mut self.store, len as u64)
125125
.await
126126
.map_err(|err| {
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
pub mod bytesource;
22
pub mod parser;
3+
pub mod shared;

application/apps/indexer/plugins_host/src/v0_1_0/parser/bindings.rs

+10-81
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,19 @@
1-
use crate::{parser_shared::COLUMN_SEP, PluginGuestInitError, PluginParseMessage};
1+
use crate::{parser_shared::COLUMN_SEP, PluginParseMessage};
22

3-
pub use self::chipmunk::plugin::{parse_types::*, shared_types::*};
3+
pub use self::chipmunk::parser::parse_types::*;
44

5-
use stypes::{ParserRenderOptions, PluginConfigValue as HostConfValue, SemanticVersion};
5+
use stypes::ParserRenderOptions;
66

77
wasmtime::component::bindgen!({
8-
path: "../plugins_api/wit/v_0.1.0/",
9-
world: "parse-plugin",
8+
path: "../plugins_api/wit/v0.1.0",
9+
world: "chipmunk:parser/parse",
1010
async: {
1111
only_imports: [],
1212
},
13+
with: {
14+
"chipmunk:shared/[email protected]": crate::v0_1_0::shared::logging,
15+
"chipmunk:shared/[email protected]": crate::v0_1_0::shared::shared_types,
16+
}
1317
});
1418

1519
impl From<&stypes::PluginParserGeneralSettings> for ParserConfig {
@@ -18,7 +22,7 @@ impl From<&stypes::PluginParserGeneralSettings> for ParserConfig {
1822
// functionality to log the message from the plugins.
1923
let current_log_level = log::max_level().to_level().unwrap_or(log::Level::Error);
2024

21-
use chipmunk::plugin::logging::Level as PlugLevel;
25+
use crate::v0_1_0::shared::logging::Level as PlugLevel;
2226
let level = match current_log_level {
2327
log::Level::Error => PlugLevel::Error,
2428
log::Level::Warn => PlugLevel::Warn,
@@ -31,18 +35,6 @@ impl From<&stypes::PluginParserGeneralSettings> for ParserConfig {
3135
}
3236
}
3337

34-
impl From<InitError> for PluginGuestInitError {
35-
fn from(value: InitError) -> Self {
36-
use PluginGuestInitError as GuestErr;
37-
match value {
38-
InitError::Config(msg) => GuestErr::Config(msg),
39-
InitError::Io(msg) => GuestErr::IO(msg),
40-
InitError::Unsupported(msg) => GuestErr::Unsupported(msg),
41-
InitError::Other(msg) => GuestErr::Other(msg),
42-
}
43-
}
44-
}
45-
4638
use parsers as p;
4739

4840
impl From<ParseYield> for p::ParseYield<PluginParseMessage> {
@@ -92,69 +84,6 @@ impl From<ParsedMessage> for PluginParseMessage {
9284
}
9385
}
9486

95-
impl From<HostConfValue> for ConfigValue {
96-
fn from(value: HostConfValue) -> Self {
97-
match value {
98-
HostConfValue::Boolean(val) => ConfigValue::Boolean(val),
99-
HostConfValue::Integer(val) => ConfigValue::Integer(val),
100-
HostConfValue::Float(val) => ConfigValue::Float(val),
101-
HostConfValue::Text(val) => ConfigValue::Text(val),
102-
HostConfValue::Files(val) => ConfigValue::Files(
103-
val.into_iter()
104-
.map(|p| p.to_string_lossy().to_string())
105-
.collect(),
106-
),
107-
HostConfValue::Directories(val) => ConfigValue::Directories(
108-
val.into_iter()
109-
.map(|p| p.to_string_lossy().to_string())
110-
.collect(),
111-
),
112-
HostConfValue::Dropdown(val) => ConfigValue::Dropdown(val),
113-
}
114-
}
115-
}
116-
117-
impl From<stypes::PluginConfigItem> for ConfigItem {
118-
fn from(item: stypes::PluginConfigItem) -> Self {
119-
Self {
120-
id: item.id,
121-
value: item.value.into(),
122-
}
123-
}
124-
}
125-
126-
use stypes::PluginConfigSchemaType as HostSchemaType;
127-
impl From<ConfigSchemaType> for HostSchemaType {
128-
fn from(value: ConfigSchemaType) -> Self {
129-
match value {
130-
ConfigSchemaType::Boolean => HostSchemaType::Boolean,
131-
ConfigSchemaType::Integer => HostSchemaType::Integer,
132-
ConfigSchemaType::Float => HostSchemaType::Float,
133-
ConfigSchemaType::Text => HostSchemaType::Text,
134-
ConfigSchemaType::Directories => HostSchemaType::Directories,
135-
ConfigSchemaType::Files(exts) => HostSchemaType::Files(exts),
136-
ConfigSchemaType::Dropdown(items) => HostSchemaType::Dropdown(items),
137-
}
138-
}
139-
}
140-
141-
impl From<ConfigSchemaItem> for stypes::PluginConfigSchemaItem {
142-
fn from(item: ConfigSchemaItem) -> Self {
143-
Self {
144-
id: item.id,
145-
title: item.title,
146-
description: item.description,
147-
input_type: item.input_type.into(),
148-
}
149-
}
150-
}
151-
152-
impl From<Version> for SemanticVersion {
153-
fn from(value: Version) -> Self {
154-
Self::new(value.major, value.minor, value.patch)
155-
}
156-
}
157-
15887
impl From<RenderOptions> for ParserRenderOptions {
15988
fn from(value: RenderOptions) -> Self {
16089
Self {

0 commit comments

Comments
 (0)