• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1From 76378fa41d8ff92b7a9ac2b78497524d06cc6845 Mon Sep 17 00:00:00 2001
2From: Erik Gilling <konkers@google.com>
3Date: Thu, 9 Jan 2025 12:44:29 -0800
4Subject: [PATCH 2/2] Add rust_srcs_subdir to rust_analyzer_toolchain
5
6This allows rust toolchains to be declared from repositories with only
7a single BUILD file.  An example would be an `http_archive` repository
8using the `build_file` argument.
9---
10 rust/private/rust_analyzer.bzl | 7 ++++++-
11 1 file changed, 6 insertions(+), 1 deletion(-)
12
13diff --git a/rust/private/rust_analyzer.bzl b/rust/private/rust_analyzer.bzl
14index bc12306a..5f40ed00 100644
15--- a/rust/private/rust_analyzer.bzl
16+++ b/rust/private/rust_analyzer.bzl
17@@ -277,6 +277,7 @@ def _rust_analyzer_toolchain_impl(ctx):
18         proc_macro_srv = ctx.executable.proc_macro_srv,
19         rustc = ctx.executable.rustc,
20         rustc_srcs = ctx.attr.rustc_srcs,
21+        rustc_srcs_subdir = ctx.attr.rustc_srcs_subdir,
22     )
23
24     return [toolchain]
25@@ -302,6 +303,10 @@ rust_analyzer_toolchain = rule(
26             doc = "The source code of rustc.",
27             mandatory = True,
28         ),
29+        "rustc_srcs_subdir": attr.string(
30+            doc = "Subdirectory relative to the location of `rust_srcs` in which the sources reside.",
31+            default = "",
32+        ),
33     },
34 )
35
36@@ -316,7 +321,7 @@ def _rust_analyzer_detect_sysroot_impl(ctx):
37
38     rustc_srcs = rust_analyzer_toolchain.rustc_srcs
39
40-    sysroot_src = rustc_srcs.label.package + "/library"
41+    sysroot_src = rustc_srcs.label.package + rust_analyzer_toolchain.rustc_srcs_subdir + "/library"
42     if rustc_srcs.label.workspace_root:
43         sysroot_src = _OUTPUT_BASE_TEMPLATE + rustc_srcs.label.workspace_root + "/" + sysroot_src
44     else:
45--
462.48.0.rc2.279.g1de40edade-goog
47
48