Skip to content

Binary uses generic x86_64 version of code even though additional target features are available #20

@Petrusion

Description

@Petrusion

EDIT: changed the title of the issue to better reflect what is happening, see comment

Hi, I was trying out this awesome tool on some toy projects, but I can't seem to be able to get conditional compilation working via #[cfg(target_feature = "...")]. Am I just doing something wrong?

If I create a project with only this code:

fn main() {
    #[cfg(target_feature = "avx")]
    {
        println!("avx");
    }
    #[cfg(not(target_feature = "avx"))]
    {
        println!("no avx");
    }
}

and this inside Cargo.toml:

[package.metadata.multivers.x86_64]
cpus = [
	"x86-64",
	"x86-64-v2",
	"x86-64-v3",
	"x86-64-v4",
	"znver1",
	"znver2",
	"znver3",
	"znver4",
	"znver5",
]

then no avx is printed if ran via cargo run --release, and avx is printed if ran via RUSTFLAGS="-C target-feature=+avx" cargo run --release or RUSTFLAGS="-C target-cpu=native" cargo run --release.

However, if I run cargo +nightly multivers --out-dir . and then run the generated executable, no avx is printed when avx is expected.

I'm using Linux and my CPU is a 5000 series ryzen (znver3)

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions