Cargo build --verbose --target=i686-linux-android makes target_os NOT android, why?

If I build my project with

cargo build --verbose --target=i686-linux-android

where looks like this

fn main() {
    #[cfg(target_os = "linux")]
        panic!("target_os is linux!!!!!!!!!!!!!");

I get the panic at panic!("target_os is linux!!!!!!!!!!!!!");, but the target is android.


Build scripts and proc macros are compiled to run on the host, not the target. That is, target_os in that context is targeting the host. But you can learn about the target with environment variables instead of cfg:


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.