diff --git a/cargo/cargo_build_script.bzl b/cargo/cargo_build_script.bzl index ea2284498a..89491739e5 100644 --- a/cargo/cargo_build_script.bzl +++ b/cargo/cargo_build_script.bzl @@ -58,7 +58,7 @@ def _build_script_impl(ctx): toolchain_tools = [ # Needed for rustc to function. toolchain.rustc_lib.files, - toolchain.rust_lib.files, + toolchain.rust_std.files, ] cc_toolchain = find_cpp_toolchain(ctx) diff --git a/docs/flatten.md b/docs/flatten.md index 557ab5f067..1c05343cf6 100644 --- a/docs/flatten.md +++ b/docs/flatten.md @@ -1103,8 +1103,8 @@ Run the test with `bazel build //hello_lib:hello_lib_test`.
 rust_toolchain(name, allocator_library, binary_ext, cargo, clippy_driver, debug_info,
-               default_edition, dylib_ext, exec_triple, opt_level, os, rust_doc, rust_lib, rustc,
-               rustc_lib, rustc_srcs, rustfmt, staticlib_ext, stdlib_linkflags, target_json,
+               default_edition, dylib_ext, exec_triple, opt_level, os, rust_doc, rust_lib, rust_std,
+               rustc, rustc_lib, rustc_srcs, rustfmt, staticlib_ext, stdlib_linkflags, target_json,
                target_triple)
 
@@ -1123,7 +1123,7 @@ rust_toolchain( name = "rust_cpuX_impl", rustc = "@rust_cpuX//:rustc", rustc_lib = "@rust_cpuX//:rustc_lib", - rust_lib = "@rust_cpuX//:rust_lib", + rust_std = "@rust_cpuX//:rust_std", rust_doc = "@rust_cpuX//:rustdoc", binary_ext = "", staticlib_ext = ".a", @@ -1166,13 +1166,14 @@ See @rules_rust//rust:repositories.bzl for examples of defining the @rust_cpuX r | opt_level | Rustc optimization levels. | Dictionary: String -> String | optional | {"dbg": "0", "fastbuild": "0", "opt": "3"} | | os | The operating system for the current toolchain | String | required | | | rust_doc | The location of the rustdoc binary. Can be a direct source or a filegroup containing one item. | Label | optional | None | -| rust_lib | The rust standard library. | Label | optional | None | +| rust_lib | **Deprecated**: Use rust_std | Label | optional | None | +| rust_std | The Rust standard library. | Label | optional | None | | rustc | The location of the rustc binary. Can be a direct source or a filegroup containing one item. | Label | optional | None | | rustc_lib | The libraries used by rustc during compilation. | Label | optional | None | | rustc_srcs | The source code of rustc. | Label | optional | None | | rustfmt | The location of the rustfmt binary. Can be a direct source or a filegroup containing one item. | Label | optional | None | | staticlib_ext | The extension for static libraries created from rustc. | String | required | | -| stdlib_linkflags | Additional linker flags to use when Rust std lib is linked by a C++ linker (rustc will deal with these automatically). Subject to location expansion with respect to the srcs of the rust_lib attribute. | List of strings | required | | +| stdlib_linkflags | Additional linker flags to use when Rust standard library is linked by a C++ linker (rustc will deal with these automatically). Subject to location expansion with respect to the srcs of the rust_std attribute. | List of strings | required | | | target_json | Override the target_triple with a custom target specification. For more details see: https://doc.rust-lang.org/rustc/targets/custom.html | Label | optional | None | | target_triple | The platform triple for the toolchains target environment. For more details see: https://docs.bazel.build/versions/master/skylark/rules.html#configurations | String | optional | "" | diff --git a/docs/rust_repositories.md b/docs/rust_repositories.md index f404c50822..7d1b1f7189 100644 --- a/docs/rust_repositories.md +++ b/docs/rust_repositories.md @@ -33,8 +33,8 @@ A dedicated filegroup-like rule for Rust stdlib artifacts.
 rust_toolchain(name, allocator_library, binary_ext, cargo, clippy_driver, debug_info,
-               default_edition, dylib_ext, exec_triple, opt_level, os, rust_doc, rust_lib, rustc,
-               rustc_lib, rustc_srcs, rustfmt, staticlib_ext, stdlib_linkflags, target_json,
+               default_edition, dylib_ext, exec_triple, opt_level, os, rust_doc, rust_lib, rust_std,
+               rustc, rustc_lib, rustc_srcs, rustfmt, staticlib_ext, stdlib_linkflags, target_json,
                target_triple)
 
@@ -53,7 +53,7 @@ rust_toolchain( name = "rust_cpuX_impl", rustc = "@rust_cpuX//:rustc", rustc_lib = "@rust_cpuX//:rustc_lib", - rust_lib = "@rust_cpuX//:rust_lib", + rust_std = "@rust_cpuX//:rust_std", rust_doc = "@rust_cpuX//:rustdoc", binary_ext = "", staticlib_ext = ".a", @@ -96,13 +96,14 @@ See @rules_rust//rust:repositories.bzl for examples of defining the @rust_cpuX r | opt_level | Rustc optimization levels. | Dictionary: String -> String | optional | {"dbg": "0", "fastbuild": "0", "opt": "3"} | | os | The operating system for the current toolchain | String | required | | | rust_doc | The location of the rustdoc binary. Can be a direct source or a filegroup containing one item. | Label | optional | None | -| rust_lib | The rust standard library. | Label | optional | None | +| rust_lib | **Deprecated**: Use rust_std | Label | optional | None | +| rust_std | The Rust standard library. | Label | optional | None | | rustc | The location of the rustc binary. Can be a direct source or a filegroup containing one item. | Label | optional | None | | rustc_lib | The libraries used by rustc during compilation. | Label | optional | None | | rustc_srcs | The source code of rustc. | Label | optional | None | | rustfmt | The location of the rustfmt binary. Can be a direct source or a filegroup containing one item. | Label | optional | None | | staticlib_ext | The extension for static libraries created from rustc. | String | required | | -| stdlib_linkflags | Additional linker flags to use when Rust std lib is linked by a C++ linker (rustc will deal with these automatically). Subject to location expansion with respect to the srcs of the rust_lib attribute. | List of strings | required | | +| stdlib_linkflags | Additional linker flags to use when Rust standard library is linked by a C++ linker (rustc will deal with these automatically). Subject to location expansion with respect to the srcs of the rust_std attribute. | List of strings | required | | | target_json | Override the target_triple with a custom target specification. For more details see: https://doc.rust-lang.org/rustc/targets/custom.html | Label | optional | None | | target_triple | The platform triple for the toolchains target environment. For more details see: https://docs.bazel.build/versions/master/skylark/rules.html#configurations | String | optional | "" | diff --git a/rust/private/repository_utils.bzl b/rust/private/repository_utils.bzl index 822c932b9d..a5f0a5a80c 100644 --- a/rust/private/repository_utils.bzl +++ b/rust/private/repository_utils.bzl @@ -141,7 +141,7 @@ _build_file_for_stdlib_template = """\ load("@rules_rust//rust:toolchain.bzl", "rust_stdlib_filegroup") rust_stdlib_filegroup( - name = "rust_lib-{target_triple}", + name = "rust_std-{target_triple}", srcs = glob( [ "lib/rustlib/{target_triple}/lib/*.rlib", @@ -154,6 +154,13 @@ rust_stdlib_filegroup( ), visibility = ["//visibility:public"], ) + +# For legacy support +alias( + name = "rust_lib-{target_triple}", + actual = "rust_std-{target_triple}", + visibility = ["//visibility:public"], +) """ def BUILD_for_stdlib(target_triple): @@ -177,7 +184,7 @@ _build_file_for_rust_toolchain_template = """\ rust_toolchain( name = "{toolchain_name}_impl", rust_doc = "@{workspace_name}//:rustdoc", - rust_lib = "@{workspace_name}//:rust_lib-{target_triple}", + rust_std = "@{workspace_name}//:rust_std-{target_triple}", rustc = "@{workspace_name}//:rustc", rustfmt = "@{workspace_name}//:rustfmt_bin", cargo = "@{workspace_name}//:cargo", diff --git a/rust/private/rustc.bzl b/rust/private/rustc.bzl index 135930d138..84175d2130 100644 --- a/rust/private/rustc.bzl +++ b/rust/private/rustc.bzl @@ -409,7 +409,7 @@ def collect_inputs( ([] if linker_script == None else [linker_script]), transitive = [ toolchain.rustc_lib.files, - toolchain.rust_lib.files, + toolchain.rust_std.files, linker_depset, crate_info.srcs, dep_info.transitive_crate_outputs, @@ -617,10 +617,10 @@ 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_lib_paths = depset([file.dirname for file in toolchain.rust_lib.files.to_list()]).to_list() + rust_std_paths = depset([file.dirname for file in toolchain.rust_std.files.to_list()]).to_list() # Tell Rustc where to find the standard library - rustc_flags.add_all(rust_lib_paths, before_each = "-L", format_each = "%s") + rustc_flags.add_all(rust_std_paths, before_each = "-L", format_each = "%s") rustc_flags.add_all(rust_flags) data_paths = getattr(attr, "data", []) + getattr(attr, "compile_data", []) @@ -674,8 +674,8 @@ def construct_arguments( data_paths, )) - # Set the SYSROOT to the directory of the rust_lib files passed to the toolchain - env["SYSROOT"] = paths.dirname(toolchain.rust_lib.files.to_list()[0].short_path) + # 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["RULES_RUST_RENAME_FIRST_PARTY_CRATES"] = str(toolchain._rename_first_party_crates).lower() env["RULES_RUST_THIRD_PARTY_DIR"] = str(toolchain._third_party_dir).lower() diff --git a/rust/private/toolchain_utils.bzl b/rust/private/toolchain_utils.bzl index aa98a4311b..9e011bef40 100644 --- a/rust/private/toolchain_utils.bzl +++ b/rust/private/toolchain_utils.bzl @@ -9,7 +9,7 @@ def find_sysroot(rust_toolchain): Returns: str: A path assignable as `SYSROOT` for an action. """ - sysroot_anchor = rust_toolchain.rust_lib.files.to_list()[0] + sysroot_anchor = rust_toolchain.rust_std.files.to_list()[0] directory = sysroot_anchor.path.split(sysroot_anchor.short_path, 1)[0] return directory.rstrip("/") @@ -57,8 +57,8 @@ def _toolchain_files_impl(ctx): files = toolchain.rustc_lib.files elif ctx.attr.tool == "rustc_srcs": files = toolchain.rustc_srcs.files - elif ctx.attr.tool == "rust_lib" or ctx.attr.tool == "rust_stdlib": - files = toolchain.rust_lib.files + elif ctx.attr.tool == "rust_std" or ctx.attr.tool == "rust_stdlib" or ctx.attr.tool == "rust_lib": + files = toolchain.rust_std.files else: fail("Unsupported tool: ", ctx.attr.tool) @@ -76,13 +76,14 @@ toolchain_files = rule( values = [ "cargo", "clippy", + "rust_lib", + "rust_std", + "rust_stdlib", + "rustc_lib", + "rustc_srcs", "rustc", "rustdoc", "rustfmt", - "rustc_lib", - "rustc_srcs", - "rust_lib", - "rust_stdlib", ], mandatory = True, ), diff --git a/rust/toolchain.bzl b/rust/toolchain.bzl index 868f28d526..3785b2edc5 100644 --- a/rust/toolchain.bzl +++ b/rust/toolchain.bzl @@ -6,7 +6,7 @@ load("//rust/private:utils.bzl", "dedent", "find_cc_toolchain", "make_static_lib load("//rust/settings:incompatible.bzl", "IncompatibleFlagInfo") def _rust_stdlib_filegroup_impl(ctx): - rust_lib = ctx.files.srcs + rust_std = ctx.files.srcs dot_a_files = [] between_alloc_and_core_files = [] core_files = [] @@ -15,11 +15,11 @@ def _rust_stdlib_filegroup_impl(ctx): alloc_files = [] self_contained_files = [ file - for file in rust_lib + for file in rust_std if file.basename.endswith(".o") and "self-contained" in file.path ] - std_rlibs = [f for f in rust_lib if f.basename.endswith(".rlib")] + std_rlibs = [f for f in rust_std if f.basename.endswith(".rlib")] if std_rlibs: # std depends on everything # @@ -46,7 +46,7 @@ def _rust_stdlib_filegroup_impl(ctx): for f in sorted(partitioned): # buildifier: disable=print print("File partitioned: {}".format(f.basename)) - fail("rust_toolchain couldn't properly partition rlibs in rust_lib. Partitioned {} out of {} files. This is probably a bug in the rule implementation.".format(partitioned_files_len, len(dot_a_files))) + fail("rust_toolchain couldn't properly partition rlibs in rust_std. Partitioned {} out of {} files. This is probably a bug in the rule implementation.".format(partitioned_files_len, len(dot_a_files))) return [ DefaultInfo( @@ -97,12 +97,12 @@ def _ltl(library, ctx, cc_toolchain, feature_configuration): pic_static_library = library, ) -def _make_libstd_and_allocator_ccinfo(ctx, rust_lib, allocator_library): +def _make_libstd_and_allocator_ccinfo(ctx, rust_std, allocator_library): """Make the CcInfo (if possible) for libstd and allocator libraries. Args: ctx (ctx): The rule's context object. - rust_lib: The rust standard library. + rust_std: The Rust standard library. allocator_library: The target to use for providing allocator functions. @@ -112,14 +112,14 @@ def _make_libstd_and_allocator_ccinfo(ctx, rust_lib, allocator_library): cc_toolchain, feature_configuration = find_cc_toolchain(ctx) cc_infos = [] - if not rust_common.stdlib_info in ctx.attr.rust_lib: + if not rust_common.stdlib_info in rust_std: fail(dedent("""\ {} -- The `rust_lib` ({}) must be a target providing `rust_common.stdlib_info` (typically `rust_stdlib_filegroup` rule from @rules_rust//rust:defs.bzl). See https://github.com/bazelbuild/rules_rust/pull/802 for more information. - """).format(ctx.label, ctx.attr.rust_lib)) - rust_stdlib_info = ctx.attr.rust_lib[rust_common.stdlib_info] + """).format(ctx.label, rust_std)) + rust_stdlib_info = rust_std[rust_common.stdlib_info] if rust_stdlib_info.self_contained_files: compilation_outputs = cc_common.create_compilation_outputs( @@ -187,7 +187,7 @@ def _make_libstd_and_allocator_ccinfo(ctx, rust_lib, allocator_library): ) link_inputs = cc_common.create_linker_input( - owner = rust_lib.label, + owner = rust_std.label, libraries = std_inputs, ) @@ -237,12 +237,21 @@ def _rust_toolchain_impl(ctx): rename_first_party_crates = ctx.attr._rename_first_party_crates[BuildSettingInfo].value third_party_dir = ctx.attr._third_party_dir[BuildSettingInfo].value + if ctx.attr.rust_lib: + # buildifier: disable=print + print("`rust_toolchain.rust_lib` is deprecated. Please update {} to use `rust_toolchain.rust_std`".format( + ctx.label, + )) + rust_std = ctx.attr.rust_lib + else: + rust_std = ctx.attr.rust_std + expanded_stdlib_linkflags = [] for flag in ctx.attr.stdlib_linkflags: expanded_stdlib_linkflags.append( ctx.expand_location( flag, - targets = ctx.attr.rust_lib[rust_common.stdlib_info].srcs, + targets = rust_std[rust_common.stdlib_info].srcs, ), ) @@ -269,7 +278,8 @@ def _rust_toolchain_impl(ctx): 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_srcs = ctx.attr.rustc_srcs, - rust_lib = ctx.attr.rust_lib, + rust_std = rust_std, + rust_lib = rust_std, # `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, @@ -286,7 +296,7 @@ def _rust_toolchain_impl(ctx): default_edition = ctx.attr.default_edition, compilation_mode_opts = compilation_mode_opts, crosstool_files = ctx.files._crosstool, - libstd_and_allocator_ccinfo = _make_libstd_and_allocator_ccinfo(ctx, ctx.attr.rust_lib, ctx.attr.allocator_library), + libstd_and_allocator_ccinfo = _make_libstd_and_allocator_ccinfo(ctx, rust_std, ctx.attr.allocator_library), _incompatible_remove_transitive_libs_from_dep_info = remove_transitive_libs_from_dep_info.enabled, _rename_first_party_crates = rename_first_party_crates, _third_party_dir = third_party_dir, @@ -354,7 +364,10 @@ rust_toolchain = rule( cfg = "exec", ), "rust_lib": attr.label( - doc = "The rust standard library.", + doc = "**Deprecated**: Use `rust_std`", + ), + "rust_std": attr.label( + doc = "The Rust standard library.", ), "rustc": attr.label( doc = "The location of the `rustc` binary. Can be a direct source or a filegroup containing one item.", @@ -379,9 +392,9 @@ rust_toolchain = rule( ), "stdlib_linkflags": attr.string_list( doc = ( - "Additional linker flags to use when Rust std lib is linked by a C++ linker " + - "(rustc will deal with these automatically). " + - "Subject to location expansion with respect to the srcs of the rust_lib attribute." + "Additional linker flags to use when Rust standard library is linked by a C++ linker " + + "(rustc will deal with these automatically). Subject to location expansion with respect " + + "to the srcs of the `rust_std` attribute." ), mandatory = True, ), @@ -432,7 +445,7 @@ rust_toolchain( name = "rust_cpuX_impl", rustc = "@rust_cpuX//:rustc", rustc_lib = "@rust_cpuX//:rustc_lib", - rust_lib = "@rust_cpuX//:rust_lib", + rust_std = "@rust_cpuX//:rust_std", rust_doc = "@rust_cpuX//:rustdoc", binary_ext = "", staticlib_ext = ".a", diff --git a/test/unit/toolchain/toolchain_test.bzl b/test/unit/toolchain/toolchain_test.bzl index 8f476a6da4..917e7d099e 100644 --- a/test/unit/toolchain/toolchain_test.bzl +++ b/test/unit/toolchain/toolchain_test.bzl @@ -59,7 +59,7 @@ def _toolchain_test(): binary_ext = "", dylib_ext = ".so", os = "linux", - rust_lib = ":std_libs", + rust_std = ":std_libs", staticlib_ext = ".a", stdlib_linkflags = [], target_triple = "toolchain-test-triple", @@ -70,7 +70,7 @@ def _toolchain_test(): binary_ext = "", dylib_ext = ".so", os = "linux", - rust_lib = ":std_libs", + rust_std = ":std_libs", staticlib_ext = ".a", stdlib_linkflags = [], target_json = ":target_json", @@ -81,7 +81,7 @@ def _toolchain_test(): binary_ext = "", dylib_ext = ".so", os = "linux", - rust_lib = ":std_libs", + rust_std = ":std_libs", staticlib_ext = ".a", stdlib_linkflags = ["test:$(location :stdlib_srcs)"], target_json = ":target_json",