@@ -79,14 +79,47 @@ rustup component add rustfmt
79
79
80
80
## Installing from source
81
81
82
- To install from source (nightly required), first checkout to the tag or branch you want to install, then issue
82
+ If you are hacking on Rustfmt and want to install it from source, do the
83
+ following:
83
84
84
- ``` sh
85
- cargo install --path .
85
+ First, take note of the toolchain
86
+ [ override] ( https://rust-lang.github.io/rustup/overrides.html ) in
87
+ ` /rust-toolchain ` . We will use this override to install Rustfmt into the right
88
+ toolchain.
89
+
90
+ > Tip: You can view the active toolchain for the current directory with `rustup
91
+ > show active-toolchain`.
92
+
93
+ From the Rustfmt project root, run the following command to build the Rustfmt
94
+ binaries and copy them into the toolchain directory. This will override the
95
+ currently installed Rustfmt component.
96
+
97
+ ``` terminal
98
+ cargo build --release --bin rustfmt --bin cargo-fmt -Zunstable-options --out-dir "$(rustc --print=sysroot)/bin"
99
+ ```
100
+
101
+ Now you may run ` cargo fmt ` in any project, using the toolchain where you
102
+ just installed Rustfmt.
103
+
104
+ ``` terminal
105
+ cd my-project
106
+ cargo +nightly-2023-01-24 fmt
107
+ ```
108
+
109
+ If you need to restore the default Rustfmt installation, run the following (from
110
+ the Rustfmt project root).
111
+
112
+ ``` terminal
113
+ rustup component remove rustfmt
114
+ rustup component add rustfmt
86
115
```
87
116
88
- This will install ` rustfmt ` in your ` ~/.cargo/bin ` . Make sure to add ` ~/.cargo/bin ` directory to
89
- your PATH variable.
117
+ > ** DO NOT** install using ` cargo install --path . --force ` since this will
118
+ > overwrite rustup
119
+ > [ proxies] ( https://rust-lang.github.io/rustup/concepts/proxies.html ) . That is,
120
+ > ` ~/.cargo/bin/cargo-fmt ` and ` ~/.cargo/bin/rustfmt ` should be hard or
121
+ > soft links to ` ~/.cargo/bin/rustup ` . You can repair these by running `rustup
122
+ > update`.
90
123
91
124
92
125
## Running
0 commit comments