Skip to content

Commit 66e2c10

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 #428 and #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 2f97db5 commit 66e2c10

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
@@ -93,6 +93,7 @@ def _clippy_aspect_impl(target, ctx):
9393
build_flags_files = build_flags_files,
9494
maker_path = clippy_marker.path,
9595
aspect = True,
96+
emit = "dep-info,metadata",
9697
)
9798

9899
# 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
@@ -424,7 +424,8 @@ def construct_arguments(
424424
build_env_file,
425425
build_flags_files,
426426
maker_path = None,
427-
aspect = False):
427+
aspect = False,
428+
emit = "dep-info,link"):
428429
"""Builds an Args object containing common rustc flags
429430
430431
Args:
@@ -443,6 +444,7 @@ def construct_arguments(
443444
build_flags_files (list): The output files of a `cargo_build_script` actions containing rustc build flags
444445
maker_path (File): An optional clippy marker file
445446
aspect (bool): True if called in an aspect context.
447+
emit (str): a string to pass to --emit
446448
447449
Returns:
448450
tuple: A tuple of the following items
@@ -525,7 +527,7 @@ def construct_arguments(
525527
args.add("--codegen=opt-level=" + compilation_mode.opt_level)
526528
args.add("--codegen=debuginfo=" + compilation_mode.debug_info)
527529

528-
args.add("--emit=dep-info,link")
530+
args.add("--emit=" + emit)
529531
args.add("--color=always")
530532
args.add("--target=" + toolchain.target_triple)
531533
if hasattr(ctx.attr, "crate_features"):

0 commit comments

Comments
 (0)