Skip to content

Commit

Permalink
backend/ninja: Generate sysroot in rust-project.json
Browse files Browse the repository at this point in the history
Rust-analyzer relies on sysroot to discover its proc-macro server [1] which is
typically installed at <sysroot>/libexec/rust-analyzer-proc-macro-srv. When
used with rust-project.json, rust-analyzer expects the json file to specify
sysroot and fails to launch the proc-macro server otherwise.

So add sysroot to the meson-generated rust-project.json and point it to the
sysroot of the detected rustc compiler.

[1] https://github.com/rust-lang/rust-analyzer/blob/2024-09-16/crates/project-model/src/sysroot.rs#L175

Signed-off-by: Junjie Mao <junjie.mao@hotmail.com>
(cherry picked from commit e5d03f5)
  • Loading branch information
eternalNight authored and eli-schwartz committed Sep 20, 2024
1 parent 72af62b commit 908f2d1
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions mesonbuild/backend/ninjabackend.py
Original file line number Diff line number Diff line change
Expand Up @@ -700,10 +700,11 @@ def generate_rust_project_json(self) -> None:
return
with open(os.path.join(self.environment.get_build_dir(), 'rust-project.json'),
'w', encoding='utf-8') as f:
sysroot = self.environment.coredata.compilers.host['rust'].get_sysroot()
json.dump(
{
"sysroot_src": os.path.join(self.environment.coredata.compilers.host['rust'].get_sysroot(),
'lib/rustlib/src/rust/library/'),
"sysroot": sysroot,
"sysroot_src": os.path.join(sysroot, 'lib/rustlib/src/rust/library/'),
"crates": [c.to_json() for c in self.rust_crates.values()],
},
f, indent=4)
Expand Down

0 comments on commit 908f2d1

Please sign in to comment.