Poperton
Poperton

Reputation: 2127

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 build.rs 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.

Why?

Upvotes: 0

Views: 961

Answers (1)

kmdreko
kmdreko

Reputation: 59902

The build.rs script is compiled and run locally and thus its #[cfg(...)] attributes will reflect the local system. If you want to know the operating system that you're ultimately building for, use the CARGO_CFG_TARGET_OS environment variable.

Others can be seen in Environment variables Cargo sets for build scripts in the Rust Reference.

Upvotes: 3

Related Questions