Oh, are you talking about
cfg(target_os = "linux")? That is done at compile time of the
build.rs script, so will always be the host OS in a build script since the build script is being compiled to run on your current host. You need to read the
TARGET environment variable and use that to determine the target OS if you need to know it in the build script. I would expect there to be some crates for helping with that.
Actually, looking for a crate to help I ran across https://crates.io/crates/target_build_utils which implies that there should be a
CARGO_CFG_TARGET_OS environment variable, which does seem to work in my test.