Skip to content

Skip linking for clippy aspect for faster builds #526

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

Merged
merged 1 commit into from
Dec 5, 2020
Merged
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions rust/private/clippy.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ def _clippy_aspect_impl(target, ctx):
build_flags_files = build_flags_files,
maker_path = clippy_marker.path,
aspect = True,
emit = ["dep-info", "metadata"],
)

# Deny the default-on clippy warning levels.
Expand Down
30 changes: 17 additions & 13 deletions rust/private/rustc.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,8 @@ def construct_arguments(
build_env_file,
build_flags_files,
maker_path = None,
aspect = False):
aspect = False,
emit = ["dep-info", "link"]):
"""Builds an Args object containing common rustc flags

Args:
Expand All @@ -416,6 +417,7 @@ def construct_arguments(
build_flags_files (list): The output files of a `cargo_build_script` actions containing rustc build flags
maker_path (File): An optional clippy marker file
aspect (bool): True if called in an aspect context.
emit (list): Values for the --emit flag to rustc.

Returns:
tuple: A tuple of the following items
Expand Down Expand Up @@ -497,7 +499,7 @@ def construct_arguments(
args.add("--codegen=opt-level=" + compilation_mode.opt_level)
args.add("--codegen=debuginfo=" + compilation_mode.debug_info)

args.add("--emit=dep-info,link")
args.add("--emit=" + ",".join(emit))
args.add("--color=always")
args.add("--target=" + toolchain.target_triple)
if hasattr(ctx.attr, "crate_features"):
Expand All @@ -516,17 +518,19 @@ def construct_arguments(
add_edition_flags(args, crate_info)

# Link!

# Rust's built-in linker can handle linking wasm files. We don't want to attempt to use the cc
# linker since it won't understand.
if toolchain.target_arch != "wasm32":
rpaths = _compute_rpaths(toolchain, output_dir, dep_info)
ld, link_args, link_env = get_linker_and_args(ctx, cc_toolchain, feature_configuration, rpaths)
env.update(link_env)
args.add("--codegen=linker=" + ld)
args.add_joined("--codegen", link_args, join_with = " ", format_joined = "link-args=%s")

add_native_link_flags(args, dep_info)
if "link" in emit:
# Rust's built-in linker can handle linking wasm files. We don't want to attempt to use the cc
# linker since it won't understand.
if toolchain.target_arch != "wasm32":
rpaths = _compute_rpaths(toolchain, output_dir, dep_info)
ld, link_args, link_env = get_linker_and_args(ctx, cc_toolchain, feature_configuration, rpaths)
env.update(link_env)
args.add("--codegen=linker=" + ld)
args.add_joined("--codegen", link_args, join_with = " ", format_joined = "link-args=%s")

add_native_link_flags(args, dep_info)

# These always need to be added, even if not linking this crate.
add_crate_link_flags(args, dep_info)

if crate_info.type == "proc-macro" and crate_info.edition != "2015":
Expand Down