Update extism (#5859)

This commit is contained in:
Nutomic 2025-07-11 20:52:53 +00:00 committed by GitHub
parent df4a79f4b6
commit b5dee35b84
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 49 additions and 125 deletions

130
Cargo.lock generated
View file

@ -756,7 +756,7 @@ dependencies = [
"cap-primitives",
"cap-std",
"io-lifetimes",
"windows-sys 0.59.0",
"windows-sys 0.52.0",
]
[[package]]
@ -773,7 +773,7 @@ dependencies = [
"maybe-owned",
"rustix 1.0.7",
"rustix-linux-procfs",
"windows-sys 0.59.0",
"windows-sys 0.52.0",
"winx",
]
@ -1396,15 +1396,6 @@ dependencies = [
"tokio",
]
[[package]]
name = "debugid"
version = "0.8.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bef552e6f588e446098f6ba40d89ac146c8c7b64aade83c051ee00bb5d2bc18d"
dependencies = [
"uuid",
]
[[package]]
name = "deprecate-until"
version = "0.1.1"
@ -1903,7 +1894,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cea14ef9355e3beab063703aa9dab15afd25f0667c341310c1e5274bb1d0da18"
dependencies = [
"libc",
"windows-sys 0.59.0",
"windows-sys 0.52.0",
]
[[package]]
@ -1930,7 +1921,7 @@ dependencies = [
[[package]]
name = "extism"
version = "0.0.0+replaced-by-ci"
source = "git+https://github.com/extism/extism.git?branch=main#2732ca198d6b8234172aa7f9836763d0e0b839f7"
source = "git+https://github.com/extism/extism.git?branch=main#3d15c761159d5346433a64f449fd2b44900519b8"
dependencies = [
"anyhow",
"cbindgen",
@ -1955,7 +1946,7 @@ dependencies = [
[[package]]
name = "extism-convert"
version = "0.0.0+replaced-by-ci"
source = "git+https://github.com/extism/extism.git?branch=main#2732ca198d6b8234172aa7f9836763d0e0b839f7"
source = "git+https://github.com/extism/extism.git?branch=main#3d15c761159d5346433a64f449fd2b44900519b8"
dependencies = [
"anyhow",
"base64 0.22.1",
@ -1970,7 +1961,7 @@ dependencies = [
[[package]]
name = "extism-convert-macros"
version = "0.0.0+replaced-by-ci"
source = "git+https://github.com/extism/extism.git?branch=main#2732ca198d6b8234172aa7f9836763d0e0b839f7"
source = "git+https://github.com/extism/extism.git?branch=main#3d15c761159d5346433a64f449fd2b44900519b8"
dependencies = [
"manyhow",
"proc-macro-crate",
@ -1982,7 +1973,7 @@ dependencies = [
[[package]]
name = "extism-manifest"
version = "0.0.0+replaced-by-ci"
source = "git+https://github.com/extism/extism.git?branch=main#2732ca198d6b8234172aa7f9836763d0e0b839f7"
source = "git+https://github.com/extism/extism.git?branch=main#3d15c761159d5346433a64f449fd2b44900519b8"
dependencies = [
"base64 0.22.1",
"serde",
@ -2025,7 +2016,7 @@ checksum = "0ce92ff622d6dadf7349484f42c93271a0d49b7cc4d466a936405bacbe10aa78"
dependencies = [
"cfg-if",
"rustix 1.0.7",
"windows-sys 0.59.0",
"windows-sys 0.52.0",
]
[[package]]
@ -2088,7 +2079,7 @@ checksum = "94e7099f6313ecacbe1256e8ff9d617b75d1bcb16a6fddef94866d225a01a14a"
dependencies = [
"io-lifetimes",
"rustix 1.0.7",
"windows-sys 0.59.0",
"windows-sys 0.52.0",
]
[[package]]
@ -2196,28 +2187,6 @@ dependencies = [
"slab",
]
[[package]]
name = "fxhash"
version = "0.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c31b6d751ae2c7f11320402d34e41349dd1016f8d5d45e48c4312bc8625af50c"
dependencies = [
"byteorder",
]
[[package]]
name = "fxprof-processed-profile"
version = "0.6.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "27d12c0aed7f1e24276a241aadc4cb8ea9f83000f34bc062b7cc2d51e3b0fabd"
dependencies = [
"bitflags 2.9.1",
"debugid",
"fxhash",
"serde",
"serde_json",
]
[[package]]
name = "generator"
version = "0.8.5"
@ -2957,7 +2926,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2285ddfe3054097ef4b2fe909ef8c3bcd1ea52a8f0d274416caebeef39f04a65"
dependencies = [
"io-lifetimes",
"windows-sys 0.59.0",
"windows-sys 0.52.0",
]
[[package]]
@ -3012,26 +2981,6 @@ version = "1.0.15"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4a5f13b858c8d314ee3e8f639011f7ccefe71f97f96e50151fb991f267928e2c"
[[package]]
name = "ittapi"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6b996fe614c41395cdaedf3cf408a9534851090959d90d54a535f675550b64b1"
dependencies = [
"anyhow",
"ittapi-sys",
"log",
]
[[package]]
name = "ittapi-sys"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "52f5385394064fa2c886205dba02598013ce83d3e92d33dbdc0c52fe0e7bf4fc"
dependencies = [
"cc",
]
[[package]]
name = "jni"
version = "0.19.0"
@ -4066,7 +4015,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "07033963ba89ebaf1584d767badaa2e8fcec21aedea6b8c0346d487d49c28667"
dependencies = [
"cfg-if",
"windows-targets 0.52.6",
"windows-targets 0.48.5",
]
[[package]]
@ -5131,9 +5080,9 @@ dependencies = [
[[package]]
name = "prost"
version = "0.13.5"
version = "0.14.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2796faa41db3ec313a31f7624d9286acf277b52de526150b7e69f3debf891ee5"
checksum = "7231bd9b3d3d33c86b58adbac74b5ec0ad9f496b19d22801d773636feaa95f3d"
dependencies = [
"bytes",
"prost-derive",
@ -5141,9 +5090,9 @@ dependencies = [
[[package]]
name = "prost-derive"
version = "0.13.5"
version = "0.14.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8a56d757972c98b346a9b766e3f02746cde6dd1cd1d1d563472929fdd74bec4d"
checksum = "9120690fafc389a67ba3803df527d0ec9cbbc9cc45e4cc20b332996dfb672425"
dependencies = [
"anyhow",
"itertools 0.14.0",
@ -5264,7 +5213,7 @@ dependencies = [
"once_cell",
"socket2",
"tracing",
"windows-sys 0.59.0",
"windows-sys 0.52.0",
]
[[package]]
@ -5714,7 +5663,7 @@ dependencies = [
"errno",
"libc",
"linux-raw-sys 0.4.15",
"windows-sys 0.59.0",
"windows-sys 0.52.0",
]
[[package]]
@ -5727,7 +5676,7 @@ dependencies = [
"errno",
"libc",
"linux-raw-sys 0.9.4",
"windows-sys 0.59.0",
"windows-sys 0.52.0",
]
[[package]]
@ -5901,9 +5850,6 @@ name = "semver"
version = "1.0.26"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "56e6fa9c48d24d85fb3de5ad847117517440f6beceb7798af16b4a87d616b8d0"
dependencies = [
"serde",
]
[[package]]
name = "serde"
@ -6196,7 +6142,7 @@ dependencies = [
"cfg-if",
"libc",
"psm",
"windows-sys 0.59.0",
"windows-sys 0.52.0",
]
[[package]]
@ -6390,7 +6336,7 @@ dependencies = [
"fd-lock",
"io-lifetimes",
"rustix 0.38.44",
"windows-sys 0.59.0",
"windows-sys 0.52.0",
"winx",
]
@ -6416,7 +6362,7 @@ dependencies = [
"getrandom 0.3.3",
"once_cell",
"rustix 1.0.7",
"windows-sys 0.59.0",
"windows-sys 0.52.0",
]
[[package]]
@ -7040,9 +6986,9 @@ checksum = "8ecb6da28b8a351d773b68d5825ac39017e680750f980f3a1a85cd8dd28a47c1"
[[package]]
name = "ureq"
version = "3.0.11"
version = "3.0.12"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b7a3e9af6113ecd57b8c63d3cd76a385b2e3881365f1f489e54f49801d0c83ea"
checksum = "9f0fde9bc91026e381155f8c67cb354bcd35260b2f4a29bcc84639f762760c39"
dependencies = [
"base64 0.22.1",
"flate2",
@ -7058,9 +7004,9 @@ dependencies = [
[[package]]
name = "ureq-proto"
version = "0.4.1"
version = "0.4.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fadf18427d33828c311234884b7ba2afb57143e6e7e69fda7ee883b624661e36"
checksum = "59db78ad1923f2b1be62b6da81fe80b173605ca0d57f85da2e005382adf693f7"
dependencies = [
"base64 0.22.1",
"http 1.3.1",
@ -7356,19 +7302,14 @@ version = "29.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "11976a250672556d1c4c04c6d5d7656ac9192ac9edc42a4587d6c21460010e69"
dependencies = [
"addr2line",
"anyhow",
"async-trait",
"bitflags 2.9.1",
"bumpalo",
"cc",
"cfg-if",
"encoding_rs",
"fxprof-processed-profile",
"gimli",
"hashbrown 0.14.5",
"indexmap 2.9.0",
"ittapi",
"libc",
"log",
"mach2",
@ -7381,10 +7322,8 @@ dependencies = [
"pulley-interpreter",
"rayon",
"rustix 0.38.44",
"semver",
"serde",
"serde_derive",
"serde_json",
"smallvec",
"sptr",
"target-lexicon",
@ -7394,11 +7333,9 @@ dependencies = [
"wasmtime-asm-macros",
"wasmtime-cache",
"wasmtime-component-macro",
"wasmtime-component-util",
"wasmtime-cranelift",
"wasmtime-environ",
"wasmtime-fiber",
"wasmtime-jit-debug",
"wasmtime-jit-icache-coherence",
"wasmtime-math",
"wasmtime-slab",
@ -7499,7 +7436,6 @@ dependencies = [
"object",
"postcard",
"rustc-demangle",
"semver",
"serde",
"serde_derive",
"smallvec",
@ -7507,7 +7443,6 @@ dependencies = [
"wasm-encoder 0.221.3",
"wasmparser 0.221.3",
"wasmprinter",
"wasmtime-component-util",
]
[[package]]
@ -7525,17 +7460,6 @@ dependencies = [
"windows-sys 0.59.0",
]
[[package]]
name = "wasmtime-jit-debug"
version = "29.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3e7b61488a5ee00c35c8c22de707c36c0aecacf419a3be803a6a2ba5e860f56a"
dependencies = [
"object",
"rustix 0.38.44",
"wasmtime-versioned-export-macros",
]
[[package]]
name = "wasmtime-jit-icache-coherence"
version = "29.0.1"
@ -7806,7 +7730,7 @@ version = "0.1.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cf221c93e13a30d793f7645a0e7762c55d169dbb0a49671918a2319d289b10bb"
dependencies = [
"windows-sys 0.59.0",
"windows-sys 0.48.0",
]
[[package]]
@ -8118,7 +8042,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3f3fd376f71958b862e7afb20cfe5a22830e1963462f3a17f49d82a6c1d1f42d"
dependencies = [
"bitflags 2.9.1",
"windows-sys 0.59.0",
"windows-sys 0.52.0",
]
[[package]]

View file

@ -219,7 +219,11 @@ tuplex = "0.1.2"
html2text = "0.15.1"
async-trait = "0.1.88"
either = { version = "1.15.0", features = ["serde"] }
extism = { git = "https://github.com/extism/extism.git", branch = "main" }
extism = { git = "https://github.com/extism/extism.git", branch = "main", default-features = false, features = [
"http",
"register-http",
"register-filesystem",
] }
extism-convert = { git = "https://github.com/extism/extism.git", branch = "main" }
unified-diff = "0.2.1"

View file

@ -28,8 +28,8 @@ pub fn plugin_hook_after<T>(name: &'static str, data: &T) -> LemmyResult<()>
where
T: Clone + Serialize + for<'b> Deserialize<'b> + Sync + Send + 'static,
{
let plugins = LemmyPlugins::init();
if !plugins.loaded(name) {
let plugins = LemmyPlugins::get_or_init();
if !plugins.function_exists(name) {
return Ok(());
}
@ -60,8 +60,8 @@ pub async fn plugin_hook_before<T>(name: &'static str, data: T) -> LemmyResult<T
where
T: Clone + Serialize + for<'a> Deserialize<'a> + Sync + Send + 'static,
{
let plugins = LemmyPlugins::init();
if !plugins.loaded(name) {
let plugins = LemmyPlugins::get_or_init();
if !plugins.function_exists(name) {
return Ok(data);
}
@ -81,7 +81,7 @@ where
}
pub fn plugin_metadata() -> Vec<PluginMetadata> {
LemmyPlugins::init()
LemmyPlugins::get_or_init()
.0
.into_iter()
.map(|p| p.metadata)
@ -93,7 +93,7 @@ struct LemmyPlugins(Vec<LemmyPlugin>);
#[derive(Clone)]
struct LemmyPlugin {
plugin_pool: Pool<()>,
plugin_pool: Pool,
metadata: PluginMetadata,
}
@ -109,10 +109,9 @@ impl LemmyPlugin {
manifest
.config
.insert("lemmy_version".to_string(), VERSION.to_string());
let plugin_pool: Pool<()> = Pool::new();
let builder = PluginBuilder::new(manifest).with_wasi(true);
let metadata: PluginMetadata = builder.clone().build()?.call("metadata", 0)?;
plugin_pool.add_builder((), builder);
let builder = move || PluginBuilder::new(manifest.clone()).with_wasi(true).build();
let metadata: PluginMetadata = builder()?.call("metadata", 0)?;
let plugin_pool: Pool = Pool::new(builder);
Ok(LemmyPlugin {
plugin_pool,
metadata,
@ -122,7 +121,7 @@ impl LemmyPlugin {
fn get(&self, name: &'static str) -> LemmyResult<Option<PoolPlugin>> {
let p = self
.plugin_pool
.get(&(), GET_PLUGIN_TIMEOUT)?
.get(GET_PLUGIN_TIMEOUT)?
.ok_or(anyhow!("plugin timeout"))?;
Ok(if p.plugin().function_exists(name) {
@ -135,7 +134,7 @@ impl LemmyPlugin {
impl LemmyPlugins {
/// Load and initialize all plugins
fn init() -> Self {
fn get_or_init() -> Self {
// TODO: use std::sync::OnceLock once get_mut_or_init() is stabilized
// https://doc.rust-lang.org/std/sync/struct.OnceLock.html#method.get_mut_or_init
static PLUGINS: Lazy<LemmyPlugins> = Lazy::new(|| {
@ -164,14 +163,11 @@ impl LemmyPlugins {
}
/// Return early if no plugin is loaded for the given hook name
fn loaded(&self, _name: &'static str) -> bool {
// Check if there is any plugin active for this hook, to avoid unnecessary data cloning
// TODO: not currently supported by pool
/*
if !self.0.iter().any(|p| p.plugin_pool.function_exists(name)) {
return Ok(None);
}
*/
!self.0.is_empty()
fn function_exists(&self, name: &'static str) -> bool {
self.0.iter().any(|p| {
p.plugin_pool
.function_exists(name, GET_PLUGIN_TIMEOUT)
.unwrap_or(false)
})
}
}