Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions cargo/private/cargo_build_script.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -416,7 +416,10 @@ def _cargo_build_script_impl(ctx):
env.update(ctx.configuration.default_shell_env)

if toolchain.cargo:
env["CARGO"] = "${pwd}/%s" % toolchain.cargo.path
if toolchain.sysroot_path:
env["CARGO"] = toolchain.sysroot_path + "/bin/cargo"
else:
env["CARGO"] = "${pwd}/%s" % toolchain.cargo.path

env.update({
"CARGO_CRATE_NAME": name_to_crate_name(pkg_name),
Expand All @@ -425,8 +428,8 @@ def _cargo_build_script_impl(ctx):
"HOST": toolchain.exec_triple.str,
"NUM_JOBS": "1",
"OPT_LEVEL": compilation_mode_opt_level,
"RUSTC": toolchain.rustc.path,
"RUSTDOC": toolchain.rust_doc.path,
"RUSTC": (toolchain.sysroot_path + "/bin/rustc") if toolchain.sysroot_path else toolchain.rustc.path,
"RUSTDOC": (toolchain.sysroot_path + "/bin/rustdoc") if toolchain.sysroot_path else toolchain.rust_doc.path,
"TARGET": toolchain.target_flag_value,
# OUT_DIR is set by the runner itself, rather than on the action.
})
Expand Down
4 changes: 3 additions & 1 deletion rust/private/clippy.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -160,12 +160,14 @@ def rust_clippy_action(ctx, clippy_executable, process_wrapper, crate_info, conf
crate_info_dict["rustc_output"] = clippy_diagnostics_file
crate_info = rust_common.create_crate_info(**crate_info_dict)

clippy_tool_path = (toolchain.sysroot_path + "/bin/clippy-driver") if toolchain.sysroot_path else clippy_executable.path

args, env = construct_arguments(
ctx = ctx,
attr = ctx.rule.attr,
file = ctx.file,
toolchain = toolchain,
tool_path = clippy_executable.path,
tool_path = clippy_tool_path,
cc_toolchain = cc_toolchain,
feature_configuration = feature_configuration,
crate_info = crate_info,
Expand Down
14 changes: 10 additions & 4 deletions rust/private/rustc.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -1193,8 +1193,10 @@ def construct_arguments(
{},
))

# Ensure the sysroot is set for the target platform
if toolchain._toolchain_generated_sysroot:
# Ensure the sysroot is set for the target platform.
# When sysroot_path is set (system toolchain), always pass --sysroot so rustc
# finds the standard library at the pre-installed location.
if toolchain.sysroot_path or toolchain._toolchain_generated_sysroot:
rustc_flags.add(toolchain.sysroot, format = "--sysroot=%s")

if toolchain._rename_first_party_crates:
Expand Down Expand Up @@ -1400,12 +1402,16 @@ def rustc_compile_action(
elif ctx.attr.require_explicit_unstable_features == -1:
require_explicit_unstable_features = toolchain.require_explicit_unstable_features

# When using a system sysroot, use the system rustc path instead of the
# sysroot-symlinked binary.
rustc_tool_path = (toolchain.sysroot_path + "/bin/rustc") if toolchain.sysroot_path else toolchain.rustc.path

args, env_from_args = construct_arguments(
ctx = ctx,
attr = attr,
file = ctx.file,
toolchain = toolchain,
tool_path = toolchain.rustc.path,
tool_path = rustc_tool_path,
cc_toolchain = cc_toolchain,
emit = emit,
feature_configuration = feature_configuration,
Expand All @@ -1432,7 +1438,7 @@ def rustc_compile_action(
attr = attr,
file = ctx.file,
toolchain = toolchain,
tool_path = toolchain.rustc.path,
tool_path = rustc_tool_path,
cc_toolchain = cc_toolchain,
emit = emit,
feature_configuration = feature_configuration,
Expand Down
9 changes: 8 additions & 1 deletion rust/private/rustdoc.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -126,12 +126,19 @@ def rustdoc_compile_action(
# arguments expecting to do so.
rustdoc_crate_info = _strip_crate_info_output(crate_info)

if toolchain.sysroot_path:
rustdoc_tool_path = toolchain.sysroot_path + "/bin/rustdoc"
elif is_test:
rustdoc_tool_path = toolchain.rust_doc.short_path
else:
rustdoc_tool_path = toolchain.rust_doc.path

args, env = construct_arguments(
ctx = ctx,
attr = ctx.attr,
file = ctx.file,
toolchain = toolchain,
tool_path = toolchain.rust_doc.short_path if is_test else toolchain.rust_doc.path,
tool_path = rustdoc_tool_path,
cc_toolchain = cc_toolchain,
feature_configuration = feature_configuration,
crate_info = rustdoc_crate_info,
Expand Down
Loading