Skip to content

Commit f407608

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

File tree

2 files changed

+122
-22
lines changed

2 files changed

+122
-22
lines changed

Diff for: Contributing.md

+62-17
Original file line numberDiff line numberDiff line change
@@ -14,40 +14,77 @@ 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. The
18+
project supports and recommends [cargo-make][cargo-make] when working on rustfmt because `cargo-make` automatically sets these variables for you and simplifies the process.
2119

20+
The available tasks for `cargo-make` are listed in `Makefile.toml` and several are detailed in sections below.
21+
22+
You can alternatively use `cargo` directly, but to do so you'll have to manually set the `CFG_RELEASE` and `CFG_RELEASE_CHANNEL` environment variables yourself and also provide the corresponding features.
23+
24+
`CFG_RELEASE_CHANNEL` must be set to either `nightly` or `beta`, and `CFG_RELEASE` should be set to your corresponding Rust version.
25+
26+
For example:
27+
```sh
28+
export CFG_RELEASE=1.45.0-nightly
29+
export CFG_RELEASE=nightly
30+
cargo +nightly build ...
31+
# And/or inline if you prefer, or need to override value(s)
32+
CFG_RELEASE_CHANNEL=nightly CFG_RELEASE=1.45.0-nightly cargo +nightly build ...
2233
```
23-
cargo +nightly make test
34+
(Windows users can use `set` to specify the environment variable values)
35+
36+
## Building
37+
To build with `cargo make`:
38+
39+
```sh
40+
cargo make build
2441
```
2542

26-
The available tasks are listed in `Makefile.toml`.
43+
Or alternatively with `cargo` directly:
44+
```sh
45+
cargo build --all-features
46+
# And/or with the required environment variables inline if you prefer, or need to override the value(s)
47+
CFG_RELEASE_CHANNEL=nightly CFG_RELEASE=1.45.0-nightly cargo build --all-features
48+
```
2749

2850
## Test and file issues
2951

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

3355

34-
## Create test cases
56+
## Running tests
3557

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.
58+
The tests can be executed with `cargo make` or directly with `cargo` provided the corresponding environment variables have been set.
59+
60+
To run tests with `cargo make`:
61+
62+
```sh
63+
cargo make test
64+
```
65+
66+
Or alternatively with `cargo` directly:
67+
```sh
68+
cargo test --all-features
69+
# And/or with the required environment variables inline if you prefer, or need to override the value(s)
70+
CFG_RELEASE_CHANNEL=beta CFG_RELEASE=1.45.0-nightly cargo test --all-features
71+
```
3872

39-
The tests can be run with `cargo make test`. This does a number of things:
73+
This does a number of things:
4074
* 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/`.
75+
* ensures that rustfmt is executed against every file in `tests/source/` and that each formatted result is equal to its associated file in `tests/target/`;
76+
* runs idempotence tests on the files in `tests/target/`.
4477
These files should not be changed by rustfmt;
4578
* checks that rustfmt's code is not changed by running on itself. This ensures
4679
that the project bootstraps.
4780

81+
## Creating test cases
82+
Having a strong test suite for a tool like this is essential. It is very easy
83+
to create regressions. Any tests you can add are very much appreciated.
84+
4885
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
86+
`tests/source/` and an equally named one in
87+
`tests/target/`. If it is only required that rustfmt leaves a
5188
piece of code unformatted, it may suffice to only create a target file.
5289

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

113+
[cargo-make]: https://sagiegurari.github.io/cargo-make/
114+
76115
## Debugging
77116

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

83122
## Hack!
84123

85-
Here are some [good starting issues](https://github.com/rust-lang/rustfmt/issues?q=is%3Aopen+is%3Aissue+label%3Agood-first-issue).
124+
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!
125+
126+
Here are some good starting issues:
127+
128+
[![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)
129+
[![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)
130+
86131

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

97142
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
143+
It's really easy, see above for details. Please [run the tests](#running-tests) locally before
99144
submitting a PR to ensure your patch passes all tests, it's pretty quick.
100145

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

Diff for: README.md

+60-5
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)