Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use a no-op package loader by default in PluggableRuntime #4055

Merged
merged 4 commits into from
Jul 5, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 15 additions & 6 deletions lib/wasix/src/runtime/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -39,10 +39,20 @@ where
fn task_manager(&self) -> &Arc<dyn VirtualTaskManager>;

/// A package loader.
fn package_loader(&self) -> Arc<dyn PackageLoader + Send + Sync>;
fn package_loader(&self) -> Arc<dyn PackageLoader + Send + Sync> {
Arc::new(UnsupportedPackageLoader::default())
}

/// A cache for compiled modules.
fn module_cache(&self) -> Arc<dyn ModuleCache + Send + Sync>;
fn module_cache(&self) -> Arc<dyn ModuleCache + Send + Sync> {
// 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<dyn Source + Send + Sync>;
Expand Down Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion lib/wasix/src/runtime/module_cache/thread_local.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {}

Expand Down
3 changes: 2 additions & 1 deletion lib/wasix/src/runtime/package_loader/mod.rs
Original file line number Diff line number Diff line change
@@ -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,
};
33 changes: 33 additions & 0 deletions lib/wasix/src/runtime/package_loader/unsupported.rs
Original file line number Diff line number Diff line change
@@ -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<Container, Error> {
Err(Error::new(Unsupported))
}

async fn load_package_tree(
&self,
_root: &Container,
_resolution: &Resolution,
) -> Result<BinaryPackage, Error> {
Err(Error::new(Unsupported))
}
}

#[derive(Debug, Copy, Clone, thiserror::Error)]
#[error("Not supported")]
Michael-F-Bryan marked this conversation as resolved.
Show resolved Hide resolved
struct Unsupported;