From 4385abeab3ae54df2c154a8292b2ca4527d82e1a Mon Sep 17 00:00:00 2001 From: Chip Collier Date: Fri, 28 Feb 2025 09:48:03 +0100 Subject: [PATCH 1/3] Allow the customization of sysroot_src in the generated rust-project.json When specifying a local rust toolchain with an unconventional rust-src location; this attribute will allow you to influence what the sysroot_src path in the resulting rust-project.json. --- rust/private/rust_analyzer.bzl | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/rust/private/rust_analyzer.bzl b/rust/private/rust_analyzer.bzl index bc12306a82..86e6c23231 100644 --- a/rust/private/rust_analyzer.bzl +++ b/rust/private/rust_analyzer.bzl @@ -277,6 +277,7 @@ def _rust_analyzer_toolchain_impl(ctx): proc_macro_srv = ctx.executable.proc_macro_srv, rustc = ctx.executable.rustc, rustc_srcs = ctx.attr.rustc_srcs, + rustc_srcs_path = ctx.attr.rustc_srcs_path, ) return [toolchain] @@ -302,6 +303,10 @@ rust_analyzer_toolchain = rule( doc = "The source code of rustc.", mandatory = True, ), + "rustc_srcs_path": attr.string( + doc = "The direct path to rustc srcs relative to rustc_srcs package root.", + mandatory = False + ) }, ) @@ -315,8 +320,15 @@ def _rust_analyzer_detect_sysroot_impl(ctx): ) rustc_srcs = rust_analyzer_toolchain.rustc_srcs + rustc_srcs_path = rust_analyzer_toolchain.rustc_srcs_path + + sysroot_src = rustc_srcs.label.package + + if not rust_analyzer_toolchain.rustc_srcs_path: + sysroot_src = sysroot_src + "/library" + else: + sysroot_src = sysroot_src + "/" + rust_analyzer_toolchain.rustc_srcs_path - sysroot_src = rustc_srcs.label.package + "/library" if rustc_srcs.label.workspace_root: sysroot_src = _OUTPUT_BASE_TEMPLATE + rustc_srcs.label.workspace_root + "/" + sysroot_src else: From 28dbf4f354aee0ab992b4a1fd8842ae107a565a4 Mon Sep 17 00:00:00 2001 From: Chip Collier Date: Fri, 2 May 2025 09:46:07 +0200 Subject: [PATCH 2/3] Update rust/private/rust_analyzer.bzl Co-authored-by: Daniel Wagner-Hall --- rust/private/rust_analyzer.bzl | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/rust/private/rust_analyzer.bzl b/rust/private/rust_analyzer.bzl index 86e6c23231..0ca3daf9f3 100644 --- a/rust/private/rust_analyzer.bzl +++ b/rust/private/rust_analyzer.bzl @@ -320,14 +320,7 @@ def _rust_analyzer_detect_sysroot_impl(ctx): ) rustc_srcs = rust_analyzer_toolchain.rustc_srcs - rustc_srcs_path = rust_analyzer_toolchain.rustc_srcs_path - - sysroot_src = rustc_srcs.label.package - - if not rust_analyzer_toolchain.rustc_srcs_path: - sysroot_src = sysroot_src + "/library" - else: - sysroot_src = sysroot_src + "/" + rust_analyzer_toolchain.rustc_srcs_path + sysroot_src = rustc_srcs.label.package + "/" + rust_analyzer_toolchain.rustc_srcs_path if rustc_srcs.label.workspace_root: sysroot_src = _OUTPUT_BASE_TEMPLATE + rustc_srcs.label.workspace_root + "/" + sysroot_src From c6752169b02a8828f3a7f31ea3504eec66137c57 Mon Sep 17 00:00:00 2001 From: Chip Collier Date: Fri, 2 May 2025 09:46:13 +0200 Subject: [PATCH 3/3] Update rust/private/rust_analyzer.bzl Co-authored-by: Daniel Wagner-Hall --- rust/private/rust_analyzer.bzl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rust/private/rust_analyzer.bzl b/rust/private/rust_analyzer.bzl index 0ca3daf9f3..51aa266148 100644 --- a/rust/private/rust_analyzer.bzl +++ b/rust/private/rust_analyzer.bzl @@ -305,7 +305,7 @@ rust_analyzer_toolchain = rule( ), "rustc_srcs_path": attr.string( doc = "The direct path to rustc srcs relative to rustc_srcs package root.", - mandatory = False + default = "library" ) }, )