Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cargo doesn't pass target features from config specified for a particular target cpu architecture #10439

Closed
EdvardD opened this issue Mar 1, 2022 · 1 comment
Labels
C-bug Category: bug

Comments

@EdvardD
Copy link

EdvardD commented Mar 1, 2022

Problem

I'm specifying Rust flags for target features in .cargo/config.toml and they aren't propagated to CARGO_CFG_TARGET_FEATURE env variable in build.rs if I protect flags with the given target_arch ([target.'cfg(target_arch="x86_64")']). It works correctly if I put flags under [build] section.

Steps

I put together this simple example: https://github.com/EdvardD/cargo-build-rs-rustflags.

To reproduce: git clone https://github.com/EdvardD/cargo-build-rs-rustflags.git && cd cargo-build-rs-rustflags && ./test.sh

Possible Solution(s)

No response

Notes

$ cat test.sh 
#!/bin/bash -e

rustup show | head -n1
rm -rf target
cargo build
cat ./target/debug/build/*/output

$ ./test.sh 
Default host: x86_64-unknown-linux-gnu
   Compiling somelib v0.1.0 (/home/edvard/cargo-build-rs-rustflags/somelib)
   Compiling cargo-build-rs-rustflags v0.1.0 (/home/edvard/cargo-build-rs-rustflags)
    Finished dev [unoptimized + debuginfo] target(s) in 0.60s
fxsr,sse,sse2

Version

cargo 1.59.0 (49d8809dc 2022-02-10)
release: 1.59.0
commit-hash: 49d8809dc2d3e6e0d5ec634fcf26d8e2aab67130
commit-date: 2022-02-10
host: x86_64-unknown-linux-gnu
libgit2: 1.3.0 (sys:0.13.23 vendored)
libcurl: 7.80.0-DEV (sys:0.4.51+curl-7.80.0 vendored ssl:OpenSSL/1.1.1l)
os: Ubuntu 21.10 (impish) [64-bit]
@ehuss
Copy link
Contributor

ehuss commented Mar 1, 2022

The problem is that cargo is unable to use the rustflags from config for computing the cfg values because that could change which [target] tables are included from the config. Cargo could potentially do that in a loop until it converges to a fixed point, but I think that's unlikely.

At a minimum, I think there could be better documentation for this.

Closing as a duplicate of #6858.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: bug
Projects
None yet
Development

No branches or pull requests

2 participants