Skip to content

Commit 3ba2529

Browse files
committed
1 parent a3b2bfc commit 3ba2529

File tree

1 file changed

+38
-5
lines changed

1 file changed

+38
-5
lines changed

README.md

Lines changed: 38 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -79,14 +79,47 @@ rustup component add rustfmt
7979

8080
## Installing from source
8181

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:
8384

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
86115
```
87116

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`.
90123
91124

92125
## Running

0 commit comments

Comments
 (0)