From bc0578798f50d018ca4278ad5610598c400992c9 Mon Sep 17 00:00:00 2001 From: David Marcin Date: Sat, 5 Dec 2020 14:37:22 -0800 Subject: [PATCH] Skip linking for clippy aspect (#526) --- rust/private/clippy.bzl | 1 + rust/private/rustc.bzl | 30 +++++++++++++++++------------- 2 files changed, 18 insertions(+), 13 deletions(-) diff --git a/rust/private/clippy.bzl b/rust/private/clippy.bzl index 7ce28119eb..2089353c22 100644 --- a/rust/private/clippy.bzl +++ b/rust/private/clippy.bzl @@ -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. diff --git a/rust/private/rustc.bzl b/rust/private/rustc.bzl index ef1eeed9b5..26da08fe49 100644 --- a/rust/private/rustc.bzl +++ b/rust/private/rustc.bzl @@ -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: @@ -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 @@ -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"): @@ -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":