If I build my project with
cargo build --verbose --target=i686-linux-android
where build.rs looks like this
build.rs
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.
panic!("target_os is linux!!!!!!!!!!!!!");
Why?
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:
target_os
cfg
https://doc.rust-lang.org/cargo/reference/environment-variables.html#environment-variables-cargo-sets-for-build-scripts
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.