From 6ad07f8b8c652059dee272b4c5c4d40f6ae1c6e8 Mon Sep 17 00:00:00 2001 From: Danielkonge Date: Thu, 23 Apr 2026 01:17:30 +0200 Subject: [PATCH] Fix rust-analyzer for core libraries --- rust/private/repository_utils.bzl | 5 ++++- rust/private/rust_analyzer.bzl | 10 ++++++++++ rust/repositories.bzl | 19 +++++++++++++++++++ 3 files changed, 33 insertions(+), 1 deletion(-) diff --git a/rust/private/repository_utils.bzl b/rust/private/repository_utils.bzl index ad8aea4814..786f4f2ab3 100644 --- a/rust/private/repository_utils.bzl +++ b/rust/private/repository_utils.bzl @@ -716,15 +716,18 @@ rust_analyzer_toolchain( name = "{name}", proc_macro_srv = {proc_macro_srv}, rust_analyzer = {rust_analyzer}, + rust_std = "//:rust_std-{target_triple}", rustc = "{rustc}", rustc_srcs = "//lib/rustlib/src:rustc_srcs", + cargo = "//:cargo", visibility = ["//visibility:public"], ) """ -def BUILD_for_rust_analyzer_toolchain(name, rustc, proc_macro_srv, rust_analyzer = None): +def BUILD_for_rust_analyzer_toolchain(name, target_triple, rustc, proc_macro_srv, rust_analyzer = None): return _build_file_for_rust_analyzer_toolchain_template.format( name = name, + target_triple = target_triple.str, rustc = rustc, proc_macro_srv = repr(proc_macro_srv), rust_analyzer = repr(rust_analyzer) if rust_analyzer else "None", diff --git a/rust/private/rust_analyzer.bzl b/rust/private/rust_analyzer.bzl index da41867985..8f3ad6508c 100644 --- a/rust/private/rust_analyzer.bzl +++ b/rust/private/rust_analyzer.bzl @@ -335,6 +335,12 @@ rust_analyzer_toolchain = rule( executable = True, allow_single_file = True, ), + "cargo": attr.label( + doc = "The path to a `cargo` binary.", + cfg = "exec", + executable = True, + allow_single_file = True, + ), "rustc": attr.label( doc = "The path to a `rustc` binary.", cfg = "exec", @@ -350,6 +356,10 @@ rust_analyzer_toolchain = rule( doc = "The direct path to rustc srcs relative to rustc_srcs package root.", default = "library", ), + "rust_std": attr.label( + doc = "The core library of rust.", + mandatory = True, + ), }, ) diff --git a/rust/repositories.bzl b/rust/repositories.bzl index e4bd37f4c6..9bf89dc617 100644 --- a/rust/repositories.bzl +++ b/rust/repositories.bzl @@ -870,6 +870,24 @@ def _rust_analyzer_toolchain_tools_repository_impl(repository_ctx): build_contents.append(BUILD_for_rust_analyzer_proc_macro_srv(host_triple)) proc_macro_srv = "//:rust_analyzer_proc_macro_srv" + rust_stdlib_content, rust_stdlib_sha256 = load_rust_stdlib( + ctx = repository_ctx, + target_triple = host_triple, + version = version, + iso_date = iso_date, + ) + build_contents.append(rust_stdlib_content) + sha256s.update(rust_stdlib_sha256) + + cargo_content, cargo_sha256 = load_cargo( + ctx = repository_ctx, + iso_date = iso_date, + target_triple = host_triple, + version = version, + ) + build_contents.append(cargo_content) + sha256s.update(cargo_sha256) + # Load rust-analyzer binary from official Rust distribution rust_analyzer = None rust_analyzer_content, rust_analyzer_sha256 = load_rust_analyzer( @@ -885,6 +903,7 @@ def _rust_analyzer_toolchain_tools_repository_impl(repository_ctx): build_contents.append(BUILD_for_rust_analyzer_toolchain( name = "rust_analyzer_toolchain", + target_triple = host_triple, rustc = rustc, proc_macro_srv = proc_macro_srv, rust_analyzer = rust_analyzer,