Skip to content

feat(kotlin-builder): rewrite builtin-plugin -Xplugin to --plugins (with warning)#22

Merged
Sam Gammon (sgammon) merged 2 commits into
mainfrom
fix/builtin-plugin-rewrite
Jun 24, 2026
Merged

feat(kotlin-builder): rewrite builtin-plugin -Xplugin to --plugins (with warning)#22
Sam Gammon (sgammon) merged 2 commits into
mainfrom
fix/builtin-plugin-rewrite

Conversation

@sgammon

Copy link
Copy Markdown
Member

Problem

When a kt_jvm_* target uses a compiler plugin that Elide also bundles (e.g. kotlinx-serialization), rules_kotlin passes -Xplugin=<jar> and Elide emits:

kotlinc: -Xplugin '…/kotlinx-serialization-compiler-plugin.jar' matches the bundled 'kotlinx.serialization' plugin. Prefer Elide's flag (--serialization or --plugins=serialization)… a raw -Xplugin loads your jar as-is and may version-mismatch or fail to load.

Fix (in the shim)

On the fast path, the KotlinBuilder shim now detects a -Xplugin=<jar> that duplicates an Elide builtin, drops it, and enables the version-pinned builtin via --plugins=<name> instead — exactly what Elide recommends. It surfaces one Bazel-visible [warning] naming the jar and the replacement.

  • Toggle: --@rules_elide//config/kotlinc:warn_builtin_plugin_rewrite=false silences the warning (the toolchain launcher then passes the shim --quiet_plugin_rewrite). The rewrite itself always happens; only the warning is suppressed.
  • Conservative mapping: serialization only for now, matched by jar basename — a non-builtin plugin (e.g. Metro) is never stripped. Our own jvm-abi-gen -Xplugin is untouched.

Tests

  • BuiltinPluginsTest: detection (classpath + passthrough), dedup, non-builtin ignore, warning text (names jar, replacement, silence flag).
  • ElideCompileTest: plan() drops the serialization -Xplugin and adds --plugins=serialization before --; keeps non-builtin jars.
  • MainTest: --quiet_plugin_rewrite parsed into Config.

//tests/... 36/36.

Copilot AI review requested due to automatic review settings June 24, 2026 01:41

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

This PR updates the Elide KotlinBuilder shim to proactively rewrite rules_kotlin-supplied -Xplugin=<jar> flags that duplicate Elide-bundled compiler plugins into Elide’s pinned builtin form (--plugins=<name>), optionally emitting a Bazel-visible warning controlled by a new build setting.

Changes:

  • Detect and drop duplicate builtin -Xplugin jars (currently serialization), replacing them with --plugins=... before the -- separator.
  • Add a warning (suppressible via //config/kotlinc:warn_builtin_plugin_rewrite=false, wired through --quiet_plugin_rewrite) and plumb the new config through the toolchain launcher + shim config.
  • Add/extend tests to cover detection, rewrite behavior, warning text, and the new shim flag parsing.

Reviewed changes

Copilot reviewed 9 out of 9 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
tests/kotlin_builder/MainTest.kt Adds coverage for parsing --quiet_plugin_rewrite into shim config.
tests/kotlin_builder/ElideCompileTest.kt Verifies plan() rewrites builtin -Xplugin to --plugins= and preserves non-builtin plugins.
tests/kotlin_builder/BuiltinPluginsTest.kt New unit tests for builtin plugin detection, deduping, ignore behavior, and warning text.
tests/kotlin_builder/BUILD.bazel Registers the new builtin_plugins_test.
elide/kotlin/toolchain.bzl Adds launcher plumbing + attribute for --quiet_plugin_rewrite, driven by a new config_setting select.
elide/kotlin/builder/Main.kt Adds config field + warning emission (unless silenced) into WorkResponse output.
elide/kotlin/builder/ElideCompile.kt Implements the actual rewrite: drop builtin jars and add --plugins=... ahead of --.
elide/kotlin/builder/BuiltinPlugins.kt Introduces builtin plugin mapping/detection and the warning formatter.
config/kotlinc/BUILD.bazel Adds warn_builtin_plugin_rewrite bool_flag and matching config_setting.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread elide/kotlin/builder/BuiltinPlugins.kt Outdated
Comment thread elide/kotlin/builder/BuiltinPlugins.kt Outdated
…arn)

When rules_kotlin delivers a `-Xplugin=<jar>` that duplicates a compiler
plugin bundled in Elide, Elide warns that the raw jar may version-mismatch
the embedded compiler and recommends its builtin. The shim now does that
automatically on the fast path: it drops the matching `-Xplugin` and enables
the version-pinned builtin via `--plugins=`, and surfaces a single Bazel
`[warning]` naming the jar and replacement.

Covers all four builtins Elide exposes via `--plugins` (per `elide kotlinc
--help`): serialization, power-assert, atomicfu, metro — matched by the
compiler-plugin jar basename (prefix-agnostic so kotlin-/kotlinx- both map;
runtimes and unrelated plugins are left alone).

The warning is on by default and silenceable once understood:
`--@rules_elide//config/kotlinc:warn_builtin_plugin_rewrite=false` makes the
toolchain launcher pass the shim `--quiet_plugin_rewrite` (the rewrite itself
always happens).

Tests: BuiltinPlugins detection (all four, both kotlin/kotlinx prefixes,
passthrough, dedup), non-builtin/runtime ignore, warning text; ElideCompile.plan
drops the serialization -Xplugin and adds --plugins=serialization before `--`
while keeping non-builtin jars; Main parses --quiet_plugin_rewrite.
@sgammon Sam Gammon (sgammon) force-pushed the fix/builtin-plugin-rewrite branch from f9f3816 to d79749e Compare June 24, 2026 01:50
Address Copilot review: builtinFor() and the rewrite warning extracted the
jar basename with substringAfterLast('/') only, so a Windows-style path
(C:\...\foo.jar) in a flagfile would neither match the builtin MAP nor print
a clean basename. Add a separator-tolerant basename() helper used in both,
with a test for backslash paths.
@codspeed-hq

codspeed-hq Bot commented Jun 24, 2026

Copy link
Copy Markdown

Merging this PR will not alter performance

⚠️ Unknown Walltime execution environment detected

Using the Walltime instrument on standard Hosted Runners will lead to inconsistent data.

For the most accurate results, we recommend using CodSpeed Macro Runners: bare-metal machines fine-tuned for performance measurement consistency.

✅ 3 untouched benchmarks


Comparing fix/builtin-plugin-rewrite (fae3089) with main (aa84819)

Open in CodSpeed

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 9 out of 9 changed files in this pull request and generated 1 comment.

Comment thread elide/kotlin/builder/BuiltinPlugins.kt
@sgammon Sam Gammon (sgammon) merged commit 795195e into main Jun 24, 2026
15 checks passed
@sgammon Sam Gammon (sgammon) deleted the fix/builtin-plugin-rewrite branch June 24, 2026 02:40
This was referenced Jun 25, 2026
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.

2 participants