Skip to content

Commit 4385abe

Browse files
committed
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.
1 parent cc65202 commit 4385abe

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

rust/private/rust_analyzer.bzl

+13-1
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,7 @@ def _rust_analyzer_toolchain_impl(ctx):
277277
proc_macro_srv = ctx.executable.proc_macro_srv,
278278
rustc = ctx.executable.rustc,
279279
rustc_srcs = ctx.attr.rustc_srcs,
280+
rustc_srcs_path = ctx.attr.rustc_srcs_path,
280281
)
281282

282283
return [toolchain]
@@ -302,6 +303,10 @@ rust_analyzer_toolchain = rule(
302303
doc = "The source code of rustc.",
303304
mandatory = True,
304305
),
306+
"rustc_srcs_path": attr.string(
307+
doc = "The direct path to rustc srcs relative to rustc_srcs package root.",
308+
mandatory = False
309+
)
305310
},
306311
)
307312

@@ -315,8 +320,15 @@ def _rust_analyzer_detect_sysroot_impl(ctx):
315320
)
316321

317322
rustc_srcs = rust_analyzer_toolchain.rustc_srcs
323+
rustc_srcs_path = rust_analyzer_toolchain.rustc_srcs_path
324+
325+
sysroot_src = rustc_srcs.label.package
326+
327+
if not rust_analyzer_toolchain.rustc_srcs_path:
328+
sysroot_src = sysroot_src + "/library"
329+
else:
330+
sysroot_src = sysroot_src + "/" + rust_analyzer_toolchain.rustc_srcs_path
318331

319-
sysroot_src = rustc_srcs.label.package + "/library"
320332
if rustc_srcs.label.workspace_root:
321333
sysroot_src = _OUTPUT_BASE_TEMPLATE + rustc_srcs.label.workspace_root + "/" + sysroot_src
322334
else:

0 commit comments

Comments
 (0)