From 141bf38f23d2737bde70a38a23bbe90fa062c450 Mon Sep 17 00:00:00 2001 From: Noah Lev Date: Mon, 25 Oct 2021 18:55:40 -0700 Subject: [PATCH] Add instructions for using rust-analyzer for Miri development --- CONTRIBUTING.md | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index eea97863d3e..caed6e3226d 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -107,6 +107,41 @@ There's a test for the cargo wrapper in the `test-cargo-miri` directory; run `./run-test.py` in there to execute it. Like `./miri test`, this respects the `MIRI_TEST_TARGET` environment variable to execute the test for another target. +## Configuring `rust-analyzer` + +To configure `rust-analyzer` and VS Code for working on Miri, save the following +to `.vscode/settings.json` in your local Miri clone: + +```json +{ + "rust-analyzer.checkOnSave.overrideCommand": [ + "./miri", + "check", + "--message-format=json" + ], + "rust-analyzer.rustfmt.extraArgs": [ + "+nightly" + ], + "rust-analyzer.rustcSource": "discover", + "rust-analyzer.linkedProjects": [ + "./Cargo.toml", + "./cargo-miri/Cargo.toml" + ] +} +``` + +> #### Note +> +> If you are [building Miri with a locally built rustc][], set +> `rust-analyzer.rustcSource` to the relative path from your Miri clone to the +> root `Cargo.toml` of the locally built rustc. For example, the path might look +> like `../rust/Cargo.toml`. + +See the rustc-dev-guide's docs on ["Configuring `rust-analyzer` for `rustc`"][rdg-r-a] +for more information about configuring VS Code and `rust-analyzer`. + +[rdg-r-a]: https://rustc-dev-guide.rust-lang.org/building/suggested.html#configuring-rust-analyzer-for-rustc + ## Advanced topic: other build environments We described above the simplest way to get a working build environment for Miri, @@ -132,6 +167,8 @@ rustc. This avoids blocking all Miri development on landing a big PR. ### Building Miri with a locally built rustc +[building Miri with a locally built rustc]: #building-miri-with-a-locally-built-rustc + A big part of the Miri driver lives in rustc, so working on Miri will sometimes require using a locally built rustc. The bug you want to fix may actually be on the rustc side, or you just need to get more detailed trace of the execution