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)
Problem
I am trying to override
rustflagsfor 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 thatcfg()is missing a few keys when compiling test binaries, notablytestandfeature.FWIW,
--testand--cfg 'feature="build-mode-standalone"'is getting passed intorustcwhen building the test binaries. So something in Cargo knows about them. It appears that these values aren't getting plumbed through tocfg()evaluation.Possible Solution(s)
I think
cfg()should have access totest,feature, and perhaps other conditional keys when building test binaries.Output of
cargo version:cargo 1.43.0 (3532cf738 2020-03-17)