Can't use cfg_attr with wasm_bindgen(skip)?

Hello everyone!

What am I doing wrong here?

use bevy_math::DVec3;

#[cfg(target_arch = "wasm32")]
use wasm_bindgen::prelude::*;

#[cfg_attr(target_arch = "wasm32", wasm_bindgen)]
pub struct CanNotSkip {
    #[cfg_attr(target_arch = "wasm32", wasm_bindgen(skip))]
    pub vec: DVec3,
}

If I compile this, I get the following error:

error: expected non-macro attribute, found attribute macro `wasm_bindgen`
  --> src/thing.rs:12:40
   |
12 |     #[cfg_attr(target_arch = "wasm32", wasm_bindgen(skip))]
   |                                        ^^^^^^^^^^^^ not a non-macro attribute

But if I remove the cfg_attr from wasm_bindgen(skip) it compiles.

#[cfg_attr(target_arch = "wasm32", wasm_bindgen)]
pub struct CanNotSkip {
    #[wasm_bindgen(skip)]
    pub vec: DVec3,
}

What am I doing wrong?

Does wasm_bindgen even do anything when not on wasm32? Not sure what the issue is with cfg_attr but I think it shouldn't be necessary anyway.

Also your example compiles fine: Rust Playground (without bevy but the error should not depend on bevy)

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.