rustup icon indicating copy to clipboard operation
rustup copied to clipboard

Command to create rust-toolchain.toml in the current directory

Open ian-h-chamberlain opened this issue 4 years ago • 5 comments

Apologies if this has already been requested, but I couldn't seem to find any issues describing something like it, nor any feature already built-in to rustup to do this. If there is, please feel free to close this issue.

Describe the problem you are trying to solve

Frequently, when I create a new binary project, I want to pin a specific toolchain immediately after initializing the project, e.g.

cargo new --bin some-project
cat >some-project/rust-toolchain.toml <<EOF
[toolchain]
channel = "stable"
EOF

However, I frequently forget the precise format of the toolchain file, and I have to search in rustup documentation to find an example and copy-paste that into my project. It would be nice if there was a simple way to generate a file with reasonable defaults that I could then customize, similar to the generated Cargo.toml created by cargo new or cargo init.

Describe the solution you'd like

Add one more more new rustup commands to create a rust-toolchain.toml in the current directory. I think this could work similarly to rustup override set (take a toolchain argument), or just use the default / currently-set toolchain. The generated file could also include comments that briefly describe some of the fields and link to the documentation.

Notes

Example of one possible workflow:

cargo new --bin some-project
cd some-project
rustup init nightly . # or whatever the syntax of the command looks like

After which the contents of some-project/rust-toolchain.toml would look like this:

# See more keys and their definitions at https://rust-lang.github.io/rustup/overrides.html#the-toolchain-file
[toolchain]
channel = "nightly"
components = []
targets = []
profile = "default"

Some possible command names:

  • rustup new (for parity with cargo new)
  • rustup init (possibly confusing with rustup-init)
  • rustup generate-toolchain-file or similar (very wordy)
  • rustup pin
  • A subcommand or flag to pass to rustup override set ?

ian-h-chamberlain avatar Oct 14 '21 18:10 ian-h-chamberlain

@rustbot claim

0xPoe avatar Mar 11 '22 13:03 0xPoe

I got here from googling "rustup create rust-toolchain file". Surprised there isn't a command for this. Ever since I lost some time with an outdated rustc version I've religiously copy and pasted the rust-toolchain file. So agreed, I'd personally expect cargo init to do it. But equally wouldn't be surprised if the responsibility fell on rustup override set or similar.

tombh avatar Jul 25 '22 21:07 tombh