Skip to content

Commit e2fa3ef

Browse files
committed
Set --sysroot in for rust_doc_test
1 parent ed63f40 commit e2fa3ef

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

rust/private/rustdoc.bzl

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,19 @@ def rustdoc_compile_action(
120120
force_link = True,
121121
)
122122

123+
# Because rustdoc tests compile tests outside of the sandbox, the sysroot
124+
# must be updated to the `short_path` equivilant as it will now be
125+
# a part of runfiles.
126+
if is_test:
127+
# Determine what the `short_path` would be for the sysroot
128+
sysroot, _, _ = toolchain.sysroot_anchor.short_path.rpartition("/")
129+
130+
env.update({"SYSROOT": "${{pwd}}/{}".format(sysroot)})
131+
132+
# `rustdoc` does not support the SYSROOT environment variable. To account
133+
# for this, the flag must be explicitly passed to the `rustdoc` binary.
134+
args.rustc_flags.add("--sysroot=${{pwd}}/{}".format(sysroot))
135+
123136
return struct(
124137
executable = ctx.executable._process_wrapper,
125138
inputs = depset([crate_info.output], transitive = [compile_inputs]),

rust/toolchain.bzl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -293,6 +293,7 @@ def _rust_toolchain_impl(ctx):
293293
rust_std_paths = depset([file.dirname for file in sysroot.rust_std.to_list()]),
294294
rust_lib = sysroot.rust_std, # `rust_lib` is deprecated and only exists for legacy support.
295295
sysroot = sysroot.sysroot_anchor.dirname,
296+
sysroot_anchor = sysroot.sysroot_anchor,
296297
binary_ext = ctx.attr.binary_ext,
297298
staticlib_ext = ctx.attr.staticlib_ext,
298299
dylib_ext = ctx.attr.dylib_ext,

0 commit comments

Comments
 (0)