Skip to content

Commit

Permalink
Recognize edition = "required" idiom
Browse files Browse the repository at this point in the history
  • Loading branch information
dtolnay committed Apr 11, 2022
1 parent 5579049 commit 7dab7eb
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions rust/private/rust.bzl
Expand Up @@ -106,7 +106,7 @@ def _determine_lib_name(name, crate_type, toolchain, lib_hash = None):
extension = extension,
)

def get_edition(attr, toolchain):
def get_edition(ctx, toolchain):
"""Returns the Rust edition from either the current rule's attirbutes or the current `rust_toolchain`
Args:
Expand All @@ -116,8 +116,10 @@ def get_edition(attr, toolchain):
Returns:
str: The target Rust edition
"""
if getattr(attr, "edition"):
return attr.edition
if getattr(ctx.attr, "edition"):
return ctx.attr.edition
elif toolchain.default_edition == "required":
fail("Attribute `edition` is required for {}.".format(ctx.label))
else:
return toolchain.default_edition

Expand Down Expand Up @@ -280,7 +282,7 @@ def _rust_library_common(ctx, crate_type):
proc_macro_deps = depset(proc_macro_deps),
aliases = ctx.attr.aliases,
output = rust_lib,
edition = get_edition(ctx.attr, toolchain),
edition = get_edition(ctx, toolchain),
rustc_env = ctx.attr.rustc_env,
is_test = False,
compile_data = depset(ctx.files.compile_data),
Expand Down Expand Up @@ -320,7 +322,7 @@ def _rust_binary_impl(ctx):
proc_macro_deps = depset(proc_macro_deps),
aliases = ctx.attr.aliases,
output = output,
edition = get_edition(ctx.attr, toolchain),
edition = get_edition(ctx, toolchain),
rustc_env = ctx.attr.rustc_env,
is_test = False,
compile_data = depset(ctx.files.compile_data),
Expand Down Expand Up @@ -386,7 +388,7 @@ def _rust_test_common(ctx, toolchain, output):
proc_macro_deps = depset(proc_macro_deps),
aliases = ctx.attr.aliases,
output = output,
edition = get_edition(ctx.attr, toolchain),
edition = get_edition(ctx, toolchain),
rustc_env = ctx.attr.rustc_env,
is_test = True,
compile_data = depset(ctx.files.compile_data),
Expand Down

0 comments on commit 7dab7eb

Please sign in to comment.