Skip to content

Add example for setting a custom compiler version with BTAPI - #1551

Open
agluszak wants to merge 6 commits into
bazel-contrib:developfrom
agluszak:btapi-compat-on-develop
Open

agluszak wants to merge 6 commits into
bazel-contrib:developfrom
agluszak:btapi-compat-on-develop

Conversation

@agluszak

@agluszak agluszak commented Apr 8, 2026

Copy link
Copy Markdown
Collaborator

No description provided.

@agluszak agluszak changed the title Add example for setting a custom compiler version with in BTAPI Add example for setting a custom compiler version with BTAPI Apr 8, 2026
@agluszak
agluszak force-pushed the btapi-compat-on-develop branch from f5a680e to b8f4bfc Compare April 8, 2026 12:30
agluszak and others added 5 commits April 28, 2026 14:10
* Drop WORKSPACE support

* Drop bzlmod-related flags
…contrib#1470)

* Drop WORKSPACE support (bazel-contrib#1480)

* Drop WORKSPACE support

* Drop bzlmod-related flags

* [maintenance] Use rules_jvm_external for getting dependencies

Stop relying on the downloaded kotlinc distribution - switching to rules_jvm_external will make it easier to use BTAPI.
 Not having to resolve dependencies manually will also let us avoid problems like KSP requiring a specific version of kotlin coroutines.
* Introduce BTAPI

* Post-merge fixes

* Repin example maven lockfiles

* Address comments

* Address comments

* Address comments

* Add more tests and minor improvements

* Run buildifier
@agluszak
agluszak force-pushed the btapi-compat-on-develop branch from b8f4bfc to 6d14206 Compare April 28, 2026 13:09
Copilot AI review requested due to automatic review settings April 28, 2026 13:09

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

Adds a new examples/btapi_compat workspace demonstrating how to pin a custom Kotlin compiler/BTAPI runtime (2.3.10) while using rules_kotlin, plus a small compiler-plugin-based verification test. Also adjusts example workspace layout and root Bazel config to account for the new example.

Changes:

  • Introduces examples/btapi_compat with a custom toolchain, Maven-pinned Kotlin artifacts, a compiler plugin, and JUnit verification tests.
  • Adds a lockfile (maven_install.json) and documentation for the new BTAPI compatibility example.
  • Removes examples/path_mapping/WORKSPACE and updates root .bazelrc deleted package list.

Reviewed changes

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

Show a summary per file
File Description
examples/path_mapping/WORKSPACE Removes the WORKSPACE-based setup for the path_mapping example.
examples/btapi_compat/src/main/kotlin/plugin/Plugin.kt Adds a compiler plugin that injects the Kotlin compiler version into IR for runtime verification.
examples/btapi_compat/src/main/kotlin/example/Compat.kt Adds JUnit tests to assert stdlib + compiler version behavior.
examples/btapi_compat/maven_install.json Adds resolved Maven lockfile for the example’s dependencies.
examples/btapi_compat/README.md Documents how the example pins/overrides BTAPI + stdlib and how it’s validated.
examples/btapi_compat/MODULE.bazel Declares the example module, Maven artifacts, and registers the custom toolchain.
examples/btapi_compat/BUILD.bazel Defines the custom toolchain, compiler plugin targets, and test target.
.bazelrc Updates --deleted_packages list to include the new example and reflect current excluded example packages.

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

name = "kotlin_2310_toolchain",
api_version = "2.3",
build_tools_impl = "@maven_rules_kotlin_btapi_compat//:org_jetbrains_kotlin_kotlin_build_tools_impl",
kotlin_stdlib = "@maven_rules_kotlin_btapi_compat//:org_jetbrains_kotlin_kotlin_stdlib",

Copilot AI Apr 28, 2026

Copy link

Choose a reason for hiding this comment

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

define_kt_toolchain (exported from @rules_kotlin//kotlin:core.bzl) doesn't accept a kotlin_stdlib parameter (the macro supports jvm_stdlibs and jvm_runtime instead). As written, this toolchain definition will fail to load or will not actually override the stdlib as the README/tests expect. Update the toolchain to set jvm_stdlibs/jvm_runtime to the desired stdlib (and any required annotations jar), and remove/replace the unsupported kotlin_stdlib argument.

Suggested change
kotlin_stdlib = "@maven_rules_kotlin_btapi_compat//:org_jetbrains_kotlin_kotlin_stdlib",
jvm_stdlibs = [
"@maven_rules_kotlin_btapi_compat//:org_jetbrains_kotlin_kotlin_stdlib",
],
jvm_runtime = "@maven_rules_kotlin_btapi_compat//:org_jetbrains_kotlin_kotlin_stdlib",

Copilot uses AI. Check for mistakes.
Comment on lines +11 to +15
The custom toolchain also overrides:

- `org.jetbrains.kotlin:kotlin-stdlib:2.3.10`

The custom toolchain is declared in `BUILD.bazel` with `define_kt_toolchain` and registered in `MODULE.bazel` via:

Copilot AI Apr 28, 2026

Copy link

Choose a reason for hiding this comment

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

This README says the toolchain overrides kotlin-stdlib via a kotlin_stdlib attribute, but define_kt_toolchain doesn't have that parameter (it uses jvm_stdlibs/jvm_runtime). Once the BUILD is corrected, please update this section to describe the actual toolchain attributes used to override the stdlib/runtime classpath so the example remains accurate.

Suggested change
The custom toolchain also overrides:
- `org.jetbrains.kotlin:kotlin-stdlib:2.3.10`
The custom toolchain is declared in `BUILD.bazel` with `define_kt_toolchain` and registered in `MODULE.bazel` via:
The custom toolchain is declared in `BUILD.bazel` with `define_kt_toolchain`. To override the Kotlin stdlib/runtime classpath, the toolchain uses:
- `jvm_stdlibs` for the Kotlin stdlib artifacts, such as `org.jetbrains.kotlin:kotlin-stdlib:2.3.10`
- `jvm_runtime` for the runtime jars made available to the toolchain
The toolchain is then registered in `MODULE.bazel` via:

Copilot uses AI. Check for mistakes.
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