Is target_arch not available in proc_macro generation?

I try to generate different code in a proc_macro crate based on the target arch with:

#[ cfg( target_arch = "wasm32" ) ]
let tokens = quote! { ... }

#[ cfg(not( target_arch = "wasm32" )) ]
let tokens = quote! { something else }

I always get the something else part in the output even if the crate that uses the macro is being compiled on target wasm32-unknown-unknown.

I turns out that in macro generation target == host, as in build scripts. It turns out that build scripts can get target information out of environment variables, but they don't seem to be set for macro generation.

Does anyone know a way of getting target info during macro generation?

I would prefer not to have to output the check in the generated code, cause there will be quite some bloat.

1 Like

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.