Skip to content

Commit 5351ea0

Browse files
authored
Make the web_asset_cache compile in single-threaded mode. (#23994)
# Objective - `cargo t -p bevy_asset --features=http,https,web_asset_cache` fails to compile. - This is because we don't want to use `async_fs::File` in single-threaded since that uses a blocking IO thread to read files. We instead just do the blocking on the async thread since we're single-threaded any way. ## Solution - Use the `FileReader` from our sync_file_asset module if `multi_threaded` is not enabled. ## Testing - The tests pass without `multi_threaded` enabled.
1 parent 1dac2ec commit 5351ea0

3 files changed

Lines changed: 6 additions & 2 deletions

File tree

crates/bevy_asset/src/io/file/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ mod file_watcher;
44
#[cfg(feature = "multi_threaded")]
55
mod file_asset;
66
#[cfg(not(feature = "multi_threaded"))]
7-
mod sync_file_asset;
7+
pub(crate) mod sync_file_asset;
88

99
#[cfg(feature = "file_watcher")]
1010
pub use file_watcher::*;

crates/bevy_asset/src/io/file/sync_file_asset.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ use std::{
1616

1717
use super::{FileAssetReader, FileAssetWriter};
1818

19-
struct FileReader(File);
19+
pub(crate) struct FileReader(pub(crate) File);
2020

2121
impl AsyncRead for FileReader {
2222
fn poll_read(

crates/bevy_asset/src/io/web.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,11 @@ mod web_asset_cache {
243243
let cache_path = PathBuf::from(CACHE_DIR).join(&filename);
244244

245245
if cache_path.exists() {
246+
#[cfg(feature = "multi_threaded")]
246247
let mut file = async_fs::File::open(&cache_path).await?;
248+
#[cfg(not(feature = "multi_threaded"))]
249+
let mut file =
250+
crate::io::file::sync_file_asset::FileReader(std::fs::File::open(&cache_path)?);
247251
let mut buffer = Vec::new();
248252
file.read_to_end(&mut buffer).await?;
249253
Ok(Some(buffer))

0 commit comments

Comments
 (0)