1

I have a struct which must be 16-byte aligned when targeting wasm.

How can I do this?

So for instance, I want to have this struct on wasm:

#[cfg(target_arch = "wasm32")] <- not sure about this
#[repr(c, align(16))]
struct Foo {...}

And this on all other architectures:

#[cfg(target_arch = "wasm32")] <- not sure about this
#[repr(c)]
struct Foo {...}

Is this possible to achieve with cfg? If so how?

markalex
  • 8,623
  • 2
  • 7
  • 32
sak
  • 2,612
  • 24
  • 55

1 Answers1

2

Looks like its possible with cfg_attr:

#[cfg_attr(not(target_arch = "wasm32"), repr(C))]
#[cfg_attr(target_arch = "wasm32", repr(C, align(16)))]
struct Foo { ... }
kelsny
  • 23,009
  • 3
  • 19
  • 48