Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,22 @@ register_toolchains(
"@rust_toolchains//:all",
)

# make these tool repos visible to the clippy_no_fail_toolchain_tools rule
use_repo(
rust,
"rust_linux_x86_64__x86_64-unknown-linux-gnu__stable_tools",
"rust_macos_aarch64__aarch64-apple-darwin__stable_tools",
)

clippy_no_fail_toolchain_tools = use_repo_rule(
"//tools/clippy_no_fail:clippy_no_fail_toolchain_tools.bzl",
"clippy_no_fail_toolchain_tools",
)

clippy_no_fail_toolchain_tools(
name = "local_clippy_no_fail_toolchain_tools",
)

bazel_dep(
name = "buildifier_prebuilt",
version = "8.2.0.2",
Expand All @@ -29,6 +45,11 @@ bazel_dep(
version = "0.12.0",
dev_dependency = True,
)
bazel_dep(
name = "rules_shell",
version = "0.6.1",
dev_dependency = True,
)

starpls = use_extension(
"//tools/starpls:extension.bzl",
Expand Down
11 changes: 11 additions & 0 deletions toolchain/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
load("@platforms//host:constraints.bzl", "HOST_CONSTRAINTS")

toolchain(
name = "local_rust_stable_clippy_no_fail",
exec_compatible_with = HOST_CONSTRAINTS,
tags = ["manual"],
target_compatible_with = HOST_CONSTRAINTS,
target_settings = ["@rules_rust//rust/toolchain/channel:stable"],
toolchain = "@local_clippy_no_fail_toolchain_tools//:rust_toolchain",
toolchain_type = "@rules_rust//rust:toolchain",
)
Empty file.
55 changes: 55 additions & 0 deletions tools/clippy_no_fail/clippy_no_fail_toolchain_tools.bzl
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
"""
Provides a rust toolchain tools repo where clippy-driver always succeeds.
"""

load("@platforms//host:constraints.bzl", "HOST_CONSTRAINTS")

STABLE_TOOL_REPOS = [
"rust_linux_x86_64__x86_64-unknown-linux-gnu__stable_tools",
"rust_macos_aarch64__aarch64-apple-darwin__stable_tools",
]

_SOURCE_TOOLS = STABLE_TOOL_REPOS[int("@platforms//os:osx" in HOST_CONSTRAINTS)]

def _clippy_no_fail_toolchain_tools_impl(rctx):
source_build = rctx.path(rctx.attr.source_build_file)
source_root = source_build.dirname

strip_root_prefix = lambda path: str(path)[len(str(source_root)) + 1:]

result = rctx.execute(["find", str(source_root), "-not", "-type", "d"])
if result.return_code != 0:
fail("find failed: " + result.stderr)

for line in result.stdout.splitlines():
src = rctx.path(line)
rel = strip_root_prefix(src)

if rel not in ("BUILD.bazel", "WORKSPACE.bazel", "bin/clippy-driver"):
rctx.symlink(src, rel)

rctx.file(
"bin/clippy-driver",
"""\
#!/usr/bin/env bash
{real_clippy_driver} "$@" || true
""".format(
real_clippy_driver = "{}/bin/clippy-driver".format(source_root),
),
executable = True,
)

rctx.file(
"BUILD.bazel",
rctx.read(source_build),
)

clippy_no_fail_toolchain_tools = repository_rule(
implementation = _clippy_no_fail_toolchain_tools_impl,
attrs = {
"source_build_file": attr.label(
default = Label("@{}//:BUILD.bazel".format(_SOURCE_TOOLS)),
allow_single_file = True,
),
},
)
15 changes: 2 additions & 13 deletions tools/rust-analyzer/rust-analyzer-check.bash
Original file line number Diff line number Diff line change
Expand Up @@ -10,25 +10,14 @@ if [[ "$label" = "{label}" ]]; then
label="//..."
fi

stamp_file="$(mktemp)"
trap 'rm -f "$stamp_file"' EXIT

build_status=0
bazelisk \
"--output_base=${output_base}" \
build \
--extra_toolchains=//toolchain:local_rust_stable_clippy_no_fail \
Comment thread
oliverlee marked this conversation as resolved.
--aspects=//tools/rust-analyzer:aspect.bzl%clippy_stdout_aspect \
--@rules_rust//rust/settings:error_format=json \
--@rules_rust//rust/settings:capture_clippy_output=true \
--output_groups=clippy_stdout \
--config=clippy_settings \
--keep_going \
-- "$label" || build_status=$?

if (( build_status != 0 )); then
while IFS= read -r -d '' diagnostics_file; do
if grep -q '^{"$message_type":"diagnostic",' "$diagnostics_file"; then
cat "$diagnostics_file"
fi
done < <(find "$output_base" -type f -name '*.clippy.diagnostics' -newer "$stamp_file" -print0 | sort -z)
fi
-- "$label" || true
Loading