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

Fixed some compilation errors introduced by #4204 that assume tokio::task::block_in_place() always exists #4402

Merged
merged 1 commit into from
Jan 16, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
15 changes: 15 additions & 0 deletions lib/wasix/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -786,3 +786,18 @@ fn mem_error_to_wasi(err: MemoryAccessError) -> Errno {
_ => Errno::Unknown,
}
}

/// Run a synchronous function that would normally be blocking.
///
/// When the `sys-thread` feature is enabled, this will call
/// [`tokio::task::block_in_place()`]. Otherwise, it calls the function
/// immediately.
pub(crate) fn block_in_place<Ret>(thunk: impl FnOnce() -> Ret) -> Ret {
cfg_if::cfg_if! {
if #[cfg(feature = "sys-thread")] {
tokio::task::block_in_place(thunk)
} else {
thunk()
}
}
}
5 changes: 1 addition & 4 deletions lib/wasix/src/runtime/package_loader/builtin_loader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -271,10 +271,7 @@ impl FileSystemCache {
async fn lookup(&self, hash: &WebcHash) -> Result<Option<Container>, Error> {
let path = self.path(hash);

#[cfg(target_arch = "wasm32")]
let container = Container::from_disk(&path);
#[cfg(not(target_arch = "wasm32"))]
let container = tokio::task::block_in_place(|| Container::from_disk(&path));
let container = crate::block_in_place(|| Container::from_disk(&path));
match container {
Ok(c) => Ok(Some(c)),
Err(ContainerError::Open { error, .. })
Expand Down
12 changes: 2 additions & 10 deletions lib/wasix/src/runtime/resolver/filesystem_source.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,9 @@ impl Source for FileSystemSource {
_ => return Err(QueryError::Unsupported),
};

#[cfg(target_arch = "wasm32")]
let webc_sha256 = WebcHash::for_file(&path)
let webc_sha256 = crate::block_in_place(|| WebcHash::for_file(&path))
.with_context(|| format!("Unable to hash \"{}\"", path.display()))?;
#[cfg(not(target_arch = "wasm32"))]
let webc_sha256 = tokio::task::block_in_place(|| WebcHash::for_file(&path))
.with_context(|| format!("Unable to hash \"{}\"", path.display()))?;
#[cfg(target_arch = "wasm32")]
let container = Container::from_disk(&path)
.with_context(|| format!("Unable to parse \"{}\"", path.display()))?;
#[cfg(not(target_arch = "wasm32"))]
let container = tokio::task::block_in_place(|| Container::from_disk(&path))
let container = crate::block_in_place(|| Container::from_disk(&path))
.with_context(|| format!("Unable to parse \"{}\"", path.display()))?;

let url = crate::runtime::resolver::utils::url_from_file_path(&path)
Expand Down
12 changes: 2 additions & 10 deletions lib/wasix/src/runtime/resolver/web_source.rs
Original file line number Diff line number Diff line change
Expand Up @@ -240,20 +240,12 @@ impl Source for WebSource {
.await
.context("Unable to get the locally cached file")?;

#[cfg(target_arch = "wasm32")]
let webc_sha256 = WebcHash::for_file(&local_path)
.with_context(|| format!("Unable to hash \"{}\"", local_path.display()))?;
#[cfg(not(target_arch = "wasm32"))]
let webc_sha256 = tokio::task::block_in_place(|| WebcHash::for_file(&local_path))
let webc_sha256 = crate::block_in_place(|| WebcHash::for_file(&local_path))
.with_context(|| format!("Unable to hash \"{}\"", local_path.display()))?;

// Note: We want to use Container::from_disk() rather than the bytes
// our HTTP client gave us because then we can use memory-mapped files
#[cfg(target_arch = "wasm32")]
let container = Container::from_disk(&local_path)
.with_context(|| format!("Unable to load \"{}\"", local_path.display()))?;
#[cfg(not(target_arch = "wasm32"))]
let container = tokio::task::block_in_place(|| Container::from_disk(&local_path))
let container = crate::block_in_place(|| Container::from_disk(&local_path))
.with_context(|| format!("Unable to load \"{}\"", local_path.display()))?;
let pkg = PackageInfo::from_manifest(container.manifest())
.context("Unable to determine the package's metadata")?;
Expand Down
4 changes: 1 addition & 3 deletions lib/wasix/src/state/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ use wasmer::{AsStoreMut, Instance, Module, Store};

#[cfg(feature = "journal")]
use crate::journal::{DynJournal, SnapshotTrigger};
#[cfg(feature = "sys")]
use crate::PluggableRuntime;
use crate::{
bin_factory::{BinFactory, BinaryPackage},
capabilities::Capabilities,
Expand Down Expand Up @@ -800,7 +798,7 @@ impl WasiEnvBuilder {
#[cfg(feature = "sys-thread")]
{
#[allow(unused_mut)]
let mut runtime = PluggableRuntime::new(Arc::new(crate::runtime::task_manager::tokio::TokioTaskManager::default()));
let mut runtime = crate::runtime::PluggableRuntime::new(Arc::new(crate::runtime::task_manager::tokio::TokioTaskManager::default()));
#[cfg(feature = "journal")]
for journal in self.journals.clone() {
runtime.add_journal(journal);
Expand Down
Loading