Skip to content

Commit

Permalink
Set --sysroot in for rust_doc_test
Browse files Browse the repository at this point in the history
  • Loading branch information
UebelAndre committed Feb 8, 2022
1 parent ed63f40 commit e2fa3ef
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
13 changes: 13 additions & 0 deletions rust/private/rustdoc.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,19 @@ def rustdoc_compile_action(
force_link = True,
)

# Because rustdoc tests compile tests outside of the sandbox, the sysroot
# must be updated to the `short_path` equivilant as it will now be
# a part of runfiles.
if is_test:
# Determine what the `short_path` would be for the sysroot
sysroot, _, _ = toolchain.sysroot_anchor.short_path.rpartition("/")

env.update({"SYSROOT": "${{pwd}}/{}".format(sysroot)})

# `rustdoc` does not support the SYSROOT environment variable. To account
# for this, the flag must be explicitly passed to the `rustdoc` binary.
args.rustc_flags.add("--sysroot=${{pwd}}/{}".format(sysroot))

return struct(
executable = ctx.executable._process_wrapper,
inputs = depset([crate_info.output], transitive = [compile_inputs]),
Expand Down
1 change: 1 addition & 0 deletions rust/toolchain.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,7 @@ def _rust_toolchain_impl(ctx):
rust_std_paths = depset([file.dirname for file in sysroot.rust_std.to_list()]),
rust_lib = sysroot.rust_std, # `rust_lib` is deprecated and only exists for legacy support.
sysroot = sysroot.sysroot_anchor.dirname,
sysroot_anchor = sysroot.sysroot_anchor,
binary_ext = ctx.attr.binary_ext,
staticlib_ext = ctx.attr.staticlib_ext,
dylib_ext = ctx.attr.dylib_ext,
Expand Down

0 comments on commit e2fa3ef

Please sign in to comment.