diff --git a/Cargo.lock b/Cargo.lock index 0d196a97b6e..e6aae3e31a1 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1898,9 +1898,9 @@ dependencies = [ [[package]] name = "hermit-abi" -version = "0.3.1" +version = "0.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fed44880c466736ef9a5c5b5facefb5ed0785676d0c02d612db14e54f0d84286" +checksum = "443144c8cdadd93ebf52ddb4056d257f5b52c04d3c804e657d19eb73fc33668b" [[package]] name = "hex" @@ -2201,7 +2201,7 @@ version = "1.0.11" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "eae7b9aee968036d54dce06cebaefd919e4472e753296daccd6d344e3e2df0c2" dependencies = [ - "hermit-abi 0.3.1", + "hermit-abi 0.3.2", "libc", "windows-sys 0.48.0", ] @@ -2218,7 +2218,7 @@ version = "0.4.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "adcf93614601c8129ddf72e2d5633df827ba6551541c6d8c59520a371475be1f" dependencies = [ - "hermit-abi 0.3.1", + "hermit-abi 0.3.2", "io-lifetimes", "rustix", "windows-sys 0.48.0", diff --git a/lib/wasix/src/runtime/mod.rs b/lib/wasix/src/runtime/mod.rs index 3cedc7bbd51..6e21c515f56 100644 --- a/lib/wasix/src/runtime/mod.rs +++ b/lib/wasix/src/runtime/mod.rs @@ -17,8 +17,8 @@ use crate::{ http::DynHttpClient, os::TtyBridge, runtime::{ - module_cache::ModuleCache, - package_loader::{BuiltinPackageLoader, PackageLoader}, + module_cache::{ModuleCache, ThreadLocalCache}, + package_loader::{PackageLoader, UnsupportedPackageLoader}, resolver::{MultiSource, Source, WapmSource}, }, WasiTtyState, @@ -39,10 +39,20 @@ where fn task_manager(&self) -> &Arc; /// A package loader. - fn package_loader(&self) -> Arc; + fn package_loader(&self) -> Arc { + Arc::new(UnsupportedPackageLoader::default()) + } /// A cache for compiled modules. - fn module_cache(&self) -> Arc; + fn module_cache(&self) -> Arc { + // Return a cache that uses a thread-local variable. This isn't ideal + // because it allows silently sharing state, possibly between runtimes. + // + // That said, it means people will still get *some* level of caching + // because each cache returned by this default implementation will go + // through the same thread-local variable. + Arc::new(ThreadLocalCache::default()) + } /// The package registry. fn source(&self) -> Arc; @@ -129,8 +139,7 @@ impl PluggableRuntime { let http_client = crate::http::default_http_client().map(|client| Arc::new(client) as DynHttpClient); - let loader = BuiltinPackageLoader::from_env() - .expect("Loading the builtin resolver should never fail"); + let loader = UnsupportedPackageLoader::default(); let mut source = MultiSource::new(); if let Some(client) = &http_client { diff --git a/lib/wasix/src/runtime/module_cache/thread_local.rs b/lib/wasix/src/runtime/module_cache/thread_local.rs index e4ff8cf88b6..5c04037028b 100644 --- a/lib/wasix/src/runtime/module_cache/thread_local.rs +++ b/lib/wasix/src/runtime/module_cache/thread_local.rs @@ -10,7 +10,7 @@ std::thread_local! { } /// A cache that will cache modules in a thread-local variable. -#[derive(Debug, Default)] +#[derive(Debug, Clone, Default)] #[non_exhaustive] pub struct ThreadLocalCache {} diff --git a/lib/wasix/src/runtime/package_loader/mod.rs b/lib/wasix/src/runtime/package_loader/mod.rs index aa9f9392b22..b9eeb649897 100644 --- a/lib/wasix/src/runtime/package_loader/mod.rs +++ b/lib/wasix/src/runtime/package_loader/mod.rs @@ -1,8 +1,9 @@ mod builtin_loader; mod load_package_tree; mod types; +mod unsupported; pub use self::{ builtin_loader::BuiltinPackageLoader, load_package_tree::load_package_tree, - types::PackageLoader, + types::PackageLoader, unsupported::UnsupportedPackageLoader, }; diff --git a/lib/wasix/src/runtime/package_loader/unsupported.rs b/lib/wasix/src/runtime/package_loader/unsupported.rs new file mode 100644 index 00000000000..be5488b1edb --- /dev/null +++ b/lib/wasix/src/runtime/package_loader/unsupported.rs @@ -0,0 +1,33 @@ +use anyhow::Error; +use webc::compat::Container; + +use crate::{ + bin_factory::BinaryPackage, + runtime::{ + package_loader::PackageLoader, + resolver::{PackageSummary, Resolution}, + }, +}; + +/// A [`PackageLoader`] implementation which will always error out. +#[derive(Debug, Default, Clone, PartialEq, Eq, Hash)] +pub struct UnsupportedPackageLoader; + +#[async_trait::async_trait] +impl PackageLoader for UnsupportedPackageLoader { + async fn load(&self, _summary: &PackageSummary) -> Result { + Err(Error::new(Unsupported)) + } + + async fn load_package_tree( + &self, + _root: &Container, + _resolution: &Resolution, + ) -> Result { + Err(Error::new(Unsupported)) + } +} + +#[derive(Debug, Copy, Clone, thiserror::Error)] +#[error("Loading of packages is not supported in this runtime (no PackageLoader configured)")] +struct Unsupported;