Is it possible to use target related cfg in build.rs?

It is cumbersome to write cfg like this

#[cfg(all(target_arch= "wasm32", not(target_os = "emscripten")))]

So I want to write rustc-cfg in build.rs instead. But it seems target related cfg cant be used in build.rs. So any ideas to resolve this? Thanks

Cargo sets environment variables that include target values:

https://doc.rust-lang.org/cargo/reference/environment-variables.html#environment-variables-cargo-sets-for-build-scripts

Make sure you use runtime std::env::var to read these, not the compile-time env! macro.

1 Like

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.