Rustfmt: Is there a simple way to install rusftmt 2.0 rc without building from source?

Created on 9 Dec 2020  路  8Comments  路  Source: rust-lang/rustfmt

Hey!
I'm new to the rust ecosystem and would like to try out 2.0. Is there a simple way to install and then uninstall the 2.0 versions?
From what I see the nightly versions on cargo are 1.4.x as well

Most helpful comment

There definitely won't be a 2.0 release in 2020, and long term I'm honestly not sure what the plan is going to be. It's entirely plausible we may never be able to do so, or at least not until there's a hypothetical 2.0 release of Rust

If rustfmt 2 is not going to be released, what does that mean for the added configuration options which were stabilised only in 2.0? Are those stabilisations going to get backported? Is there a blog or discussion thread somewhere with more insight into what is going to be happening instead? I鈥檇 been holding off for an official v2 release to formally adopt rustfmt in a project I have been working on, so it would be nice to get a sense of what the plan is. A quick search did not surface anything about this on rust-internals or rust-users forums. Thanks!

All 8 comments

hello @Kungitoo :wave: thanks for the question and welcome! :crab:

Is there a simple way to install rusftmt 2.0 rc without building from source?

No there's not. The primary distribution channel for rustfmt is via rustup and the associated rust releases.

https://github.com/rust-lang/rustfmt#installing-from-source

rustfmt is also available on crates.io (though it's several versions behind the latest version available via rustup), but there's really not must of a difference in the experience between installing from crates.io vs. installing from source: both involve building and both utilize the cargo install ...

Is there a simple way to install and then uninstall the 2.0 versions?

Think the installation bit was covered above, and cargo uninstall can be used to uninstall both an install from source or crates.io

Also regarding your question from https://github.com/rust-lang/rustfmt/issues/4437#issuecomment-741845052

can we know if 2.0 is planned for 2020 or is there a roadmap somewhere?

We were actually ready to ship the 2.0 release back in the spring, but as we were starting that process there were various concerns and objections about having a breaking/2.0 release for an official tool that ships with the main Rust distribution (which itself is on a 1.x version).

There definitely won't be a 2.0 release in 2020, and long term I'm honestly not sure what the plan is going to be. It's entirely plausible we may never be able to do so, or at least not until there's a hypothetical 2.0 release of Rust, due to the combination of how seriously Rust takes stability and rustfmt's own stability guarantee.

Here was the original milestone we had tracking the 2.0 release:
https://github.com/rust-lang/rustfmt/milestone/8

Could you release 2.0 version to be available under some flag? I know this would never pass, but could you bundle 2.0 code with the 1.x package and then when some flag is specified we use the 2.0 code which is completely separate so it doesn't interfere with the stable 1.x version?

If you only need rust-fmt, you can build rustfmt feature from source code, and then replace it from toolchains.

  • Windows
set CFG_RELEASE=1.45.0-nightly <--(Specify yours)
set CFG_RELEASE_CHANNEL=nightly

cargo build --bin rustfmt --features="rustfmt"

cp debug\target\rust-fmt.exe C:\Users\Francis\.rustup\toolchains\nightly-x86_64-pc-windows-msvc\bin
  • Linux/Mac
export CFG_RELEASE=1.45.0-nightly <--(Specify yours)
export CFG_RELEASE_CHANNEL=nightly

cargo build --bin rustfmt --features="rustfmt"

cp debug/target/rust-fmt ~/.rustup/toolchains/nightly-***/bin

It's mine

> cargo fmt --version
rustfmt 2.0.0-rc.2-beta (2ce75b11 2020-12-09)

Could you release 2.0 version to be available under some flag?

No. I appreciate your interest in the potential 2.0 version, but it's not released right now by design for the reasons I shared above and that's not going to change any time soon. If you want to use the unreleased version of rustfmt from the source control repository, then you're going to have to work with the source control repository in your local and/or CI environments.

Going to go ahead and close this given that the question has been answered, thanks again for reaching out!

@francis-du - I'd advise against mixing and matching different major versions of cargo fmt and rustfmt, but even if you decide you want to take that risk, note that it'd be easier to utilize the RUSTFMT environment variable to specify the custom path to the rustfmt binary instead of hacking up rustup managed directories.

https://github.com/rust-lang/rustfmt#running-cargo-fmt

Please be aware that there's substantial differences in the 2.x version of rustfmt that the 1.x version of cargo fmt doesn't necessarily work with, notably, rustfmt 2.x is not recursive by default so if you run cargo fmt 1.x it will result in only the entry point files for the respective targets in your projects being formatted (main.rs, lib.rs, build.rs, etc.); all other files would be ignored unless you change your invocation to cargo fmt -- --recursive

@calebcartwright Thanks for reminding : )

@calebcartwright Thanks for reminding : )

Sure thing, thanks for sharing your findings!

There definitely won't be a 2.0 release in 2020, and long term I'm honestly not sure what the plan is going to be. It's entirely plausible we may never be able to do so, or at least not until there's a hypothetical 2.0 release of Rust

If rustfmt 2 is not going to be released, what does that mean for the added configuration options which were stabilised only in 2.0? Are those stabilisations going to get backported? Is there a blog or discussion thread somewhere with more insight into what is going to be happening instead? I鈥檇 been holding off for an official v2 release to formally adopt rustfmt in a project I have been working on, so it would be nice to get a sense of what the plan is. A quick search did not surface anything about this on rust-internals or rust-users forums. Thanks!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

BartMassey picture BartMassey  路  4Comments

cramertj picture cramertj  路  4Comments

torkleyy picture torkleyy  路  5Comments

ozkriff picture ozkriff  路  4Comments

thomaseizinger picture thomaseizinger  路  3Comments