rules_kotlin
rules_kotlin copied to clipboard
Bzlmod: kotlin compiler is unconditionally downloaded
Reproducible case
https://github.com/meteorcloudy/my_tests/tree/master/rules_kotlin_test
$ bazel build //:bin
INFO: Invocation ID: f643fade-db51-4d9b-82ae-25bdb900fa0f
INFO: Options provided by the client:
Inherited 'common' options: --isatty=1 --terminal_columns=240
INFO: Reading rc options for 'build' from /Users/pcloudy/.bazelrc:
'build' options: --verbose_failures --announce_rc --disk_cache=/tmp/bazel_disk_cache --repository_cache=/tmp/bazel_repository_cache
INFO: Analyzed target //:bin (45 packages loaded, 232 targets configured).
INFO: Found 1 target...
Target //:bin up-to-date:
bazel-bin/bin
INFO: Elapsed time: 4.112s, Critical Path: 0.04s
INFO: 7 processes: 2 disk cache hit, 5 internal.
INFO: Build completed successfully, 7 total actions
Check the external repo directoires:
$ ls $(bazel info output_base)/external/rules_kotlin*
INFO: Invocation ID: e1aadea7-36c9-401e-9d4c-d5dfd89a62e6
INFO: Options provided by the client:
Inherited 'common' options: --isatty=0 --terminal_columns=80
INFO: Reading rc options for 'info' from /Users/pcloudy/.bazelrc:
Inherited 'build' options: --verbose_failures --announce_rc --disk_cache=/tmp/bazel_disk_cache --repository_cache=/tmp/bazel_repository_cache
/private/var/tmp/_bazel_pcloudy/866f0b7a8d0e88178146ef74d48040fc/external/rules_kotlin~1.9.0:
BUILD.bazel MODULE.bazel WORKSPACE WORKSPACE.bzlmod kotlin src third_party
/private/var/tmp/_bazel_pcloudy/866f0b7a8d0e88178146ef74d48040fc/external/rules_kotlin~1.9.0~rules_kotlin_extensions~com_github_jetbrains_kotlin:
BUILD.bazel WORKSPACE bin build.txt capabilities.bzl lib license
The kotlin compiler is downloaded through com_github_jetbrains_kotlin even though building //:bin doesn't require it.
Cause
https://github.com/bazelbuild/rules_kotlin/blob/540893abf884e936954d69840dff99e8da58a4b6/MODULE.bazel#L24
the default toolchain target depends directly on the kotlin compiler repo. This can be work around by defining the target in a config repo, which should avoid fetching the actual compiler.
/cc @fmeum @comius Can you give some examples from rules_go or rules_java on how to fix this?
Oh, probably it was caused by https://github.com/bazelbuild/rules_kotlin/blob/540893abf884e936954d69840dff99e8da58a4b6/src/main/starlark/core/options/opts.kotlinc.bzl#L15
You should probably generate the capabilities.bzl file in a different repo: https://github.com/bazelbuild/rules_kotlin/blob/540893abf884e936954d69840dff99e8da58a4b6/src/main/starlark/core/repositories/compiler.bzl#L19-L22
@Bencodes Do you have time to take a look at this?
@meteorcloudy I believe @restingbull is looking into this one for you.