Skip to content

Commit c6eb598

Browse files
committed
test
1 parent f9a8278 commit c6eb598

File tree

3 files changed

+37
-1
lines changed

3 files changed

+37
-1
lines changed

rust/private/rustdoc_test.bzl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
# buildifier: disable=module-docstring
1616
load("//rust/private:common.bzl", "rust_common")
17+
load("//rust/private:toolchain_utils.bzl", "find_sysroot")
1718
load("//rust/private:utils.bzl", "find_toolchain", "get_lib_name", "get_preferred_artifact")
1819
load("//util/launcher:launcher.bzl", "create_launcher")
1920

@@ -114,6 +115,10 @@ def _build_rustdoc_flags(dep_info, crate_info, toolchain):
114115
link_flags += ["--extern=" + c.name + "=" + c.dep.output.short_path for c in d.direct_crates.to_list()]
115116
link_search_flags += ["-Ldependency={}".format(_dirname(c.output.short_path)) for c in d.transitive_crates.to_list()]
116117

118+
sysroot = find_sysroot(toolchain, short_path = True)
119+
if sysroot:
120+
link_search_flags.extend(["--sysroot", "${{pwd}}/{}".format(sysroot)])
121+
117122
# TODO(hlopko): use the more robust logic from rustc.bzl also here, through a reasonable API.
118123
for lib_to_link in dep_info.transitive_noncrates.to_list():
119124
is_static = bool(lib_to_link.static_library or lib_to_link.pic_static_library)

rust/private/toolchain_utils.bzl

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,31 @@
11
"""A module defining toolchain utilities"""
22

3+
def find_sysroot(rust_toolchain, short_path = False):
4+
"""Locate the sysroot for a given toolchain
5+
6+
Args:
7+
rust_toolchain (rust_toolchain): A rust toolchain
8+
short_path (bool): Whether or not to use a short path to the sysroot
9+
10+
Returns:
11+
str, optional: The path of the toolchain's sysroot
12+
"""
13+
14+
# Sysroot is determined by using a rust stdlib file, expected to be at
15+
# `${SYSROOT}/lib/rustlib/${target_triple}/lib`, and strip the known
16+
# directories from the sysroot path.
17+
rust_stdlib_files = rust_toolchain.rust_lib.files.to_list()
18+
if rust_stdlib_files:
19+
# Determine the sysroot by taking a rust stdlib file, expected to be `${sysroot}/lib`
20+
if short_path:
21+
split = rust_stdlib_files[0].short_path.rsplit("/", 5)
22+
else:
23+
split = rust_stdlib_files[0].path.rsplit("/", 5)
24+
sysroot = split[0]
25+
return sysroot
26+
27+
return None
28+
329
def _toolchain_files_impl(ctx):
430
toolchain = ctx.toolchains[str(Label("//rust:toolchain"))]
531

util/launcher/launcher_main.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,10 +75,15 @@ fn args() -> Vec<String> {
7575
let args_path = std::env::args().next().expect("arg 0 was not set") + LAUNCHFILES_ARGS_PATH;
7676
let file = File::open(args_path).expect("Failed to load the environment file");
7777

78+
// Variables will have the `${pwd}` variable replaced which is rendered by
79+
// `@rules_rust//rust/private:util.bzl::expand_dict_value_locations`
80+
let pwd = std::env::current_dir().expect("Failed to get current working directory");
81+
let pwd_str = pwd.to_string_lossy();
82+
7883
// Note that arguments from the args file always go first
7984
BufReader::new(file)
8085
.lines()
81-
.map(|line| line.expect("Failed to read file"))
86+
.map(|line| line.expect("Failed to read file").replace("${pwd}", &pwd_str))
8287
.chain(std::env::args().skip(1))
8388
.collect()
8489
}

0 commit comments

Comments
 (0)