Skip to content

Commit 0370291

Browse files
committed
Rust: add rust-analyzer update instructions
1 parent c3773e1 commit 0370291

File tree

1 file changed

+48
-0
lines changed

1 file changed

+48
-0
lines changed

rust/README.md

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,3 +62,51 @@ Sometimes, especially if resolving conflicts on generated files, you might need
6262
bazel run @codeql//rust/codegen -- --force
6363
```
6464
for code generation to succeed.
65+
66+
### Updating `rust-analyzer`
67+
68+
Here's a rundown of the typical actions to perform to do a rust-analyzer (and other dependencies) update. A one-time setup consists in
69+
installing [`cargo-edit`](https://crates.io/crates/cargo-edit) with `cargo install cargo-edit`. On Ubuntu that also requires
70+
`sudo apt install libssl-dev pkg-config`.
71+
72+
1. from the root of the `codeql` repo checkout, run an upgrade, and commit the changes (skipping `pre-commit` hooks if you have them enabled):
73+
```
74+
cargo upgrade --incompatible --pinned
75+
```
76+
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.
77+
Otherwise, it means the latest `rust-analyzer` update has not been fully rolled out to all its crates in `crates.io`.
78+
_All `ra_ap_` versions must agree!_
79+
Downgrade by hand to the minimum one you see, and run a `cargo update` after that to fix the `Cargo.lock` file.
80+
3. Commit the changes, skipping `pre-commit` hooks if you have them enabled:
81+
```
82+
git commit -am 'Cargo: upgrade dependencies' --no-verify
83+
```
84+
4. Regenerate vendored bazel files, commit the changes:
85+
```
86+
misc/bazel/3rdparty/update_tree_sitter_extractors_deps.sh
87+
git add .
88+
git commit -am 'Bazel: regenerate vendored cargo dependencies' --no-verify
89+
```
90+
5. Run codegen
91+
```
92+
bazel run //rust/codegen
93+
```
94+
Take note whether `rust/schema/ast.py` was changed. That might need tweaks, new tests and/or downgrade/upgrade scripts down the line
95+
6. Try compiling
96+
```
97+
bazel run //rust:install
98+
```
99+
* if it succeeds: good! You can move on to the next step.
100+
* if it fails while compiling rust-analyzer dependencies, you need to update the rust toolchain. Sometimes the error will tell you
101+
so explcitly, but it may happen that the error is more obscure. To update the rust toolchain:
102+
* you will need to open a PR on the internal repo updating `RUST_VERSION` in `MODULE.bazel`. In general you can have this merged
103+
independently of the changes in `codeql`.
104+
* in `codeql`, update both `RUST_VERSION` in `MODULE.bazel` _and_ `rust-toolchain.toml` files. You may want to also update the
105+
nightly toolchain in `rust/extractor/src/nightly-toolchain/rust-toolchain.toml` to a more recent date while you're at it.
106+
* if it fails while compiling rust extractor code, you will need to adapt it to the new library version.
107+
108+
If you had to do any changes, commit them. If you updated the rust toolchain, running `rust/lint.py` might reformat or apply new
109+
lints to the code.
110+
7. If in step 5 the schema was updated, add upgrade/downgrade scripts and a change note
111+
8. Check with CI if everything is in order.
112+
9. Run DCA. Iterate on the code if needed.

0 commit comments

Comments
 (0)