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 installing
cargo-edit with cargo install cargo-edit. On Ubuntu that also requires sudo apt install libssl-dev pkg-config.
Tip
All steps up to and including running bazel run //rust:install are (barring
any errors) carried out by the script rust/scripts/update_rust_analyzer.py.
Prefer using the script.
-
Update dependencies.
- From the root of the
codeqlrepo checkout, run a Cargo upgrade:cargo upgrade --incompatible --pinned - Look at a diff of the
Cargo.tomlfiles: if allra_ap_prefixed dependencies have been updated to the same number, go on to the next step. Otherwise, it means the latestrust-analyzerupdate has not been fully rolled out to all its crates incrates.io. Allra_ap_versions must agree! Downgrade by hand to the minimum one you see, and run acargo updateafter that to fix theCargo.lockfile. - Commit the changes, skipping
pre-commithooks if you have them enabled:git commit -am 'Cargo: upgrade dependencies' --no-verify
- From the root of the
-
Update the rust-analyzer sources used by the AST generator.
In
MODULE.bazel, updateRUST_ANALYZER_SRC_TAGto the release date of the newra_ap_crates and updateRUST_ANALYZER_SRC_INTEGRITYwith the integrity of the corresponding source archive.Commit the changes:
git commit -am 'Rust: Update rust-analyzer sources' -
Update the fixed Rust toolchain used by the extractor.
The version should be updated to the latest release that precedes the new rust-analyzer version.
Grepping for
FIXED_RUST_TOOLCHAINshows the places where this version is written down.Commit the changes:
git commit -am 'Rust: Update fixed toolchain' -
Regenerate vendored bazel files (these allow faster builds, particularly on CI where it has to start from scratch each time), commit the changes:
misc/bazel/3rdparty/update_tree_sitter_extractors_deps.sh git add . git commit -am 'Bazel: regenerate vendored cargo dependencies' --no-verify[!NOTE] If in step 6 you also bump
rules_rustor the Rust toolchain used for building the extractor, those changes invalidate all vendored files (including the Python ones undermisc/bazel/3rdparty/py_deps), not just the tree-sitter ones. In that case run the umbrella scriptmisc/bazel/3rdparty/update_cargo_deps.shinstead (it regenerates bothpy_depsandtree_sitter_extractors_deps, and runsbazel mod tidy), then commit all the regenerated files. -
Run codegen
bazel run //rust/codegenIf codegen fails, other changes might be necessary. For instance, adaptations to
annotations.py. Make these changes in separate commits.Once codegen succeeds commit only the changes made by codegen with
git commit -am 'Rust: Run codegen'Take note whether
rust/schema/ast.pywas changed. That might need tweaks, new tests and/or downgrade/upgrade scripts down the line. -
Try compiling
bazel run //rust:install- if it succeeds: good! You can move on to the next step.
- if it fails while compiling rust-analyzer dependencies, you need to update
the Rust toolchain. Sometimes the error will tell you so explicitly, but
it may happen that the error is more obscure. To update the rust
toolchain:
- you will need to open a PR on the internal repo updating
RUST_VERSIONinMODULE.bazel. In general you can have this merged independently of the changes incodeql. - in
codeql, update bothRUST_VERSIONinMODULE.bazelandrust-toolchain.tomlfiles. You may want to also update the nightly toolchain inrust/extractor/src/nightly-toolchain/rust-toolchain.tomlto a more recent date while you're at it. - a toolchain and/or
rules_rustbump invalidates the vendored files, so re-runmisc/bazel/3rdparty/update_cargo_deps.sh(see the note in step
- and commit the regenerated files.
- you will need to open a PR on the internal repo updating
- if it fails while compiling rust extractor code, you will need to adapt it
to the new library version.
- for example updating annotations in
annotations.py, adding / removing generated tests.
- for example updating annotations in
If you had to do any changes, commit them. If you updated the rust toolchain, running
rust/lint.pymight reformat or apply new lints to the code. -
Update
.expectedfiles by running:codeql test run --learn --search-path=rust/extractor-pack:. \ --consistency-queries=rust/ql/consistency-queries rust/ql/testThe search path selects the newly built extractor from step 6.
If there are changes, commit the updated expectations:
git add 'rust/ql/test/**/*.expected' git commit -m 'Rust: Update test expectations' -
Check the
.expectedfiles fortestFailuresand fix the underlying problems.For each separate problem address the issue, regenerate the
.expectedfiles with the command from step 7, and create a commit.Repeat until no rows under
testFailuresremain and the tests pass. -
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 merge conflicts (none of the other testing depends on having upgrade and downgrade scripts in place). See Upgrading a language database schema.
-
Create a PR with the changes thus far.
-
Check with CI if everything is in order.
-
Run DCA with database caching disabled. Iterate on the code if needed.
