Skip to content

Commit 8d28fc5

Browse files
docs: update build/test/install instructions
1 parent bb8578d commit 8d28fc5

File tree

2 files changed

+118
-22
lines changed

2 files changed

+118
-22
lines changed

Contributing.md

Lines changed: 58 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -14,40 +14,73 @@ Conduct](CODE_OF_CONDUCT.md).
1414
Rustfmt requires a nightly compiler. Replace all invocations of `cargo` by
1515
`cargo +nightly` if necessary.
1616

17-
At all times the environment variables `CFG_RELEASE_CHANNEL` and `CFG_RELEASE` must
18-
be set to either `nightly` or `beta`. Both should be set to the same value. The
19-
project supports [cargo-make](https://github.com/sagiegurari/cargo-make) which
20-
automatically sets these variables for you:
17+
At all times the environment variables `CFG_RELEASE_CHANNEL` and `CFG_RELEASE` must be set. `CFG_RELEASE_CHANNEL` must be set to either `nightly` or `beta`, and `CFG_RELEASE` should be set to your corresponding Rust version. The
18+
project supports and recommends [cargo-make][cargo-make] when working on rustfmt, because `cargo-make` automatically sets these variables for you
2119

20+
The available tasks are listed in `Makefile.toml`.
21+
22+
You can alternatively use `cargo` directly, but you'll have to set the `CFG_RELEASE` and `CFG_RELEASE_CHANNEL` environment variables and also provide the corresponding features.
23+
24+
For example:
25+
```sh
26+
export CFG_RELEASE=1.45.0-nightly
27+
export CFG_RELEASE=nightly
2228
```
23-
cargo +nightly make test
29+
(Windows users can use `set` to specify the environment variable values)
30+
31+
## Building
32+
To build with `cargo make`:
33+
34+
```sh
35+
cargo make build
2436
```
2537

26-
The available tasks are listed in `Makefile.toml`.
38+
Or alternatively with `cargo` directly:
39+
```sh
40+
cargo build --all-features
41+
# or
42+
CFG_RELEASE_CHANNEL=nightly CFG_RELEASE=1.45.0-nightly cargo build --all-features
43+
```
2744

2845
## Test and file issues
2946

3047
It would be really useful to have people use rustfmt on their projects and file
3148
issues where it does something you don't expect.
3249

3350

34-
## Create test cases
51+
## Running tests
3552

36-
Having a strong test suite for a tool like this is essential. It is very easy
37-
to create regressions. Any tests you can add are very much appreciated.
53+
The tests can be executed with `cargo make` or directly with `cargo` provided the corresponding environment variables have been set.
3854

39-
The tests can be run with `cargo make test`. This does a number of things:
55+
To run tests with `cargo make`:
56+
57+
```sh
58+
cargo make test
59+
```
60+
61+
Or alternatively with `cargo` directly:
62+
```sh
63+
cargo test --all-features
64+
# or
65+
CFG_RELEASE_CHANNEL=nightly CFG_RELEASE=1.45.0-nightly cargo test --all-features
66+
```
67+
68+
This does a number of things:
4069
* runs the unit tests for a number of internal functions;
41-
* makes sure that rustfmt run on every file in `rustfmt-core/rustfmt-lib/tests/source/`
42-
is equal to its associated file in `rustfmt-core/rustfmt-lib/tests/target/`;
43-
* runs idempotence tests on the files in `rustfmt-core/rustfmt-lib/tests/target/`.
70+
* makes sure that rustfmt run on every file in `tests/source/`
71+
is equal to its associated file in `tests/target/`;
72+
* runs idempotence tests on the files in `tests/target/`.
4473
These files should not be changed by rustfmt;
4574
* checks that rustfmt's code is not changed by running on itself. This ensures
4675
that the project bootstraps.
4776

77+
## Creating test cases
78+
Having a strong test suite for a tool like this is essential. It is very easy
79+
to create regressions. Any tests you can add are very much appreciated.
80+
4881
Creating a test is as easy as creating a new file in
49-
`rustfmt-core/rustfmt-lib/tests/source/` and an equally named one in
50-
`rustfmt-core/rustfmt-lib/tests/target/`. If it is only required that rustfmt leaves a
82+
`tests/source/` and an equally named one in
83+
`tests/target/`. If it is only required that rustfmt leaves a
5184
piece of code unformatted, it may suffice to only create a target file.
5285

5386
Whenever there's a discrepancy between the expected output when running tests, a
@@ -73,6 +106,8 @@ would need a configuration file named `test-indent.toml` in that directory. As a
73106
example, the `issue-1111.rs` test file is configured by the file
74107
`./tests/config/issue-1111.toml`.
75108

109+
[cargo-make]: https://sagiegurari.github.io/cargo-make/
110+
76111
## Debugging
77112

78113
Some `rewrite_*` methods use the `debug!` macro for printing useful information.
@@ -82,7 +117,13 @@ and get a better grasp on the execution flow.
82117

83118
## Hack!
84119

85-
Here are some [good starting issues](https://github.com/rust-lang/rustfmt/issues?q=is%3Aopen+is%3Aissue+label%3Agood-first-issue).
120+
There are a lot of open issues on the backlog for those interested in hacking on rustfmt. If you find an issue that you are interested in working on, add a comment to the issue to let us (and other potential contributors) know!
121+
122+
Here are some good starting issues:
123+
124+
[![GitHub good-first-issue](https://img.shields.io/github/issues/rust-lang/rustfmt/good-first-issue?style=flat-square)](https://github.com/rust-lang/rustfmt/issues?q=is%3Aopen+is%3Aissue+label%3Agood%20first%20issue)
125+
[![GitHub help-wanted](https://img.shields.io/github/issues/rust-lang/rustfmt/help-wanted?style=flat-square)](https://github.com/rust-lang/rustfmt/issues?q=is%3Aopen+is%3Aissue+label%3Ahelp-wanted)
126+
86127

87128
If you've found areas which need polish and don't have issues, please submit a
88129
PR, don't feel there needs to be an issue.
@@ -95,7 +136,7 @@ source code. So, basically, the only style guideline is that you must pass the
95136
tests. That ensures that the Rustfmt source code adheres to our own conventions.
96137

97138
Talking of tests, if you add a new feature or fix a bug, please also add a test.
98-
It's really easy, see above for details. Please run `cargo test` before
139+
It's really easy, see above for details. Please [run the tests](#running-tests) locally before
99140
submitting a PR to ensure your patch passes all tests, it's pretty quick.
100141

101142
Rustfmt is post-1.0 and within major version releases we strive for backwards

README.md

Lines changed: 60 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# rustfmt [![Build Status](https://travis-ci.com/rust-lang/rustfmt.svg?branch=master)](https://travis-ci.com/rust-lang/rustfmt) [![Build Status](https://ci.appveyor.com/api/projects/status/github/rust-lang/rustfmt?svg=true)](https://ci.appveyor.com/project/rust-lang-libs/rustfmt) [![crates.io](https://img.shields.io/crates/v/rustfmt-nightly.svg)](https://crates.io/crates/rustfmt-nightly) [![Travis Configuration Status](https://img.shields.io/travis/davidalber/rustfmt-travis.svg?label=travis%20example)](https://travis-ci.org/davidalber/rustfmt-travis)
1+
# rustfmt [![Linux badge][linux-build-status]][linux-build] [![Mac badge][mac-build-status]][mac-build] [![Windows badge][windows-build-status]][windows-build] [![crates.io badge][cratesio-badge]][cratesio-package] [![Travis config badge][travis-config-badge]][travis-config-job]
22

33
A tool for formatting Rust code according to style guidelines.
44

@@ -82,11 +82,22 @@ rustup component add rustfmt
8282

8383
## Installing from source
8484

85-
To install from source (nightly required), first checkout to the tag or branch you want to install, then issue
85+
To install from source (nightly required), first checkout to the tag or branch for the version of rustfmt you want.
86+
87+
The easiest way to install is via [cargo make][cargo-make]
88+
89+
```sh
90+
cargo make install
91+
```
92+
93+
Alternatively, you can run `cargo install` directly as long as you set the required environment variables and features.
8694

8795
```sh
88-
cargo install --path .
96+
export CFG_RELEASE=1.45.0-nightly
97+
export CFG_RELEASE=nightly
98+
cargo install --path . --force --locked --features rustfmt,cargo-fmt
8999
```
100+
(Windows users can use `set` to specify the environment variable values)
90101

91102
This will install `rustfmt` in your `~/.cargo/bin`. Make sure to add `~/.cargo/bin` directory to
92103
your PATH variable.
@@ -146,9 +157,42 @@ for more info.
146157
147158
## How to build and test
148159
149-
`cargo build` to build.
160+
We recommend using [cargo make][cargo-make] when working with the rustfmt codebase.
161+
162+
You can alternatively use `cargo` directly, but you'll have to set the `CFG_RELEASE` and `CFG_RELEASE_CHANNEL` environment variables and also provide the corresponding features.
163+
164+
For example:
165+
```sh
166+
export CFG_RELEASE=1.45.0-nightly
167+
export CFG_RELEASE=nightly
168+
```
169+
(Windows users can use `set` to specify the environment variable values)
170+
171+
To build with `cargo make`:
172+
173+
```sh
174+
cargo make build
175+
```
176+
177+
Or alternatively with `cargo` directly:
178+
```sh
179+
cargo build --all-features
180+
# or
181+
CFG_RELEASE_CHANNEL=nightly CFG_RELEASE=1.45.0-nightly cargo build --all-features
182+
```
183+
184+
To run tests with `cargo make`:
150185

151-
`cargo test --manifest-path rustfmt-core/Cargo.toml` to run all tests.
186+
```sh
187+
cargo make test
188+
```
189+
190+
Or alternatively with `cargo` directly:
191+
```sh
192+
cargo test --all-features
193+
# or
194+
CFG_RELEASE_CHANNEL=nightly CFG_RELEASE=1.45.0-nightly cargo test --all-features
195+
```
152196

153197
To run rustfmt after this, use `cargo run --bin rustfmt -- filename`. See the
154198
notes above on running rustfmt.
@@ -231,3 +275,14 @@ See [LICENSE-APACHE](LICENSE-APACHE) and [LICENSE-MIT](LICENSE-MIT) for details.
231275
[rust]: https://github.com/rust-lang/rust
232276
[fmt rfcs]: https://github.com/rust-lang-nursery/fmt-rfcs
233277
[style guide]: https://github.com/rust-lang-nursery/fmt-rfcs/blob/master/guide/guide.md
278+
[cargo-make]: https://sagiegurari.github.io/cargo-make/
279+
[linux-build-status]: https://img.shields.io/github/workflow/status/rust-lang/rustfmt/linux/master?label=linux&style=flat-square
280+
[linux-build]: https://github.com/rust-lang/rustfmt/actions?query=workflow%3Alinux+branch%3Amaster
281+
[mac-build-status]: https://img.shields.io/github/workflow/status/rust-lang/rustfmt/mac/master?label=mac&style=flat-square
282+
[mac-build]: https://github.com/rust-lang/rustfmt/actions?query=workflow%3Amac+branch%3Amaster
283+
[windows-build-status]: https://img.shields.io/github/workflow/status/rust-lang/rustfmt/windows/master?label=windows&style=flat-square
284+
[windows-build]: https://github.com/rust-lang/rustfmt/actions?query=workflow%3Awindows+branch%3Amaster
285+
[cratesio-badge]: https://img.shields.io/crates/v/rustfmt-nightly?style=flat-square
286+
[cratesio-package]: https://crates.io/crates/rustfmt-nightly
287+
[travis-config-badge]: https://img.shields.io/travis/davidalber/rustfmt-travis?label=travis%20example&style=flat-square
288+
[travis-config-job]: https://travis-ci.org/davidalber/rustfmt-travis

0 commit comments

Comments
 (0)