Per-class tracking to achieve higher level of compilation avoidance#1530
Open
oliviernotteghem wants to merge 1 commit intobazel-contrib:masterfrom
Open
Per-class tracking to achieve higher level of compilation avoidance#1530oliviernotteghem wants to merge 1 commit intobazel-contrib:masterfrom
oliviernotteghem wants to merge 1 commit intobazel-contrib:masterfrom
Conversation
agluszak
reviewed
Mar 19, 2026
| repeated SourceLocation location = 3; | ||
|
|
||
| // List of used classes from this dependency (for per-class compilation avoidance). | ||
| repeated UsedClass usedClasses = 4; |
Contributor
Author
There was a problem hiding this comment.
See my comment below (where the same proto changes are done in the mentioned PR).
| ], | ||
| ), | ||
| "experimental_track_class_usage": attr.string( | ||
| doc = """Enable per-class compilation avoidance. Records which specific classes |
Collaborator
There was a problem hiding this comment.
turning this on doesn't really enable (as in: cause) any compilation avoidance, right?
Contributor
Author
There was a problem hiding this comment.
@agluszak : you're absolutely right. To enable consumption of the class usage data and enable more granular compilation avoidance you need also this change on Bazel core bazelbuild/bazel#16457
7bae6b9 to
d4a37d3
Compare
d4a37d3 to
37c8787
Compare
ryanulep
pushed a commit
to uber-common/rules_kotlin
that referenced
this pull request
Apr 9, 2026
ryanulep
pushed a commit
to uber-common/rules_kotlin
that referenced
this pull request
Apr 16, 2026
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.
This change adds support for per-class compilation avoidance, enabling fine-grained dependency tracking during Kotlin compilation. When enabled, the jdeps output records exactly
which classes from each dependency JAR are used, along with SHA-256 hashes of their bytecode.
Motivation
Traditional compilation avoidance works at the JAR level—if any file in a dependency JAR changes, all dependents must recompile. Per-class tracking improves this by allowing
build systems to skip recompilation when a dependency JAR changes but the specific classes actually used remain unchanged (same hashes).
Configuration
Two new toolchain attributes:
define_kt_toolchain(
name = "my_toolchain",
experimental_track_class_usage = "on", # Track class usage with hashes
experimental_track_resource_usage = "on", # Track Android R class references
)
Changes
Proto definitions:
JDeps plugin:
Builder:
Starlark rules:
Output Format
When enabled, jdeps includes per-class entries:
dependency {
path: "bazel-out/.../libparser.jar" kind: EXPLICIT usedClasses { fullyQualifiedName: "com.lib.Parser" internalPath: "com/lib/Parser.class"
hash: <32 bytes SHA-256>
} }
Testing
Added KotlinBuilderJvmClassTrackingTest with tests verifying: