Target triple and conditional compilation for Android

Hello,

I have a library which has a section I do not want to build when compiling for Android, I used target_os = "android" to detect this at compile time. However, my approach still fails. I have attached the relevant code and the list of targets below.

Conditional compilation code

#[cfg(
    all(
        not(feature = "pure-rust"),
        any(target_arch = "x86_64", target_arch = "aarch64"),
        not(any(target_os="android", target_os="androideabi",
                target_os="ios"))
    )
)]

For when "pure-rust" feature is not specified, and architecture is supported, and not on android or ios.

#[cfg(
    not(
        all(
            not(feature = "pure-rust"),
            any(target_arch = "x86_64", target_arch = "aarch64"),
            not(any(target_os="android", target_os="androideabi",
                    target_os="ios"))
        )
    )
)]

For when "pure-rust" feature is specified, or architecture is not supported, or target_os is not supported. Just a negation of above one.

Target I have trouble with

  • aarch64-linux-android

My confusion

target_os of the above target should yield android right?

Additional questions

For armv7-linux-androideabi, is target_os = "androideabi"?
For i686-linux-android, is target_os = "android"

Full context

This question originated from this issue and I'm trying to fix it in this PR.

Thanks,
Darren

Hmm, looks alright to me, not sure why it's not working.

For armv7-linux-androideabi , target_os = "android"

1 Like

I faced similar issues that the community helped resolve- see https://www.reddit.com/r/rust/comments/9yve3r/how_to_detect_if_im_on_a_raspberry_pi/

Specifically in your code above, I could not get "aarch64" or "aarch32" to detect in any formulation to detect a Raspberry Pi 3B+. But checking other values worked as expected based on the compiler target.

1 Like