Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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

>Solution :

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

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading