Skip to content

Commit

Permalink
Renamed rust_toolchain.rust_lib to rust_toolchain.rust_std (#1102)
Browse files Browse the repository at this point in the history
  • Loading branch information
UebelAndre committed Jan 24, 2022
1 parent 67adb4c commit cc682aa
Show file tree
Hide file tree
Showing 8 changed files with 69 additions and 46 deletions.
2 changes: 1 addition & 1 deletion cargo/cargo_build_script.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
11 changes: 6 additions & 5 deletions docs/flatten.md
Original file line number Diff line number Diff line change
Expand Up @@ -1103,8 +1103,8 @@ Run the test with `bazel build //hello_lib:hello_lib_test`.

<pre>
rust_toolchain(<a href="#rust_toolchain-name">name</a>, <a href="#rust_toolchain-allocator_library">allocator_library</a>, <a href="#rust_toolchain-binary_ext">binary_ext</a>, <a href="#rust_toolchain-cargo">cargo</a>, <a href="#rust_toolchain-clippy_driver">clippy_driver</a>, <a href="#rust_toolchain-debug_info">debug_info</a>,
<a href="#rust_toolchain-default_edition">default_edition</a>, <a href="#rust_toolchain-dylib_ext">dylib_ext</a>, <a href="#rust_toolchain-exec_triple">exec_triple</a>, <a href="#rust_toolchain-opt_level">opt_level</a>, <a href="#rust_toolchain-os">os</a>, <a href="#rust_toolchain-rust_doc">rust_doc</a>, <a href="#rust_toolchain-rust_lib">rust_lib</a>, <a href="#rust_toolchain-rustc">rustc</a>,
<a href="#rust_toolchain-rustc_lib">rustc_lib</a>, <a href="#rust_toolchain-rustc_srcs">rustc_srcs</a>, <a href="#rust_toolchain-rustfmt">rustfmt</a>, <a href="#rust_toolchain-staticlib_ext">staticlib_ext</a>, <a href="#rust_toolchain-stdlib_linkflags">stdlib_linkflags</a>, <a href="#rust_toolchain-target_json">target_json</a>,
<a href="#rust_toolchain-default_edition">default_edition</a>, <a href="#rust_toolchain-dylib_ext">dylib_ext</a>, <a href="#rust_toolchain-exec_triple">exec_triple</a>, <a href="#rust_toolchain-opt_level">opt_level</a>, <a href="#rust_toolchain-os">os</a>, <a href="#rust_toolchain-rust_doc">rust_doc</a>, <a href="#rust_toolchain-rust_lib">rust_lib</a>, <a href="#rust_toolchain-rust_std">rust_std</a>,
<a href="#rust_toolchain-rustc">rustc</a>, <a href="#rust_toolchain-rustc_lib">rustc_lib</a>, <a href="#rust_toolchain-rustc_srcs">rustc_srcs</a>, <a href="#rust_toolchain-rustfmt">rustfmt</a>, <a href="#rust_toolchain-staticlib_ext">staticlib_ext</a>, <a href="#rust_toolchain-stdlib_linkflags">stdlib_linkflags</a>, <a href="#rust_toolchain-target_json">target_json</a>,
<a href="#rust_toolchain-target_triple">target_triple</a>)
</pre>

Expand All @@ -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",
Expand Down Expand Up @@ -1166,13 +1166,14 @@ See @rules_rust//rust:repositories.bzl for examples of defining the @rust_cpuX r
| <a id="rust_toolchain-opt_level"></a>opt_level | Rustc optimization levels. | <a href="https://bazel.build/docs/skylark/lib/dict.html">Dictionary: String -> String</a> | optional | {"dbg": "0", "fastbuild": "0", "opt": "3"} |
| <a id="rust_toolchain-os"></a>os | The operating system for the current toolchain | String | required | |
| <a id="rust_toolchain-rust_doc"></a>rust_doc | The location of the <code>rustdoc</code> binary. Can be a direct source or a filegroup containing one item. | <a href="https://bazel.build/docs/build-ref.html#labels">Label</a> | optional | None |
| <a id="rust_toolchain-rust_lib"></a>rust_lib | The rust standard library. | <a href="https://bazel.build/docs/build-ref.html#labels">Label</a> | optional | None |
| <a id="rust_toolchain-rust_lib"></a>rust_lib | **Deprecated**: Use <code>rust_std</code> | <a href="https://bazel.build/docs/build-ref.html#labels">Label</a> | optional | None |
| <a id="rust_toolchain-rust_std"></a>rust_std | The Rust standard library. | <a href="https://bazel.build/docs/build-ref.html#labels">Label</a> | optional | None |
| <a id="rust_toolchain-rustc"></a>rustc | The location of the <code>rustc</code> binary. Can be a direct source or a filegroup containing one item. | <a href="https://bazel.build/docs/build-ref.html#labels">Label</a> | optional | None |
| <a id="rust_toolchain-rustc_lib"></a>rustc_lib | The libraries used by rustc during compilation. | <a href="https://bazel.build/docs/build-ref.html#labels">Label</a> | optional | None |
| <a id="rust_toolchain-rustc_srcs"></a>rustc_srcs | The source code of rustc. | <a href="https://bazel.build/docs/build-ref.html#labels">Label</a> | optional | None |
| <a id="rust_toolchain-rustfmt"></a>rustfmt | The location of the <code>rustfmt</code> binary. Can be a direct source or a filegroup containing one item. | <a href="https://bazel.build/docs/build-ref.html#labels">Label</a> | optional | None |
| <a id="rust_toolchain-staticlib_ext"></a>staticlib_ext | The extension for static libraries created from rustc. | String | required | |
| <a id="rust_toolchain-stdlib_linkflags"></a>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 | |
| <a id="rust_toolchain-stdlib_linkflags"></a>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 <code>rust_std</code> attribute. | List of strings | required | |
| <a id="rust_toolchain-target_json"></a>target_json | Override the target_triple with a custom target specification. For more details see: https://doc.rust-lang.org/rustc/targets/custom.html | <a href="https://bazel.build/docs/build-ref.html#labels">Label</a> | optional | None |
| <a id="rust_toolchain-target_triple"></a>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 | "" |

Expand Down
11 changes: 6 additions & 5 deletions docs/rust_repositories.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ A dedicated filegroup-like rule for Rust stdlib artifacts.

<pre>
rust_toolchain(<a href="#rust_toolchain-name">name</a>, <a href="#rust_toolchain-allocator_library">allocator_library</a>, <a href="#rust_toolchain-binary_ext">binary_ext</a>, <a href="#rust_toolchain-cargo">cargo</a>, <a href="#rust_toolchain-clippy_driver">clippy_driver</a>, <a href="#rust_toolchain-debug_info">debug_info</a>,
<a href="#rust_toolchain-default_edition">default_edition</a>, <a href="#rust_toolchain-dylib_ext">dylib_ext</a>, <a href="#rust_toolchain-exec_triple">exec_triple</a>, <a href="#rust_toolchain-opt_level">opt_level</a>, <a href="#rust_toolchain-os">os</a>, <a href="#rust_toolchain-rust_doc">rust_doc</a>, <a href="#rust_toolchain-rust_lib">rust_lib</a>, <a href="#rust_toolchain-rustc">rustc</a>,
<a href="#rust_toolchain-rustc_lib">rustc_lib</a>, <a href="#rust_toolchain-rustc_srcs">rustc_srcs</a>, <a href="#rust_toolchain-rustfmt">rustfmt</a>, <a href="#rust_toolchain-staticlib_ext">staticlib_ext</a>, <a href="#rust_toolchain-stdlib_linkflags">stdlib_linkflags</a>, <a href="#rust_toolchain-target_json">target_json</a>,
<a href="#rust_toolchain-default_edition">default_edition</a>, <a href="#rust_toolchain-dylib_ext">dylib_ext</a>, <a href="#rust_toolchain-exec_triple">exec_triple</a>, <a href="#rust_toolchain-opt_level">opt_level</a>, <a href="#rust_toolchain-os">os</a>, <a href="#rust_toolchain-rust_doc">rust_doc</a>, <a href="#rust_toolchain-rust_lib">rust_lib</a>, <a href="#rust_toolchain-rust_std">rust_std</a>,
<a href="#rust_toolchain-rustc">rustc</a>, <a href="#rust_toolchain-rustc_lib">rustc_lib</a>, <a href="#rust_toolchain-rustc_srcs">rustc_srcs</a>, <a href="#rust_toolchain-rustfmt">rustfmt</a>, <a href="#rust_toolchain-staticlib_ext">staticlib_ext</a>, <a href="#rust_toolchain-stdlib_linkflags">stdlib_linkflags</a>, <a href="#rust_toolchain-target_json">target_json</a>,
<a href="#rust_toolchain-target_triple">target_triple</a>)
</pre>

Expand All @@ -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",
Expand Down Expand Up @@ -96,13 +96,14 @@ See @rules_rust//rust:repositories.bzl for examples of defining the @rust_cpuX r
| <a id="rust_toolchain-opt_level"></a>opt_level | Rustc optimization levels. | <a href="https://bazel.build/docs/skylark/lib/dict.html">Dictionary: String -> String</a> | optional | {"dbg": "0", "fastbuild": "0", "opt": "3"} |
| <a id="rust_toolchain-os"></a>os | The operating system for the current toolchain | String | required | |
| <a id="rust_toolchain-rust_doc"></a>rust_doc | The location of the <code>rustdoc</code> binary. Can be a direct source or a filegroup containing one item. | <a href="https://bazel.build/docs/build-ref.html#labels">Label</a> | optional | None |
| <a id="rust_toolchain-rust_lib"></a>rust_lib | The rust standard library. | <a href="https://bazel.build/docs/build-ref.html#labels">Label</a> | optional | None |
| <a id="rust_toolchain-rust_lib"></a>rust_lib | **Deprecated**: Use <code>rust_std</code> | <a href="https://bazel.build/docs/build-ref.html#labels">Label</a> | optional | None |
| <a id="rust_toolchain-rust_std"></a>rust_std | The Rust standard library. | <a href="https://bazel.build/docs/build-ref.html#labels">Label</a> | optional | None |
| <a id="rust_toolchain-rustc"></a>rustc | The location of the <code>rustc</code> binary. Can be a direct source or a filegroup containing one item. | <a href="https://bazel.build/docs/build-ref.html#labels">Label</a> | optional | None |
| <a id="rust_toolchain-rustc_lib"></a>rustc_lib | The libraries used by rustc during compilation. | <a href="https://bazel.build/docs/build-ref.html#labels">Label</a> | optional | None |
| <a id="rust_toolchain-rustc_srcs"></a>rustc_srcs | The source code of rustc. | <a href="https://bazel.build/docs/build-ref.html#labels">Label</a> | optional | None |
| <a id="rust_toolchain-rustfmt"></a>rustfmt | The location of the <code>rustfmt</code> binary. Can be a direct source or a filegroup containing one item. | <a href="https://bazel.build/docs/build-ref.html#labels">Label</a> | optional | None |
| <a id="rust_toolchain-staticlib_ext"></a>staticlib_ext | The extension for static libraries created from rustc. | String | required | |
| <a id="rust_toolchain-stdlib_linkflags"></a>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 | |
| <a id="rust_toolchain-stdlib_linkflags"></a>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 <code>rust_std</code> attribute. | List of strings | required | |
| <a id="rust_toolchain-target_json"></a>target_json | Override the target_triple with a custom target specification. For more details see: https://doc.rust-lang.org/rustc/targets/custom.html | <a href="https://bazel.build/docs/build-ref.html#labels">Label</a> | optional | None |
| <a id="rust_toolchain-target_triple"></a>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 | "" |

Expand Down
11 changes: 9 additions & 2 deletions rust/private/repository_utils.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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):
Expand All @@ -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",
Expand Down
10 changes: 5 additions & 5 deletions rust/private/rustc.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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", [])
Expand Down Expand Up @@ -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)

# extra_rustc_flags apply to the target configuration, not the exec configuration.
if hasattr(ctx.attr, "_extra_rustc_flags") and is_exec_configuration(ctx):
Expand Down
15 changes: 8 additions & 7 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_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("/")

Expand Down Expand Up @@ -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)

Expand All @@ -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,
),
Expand Down
Loading

0 comments on commit cc682aa

Please sign in to comment.