Skip to content

Commit 04e44e9

Browse files
committed
Rust: Improvements and additions to the rust-analyzer update instructions
1 parent 16e1aab commit 04e44e9

1 file changed

Lines changed: 58 additions & 23 deletions

File tree

‎rust/updating-rust-analyzer.md‎

Lines changed: 58 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -4,40 +4,70 @@ Here's a rundown of the typical actions to perform to do a rust-analyzer (and ot
44
installing [`cargo-edit`](https://crates.io/crates/cargo-edit) with `cargo install cargo-edit`. On Ubuntu that also requires
55
`sudo apt install libssl-dev pkg-config`.
66

7-
1. From the root of the `codeql` repo checkout, run a Cargo upgrade:
8-
```
9-
cargo upgrade --incompatible --pinned
10-
```
11-
2. Look at a diff of the `Cargo.toml` files: if all `ra_ap_` prefixed dependencies have been updated to the same number, go on to the next step.
12-
Otherwise, it means the latest `rust-analyzer` update has not been fully rolled out to all its crates in `crates.io`.
13-
_All `ra_ap_` versions must agree!_
14-
Downgrade by hand to the minimum one you see, and run a `cargo update` after that to fix the `Cargo.lock` file.
15-
3. Commit the changes, skipping `pre-commit` hooks if you have them enabled:
16-
```
17-
git commit -am 'Cargo: upgrade dependencies' --no-verify
18-
```
19-
4. Regenerate vendored bazel files (these allow faster builds, particularly on CI where it has to start from scratch each time), commit the changes:
7+
> [!TIP]
8+
> All steps up to and including running `bazel run //rust:install` are (barring
9+
> any errors) caried out by the script `./scripts/update_rust_analyzer.py`.
10+
> Prefer using the script.
11+
12+
1. Update dependencies.
13+
1. From the root of the `codeql` repo checkout, run a Cargo upgrade:
14+
```
15+
cargo upgrade --incompatible --pinned
16+
```
17+
2. Look at a diff of the `Cargo.toml` files: if all `ra_ap_` prefixed dependencies have been updated to the same number, go on to the next step.
18+
Otherwise, it means the latest `rust-analyzer` update has not been fully rolled out to all its crates in `crates.io`.
19+
_All `ra_ap_` versions must agree!_
20+
Downgrade by hand to the minimum one you see, and run a `cargo update` after that to fix the `Cargo.lock` file.
21+
3. Commit the changes, skipping `pre-commit` hooks if you have them enabled:
22+
```
23+
git commit -am 'Cargo: upgrade dependencies' --no-verify
24+
```
25+
26+
2. Update the fixed Rust toolchain used by the extractor.
27+
28+
The version should be updated to the latest release that precedes the new
29+
rust-analyzer version.
30+
31+
Grepping for `FIXED_RUST_TOOLCHAIN` shows the places where this version is
32+
written down.
33+
34+
Commit the changes: `git commit -am 'Rust: Update fixed toolchain'`
35+
36+
3. Regenerate vendored bazel files (these allow faster builds, particularly on
37+
CI where it has to start from scratch each time), commit the changes:
2038
```
2139
misc/bazel/3rdparty/update_tree_sitter_extractors_deps.sh
2240
git add .
2341
git commit -am 'Bazel: regenerate vendored cargo dependencies' --no-verify
2442
```
2543
> [!NOTE]
26-
> If in step 6 you also bump `rules_rust` or the rust toolchain, those changes invalidate _all_ vendored files (including the
44+
> If in step 5 you also bump `rules_rust` or the Rust toolchain used for building the extractor, those changes invalidate _all_ vendored files (including the
2745
> Python ones under `misc/bazel/3rdparty/py_deps`), not just the tree-sitter ones. In that case run the umbrella script
2846
> `misc/bazel/3rdparty/update_cargo_deps.sh` instead (it regenerates both `py_deps` and `tree_sitter_extractors_deps`, and runs
2947
> `bazel mod tidy`), then commit all the regenerated files.
30-
5. Run codegen
48+
49+
4. Run codegen
3150
```
3251
bazel run //rust/codegen
3352
```
34-
Take note whether `rust/schema/ast.py` was changed. That might need tweaks, new tests and/or downgrade/upgrade scripts down the line.
35-
6. Try compiling
53+
If codegen fails other changes might be neccessary. For instance, adaptions
54+
to `annotations.py`. Make these changes in separate commits.
55+
56+
Once codegen succeeds commit only the changes made by codegen with
57+
```
58+
git commit -am 'Rust: Run codegen'
59+
```
60+
61+
Take note whether `rust/schema/ast.py` was changed. That might need tweaks,
62+
new tests and/or downgrade/upgrade scripts down the line.
63+
64+
65+
5. Try compiling
3666
```
3767
bazel run //rust:install
3868
```
3969
* if it succeeds: good! You can move on to the next step.
40-
* if it fails while compiling rust-analyzer dependencies, you need to update the rust toolchain. Sometimes the error will tell you
70+
* if it fails while compiling rust-analyzer dependencies, you need to update the Rust toolchain. Sometimes the error will tell you
4171
so explicitly, but it may happen that the error is more obscure. To update the rust toolchain:
4272
* you will need to open a PR on the internal repo updating `RUST_VERSION` in `MODULE.bazel`. In general you can have this merged
4373
independently of the changes in `codeql`.
@@ -50,8 +80,13 @@ installing [`cargo-edit`](https://crates.io/crates/cargo-edit) with `cargo insta
5080
5181
If you had to do any changes, commit them. If you updated the rust toolchain, running `rust/lint.py` might reformat or apply new
5282
lints to the code.
53-
7. Check with CI if everything is in order.
54-
8. Run DCA with database caching disabled. Iterate on the code if needed.
55-
9. If in step 5 the schema was updated, add upgrade/downgrade scripts and a change note. This is best done last to reduce the chance of
56-
merge conflicts (none of the other testing depends on having upgrade and downgrade scripts in place). See
57-
[Upgrading a language database schema](docs/prepare-db-upgrade.md).
83+
84+
6. Check with CI if everything is in order.
85+
86+
7. Run DCA with database caching disabled. Iterate on the code if needed.
87+
88+
8. If in step 4 the schema was updated, add upgrade/downgrade scripts and a
89+
change note. This is best done last to reduce the chance of merge conflicts
90+
(none of the other testing depends on having upgrade and downgrade scripts
91+
in place). See [Upgrading a language database
92+
schema](docs/prepare-db-upgrade.md).

0 commit comments

Comments
 (0)