From c947c5ccaf3598a73038507c14a6a1b6e82c13c4 Mon Sep 17 00:00:00 2001 From: Ross Beazley Date: Wed, 17 Sep 2025 10:23:53 +0200 Subject: [PATCH 1/3] Add data attr to kt_plugin_cfg and kt_compiler_plugin --- kotlin/internal/jvm/impl.bzl | 7 +++++-- kotlin/internal/jvm/jvm.bzl | 10 ++++++++++ 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/kotlin/internal/jvm/impl.bzl b/kotlin/internal/jvm/impl.bzl index 5b47c95a8..ead03fdb1 100644 --- a/kotlin/internal/jvm/impl.bzl +++ b/kotlin/internal/jvm/impl.bzl @@ -392,6 +392,9 @@ def _reshade_embedded_kotlinc_jars(target, ctx, jars, deps): ], ) +def _expand_location_with_data_deps(ctx): + return lambda targets: ctx.expand_location(targets, ctx.attr.data) + def kt_compiler_plugin_impl(ctx): plugin_id = ctx.attr.id @@ -413,7 +416,7 @@ def kt_compiler_plugin_impl(ctx): classpath = depset(info.runtime_output_jars, transitive = [info.transitive_runtime_jars]) # TODO(1035): Migrate kt_compiler_plugin.options to string_list_dict - options = plugin_common.resolve_plugin_options(plugin_id, {k: [v] for (k, v) in ctx.attr.options.items()}, ctx.expand_location) + options = plugin_common.resolve_plugin_options(plugin_id, {k: [v] for (k, v) in ctx.attr.options.items()}, _expand_location_with_data_deps(ctx)) return [ DefaultInfo(files = classpath), @@ -432,7 +435,7 @@ def kt_plugin_cfg_impl(ctx): plugin = ctx.attr.plugin[_KtCompilerPluginInfo] return [ plugin, - ] + plugin.resolve_cfg(plugin, ctx.attr.options, ctx.attr.deps, ctx.expand_location) + ] + plugin.resolve_cfg(plugin, ctx.attr.options, ctx.attr.deps, _expand_location_with_data_deps(ctx)) def kt_ksp_plugin_impl(ctx): deps = ctx.attr.deps diff --git a/kotlin/internal/jvm/jvm.bzl b/kotlin/internal/jvm/jvm.bzl index 8e16b22de..805f88d48 100644 --- a/kotlin/internal/jvm/jvm.bzl +++ b/kotlin/internal/jvm/jvm.bzl @@ -535,6 +535,11 @@ kt_jvm_library( ``` """, attrs = { + "data": attr.label_list( + doc = "The list of data files to be used by compiler's plugin", + providers = [DefaultInfo], + cfg = "exec", + ), "deps": attr.label_list( doc = "The list of libraries to be added to the compiler's plugin classpath", providers = [JavaInfo], @@ -663,6 +668,11 @@ kt_plugin_cfg = rule( ], cfg = "exec", ), + "data": attr.label_list( + doc = "The list of data files to be used by compiler's plugin", + providers = [DefaultInfo], + cfg = "exec", + ), }, ) From e01e4651ae50b98bb908c5ef3ed577b6396afe5a Mon Sep 17 00:00:00 2001 From: Ross Beazley Date: Wed, 17 Sep 2025 10:52:33 +0200 Subject: [PATCH 2/3] Regenerate docs --- docs/kotlin.md | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/docs/kotlin.md b/docs/kotlin.md index d888156a5..51325f6d0 100755 --- a/docs/kotlin.md +++ b/docs/kotlin.md @@ -297,7 +297,8 @@ Lint Kotlin files, and fail if the linter raises errors.
 load("@rules_kotlin//kotlin:core.bzl", "kt_compiler_plugin")
 
-kt_compiler_plugin(name, deps, compile_phase, id, options, stubs_phase, target_embedded_compiler)
+kt_compiler_plugin(name, deps, data, compile_phase, id, options, stubs_phase,
+                   target_embedded_compiler)
 
Define a plugin for the Kotlin compiler to run. The plugin can then be referenced in the `plugins` attribute @@ -339,6 +340,7 @@ kt_jvm_library( | :------------- | :------------- | :------------- | :------------- | :------------- | | name | A unique name for this target. | Name | required | | | deps | The list of libraries to be added to the compiler's plugin classpath | List of labels | optional | `[]` | +| data | The list of data files to be used by compiler's plugin | List of labels | optional | `[]` | | compile_phase | Runs the compiler plugin during kotlin compilation. Known examples: `allopen`, `sam_with_reciever` | Boolean | optional | `True` | | id | The ID of the plugin | String | required | | | options | Dictionary of options to be passed to the plugin. Supports the following template values:

- `{generatedClasses}`: directory for generated class output - `{temp}`: temporary directory, discarded between invocations - `{generatedSources}`: directory for generated source output - `{classpath}` : replaced with a list of jars separated by the filesystem appropriate separator. | Dictionary: String -> String | optional | `{}` | @@ -488,7 +490,7 @@ kt_jvm_library(
 load("@rules_kotlin//kotlin:core.bzl", "kt_plugin_cfg")
 
-kt_plugin_cfg(name, deps, options, plugin)
+kt_plugin_cfg(name, deps, data, options, plugin)
 
Configurations for kt_compiler_plugin, ksp_plugin, and java_plugin. @@ -502,6 +504,7 @@ This allows setting options and dependencies independently from the initial plug | :------------- | :------------- | :------------- | :------------- | :------------- | | name | A unique name for this target. | Name | required | | | deps | Dependencies for this configuration. | List of labels | optional | `[]` | +| data | The list of data files to be used by compiler's plugin | List of labels | optional | `[]` | | options | A dictionary of flag to values to be used as plugin configuration options. | Dictionary: String -> List of strings | optional | `{}` | | plugin | The plugin to associate with this configuration | Label | required | | From bb4f7777a8dcfd2ef000a38d890fbb383a4ba894 Mon Sep 17 00:00:00 2001 From: Ross Beazley Date: Thu, 18 Sep 2025 10:56:14 +0200 Subject: [PATCH 3/3] Update JC example with stability conf --- examples/jetpack_compose/BUILD | 7 +++++++ examples/jetpack_compose/WORKSPACE | 1 + examples/jetpack_compose/stability.conf | 1 + 3 files changed, 9 insertions(+) create mode 100644 examples/jetpack_compose/stability.conf diff --git a/examples/jetpack_compose/BUILD b/examples/jetpack_compose/BUILD index cdf2c0958..621fc3d62 100644 --- a/examples/jetpack_compose/BUILD +++ b/examples/jetpack_compose/BUILD @@ -18,9 +18,11 @@ define_kt_toolchain( kt_compiler_plugin( name = "jetpack_compose_compiler_plugin", + data = [":stability_config"], id = "androidx.compose.compiler.plugins.kotlin", options = { "sourceInformation": "true", # Required for AS Layout Inspector, disable for release builds + "stabilityConfigurationPath": "$(locations :stability_config)", }, target_embedded_compiler = True, visibility = ["//visibility:public"], @@ -29,6 +31,11 @@ kt_compiler_plugin( ], ) +filegroup( + name = "stability_config", + srcs = ["stability.conf"], +) + platform( name = "arm64-v8a", constraint_values = [ diff --git a/examples/jetpack_compose/WORKSPACE b/examples/jetpack_compose/WORKSPACE index 904dee28b..4fd4995ba 100644 --- a/examples/jetpack_compose/WORKSPACE +++ b/examples/jetpack_compose/WORKSPACE @@ -1,5 +1,6 @@ load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") +# TODO (rbeazleyspot) Update release url when #1364 is released http_archive( name = "rules_kotlin", sha256 = "34e8c0351764b71d78f76c8746e98063979ce08dcf1a91666f3f3bc2949a533d", diff --git a/examples/jetpack_compose/stability.conf b/examples/jetpack_compose/stability.conf new file mode 100644 index 000000000..af113a9c2 --- /dev/null +++ b/examples/jetpack_compose/stability.conf @@ -0,0 +1 @@ +android.net.Uri