Skip to content

Commit 031f67e

Browse files
authored
fix error and lints when building for wasm32 (#18500)
# Objective - Some crates don't compile or have clippy warnings when building for wasm32 ## Solution - bevy_asset: unused lifetime - bevy_gltf: the error is not too large in wasm32 - bevy_remote: fails to compile as feature http is also gated on wasm32 - bevy_winit: unused import `error`
1 parent dd56d45 commit 031f67e

File tree

7 files changed

+31
-17
lines changed

7 files changed

+31
-17
lines changed

crates/bevy_asset/src/io/wasm.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ fn js_value_to_err(context: &str) -> impl FnOnce(JsValue) -> std::io::Error + '_
5252
}
5353

5454
impl HttpWasmAssetReader {
55-
async fn fetch_bytes<'a>(&self, path: PathBuf) -> Result<impl Reader, AssetReaderError> {
55+
async fn fetch_bytes(&self, path: PathBuf) -> Result<impl Reader, AssetReaderError> {
5656
// The JS global scope includes a self-reference via a specializing name, which can be used to determine the type of global context available.
5757
let global: Global = js_sys::global().unchecked_into();
5858
let promise = if !global.window().is_undefined() {

crates/bevy_gltf/src/loader/gltf_ext/mesh.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,12 @@ pub(crate) fn primitive_name(mesh: &Mesh<'_>, primitive: &Primitive) -> String {
1414
}
1515

1616
/// Maps the `primitive_topology` from glTF to `wgpu`.
17-
#[expect(
18-
clippy::result_large_err,
19-
reason = "`GltfError` is only barely past the threshold for large errors."
17+
#[cfg_attr(
18+
not(target_arch = "wasm32"),
19+
expect(
20+
clippy::result_large_err,
21+
reason = "`GltfError` is only barely past the threshold for large errors."
22+
)
2023
)]
2124
pub(crate) fn primitive_topology(mode: Mode) -> Result<PrimitiveTopology, GltfError> {
2225
match mode {

crates/bevy_gltf/src/loader/gltf_ext/mod.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,12 @@ use super::GltfError;
1414

1515
use self::{material::extension_texture_index, scene::check_is_part_of_cycle};
1616

17-
#[expect(
18-
clippy::result_large_err,
19-
reason = "need to be signature compatible with `load_gltf`"
17+
#[cfg_attr(
18+
not(target_arch = "wasm32"),
19+
expect(
20+
clippy::result_large_err,
21+
reason = "need to be signature compatible with `load_gltf`"
22+
)
2023
)]
2124
/// Checks all glTF nodes for cycles, starting at the scene root.
2225
pub(crate) fn check_for_cycles(gltf: &Gltf) -> Result<(), GltfError> {

crates/bevy_gltf/src/loader/gltf_ext/scene.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,12 @@ pub(crate) fn node_transform(node: &Node) -> Transform {
4343
}
4444
}
4545

46-
#[expect(
47-
clippy::result_large_err,
48-
reason = "need to be signature compatible with `load_gltf`"
46+
#[cfg_attr(
47+
not(target_arch = "wasm32"),
48+
expect(
49+
clippy::result_large_err,
50+
reason = "need to be signature compatible with `load_gltf`"
51+
)
4952
)]
5053
/// Check if [`Node`] is part of cycle
5154
pub(crate) fn check_is_part_of_cycle(

crates/bevy_gltf/src/loader/mod.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1281,9 +1281,12 @@ fn load_material(
12811281
}
12821282

12831283
/// Loads a glTF node.
1284-
#[expect(
1285-
clippy::result_large_err,
1286-
reason = "`GltfError` is only barely past the threshold for large errors."
1284+
#[cfg_attr(
1285+
not(target_arch = "wasm32"),
1286+
expect(
1287+
clippy::result_large_err,
1288+
reason = "`GltfError` is only barely past the threshold for large errors."
1289+
)
12871290
)]
12881291
fn load_node(
12891292
gltf_node: &Node,

crates/bevy_remote/src/builtin_methods.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ use crate::{
2828
BrpError, BrpResult,
2929
};
3030

31-
#[cfg(feature = "http")]
31+
#[cfg(all(feature = "http", not(target_family = "wasm")))]
3232
use {crate::schemas::open_rpc::ServerObject, bevy_utils::default};
3333

3434
/// The method path for a `bevy/get` request.
@@ -821,7 +821,7 @@ pub fn process_remote_list_methods_request(
821821
) -> BrpResult {
822822
let remote_methods = world.resource::<crate::RemoteMethods>();
823823

824-
#[cfg(feature = "http")]
824+
#[cfg(all(feature = "http", not(target_family = "wasm")))]
825825
let servers = match (
826826
world.get_resource::<crate::http::HostAddress>(),
827827
world.get_resource::<crate::http::HostPort>(),
@@ -839,7 +839,7 @@ pub fn process_remote_list_methods_request(
839839
_ => None,
840840
};
841841

842-
#[cfg(not(feature = "http"))]
842+
#[cfg(any(not(feature = "http"), target_family = "wasm"))]
843843
let servers = None;
844844

845845
let doc = OpenRpcDocument {

crates/bevy_winit/src/state.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,9 @@ use bevy_input::{
1616
gestures::*,
1717
mouse::{MouseButtonInput, MouseMotion, MouseScrollUnit, MouseWheel},
1818
};
19-
use bevy_log::{error, trace, warn};
19+
#[cfg(any(not(target_arch = "wasm32"), feature = "custom_cursor"))]
20+
use bevy_log::error;
21+
use bevy_log::{trace, warn};
2022
#[cfg(feature = "custom_cursor")]
2123
use bevy_math::URect;
2224
use bevy_math::{ivec2, DVec2, Vec2};

0 commit comments

Comments
 (0)