Repository navigation
rust-analyzer doesn't work on bootstrap anymore #101070
Description
Activity
- addedT-bootstrapRelevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap)Relevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap)C-bugCategory: This is a bug.Category: This is a bug.
on Aug 27, 2022 - changed the title
[-]rust-analyzer doesn't work on bootstrap[/-][+]rust-analyzer doesn't work on bootstrap anymore[/+]on Aug 27, 2022 Also see rust-lang/rust-analyzer#10793 -- this is somewhat blocked on RA getting better support for projects that use custom build scripts such as
./x.py.yeah, you can set linked-workspaces to have it use both, but then you get a bunch of spurious errors when you open the project
Blocked on rust-lang/rust-analyzer#13128.
Build scripts now work properly when
rust-analyzer.linkedProjectsis set if you follow the updated dev-guide instructions rust-lang/rustc-dev-guide#1487... is what I would like to say but there is one small problem:Looks like I either fixed it, or its a spurious problem
x.py check --json-outputdoes not emit build data for dependencies ofbootstrapfor example, so if you setlinkedProjectsto the bootstrap toml, r-a will currently fail to find the proc-macro dylibs for serde, because bootstrap uses a different serde version than the top level workspace has, and only the top level used one is reported (if I upgrade theserdeversion ofbootstrapto the top-level one r-a finds the proc-macro dylibs forserde).@Veykril I can't get this working. I have in .vscode/settings.json:
"rust-analyzer.checkOnSave.enable": true, "rust-analyzer.checkOnSave.overrideCommand": [ "python3", "x.py", "check", "--json-output" ], "rust-analyzer.rustfmt.overrideCommand": [ "./build/x86_64-unknown-linux-gnu/stage0/bin/rustfmt", "--edition=2021" ], "rust-analyzer.cargo.buildScripts.enable": true, "rust-analyzer.cargo.buildScripts.invocationLocation": "root", "rust-analyzer.cargo.buildScripts.invocationStrategy": "once", "rust-analyzer.cargo.buildScripts.overrideCommand": [ "python3", "x.py", "check", "--json-output" ], "rust-analyzer.rustc.source": "./Cargo.toml", "rust-analyzer.cargo.sysroot": "./build/x86_64-unknown-linux-gnu/stage0-sysroot", "rust-analyzer.procMacro.enable": true, "rust-analyzer.linkedProjects": ["Cargo.toml", "src/bootstrap/Cargo.toml"],
which fails to find x.py:
[ERROR flycheck] Flycheck failed to run the following command: "python3" "x.py" "check" "--json-output" [ERROR rust_analyzer::lsp_utils] cargo check failed Cargo watcher failed, the command produced no valid metadata (exit code: ExitStatus(unix_wait_status(512))): python3: can't open file 'x.py': [Errno 2] No such file or directoryIf I disable
checkOnSaveit does seem to work ok, though. Maybe the options you added need to be global instead of specific to build scripts?You'll need to set
"rust-analyzer.cargo.checkOnSave.invocationLocation": "root", "rust-analyzer.cargo.checkOnSave.invocationStrategy": "once",
The reason I didn't add those to the dev guide is that you won't get diagnostics for linked projects anyways until
x.pychanges the paths in its output to be relative to the project root or rust-lang/cargo#11007 is fixed (assuming x.py is using that flag). Otherwise r-a will not be able to deduce the correct files for the diagnostics as they are relative to the Cargo.toml of the linked projects without knowing which diagnostics come from what linked project.Reacted by jynYou'll need to set
"rust-analyzer.cargo.checkOnSave.invocationLocation": "root", "rust-analyzer.cargo.checkOnSave.invocationStrategy": "once",
The reason I didn't add those to the dev guide is that you won't get diagnostics for linked projects anyways until
x.pychanges the paths in its output to be relative to the project root or rust-lang/cargo#11007 is fixed (assuming x.py is using that flag). Otherwise r-a will not be able to deduce the correct files for the diagnostics as they are relative to the Cargo.toml of the linked projects without knowing which diagnostics come from what linked project.I think we should add them anyway - even if the diagnostics are missing, having go-to-definition available is still extremely useful.
Reacted by Josh StoneMentoring instructions: add
"rust-analyzer.linkedProjects": ["src/bootstrap/Cargo.toml", "Cargo.toml"],to this section of the dev-guide.- addedE-easyCall for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue.Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue.E-mentorCall for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion.Call for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion.A-docsArea: Documentation for any part of the project, including the compiler, standard library, and toolsArea: Documentation for any part of the project, including the compiler, standard library, and tools
on Feb 3, 2023 Happy to help add this to the dev-guide but I noticed that the
settings.jsonportion in the dev guide is no longer there. Is it due to #107547 ?@rustbot claim
Oh, sorry - this was fixed by #107757
Reacted by Zephaniah Ong
#97513 took bootstrap out of the cargo workspace, meaning that rust-analyzer can't see it anymore. I haven't yet found a config that makes rust-analyzer see it, short of opening bootstrap in a separate window.
This is annoying since I rust-analyzer particularly useful when working on bootstrap, but at least opening another window works for now.
cc @jyn514