|
1 | 1 | # Suggested Workflows
|
2 | 2 |
|
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 |
4 | 4 | to make your life easier.
|
5 | 5 |
|
| 6 | +## Configuring `rust-analyser` for `rustc` |
| 7 | + |
| 8 | +`rust-analyser` can help you check and format your code whenever you save |
| 9 | +a file. By default, `rust-analyser` 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-analyser` to use |
| 29 | +`x.py check` to check the sources, and the stage 0 rustfmt to format them. |
| 30 | + |
6 | 31 | ## Check, check, and check again
|
7 | 32 |
|
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-analyser` 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 |
12 | 37 | method). You can then run `./x.py build` when you actually need to
|
13 | 38 | run tests.
|
14 | 39 |
|
@@ -62,6 +87,35 @@ You can also use `--keep-stage 1` when running tests. Something like this:
|
62 | 87 | - Initial test run: `./x.py test -i --stage 1 src/test/ui`
|
63 | 88 | - Subsequent test run: `./x.py test -i --stage 1 src/test/ui --keep-stage 1`
|
64 | 89 |
|
| 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 | +Fortunately, Git has a better solution called [worktrees]. This lets you |
| 98 | +create multiple "working trees", which all share the same Git database. |
| 99 | + |
| 100 | +Given you are inside the root directory for your rust repository, you can |
| 101 | +create a "linked working tree" in a new "rust2" directory by running |
| 102 | +the following command: |
| 103 | + |
| 104 | +```bash |
| 105 | +git worktree add ../rust2 |
| 106 | +``` |
| 107 | + |
| 108 | +Creating a new worktree for a new branch based on `master` looks like: |
| 109 | + |
| 110 | +```bash |
| 111 | +git worktree add -b my-feature ../rust2 master |
| 112 | +``` |
| 113 | + |
| 114 | +You can then use that rust2 folder as a separate workspace for modifying |
| 115 | +and building `rustc`! |
| 116 | + |
| 117 | +[worktrees]: https://git-scm.com/docs/git-worktree |
| 118 | + |
65 | 119 | ## Building with system LLVM
|
66 | 120 |
|
67 | 121 | By default, LLVM is built from source, and that can take significant amount of
|
|
0 commit comments