@@ -36,7 +36,7 @@ def _rust_doc_test_impl(ctx):
36
36
37
37
# Construct rustdoc test command, which will be written to a shell script
38
38
# to be executed to run the test.
39
- flags = _build_rustdoc_flags (dep_info , crate )
39
+ flags = _build_rustdoc_flags (dep_info , crate , toolchain )
40
40
if toolchain .os != "windows" :
41
41
rust_doc_test = _build_rustdoc_test_bash_script (ctx , toolchain , flags , crate )
42
42
else :
@@ -77,12 +77,13 @@ def _dirname(path_str):
77
77
"""
78
78
return "/" .join (path_str .split ("/" )[:- 1 ])
79
79
80
- def _build_rustdoc_flags (dep_info , crate ):
80
+ def _build_rustdoc_flags (dep_info , crate , toolchain ):
81
81
"""Constructs the rustdoc script used to test `crate`.
82
82
83
83
Args:
84
84
dep_info (DepInfo): The DepInfo provider
85
85
crate (CrateInfo): The CrateInfo provider
86
+ toolchain (rust_toolchain): The rust toolchain
86
87
87
88
Returns:
88
89
list: A list of rustdoc flags (str)
@@ -98,6 +99,13 @@ def _build_rustdoc_flags(dep_info, crate):
98
99
link_flags += ["--extern=" + c .name + "=" + c .dep .output .short_path for c in d .direct_crates .to_list ()]
99
100
link_search_flags += ["-Ldependency={}" .format (_dirname (c .output .short_path )) for c in d .transitive_crates .to_list ()]
100
101
102
+ # Gets the paths to the folders containing the standard library (or libcore)
103
+ rust_lib_files = depset (transitive = [toolchain .rust_lib .files , toolchain .rustc_lib .files ])
104
+ rust_lib_paths = depset ([file .dirname for file in rust_lib_files .to_list ()]).to_list ()
105
+
106
+ # Tell Rustc where to find the standard library
107
+ link_search_flags .extend (["-L {}" .format (lib ) for lib in rust_lib_paths ])
108
+
101
109
# TODO(hlopko): use the more robust logic from rustc.bzl also here, through a reasonable API.
102
110
for lib_to_link in dep_info .transitive_noncrates .to_list ():
103
111
is_static = bool (lib_to_link .static_library or lib_to_link .pic_static_library )
0 commit comments