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

Passing unstable flags only on nightly toolchains #14733

Open
P1n3appl3 opened this issue Oct 26, 2024 · 2 comments
Open

Passing unstable flags only on nightly toolchains #14733

P1n3appl3 opened this issue Oct 26, 2024 · 2 comments
Labels
A-configuration Area: cargo config files and env vars A-rustflags Area: rustflags A-rustup Area: rustup interaction A-unstable Area: nightly unstable support C-feature-request Category: proposal for a feature. Before PR, ping rust-lang/cargo if this is not `Feature accepted` S-needs-design Status: Needs someone to work further on the design for the feature or fix. NOT YET accepted.

Comments

@P1n3appl3
Copy link
Contributor

P1n3appl3 commented Oct 26, 2024

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.

@P1n3appl3 P1n3appl3 added C-feature-request Category: proposal for a feature. Before PR, ping rust-lang/cargo if this is not `Feature accepted` S-triage Status: This issue is waiting on initial triage. labels Oct 26, 2024
@epage
Copy link
Contributor

epage commented Oct 26, 2024

We do have

[target.<cfg>]
runner = ""            # wrapper to run executables
rustflags = ["", ""]  # custom flags for `rustc`

There is an approved RFC for cfg(version) and cfg(accessible) but that doesn't cover release channels. These are generally geared around detecting what can be used for community libraries. For nightlies, a feature is tied to a range of them so it can't be used for that case. If you set aside dependents and only focus on development, assumptions like in your proposal can be made.

A user could emulate this by manually passing in --cfg nightly.

For myself, I would want the exploration of a toolchain = nightly to be generalized to rustc and Cargo before considering whether we'd want to do a Cargo-only solution.

Another part to this is what about Cargo unstable features. cfg tables are generally evaluated as part of compilation and I assume have to deal with host/target settings. Doing it also in a way to evaluate unstable features might be a bit much.

@epage epage added A-configuration Area: cargo config files and env vars A-rustflags Area: rustflags A-unstable Area: nightly unstable support labels Oct 26, 2024
@weihanglo
Copy link
Member

but that doesn't cover release channels.

I didn't follow the RFC too close, though channels is a concept in rustup. Not sure if there is a plan for cargo/rustc to support it natively.

@weihanglo weihanglo added S-needs-design Status: Needs someone to work further on the design for the feature or fix. NOT YET accepted. A-rustup Area: rustup interaction and removed S-triage Status: This issue is waiting on initial triage. labels Nov 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-configuration Area: cargo config files and env vars A-rustflags Area: rustflags A-rustup Area: rustup interaction A-unstable Area: nightly unstable support C-feature-request Category: proposal for a feature. Before PR, ping rust-lang/cargo if this is not `Feature accepted` S-needs-design Status: Needs someone to work further on the design for the feature or fix. NOT YET accepted.
Projects
None yet
Development

No branches or pull requests

3 participants