Skip to content

Commit 6ad07f8

Browse files
committed
Fix rust-analyzer for core libraries
1 parent 6d85959 commit 6ad07f8

3 files changed

Lines changed: 33 additions & 1 deletion

File tree

rust/private/repository_utils.bzl

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -716,15 +716,18 @@ rust_analyzer_toolchain(
716716
name = "{name}",
717717
proc_macro_srv = {proc_macro_srv},
718718
rust_analyzer = {rust_analyzer},
719+
rust_std = "//:rust_std-{target_triple}",
719720
rustc = "{rustc}",
720721
rustc_srcs = "//lib/rustlib/src:rustc_srcs",
722+
cargo = "//:cargo",
721723
visibility = ["//visibility:public"],
722724
)
723725
"""
724726

725-
def BUILD_for_rust_analyzer_toolchain(name, rustc, proc_macro_srv, rust_analyzer = None):
727+
def BUILD_for_rust_analyzer_toolchain(name, target_triple, rustc, proc_macro_srv, rust_analyzer = None):
726728
return _build_file_for_rust_analyzer_toolchain_template.format(
727729
name = name,
730+
target_triple = target_triple.str,
728731
rustc = rustc,
729732
proc_macro_srv = repr(proc_macro_srv),
730733
rust_analyzer = repr(rust_analyzer) if rust_analyzer else "None",

rust/private/rust_analyzer.bzl

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -335,6 +335,12 @@ rust_analyzer_toolchain = rule(
335335
executable = True,
336336
allow_single_file = True,
337337
),
338+
"cargo": attr.label(
339+
doc = "The path to a `cargo` binary.",
340+
cfg = "exec",
341+
executable = True,
342+
allow_single_file = True,
343+
),
338344
"rustc": attr.label(
339345
doc = "The path to a `rustc` binary.",
340346
cfg = "exec",
@@ -350,6 +356,10 @@ rust_analyzer_toolchain = rule(
350356
doc = "The direct path to rustc srcs relative to rustc_srcs package root.",
351357
default = "library",
352358
),
359+
"rust_std": attr.label(
360+
doc = "The core library of rust.",
361+
mandatory = True,
362+
),
353363
},
354364
)
355365

rust/repositories.bzl

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -870,6 +870,24 @@ def _rust_analyzer_toolchain_tools_repository_impl(repository_ctx):
870870
build_contents.append(BUILD_for_rust_analyzer_proc_macro_srv(host_triple))
871871
proc_macro_srv = "//:rust_analyzer_proc_macro_srv"
872872

873+
rust_stdlib_content, rust_stdlib_sha256 = load_rust_stdlib(
874+
ctx = repository_ctx,
875+
target_triple = host_triple,
876+
version = version,
877+
iso_date = iso_date,
878+
)
879+
build_contents.append(rust_stdlib_content)
880+
sha256s.update(rust_stdlib_sha256)
881+
882+
cargo_content, cargo_sha256 = load_cargo(
883+
ctx = repository_ctx,
884+
iso_date = iso_date,
885+
target_triple = host_triple,
886+
version = version,
887+
)
888+
build_contents.append(cargo_content)
889+
sha256s.update(cargo_sha256)
890+
873891
# Load rust-analyzer binary from official Rust distribution
874892
rust_analyzer = None
875893
rust_analyzer_content, rust_analyzer_sha256 = load_rust_analyzer(
@@ -885,6 +903,7 @@ def _rust_analyzer_toolchain_tools_repository_impl(repository_ctx):
885903

886904
build_contents.append(BUILD_for_rust_analyzer_toolchain(
887905
name = "rust_analyzer_toolchain",
906+
target_triple = host_triple,
888907
rustc = rustc,
889908
proc_macro_srv = proc_macro_srv,
890909
rust_analyzer = rust_analyzer,

0 commit comments

Comments
 (0)