I'm writing a Cargo helper command that needs to know the default target triple used by Rust/Cargo (which I presume is the same as host's target triple). Ideally it should be a compile-time constant.
There's ARCH
constant, but it's not a full triple. For example, it doesn't distinguish between soft float and hard float ARM ABIs.
env!("TARGET")
would be ideal, but it's set only for build scripts, and not the lib/bin targets. I could pass it on to the lib with build.rs
and dynamic source code generation (writing the value to an .rs
file in OUT_DIR
), but it seems like a heavy hack just to get one string that the compiler has to know anyway.
Is there a more straightforward way to get the current target triple in lib/bin target built with Cargo?