Skip to content

Commit 7020ecc

Browse files
photexillicitonion
andauthored
Allow the customization of sysroot_src in the generated rust-project.… (#3306)
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. In my particular case I'm working in a conda environment which I configure as a new_local_repo in my project. There I define a rust toolchain and my rustc sources live in `$CONDA_PREFIX/lib/rustlib/src/rust/library`. By default, if I'm unable to provide this path, the resulting sysroot_src in my project ends up resolving to the equivalent of `$CONDA_PREFIX/library`. --------- Co-authored-by: Daniel Wagner-Hall <dawagner@gmail.com>
1 parent 52d3fd8 commit 7020ecc

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

rust/private/rust_analyzer.bzl

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -298,6 +298,7 @@ def _rust_analyzer_toolchain_impl(ctx):
298298
proc_macro_srv = ctx.executable.proc_macro_srv,
299299
rustc = ctx.executable.rustc,
300300
rustc_srcs = ctx.attr.rustc_srcs,
301+
rustc_srcs_path = ctx.attr.rustc_srcs_path,
301302
)
302303

303304
return [toolchain]
@@ -323,6 +324,10 @@ rust_analyzer_toolchain = rule(
323324
doc = "The source code of rustc.",
324325
mandatory = True,
325326
),
327+
"rustc_srcs_path": attr.string(
328+
doc = "The direct path to rustc srcs relative to rustc_srcs package root.",
329+
default = "library",
330+
),
326331
},
327332
)
328333

@@ -336,8 +341,8 @@ def _rust_analyzer_detect_sysroot_impl(ctx):
336341
)
337342

338343
rustc_srcs = rust_analyzer_toolchain.rustc_srcs
344+
sysroot_src = rustc_srcs.label.package + "/" + rust_analyzer_toolchain.rustc_srcs_path
339345

340-
sysroot_src = rustc_srcs.label.package + "/library"
341346
if rustc_srcs.label.workspace_root:
342347
sysroot_src = _OUTPUT_BASE_TEMPLATE + rustc_srcs.label.workspace_root + "/" + sysroot_src
343348
else:

0 commit comments

Comments
 (0)