rust: Support latest version of `rust-analyzer`
Subsystems (2)
PATCH v3 1/1 rust: Support latest version of `rust-analyzer`
Sets the sysroot field in rust-project.json which is now needed in newer versions of rust-analyzer instead of the sysroot_src field.
Till [1] rust-analyzer used to guess the sysroot based on the sysroot_src at [2]. Now sysroot is a required parameter for a rust-project.json file. It is required because rust-analyzer need it to find the proc-macro server [3].
In the current version of rust-analyzer the sysroot_src is only used to include the inbuilt library crates (std, core, alloc, etc) [4]. Since we already specify the core library to be included in the rust-project.json we don't need to define the sysroot_src.
Code editors like VS Code try to use the latest version of rust-analyzer (which is updated every week) instead of the version of rust-analyzer that comes with the rustup toolchain (which is updated every six weeks along with the rust version).
Without this change rust-analyzer is breaking for anyone using VS Code. As they are getting the latest version of rust-analyzer with the changes made in [1].
rust-analyzer will also start breaking for other developers as they update thier rust version (assuming that also updates the rust-analyzer version on their system).
This patch should work with every setup as there is no more guess work being done by rust-analyzer.
---
Hello,
This version contains more a more detailed justification for this patch. Also fixes some issues with using the wrong email amoung others.
Previous Version:
v2: Fixed typos
v1: Initial patch
rust/Makefile | 2 +- scripts/generate_rust_analyzer.py | 6 +++++- 2 files changed, 6 insertions(+), 2 deletions(-)
rust/Makefile +1 -1
@@ -350,7 +350,7 @@ rust-analyzer: $(Q)$(srctree)/scripts/generate_rust_analyzer.py \ --cfgs='core=$(core-cfgs)' --cfgs='alloc=$(alloc-cfgs)' \ $(realpath $(srctree)) $(realpath $(objtree)) \ - $(RUST_LIB_SRC) $(KBUILD_EXTMOD) > \ + $(rustc_sysroot) $(RUST_LIB_SRC) $(KBUILD_EXTMOD) > \ $(if $(KBUILD_EXTMOD),$(extmod_prefix),$(objtree))/rust-project.json redirect-intrinsics = \
scripts/generate_rust_analyzer.py +5 -1
@@ -145,6 +145,7 @@ def main(): parser.add_argument('--cfgs', action='append', default=[]) parser.add_argument("srctree", type=pathlib.Path) parser.add_argument("objtree", type=pathlib.Path) + parser.add_argument("sysroot", type=pathlib.Path) parser.add_argument("sysroot_src", type=pathlib.Path) parser.add_argument("exttree", type=pathlib.Path, nargs="?") args = parser.parse_args()
@@ -154,9 +155,12 @@ def main(): level=logging.INFO if args.verbose else logging.WARNING ) + # Making sure that the sysroot and sysroot_src belong to the same toolchain + assert args.sysroot in args.sysroot_src.parents + rust_project = { "crates": generate_crates(args.srctree, args.objtree, args.sysroot_src, args.exttree, args.cfgs), - "sysroot_src": str(args.sysroot_src), + "sysroot": str(args.sysroot), } json.dump(rust_project, sys.stdout, sort_keys=True, indent=4)
Signature · 1 line
2.45.2
A polite reminder to please take a look at this patch.
Quoted 1 line · Sarthak Singh
A polite reminder to please take a look at this patch.
Would it make sense to apply this to rust-fixes and/or send it to Linus as fix for inclusion into 6.11-rcX?
Best regards
Dirk
Quoted 3 lines · Dirk Behme
Would it make sense to apply this to rust-fixes and/or send it to Linus as fix for inclusion into 6.11-rcX?
Yes, that is the plan -- it would be nice if someone else confirms it fixes it for them, though (especially if they use another setup than yours, e.g. no VS Code) and gives a Tested-by tag for that.
Thanks!
Cheers,
Miguel
A message that is not in the archive (sent off-list or not yet received): CAH_eo809VXLGVf2vs9gVGr9r_9y0pP+4ku=zoZv05U_ZWbnaHA@mail.gmail.com
Quoted 2 lines · Sarthak Singh
A polite reminder to please take a look at this patch.
It is not forgotten :)
I think you didn't reply to my v2 message? The changelog does not really explain what changed, so to understand what is going on one needs to recall all the details, diff your patch messages and try to understand if there is still something missing from the v2 discussion, e.g.
So I assume things could break (or be confusing) if someone provides (intentionally) a RUST_LIB_SRC that is different than the one in the actual sysroot, no?
Please do not get me wrong, the patch contents are probably good, I am just saying this because it helps others keep up so that you get feedback sooner.
In this commit message, you say:
Now sysroot is a required parameter for a rust-project.json file.
But that does not seem to be true given their docs. I guess you mean for combination in particular, so I guess it it is fine.
(Cc'd Lukas)
Cheers,
Miguel
Quoted 3 lines · Miguel Ojeda
But that does not seem to be true given their docs. I guess you mean for combination in particular, so I guess it it is fine.
It seems I had a brain shortcircuit here given the several typos.
In particular, I meant: "for this/our combination in particular" (rather than in general).
Cheers,
Miguel
A message that is not in the archive (sent off-list or not yet received): CAJDY-vRjxd1yM4nL_Z3_S_CojqUNVb3V0VBjceV0V5NiB_A45A@mail.gmail.com
Quoted 2 lines · Lukas Wirth
sysroot_srcis required now if you want to have the sysroot source libraries be loaded. I think we used to infer it as{sysroot}/lib/rustlib/src/rust/librarybefore when only thesysrootfield was given but that was since changed to make it possible in having a sysroot without the standard library sources (that is only have the binaries available). So if you want the library sources to be loaded by rust-analyzer you will have to set that field as well now.
Thanks a lot Lukas for confirming that.
Cheers,
Miguel
Quoted 3 lines · Sarthak Singh
Sets the
sysrootfield in rust-project.json which is now needed in newer versions of rust-analyzer instead of thesysroot_srcfield.
Applied to rust-fixes -- thanks everyone! I tested it in a vim + coc.nvim setup and that error goes away for me too.
[ Lukas, who leads the rust-analyzer team, says:
sysroot_src is required now if you want to have the sysroot source libraries be loaded. I think we used to infer it as {sysroot}/lib/rustlib/src/rust/library before when only the sysroot field was given but that was since changed to make it possible in having a sysroot without the standard library sources (that is only have the binaries available). So if you want the library sources to be loaded by rust-analyzer you will have to set that field as well now.
- Miguel ]
[ Formatted comment, fixed typo and removed spurious empty line. - Miguel ]
Cheers,
Miguel
Quoted 19 lines · Miguel Ojeda
Quoted 3 lines · Sarthak Singh
Sets the
sysrootfield in rust-project.json which is now needed in newer versions of rust-analyzer instead of thesysroot_srcfield.Applied to
rust-fixes-- thanks everyone! I tested it in a vim + coc.nvim setup and that error goes away for me too.[ Lukas, who leads the rust-analyzer team, says:
sysroot_srcis required now if you want to have the sysroot source libraries be loaded. I think we used to infer it as{sysroot}/lib/rustlib/src/rust/librarybefore when only thesysrootfield was given but that was since changed to make it possible in having a sysroot without the standard library sources (that is only have the binaries available). So if you want the library sources to be loaded by rust-analyzer you will have to set that field as well now.
Quoted 3 lines
- Miguel ]
[ Formatted comment, fixed typo and removed spurious empty line. - Miguel ]
Why is it not possible to fall back to the inferred path when the argument is not provided? It's rather annoying to require different incantations for the script while hoping around between different kernels.
Cheers,
Conor.
Quoted 5 lines · Conor Dooley
Why is it not possible to fall back to the inferred path when the argument is not provided? It's rather annoying to require different incantations for the script while hoping around between different kernels.
Why do you need to call the script directly?
Cheers,
Miguel