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

-C target-feature=+foo overrides previous values #56527

Closed
jbeich opened this issue Dec 5, 2018 · 3 comments · Fixed by #72094
Closed

-C target-feature=+foo overrides previous values #56527

jbeich opened this issue Dec 5, 2018 · 3 comments · Fixed by #72094
Labels
A-driver Area: rustc_driver that ties everything together into the `rustc` compiler

Comments

@jbeich
Copy link

jbeich commented Dec 5, 2018

I'm trying to pass multiple -C target-feature conditionally downstream. However, despite +/- for adding/removing a feature it appears only the last value takes effect.

$ cat >a.rs
fn main() {
    if cfg!(target_feature="avx2") {
        println!("AVX2 available");
    }
    if cfg!(target_feature="fma") {
        println!("FMA available");
    }
}

$ rustc a.rs -C target-feature=+avx2 -C target-feature=+fma
$ ./a
FMA available
$ rustc a.rs -C target-feature=+avx2,+fma
$ ./a
AVX2 available
FMA available
uqs pushed a commit to freebsd/freebsd-ports that referenced this issue Dec 5, 2018
error[E0432]: unresolved import `simd::x86::avx`
  --> cargo-crates/bytecount-0.3.2/src/lib.rs:49:16
   |
49 | use simd::x86::avx::{LowHigh128, u8x32};
   |                ^^^ could not find `avx` in `x86`

rust-lang/rust#56527


git-svn-id: svn+ssh://svn.freebsd.org/ports/head@486650 35697150-7ecd-e111-bb59-0022644237b5
uqs pushed a commit to freebsd/freebsd-ports that referenced this issue Dec 5, 2018
textproc/ripgrep: unbreak AVX=on on i386 after r454995

error[E0432]: unresolved import `simd::x86::avx`
  --> cargo-crates/bytecount-0.3.2/src/lib.rs:49:16
   |
49 | use simd::x86::avx::{LowHigh128, u8x32};
   |                ^^^ could not find `avx` in `x86`

rust-lang/rust#56527

Approved by:	ports-secteam blanket
uqs pushed a commit to freebsd/freebsd-ports that referenced this issue Dec 5, 2018
error[E0432]: unresolved import `simd::x86::avx`
  --> cargo-crates/bytecount-0.3.2/src/lib.rs:49:16
   |
49 | use simd::x86::avx::{LowHigh128, u8x32};
   |                ^^^ could not find `avx` in `x86`

rust-lang/rust#56527
swills pushed a commit to swills/freebsd-ports that referenced this issue Dec 5, 2018
error[E0432]: unresolved import `simd::x86::avx`
  --> cargo-crates/bytecount-0.3.2/src/lib.rs:49:16
   |
49 | use simd::x86::avx::{LowHigh128, u8x32};
   |                ^^^ could not find `avx` in `x86`

rust-lang/rust#56527


git-svn-id: svn+ssh://svn.freebsd.org/ports/head@486650 35697150-7ecd-e111-bb59-0022644237b5
Jehops pushed a commit to Jehops/freebsd-ports-legacy that referenced this issue Dec 5, 2018
error[E0432]: unresolved import `simd::x86::avx`
  --> cargo-crates/bytecount-0.3.2/src/lib.rs:49:16
   |
49 | use simd::x86::avx::{LowHigh128, u8x32};
   |                ^^^ could not find `avx` in `x86`

rust-lang/rust#56527


git-svn-id: svn+ssh://svn.freebsd.org/ports/head@486650 35697150-7ecd-e111-bb59-0022644237b5
@cuviper
Copy link
Member

cuviper commented Dec 7, 2018

FWIW, you can check for cfg values without any test program like:

$ rustc --print cfg  -C target-feature=+avx2 -C target-feature=+fma

$ rustc --print cfg  -C target-feature=+avx2,+fma

@jonas-schievink jonas-schievink added the A-driver Area: rustc_driver that ties everything together into the `rustc` compiler label Jan 27, 2019
@petrochenkov
Copy link
Contributor

I agree that it's a bug and will try to fix it.

@petrochenkov
Copy link
Contributor

Fixed in #72094.

@petrochenkov petrochenkov removed their assignment May 12, 2020
RalfJung added a commit to RalfJung/rust that referenced this issue May 15, 2020
cmdline: Make target features individually overridable

Fixes rust-lang#56527

Previously `-C target-feature=+avx2 -C target-feature=+fma` was equivalent to `-C target-feature=+fma` because the later `-C target-feature` option fully overridden previous `-C target-feature`.
With this PR `-C target-feature=+avx2 -C target-feature=+fma` is equivalent to `-C target-feature=+avx2,+fma` and the options are combined.

I'm not sure where the comma-separated features in a single option came from (clang uses a scheme with single feature per-option), but logically these features are entirely independent options.
So they should be overridable individually as well to be more useful in hierarchical build system, and more consistent with other rustc options and clang behavior as well.

Target feature options have a few other issues (rust-lang#44815), but fixing those is going to be a bit more invasive.
@bors bors closed this as completed in 4fe6d52 May 16, 2020
uqs pushed a commit to freebsd/freebsd-ports that referenced this issue Apr 1, 2021
textproc/ripgrep: unbreak AVX=on on i386 after r454995

error[E0432]: unresolved import `simd::x86::avx`
  --> cargo-crates/bytecount-0.3.2/src/lib.rs:49:16
   |
49 | use simd::x86::avx::{LowHigh128, u8x32};
   |                ^^^ could not find `avx` in `x86`

rust-lang/rust#56527

Approved by:	ports-secteam blanket
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-driver Area: rustc_driver that ties everything together into the `rustc` compiler
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants