Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace Targets and lists of files in rust_toolchain with depsets #1109

Merged
merged 7 commits into from
Jan 31, 2022
Merged
Show file tree
Hide file tree
Changes from 4 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
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
10 changes: 5 additions & 5 deletions rust/private/rustc.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@
# limitations under the License.

# buildifier: disable=module-docstring
load("@bazel_skylib//lib:paths.bzl", "paths")
load(
"@bazel_tools//tools/build_defs/cc:action_names.bzl",
"CPP_LINK_EXECUTABLE_ACTION_NAME",
)
load("//rust/private:common.bzl", "rust_common")
load("//rust/private:providers.bzl", _BuildInfo = "BuildInfo")
load("//rust/private:stamp.bzl", "is_stamping_enabled")
load("//rust/private:toolchain_utils.bzl", "find_sysroot")
load(
"//rust/private:utils.bzl",
"expand_dict_value_locations",
Expand Down Expand Up @@ -408,8 +408,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 @@ -617,7 +617,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()
UebelAndre marked this conversation as resolved.
Show resolved Hide resolved

# 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 @@ -675,7 +675,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"] = find_sysroot(toolchain)
UebelAndre marked this conversation as resolved.
Show resolved Hide resolved

# 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[DefaultInfo].files,
UebelAndre marked this conversation as resolved.
Show resolved Hide resolved
rust_lib = rust_std[DefaultInfo].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