Attempt to use bazel rules directly to engage periphery#1127
Open
maxwellE wants to merge 4 commits into
Open
Conversation
Adds two new public rules in bazel/rules.bzl alongside the existing scan rule: - scan_test: a test target that runs the scan with --strict so `bazel test` fails when unused code is found. Wires Periphery into CI without invoking the --bazel driver. - scan_report: a build target that runs Periphery at build time and exposes the formatted report as a regular file output, so other rules can take it as a data dep / src. Also fixes ScanCommand to always honor --write-results, instead of skipping the file write when there are no findings. The previous behavior broke any Bazel action that declared the report as an output. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Adds a new `bazel/tests/` package with two Swift fixtures (Clean.swift and Unused.swift) that exercise all three rules end-to-end: - clean_scan / clean_scan_test / clean_scan_report run against a fixture with no unused code, validating the rules wire up correctly and the test rule passes on clean inputs. - unused_scan_report runs against a fixture with an intentionally unused declaration; an sh_test asserts the resulting JSON report contains the expected symbol name. Also fixes both scan templates to omit `--config` when no config attribute is set, instead of passing `--config ""` (which periphery rejects as a nonexistent path). The existing rule worked in practice only because the BazelProjectDriver always supplies an absolute config path. Wires `bazel test //bazel/tests/...` into the existing Bazel CI job on both macOS and Linux × Bazel 8 and 9, and adds rules_shell as a dev dep for the sh_test rule (no longer built-in in Bazel 8+).
The previous force_indexstore transition only enabled swift.index_while_building. Without whole-module optimization, each module compiles file-by-file and emits a fragmented indexstore that doesn't capture cross-file references the way periphery expects, leading to false positives. Renames the transition to periphery_deps_transition and expands it to set: - compilation_mode = opt, which is the prerequisite for WMO in rules_swift. - swift.opt_uses_wmo, which actually triggers whole-module compilation. - swift.index_while_building, unchanged. Also clears swift.opt_uses_osize so size-driven optimizations don't elide declarations periphery should observe. The transition is hermetic, so deps used outside the scan/scan_test/scan_report path are unaffected.
The prior transition set compilation_mode=opt purely to make rules_swift's swift.opt_uses_wmo feature kick in. That's a sledgehammer: opt also turns on inlining, dead-code elimination, and size optimizations that we don't need and don't want around an indexing build. rules_swift's toolchain (swift/internal/wmo.bzl) already scans the @rules_swift//swift:copt build setting for `-wmo`, `-whole-module-optimization`, or `-force-single-frontend-invocation` and auto-enables the private swift._wmo_in_swiftcopts feature. Setting `-wmo` via that build setting in the transition triggers the same WMO codegen path without changing compilation_mode, so scanned deps stay in fastbuild. Verified via bazel aquery that the SwiftCompile action for scanned targets has -wmo / -whole-module-optimization on its command line and its output path is under darwin_arm64-fastbuild-..., not -opt-.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Adds the ability to build periphery reports inside of bazel without using bazel run. This allows users to do things like
scan_testwhich is a failing version ofscan. We also now havescan_reportwhich can be used as adatadep in other bazel rules