Skip to content

Commit 75eeb20

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 68bab60 commit 75eeb20

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
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
# Turn any warnings from clippy or rustc into an error, as otherwise

rust/private/rustc.bzl

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -409,7 +409,8 @@ def construct_arguments(
409409
build_env_file,
410410
build_flags_files,
411411
maker_path = None,
412-
aspect = False):
412+
aspect = False,
413+
emit = "dep-info,link"):
413414
"""Builds an Args object containing common rustc flags
414415
415416
Args:
@@ -427,7 +428,8 @@ def construct_arguments(
427428
build_env_file (str): The output file of a `cargo_build_script` action containing rustc environment variables
428429
build_flags_files (list): The output files of a `cargo_build_script` actions containing rustc build flags
429430
maker_path (File): An optional clippy marker file
430-
aspect (bool): True if called in an aspect context.
431+
aspect (bool): True if called in an aspect context
432+
emit (str): A string to pass to --emit
431433
432434
Returns:
433435
tuple: A tuple of the following items
@@ -506,7 +508,7 @@ def construct_arguments(
506508
args.add("--codegen=opt-level=" + compilation_mode.opt_level)
507509
args.add("--codegen=debuginfo=" + compilation_mode.debug_info)
508510

509-
args.add("--emit=dep-info,link")
511+
args.add("--emit=" + emit)
510512
args.add("--color=always")
511513
args.add("--target=" + toolchain.target_triple)
512514
if hasattr(ctx.attr, "crate_features"):

0 commit comments

Comments
 (0)