Skip to content

Commit b8cc0a5

Browse files
caasscamelid
authored and
Joshua Nelson
committed
Add section describing git hook functionality
This is a companion to [this PR](rust-lang/rust#76356), which deals with including functionality for automatically running `tidy --bless` on each commit. Undo editor auto-formatting and clarify git hook renaming a word Phrasing Apply suggestions from code review Co-authored-by: Camelid <[email protected]>
1 parent d4581a5 commit b8cc0a5

File tree

1 file changed

+20
-6
lines changed

1 file changed

+20
-6
lines changed

src/building/suggested.md

+20-6
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,19 @@
33
The full bootstrapping process takes quite a while. Here are some suggestions
44
to make your life easier.
55

6+
## Installing a pre-commit hook
7+
8+
CI will automatically fail your build if it doesn't pass `tidy`, our
9+
internal tool for ensuring code quality. If you'd like, you can install a
10+
[Git hook](https://git-scm.com/book/en/v2/Customizing-Git-Git-Hooks)
11+
that will automatically run `x.py test tidy --bless` on each commit, to ensure
12+
your code is up to par. If you decide later that this behavior is
13+
undesirable, you can delete the `pre-commit` file in `.git/hooks`.
14+
15+
A prebuilt git hook lives at [`src/etc/pre-commit.sh`](https://github.com/rust-lang/rust/blob/master/src/etc/pre-commit.sh) which can be copied into your `.git/hooks` folder as `pre-commit` (without the `.sh` extension!).
16+
17+
You can also install the hook as a step of running `x.py setup`!
18+
619
## Configuring `rust-analyzer` for `rustc`
720

821
`rust-analyzer` can help you check and format your code whenever you save
@@ -82,7 +95,7 @@ directories you have [setup a worktree for]. You may need to use the pinned
8295
nightly version from `src/stage0.txt`, but often the normal `nightly` channel
8396
will work.
8497

85-
**Note** see [the section on vscode] for how to configure it with this real rustfmt `x.py` uses,
98+
**Note** see [the section on vscode] for how to configure it with this real rustfmt `x.py` uses,
8699
and [the section on rustup] for how to setup `rustup` toolchain for your bootstrapped compiler
87100

88101
**Note** This does _not_ allow you to build `rustc` with cargo directly. You
@@ -100,7 +113,7 @@ Sometimes just checking
100113
whether the compiler builds is not enough. A common example is that
101114
you need to add a `debug!` statement to inspect the value of some
102115
state or better understand the problem. In that case, you really need
103-
a full build. By leveraging incremental, though, you can often get
116+
a full build. By leveraging incremental, though, you can often get
104117
these builds to complete very fast (e.g., around 30 seconds). The only
105118
catch is this requires a bit of fudging and may produce compilers that
106119
don't work (but that is easily detected and fixed).
@@ -118,10 +131,10 @@ The sequence of commands you want is as follows:
118131

119132
[documented previously]: ./how-to-build-and-run.md#building-the-compiler
120133

121-
As mentioned, the effect of `--keep-stage 1` is that we just *assume* that the
134+
As mentioned, the effect of `--keep-stage 1` is that we just _assume_ that the
122135
old standard library can be re-used. If you are editing the compiler, this
123136
is almost always true: you haven't changed the standard library, after
124-
all. But sometimes, it's not true: for example, if you are editing
137+
all. But sometimes, it's not true: for example, if you are editing
125138
the "metadata" part of the compiler, which controls how the compiler
126139
encodes types and other states into the `rlib` files, or if you are
127140
editing things that wind up in the metadata (such as the definition of
@@ -131,7 +144,7 @@ the MIR).
131144
using `--keep-stage 1`** -- for example, strange
132145
[ICEs](../appendix/glossary.html#ice) or other panics. In that case, you
133146
should simply remove the `--keep-stage 1` from the command and
134-
rebuild. That ought to fix the problem.
147+
rebuild. That ought to fix the problem.
135148

136149
You can also use `--keep-stage 1` when running tests. Something like this:
137150

@@ -147,6 +160,7 @@ crates you'll have to rebuild
147160
For example, when working on `rustc_mir_build`, the `rustc_mir_build` and
148161
`rustc_driver` crates take the most time to incrementally rebuild. You could
149162
therefore set the following in the root `Cargo.toml`:
163+
150164
```toml
151165
[profile.release.package.rustc_mir_build]
152166
opt-level = 0
@@ -218,6 +232,6 @@ Note that you need to have the LLVM `FileCheck` tool installed, which is used
218232
for codegen tests. This tool is normally built with LLVM, but if you use your
219233
own preinstalled LLVM, you will need to provide `FileCheck` in some other way.
220234
On Debian-based systems, you can install the `llvm-N-tools` package (where `N`
221-
is the LLVM version number, e.g. `llvm-8-tools`). Alternately, you can specify
235+
is the LLVM version number, e.g. `llvm-8-tools`). Alternately, you can specify
222236
the path to `FileCheck` with the `llvm-filecheck` config item in `config.toml`
223237
or you can disable codegen test with the `codegen-tests` item in `config.toml`.

0 commit comments

Comments
 (0)