Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I exclude an architecture with cfg?

I'm working on a project which should target wasm, but some functionality will not be supported.

It looks like I can conditionally include a function in this way:

#[cfg(target_arch = "wasm32")]
fn my_func() { ... }

Or conditionally call it like so:

if cfg!(target_arch = "wasm32") {
    my_func();
} else {
    ...
}

But how can I conditionally exclude a declaration or a block of code on wasm?

I.e. I am looking for something similar to #ifndef in c macros:

#ifndef WASM
native_only_func();
#endif
like image 657
sak Avatar asked Jan 24 '26 23:01

sak


1 Answers

To negate condition use #[cfg(not(condition))]. You can read more about conditional compilation in this section of The Rust Reference.

like image 75
Aleksander Krauze Avatar answered Jan 26 '26 15:01

Aleksander Krauze