Skip to content

Commit e364d38

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 d1d04eb commit e364d38

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
@@ -415,7 +415,8 @@ def construct_arguments(
415415
out_dir,
416416
build_env_file,
417417
build_flags_files,
418-
maker_path = None):
418+
maker_path = None,
419+
emit = "dep-info,link"):
419420
"""Builds an Args object containing common rustc flags
420421
421422
Args:
@@ -433,6 +434,7 @@ def construct_arguments(
433434
build_env_file (str): The output file of a `cargo_build_script` action containing rustc environment variables
434435
build_flags_files (list): The output files of a `cargo_build_script` actions containing rustc build flags
435436
maker_path (File): An optional clippy marker file
437+
emit (str): a string to pass to --emit
436438
437439
Returns:
438440
tuple: A tuple of the following items
@@ -515,7 +517,7 @@ def construct_arguments(
515517
args.add("--codegen=opt-level=" + compilation_mode.opt_level)
516518
args.add("--codegen=debuginfo=" + compilation_mode.debug_info)
517519

518-
args.add("--emit=dep-info,link")
520+
args.add("--emit=" + emit)
519521
args.add("--color=always")
520522
args.add("--target=" + toolchain.target_triple)
521523
if hasattr(ctx.attr, "crate_features"):

0 commit comments

Comments
 (0)