Skip to content

Passing unstable flags only on nightly toolchains #14733

Open
@P1n3appl3

Description

@P1n3appl3

Problem

I sometimes enable unstable rustc features in my user level config.toml, such as the parallel frontend (-Zthreads).

This works fine when I'm using the nightly toolchain, but when I rustup default stable it causes builds to fail with error: the option Z is only accepted on the nightly compiler until I go comment that flag out in the config.

Proposed Solution

Adding a new target specifier for toolchain name or channel seems like the nicest solution, I'd love to be able to write:

[cfg.nightly]
rustflags = ["-Zthreads=0"]

And have that flag tacked on only when I'm using nightly. I think this works well with the existing behavior for targets and cfgs:

  1. All matching target.<triple>.rustflags and target.<cfg>.rustflags config entries joined together.

Theoretically you could also introduce a cfg type for the current toolchain so you could write:

[target.'cfg(toolchain = "nightly")']
rustflags = ["-Zthreads=0"]

... but I'm not sure that it makes sense given that code generally isn't aware of what toolchain it's built under, not to mention that adding a new cfg type seems like a bigger change than is necessary.

Notes

This question was asked on the rust discord around a year ago (by @RocketPrinter) and @danielhenrymantilla suggested the following workaround:

Something you could do is setup a rustc_wrapper.sh script which would do something along the following lines:

#!/bin/sh
if "$1" -V | grep -q nightly; then
   "$@" -Z ...
else
   "$@"
fi

I'm currently using this, but it feels gross to rely on the path of the running rustc and in the long term it'd be nice to not need a wrapper.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-configurationArea: cargo config files and env varsA-rustflagsArea: rustflagsA-rustupArea: rustup interactionA-unstableArea: nightly unstable supportC-feature-requestCategory: proposal for a feature. Before PR, ping rust-lang/cargo if this is not `Feature accepted`S-needs-designStatus: Needs someone to work further on the design for the feature or fix. NOT YET accepted.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions