Skip to content

Commit 8c2b4a2

Browse files
committed
skip link step when running clippy
I have a crate that uses pyo3 to create a Python extension module. On macOS, special link flags are required: rustc_flags = selects.with_or({ ( "@io_bazel_rules_rust//rust/platform:x86_64-apple-darwin", ): [ "-Clink-arg=-undefined", "-Clink-arg=dynamic_lookup", ], "//conditions:default": [], }), Without them, the linker on macOS fails, as the Python API is not available until runtime. rules_rust's clippy implementation was passing --emit=dep-info,link to the clippy invocation, causing a clippy run to fail with linking errors. This patch changes the invocation to use --emit=dep-info,metadata instead, which is what cargo uses. It also shaves a bit of time off the check, as linking no longer needs to happen. Tangentially related to bazelbuild#428 and bazelbuild#421 - currently the clippy aspect seems to be falling back on a non-worker compile, so it's still noticeably slower than running cargo clippy directly when minor changes have been made.
1 parent 726b182 commit 8c2b4a2

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-2
lines changed

rust/private/clippy.bzl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ def _clippy_aspect_impl(target, ctx):
9292
build_env_file = build_env_file,
9393
build_flags_files = build_flags_files,
9494
maker_path = clippy_marker.path,
95+
emit = "dep-info,metadata",
9596
)
9697

9798
# Deny the default-on clippy warning levels.

rust/private/rustc.bzl

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -392,7 +392,8 @@ def construct_arguments(
392392
out_dir,
393393
build_env_file,
394394
build_flags_files,
395-
maker_path = None):
395+
maker_path = None,
396+
emit = "dep-info,link"):
396397
"""Builds an Args object containing common rustc flags
397398
398399
Args:
@@ -410,6 +411,7 @@ def construct_arguments(
410411
build_env_file (str): The output file of a `cargo_build_script` action containing rustc environment variables
411412
build_flags_files (list): The output files of a `cargo_build_script` actions containing rustc build flags
412413
maker_path (File): An optional clippy marker file
414+
emit (str): a string to pass to --emit
413415
414416
Returns:
415417
tuple: A tuple of the following items
@@ -488,7 +490,7 @@ def construct_arguments(
488490
args.add("--codegen=opt-level=" + compilation_mode.opt_level)
489491
args.add("--codegen=debuginfo=" + compilation_mode.debug_info)
490492

491-
args.add("--emit=dep-info,link")
493+
args.add("--emit=" + emit)
492494
args.add("--color=always")
493495
args.add("--target=" + toolchain.target_triple)
494496
if hasattr(ctx.attr, "crate_features"):

0 commit comments

Comments
 (0)