Skip to content

Commit

Permalink
Merge pull request #4055 from wasmerio/default-package-loader
Browse files Browse the repository at this point in the history
Use a no-op package loader by default in PluggableRuntime
  • Loading branch information
Michael-F-Bryan committed Jul 5, 2023
2 parents e1edc6e + feef9d6 commit 526292d
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 12 deletions.
8 changes: 4 additions & 4 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

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("Loading of packages is not supported in this runtime (no PackageLoader configured)")]
struct Unsupported;

0 comments on commit 526292d

Please sign in to comment.