Skip to content

Commit 2c2fb3f

Browse files
LeSeulArtichautmark-i-mspastorino
authored
Add more info on useful workflows (#727)
* Add more info on useful workflows * Apply suggestions from code review Co-authored-by: mark-i-m <mark-i-m@users.noreply.github.com> Co-authored-by: spastorino <spastorino@gmail.com> Co-authored-by: mark-i-m <mark-i-m@users.noreply.github.com> Co-authored-by: spastorino <spastorino@gmail.com>
1 parent 37117d5 commit 2c2fb3f

File tree

1 file changed

+64
-5
lines changed

1 file changed

+64
-5
lines changed

src/building/suggested.md

Lines changed: 64 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,39 @@
11
# Suggested Workflows
22

3-
The full bootstrapping process takes quite a while. Here are three suggestions
3+
The full bootstrapping process takes quite a while. Here are five suggestions
44
to make your life easier.
55

6+
## Configuring `rust-analyzer` for `rustc`
7+
8+
`rust-analyzer` can help you check and format your code whenever you save
9+
a file. By default, `rust-analyzer` runs the `cargo check` and `rustfmt`
10+
commands, but you can override these commands to use more adapted versions
11+
of these tools when hacking on `rustc`. For example, for Visual Studio Code,
12+
you can write:
13+
14+
```JSON
15+
{
16+
"rust-analyzer.checkOnSave.overrideCommand": [
17+
"./x.py",
18+
"check",
19+
"--json-output"
20+
],
21+
"rust-analyzer.rustfmt.overrideCommand": [
22+
"./build/TARGET_TRIPLE/stage0/bin/rustfmt"
23+
],
24+
"editor.formatOnSave": true
25+
}
26+
```
27+
28+
in your `.vscode/settings.json` file. This will ask `rust-analyzer` to use
29+
`x.py check` to check the sources, and the stage 0 rustfmt to format them.
30+
631
## Check, check, and check again
732

8-
The first workflow, which is useful
9-
when doing simple refactorings, is to run `./x.py check`
10-
continuously. Here you are just checking that the compiler can
11-
**build**, but often that is all you need (e.g., when renaming a
33+
When doing simple refactorings, it can be useful to run `./x.py check`
34+
continuously. If you set up `rust-analyzer` as described above, this will
35+
be done for you every time you save a file. Here you are just checking that
36+
the compiler can **build**, but often that is all you need (e.g., when renaming a
1237
method). You can then run `./x.py build` when you actually need to
1338
run tests.
1439

@@ -62,6 +87,40 @@ You can also use `--keep-stage 1` when running tests. Something like this:
6287
- Initial test run: `./x.py test -i --stage 1 src/test/ui`
6388
- Subsequent test run: `./x.py test -i --stage 1 src/test/ui --keep-stage 1`
6489

90+
## Working on multiple branches at the same time
91+
92+
Working on multiple branches in parallel can be a little annoying, since
93+
building the compiler on one branch will cause the old build and the
94+
incremental compilation cache to be overwritten. One solution would be
95+
to have multiple clones of the repository, but that would mean storing the
96+
Git metadata multiple times, and having to update each clone individually.
97+
98+
Fortunately, Git has a better solution called [worktrees]. This lets you
99+
create multiple "working trees", which all share the same Git database.
100+
Moreover, because all of the worktrees share the same object database,
101+
if you update a branch (e.g. master) in any of them, you can use the new
102+
commits from any of the worktrees. One caveat, though, is that submodules
103+
do not get shared. They will still be cloned multiple times.
104+
105+
[worktrees]: https://git-scm.com/docs/git-worktree
106+
107+
Given you are inside the root directory for your rust repository, you can
108+
create a "linked working tree" in a new "rust2" directory by running
109+
the following command:
110+
111+
```bash
112+
git worktree add ../rust2
113+
```
114+
115+
Creating a new worktree for a new branch based on `master` looks like:
116+
117+
```bash
118+
git worktree add -b my-feature ../rust2 master
119+
```
120+
121+
You can then use that rust2 folder as a separate workspace for modifying
122+
and building `rustc`!
123+
65124
## Building with system LLVM
66125

67126
By default, LLVM is built from source, and that can take significant amount of

0 commit comments

Comments
 (0)