Skip to content

Commit

Permalink
Replace Targets and lists of files in rust_toolchain with depsets (b…
Browse files Browse the repository at this point in the history
…azelbuild#1109)

* Replace lists of files and Targets in `rust_toolchain` with depsets

* Use `find_sysroot` helper.

* Simply use `rust_std` files directly

* Revert "Use `find_sysroot` helper."

This reverts commit 914d159.

* files
  • Loading branch information
UebelAndre committed Jan 31, 2022
1 parent 0946fe9 commit d5ab414
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 17 deletions.
4 changes: 2 additions & 2 deletions cargo/cargo_build_script.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ def _build_script_impl(ctx):

toolchain_tools = [
# Needed for rustc to function.
toolchain.rustc_lib.files,
toolchain.rust_std.files,
toolchain.rustc_lib,
toolchain.rust_std,
]

cc_toolchain = find_cpp_toolchain(ctx)
Expand Down
8 changes: 4 additions & 4 deletions rust/private/rustc.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -413,8 +413,8 @@ def collect_inputs(
([toolchain.target_json] if toolchain.target_json else []) +
([] if linker_script == None else [linker_script]),
transitive = [
toolchain.rustc_lib.files,
toolchain.rust_std.files,
toolchain.rustc_lib,
toolchain.rust_std,
linker_depset,
crate_info.srcs,
dep_info.transitive_crate_outputs,
Expand Down Expand Up @@ -622,7 +622,7 @@ def construct_arguments(
rustc_flags.add(linker_script.path, format = "--codegen=link-arg=-T%s")

# Gets the paths to the folders containing the standard library (or libcore)
rust_std_paths = depset([file.dirname for file in toolchain.rust_std.files.to_list()]).to_list()
rust_std_paths = depset([file.dirname for file in toolchain.rust_std.to_list()]).to_list()

# Tell Rustc where to find the standard library
rustc_flags.add_all(rust_std_paths, before_each = "-L", format_each = "%s")
Expand Down Expand Up @@ -680,7 +680,7 @@ def construct_arguments(
))

# Set the SYSROOT to the directory of the rust_std files passed to the toolchain
env["SYSROOT"] = paths.dirname(toolchain.rust_std.files.to_list()[0].short_path)
env["SYSROOT"] = paths.dirname(toolchain.rust_std.to_list()[0].short_path)

# extra_rustc_flags apply to the target configuration, not the exec configuration.
if hasattr(ctx.attr, "_extra_rustc_flags") and not is_exec_configuration(ctx):
Expand Down
16 changes: 8 additions & 8 deletions rust/private/toolchain_utils.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ def find_sysroot(rust_toolchain):
Returns:
str: A path assignable as `SYSROOT` for an action.
"""
sysroot_anchor = rust_toolchain.rust_std.files.to_list()[0]
sysroot_anchor = rust_toolchain.rust_std.to_list()[0]
directory = sysroot_anchor.path.split(sysroot_anchor.short_path, 1)[0]
return directory.rstrip("/")

Expand All @@ -24,7 +24,7 @@ def _toolchain_files_impl(ctx):
toolchain.cargo,
toolchain.rustc,
],
transitive_files = toolchain.rustc_lib.files,
transitive_files = toolchain.rustc_lib,
)
elif ctx.attr.tool == "clippy":
files = depset([toolchain.clippy_driver])
Expand All @@ -33,32 +33,32 @@ def _toolchain_files_impl(ctx):
toolchain.clippy_driver,
toolchain.rustc,
],
transitive_files = toolchain.rustc_lib.files,
transitive_files = toolchain.rustc_lib,
)
elif ctx.attr.tool == "rustc":
files = depset([toolchain.rustc])
runfiles = ctx.runfiles(
files = [toolchain.rustc],
transitive_files = toolchain.rustc_lib.files,
transitive_files = toolchain.rustc_lib,
)
elif ctx.attr.tool == "rustdoc":
files = depset([toolchain.rust_doc])
runfiles = ctx.runfiles(
files = [toolchain.rust_doc],
transitive_files = toolchain.rustc_lib.files,
transitive_files = toolchain.rustc_lib,
)
elif ctx.attr.tool == "rustfmt":
files = depset([toolchain.rustfmt])
runfiles = ctx.runfiles(
files = [toolchain.rustfmt],
transitive_files = toolchain.rustc_lib.files,
transitive_files = toolchain.rustc_lib,
)
elif ctx.attr.tool == "rustc_lib":
files = toolchain.rustc_lib.files
files = toolchain.rustc_lib
elif ctx.attr.tool == "rustc_srcs":
files = toolchain.rustc_srcs.files
elif ctx.attr.tool == "rust_std" or ctx.attr.tool == "rust_stdlib" or ctx.attr.tool == "rust_lib":
files = toolchain.rust_std.files
files = toolchain.rust_std
else:
fail("Unsupported tool: ", ctx.attr.tool)

Expand Down
6 changes: 3 additions & 3 deletions rust/toolchain.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -276,10 +276,10 @@ def _rust_toolchain_impl(ctx):
clippy_driver = ctx.file.clippy_driver,
target_json = ctx.file.target_json,
target_flag_value = ctx.file.target_json.path if ctx.file.target_json else ctx.attr.target_triple,
rustc_lib = ctx.attr.rustc_lib,
rustc_lib = depset(ctx.files.rustc_lib),
rustc_srcs = ctx.attr.rustc_srcs,
rust_std = rust_std,
rust_lib = rust_std, # `rust_lib` is deprecated and only exists for legacy support.
rust_std = rust_std.files,
rust_lib = rust_std.files, # `rust_lib` is deprecated and only exists for legacy support.
binary_ext = ctx.attr.binary_ext,
staticlib_ext = ctx.attr.staticlib_ext,
dylib_ext = ctx.attr.dylib_ext,
Expand Down

0 comments on commit d5ab414

Please sign in to comment.