Skip to content

cfg(target_arch) in build scripts for FFI still refer to the host rather than the target #1285

Answered by Emilgardis
jguhlin asked this question in Q&A
Discussion options

You must be logged in to vote

cfg(target_arch) will always refer to the target the current crate is built for, and build scripts are always built for the host, not the target.

Instead, use the environment variable CARGO_CFG_TARGET_ARCH

as noted in the text, ensure that you actually retrieve the env var at runtime using env::var("CARGO_CFG_TARGET_ARCH")

note that this behaviour is not changed by cross, rather it's how cargo/rust works

Replies: 2 comments

Comment options

You must be logged in to vote
0 replies
Answer selected by jguhlin
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants