Replace Targets and lists of files in `rust_toolchain` with depsets (#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 914d159f077404568270dc57dfb3edabba3eab16.
* files
diff --git a/cargo/cargo_build_script.bzl b/cargo/cargo_build_script.bzl
index 8949173..688fe31 100644
--- a/cargo/cargo_build_script.bzl
+++ b/cargo/cargo_build_script.bzl
@@ -57,8 +57,8 @@
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)
diff --git a/rust/private/rustc.bzl b/rust/private/rustc.bzl
index 260bb7b..3e2f38e 100644
--- a/rust/private/rustc.bzl
+++ b/rust/private/rustc.bzl
@@ -413,8 +413,8 @@
([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,
@@ -622,7 +622,7 @@
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")
@@ -680,7 +680,7 @@
))
# 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):
diff --git a/rust/private/toolchain_utils.bzl b/rust/private/toolchain_utils.bzl
index 9e011be..6b8b315 100644
--- a/rust/private/toolchain_utils.bzl
+++ b/rust/private/toolchain_utils.bzl
@@ -9,7 +9,7 @@
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("/")
@@ -24,7 +24,7 @@
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])
@@ -33,32 +33,32 @@
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)
diff --git a/rust/toolchain.bzl b/rust/toolchain.bzl
index d9eea01..58f58b3 100644
--- a/rust/toolchain.bzl
+++ b/rust/toolchain.bzl
@@ -276,10 +276,10 @@
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,