From bc64716a653339cce36b97651ee2c024f4cd7ef6 Mon Sep 17 00:00:00 2001 From: Michael-F-Bryan Date: Wed, 5 Jul 2023 12:56:27 +0800 Subject: [PATCH 1/4] Make PluggableRuntime use a no-op PackageLoader by default --- lib/wasix/src/runtime/mod.rs | 5 ++- lib/wasix/src/runtime/package_loader/mod.rs | 3 +- .../src/runtime/package_loader/unsupported.rs | 33 +++++++++++++++++++ 3 files changed, 37 insertions(+), 4 deletions(-) create mode 100644 lib/wasix/src/runtime/package_loader/unsupported.rs diff --git a/lib/wasix/src/runtime/mod.rs b/lib/wasix/src/runtime/mod.rs index 3cedc7bbd51..d474150bc33 100644 --- a/lib/wasix/src/runtime/mod.rs +++ b/lib/wasix/src/runtime/mod.rs @@ -18,7 +18,7 @@ use crate::{ os::TtyBridge, runtime::{ module_cache::ModuleCache, - package_loader::{BuiltinPackageLoader, PackageLoader}, + package_loader::{PackageLoader, UnsupportedPackageLoader}, resolver::{MultiSource, Source, WapmSource}, }, WasiTtyState, @@ -129,8 +129,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/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..0c24f13c3a7 --- /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("Not supported")] +struct Unsupported; From d3aa6de15dbfb6dc11cba26e45e6b32799b03f53 Mon Sep 17 00:00:00 2001 From: Michael-F-Bryan Date: Wed, 5 Jul 2023 12:56:57 +0800 Subject: [PATCH 2/4] Add default implementations for Runtime::module_cache() and Runtime::package_loader() --- lib/wasix/src/runtime/mod.rs | 16 +++++++++++++--- .../src/runtime/module_cache/thread_local.rs | 2 +- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/lib/wasix/src/runtime/mod.rs b/lib/wasix/src/runtime/mod.rs index d474150bc33..6e21c515f56 100644 --- a/lib/wasix/src/runtime/mod.rs +++ b/lib/wasix/src/runtime/mod.rs @@ -17,7 +17,7 @@ use crate::{ http::DynHttpClient, os::TtyBridge, runtime::{ - module_cache::ModuleCache, + module_cache::{ModuleCache, ThreadLocalCache}, package_loader::{PackageLoader, UnsupportedPackageLoader}, resolver::{MultiSource, Source, WapmSource}, }, @@ -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; 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 {} From 6a5a94b3a25ace44bdf0c90e4efe873aac9883f0 Mon Sep 17 00:00:00 2001 From: Michael-F-Bryan Date: Wed, 5 Jul 2023 14:08:49 +0800 Subject: [PATCH 3/4] Bumped hermit-abi to a non-yanked version --- Cargo.lock | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) 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", From feef9d6b36c4d7d101f9546c2a5a41f23952f065 Mon Sep 17 00:00:00 2001 From: Michael Bryan Date: Wed, 5 Jul 2023 15:09:00 +0800 Subject: [PATCH 4/4] Update lib/wasix/src/runtime/package_loader/unsupported.rs Co-authored-by: Christoph Herzog --- lib/wasix/src/runtime/package_loader/unsupported.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/wasix/src/runtime/package_loader/unsupported.rs b/lib/wasix/src/runtime/package_loader/unsupported.rs index 0c24f13c3a7..be5488b1edb 100644 --- a/lib/wasix/src/runtime/package_loader/unsupported.rs +++ b/lib/wasix/src/runtime/package_loader/unsupported.rs @@ -29,5 +29,5 @@ impl PackageLoader for UnsupportedPackageLoader { } #[derive(Debug, Copy, Clone, thiserror::Error)] -#[error("Not supported")] +#[error("Loading of packages is not supported in this runtime (no PackageLoader configured)")] struct Unsupported;