Cfg wasm32 // conditional compilation

#1
  1. I am a bit confused by https://github.com/rustwasm/team/issues/161

  2. What is the “correct” way to have a piece of code that compiles only under the wasm32 target?

0 Likes

#2

https://doc.rust-lang.org/1.30.0/book/first-edition/conditional-compilation.html

#[cfg(target_arch = "wasm32")]
fn hello() {
    println!("with wasm")!
}

#[cfg(not(target_arch = "wasm32"))]
fn hello() {
    println!("not wasm")!
}

BTW. I can’t find where this feature is documented in the second edition of the book.

1 Like

#3

Thanks or the sample code!

0 Likes