Skip to content

[target.'cfg(...)'] doesn't expose all keys (like test and features) #8170

Open
@indygreg

Description

@indygreg

Problem

I am trying to override rustflags for my test binaries. But I don't want to do this for the normal, non-test binaries.

In theory, you can use the [target.'cfg(...)'] syntax to influence rustflags on a very granular basis. However, it appears that cfg() is missing a few keys when compiling test binaries, notably test and feature.

# Works
[target.'cfg(target_os = "linux")']
rustflags = ["-C", "link-args=-Wl,-export-dynamic"]

# Does not work - feature test fails.
[target.'cfg(feature = "build-mode-standalone")']
rustflags = ["-C", "link-args=-Wl,-export-dynamic"]

# Does not work - test not defined.
[target.'cfg(test)']
rustflags = ["-C", "link-args=-Wl,-export-dynamic"]

FWIW, --test and --cfg 'feature="build-mode-standalone"' is getting passed into rustc when building the test binaries. So something in Cargo knows about them. It appears that these values aren't getting plumbed through to cfg() evaluation.

Possible Solution(s)

I think cfg() should have access to test, feature, and perhaps other conditional keys when building test binaries.

Output of cargo version: cargo 1.43.0 (3532cf738 2020-03-17)

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-cfg-exprArea: Platform cfg expressionsA-configurationArea: cargo config files and env varsA-target-dependenciesArea: [target.'cfg(foo)'.dependencies]C-bugCategory: bugS-propose-closeStatus: A team member has nominated this for closing, pending further input from the team

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions