Skip to content

feat: allow passing KSP options via kt_ksp_plugin#1478

Merged
restingbull merged 4 commits intobazel-contrib:masterfrom
monosoul:feat/KSP-environment-options
Mar 11, 2026
Merged

feat: allow passing KSP options via kt_ksp_plugin#1478
restingbull merged 4 commits intobazel-contrib:masterfrom
monosoul:feat/KSP-environment-options

Conversation

@monosoul
Copy link
Copy Markdown
Contributor

@monosoul monosoul commented Mar 9, 2026

Adds options arg to kt_ksp_plugin, so that end users can pass options to KSP processors from the build files and use those in codegen.

@monosoul monosoul force-pushed the feat/KSP-environment-options branch from 9cf6e33 to fe71e4b Compare March 9, 2026 15:27
@agluszak
Copy link
Copy Markdown
Collaborator

agluszak commented Mar 9, 2026

Could you add an integration test - write the simplest possible KSP plugin that prints the options passed to it and make asserts on that?

@monosoul
Copy link
Copy Markdown
Contributor Author

monosoul commented Mar 9, 2026

@agluszak done: c9fcc16

Comment thread kotlin/internal/jvm/plugins.bzl Outdated
options = {}
for t in targets:
if _KspPluginInfo in t:
options.update(t[_KspPluginInfo].options)
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will silently overwrite options that conflict with other plugins.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's a good point. Tbh, probably it makes more sense to have those options at the plugin consumer targets rather than kt_ksp_plugin. Otherwise we'll have to either pick the behavior for the end users (i.e. either merge the options or throw an error on conflict), or provide a config option for the merge strategy. If we go for the latter, probably such option would have to live at plugin consumer targets (kt_jvm_library, kt_jvm_test). And at that point I think it makes more sense to simply move the options there.

Copy link
Copy Markdown
Contributor Author

@monosoul monosoul Mar 10, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you say about this: c90f0fb ?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On the other hand, kinda weird to have plugin-specific options on kt_jvm_library 🤔 If that doesn't work, then I'd prefer merging the options, as it was, just with explicit mention of that behavior in the docs.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, it looks kinda weird. Would there be any practical use case for it?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, in my case I need to pass a list of service names to be used in codegen. The same service names are passed to some other bazel rules, so I'd like to have a single place where I declare those.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's go with fail for now. Principal of least surprise and all.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment thread src/test/starlark/ksp/ksp_test.bzl Outdated
"Should have at least one KotlinKsp2 action when plugin has options",
)

if ksp2_actions:
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this conditional actually needed since the assertion above this already checks for the existence of a KSP action?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch, yeah, that was unnecessary

Copy link
Copy Markdown
Collaborator

@restingbull restingbull left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Generally LGTM -- except for the silent overwrite on option conflict.

What would be a good merge strategy?

@monosoul monosoul requested a review from restingbull March 10, 2026 11:16
@monosoul monosoul force-pushed the feat/KSP-environment-options branch from 1008236 to c90f0fb Compare March 10, 2026 11:20
@monosoul monosoul force-pushed the feat/KSP-environment-options branch from c90f0fb to b7772e1 Compare March 11, 2026 10:49
@restingbull restingbull merged commit d8825d3 into bazel-contrib:master Mar 11, 2026
1 check passed
@monosoul
Copy link
Copy Markdown
Contributor Author

Hey folks, is there any ETA for when this will get released?

@agluszak
Copy link
Copy Markdown
Collaborator

Hey folks, is there any ETA for when this will get released?

Today kotlin 2.3.20 was released, so I guess it's a good time to cut a release of rules_kotlin :)

@monosoul
Copy link
Copy Markdown
Contributor Author

Any chance for a release this week?

@monosoul
Copy link
Copy Markdown
Contributor Author

Seems like BCR PR to bump the version is missing even though a new rules version got released

@agluszak
Copy link
Copy Markdown
Collaborator

Seems like BCR PR to bump the version is missing even though a new rules version got released

New version appears to be released correctly, doesn't it?

https://registry.bazel.build/modules/rules_kotlin/2.3.20

@monosoul
Copy link
Copy Markdown
Contributor Author

Yeah, I've created a PR to get it to BCR 🙂

@agluszak
Copy link
Copy Markdown
Collaborator

Ah, thanks then :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants