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

Treat rustfmt as optional #1164

Merged
merged 1 commit into from
Mar 3, 2022
Merged
Changes from all 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
9 changes: 8 additions & 1 deletion rust/private/repository_utils.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ rust_toolchain(
rust_doc = "@{workspace_name}//:rustdoc",
rust_std = "@{workspace_name}//:rust_std-{target_triple}",
rustc = "@{workspace_name}//:rustc",
rustfmt = "@{workspace_name}//:rustfmt_bin",
rustfmt = {rustfmt_label},
cargo = "@{workspace_name}//:cargo",
clippy_driver = "@{workspace_name}//:clippy_driver_bin",
rustc_lib = "@{workspace_name}//:rustc_lib",
Expand All @@ -210,6 +210,7 @@ def BUILD_for_rust_toolchain(
target_triple,
include_rustc_srcs,
default_edition,
include_rustfmt,
stdlib_linkflags = None):
"""Emits a toolchain declaration to match an existing compiler and stdlib.
Expand All @@ -220,6 +221,7 @@ def BUILD_for_rust_toolchain(
target_triple (str): The rust-style target triple of the tool
include_rustc_srcs (bool, optional): Whether to download rustc's src code. This is required in order to use rust-analyzer support. Defaults to False.
default_edition (str): Default Rust edition.
include_rustfmt (bool): Whether rustfmt is present in the toolchain.
stdlib_linkflags (list, optional): Overriden flags needed for linking to rust
stdlib, akin to BAZEL_LINKLIBS. Defaults to
None.
Expand All @@ -235,6 +237,9 @@ def BUILD_for_rust_toolchain(
rustc_srcs = "None"
if include_rustc_srcs:
rustc_srcs = "\"@{workspace_name}//lib/rustlib/src:rustc_srcs\"".format(workspace_name = workspace_name)
rustfmt_label = "None"
if include_rustfmt:
rustfmt_label = "\"@{workspace_name}//:rustfmt_bin\"".format(workspace_name = workspace_name)

return _build_file_for_rust_toolchain_template.format(
toolchain_name = name,
Expand All @@ -248,6 +253,7 @@ def BUILD_for_rust_toolchain(
default_edition = default_edition,
exec_triple = exec_triple,
target_triple = target_triple,
rustfmt_label = rustfmt_label,
)

_build_file_for_toolchain_template = """\
Expand Down Expand Up @@ -402,6 +408,7 @@ def load_rust_stdlib(ctx, target_triple):
stdlib_linkflags = stdlib_linkflags,
workspace_name = ctx.attr.name,
default_edition = ctx.attr.edition,
include_rustfmt = not (not ctx.attr.rustfmt_version),
)

return stdlib_build_file + toolchain_build_file
Expand Down