rules_scala icon indicating copy to clipboard operation
rules_scala copied to clipboard

[Compiler Toolchains] Add support for plugins

Open FrankPortman opened this issue 3 months ago • 1 comments

Description

Right now, you can only supply compiler plugins into scala_library targets. This allows you to set them at the compiler toolchain level, in order for them to apply to every target.

Motivation

Sometimes you want to apply your plugins to your entire monorepo, or apply the plugins broadly based on flags. The current ways to do so would involve "wrapping" scala_library and injecting these specifics into it via macro, which feels regrettable because of how foundational of a concept it is. On the other hand, if you "wrap" scala_library and create new_scala_library, you must then know when/where to use this other version.

TODO

  • [ ] Add real tests
  • [ ] Document plugins attr
  • [ ] Any release notes/chores that need doing or no?

Test for now

  # Test WITH plugin - should compile successfully
  bazel build //test/toolchain_plugins:requires_plugin --extra_toolchains=//test/toolchain_plugins:with_plugin

  # Test WITHOUT plugin - should FAIL with "Either[String,<error>] takes no type parameters"
  bazel build //test/toolchain_plugins:requires_plugin --extra_toolchains=//test/toolchain_plugins:without_plugin

  # Control test - should always work
  bazel build //test/toolchain_plugins:no_plugin_needed

FrankPortman avatar Nov 24 '25 21:11 FrankPortman

@FrankPortman This generally looks OK to me, but in addition to converting the manual tests to test scripts, please look into the test failures from CI and fix those. They all appear to be of the following form, which seems like it should prove easily reproducible locally:

ERROR: /workdir/test/toolchain_plugins/BUILD.bazel:33:14:
  scala @@//test/toolchain_plugins:requires_plugin failed: (Exit 1):
  scalac failed: error executing Scalac command 
  from target //test/toolchain_plugins:requires_plugin)
  bazel-out/.../bin/src/java/io/bazel/rulesscala/scalac/scalac
  @bazel-out/.../bin/test/toolchain_plugins/requires_plugin.jar-0.params
--
test/toolchain_plugins/RequiresPlugin.scala:7: error: not found: type *
class RequiresPlugin extends HKT[Either[String, *]]
^
test/toolchain_plugins/RequiresPlugin.scala:7: error: Either[String,<error>] takes no type parameters, expected: one
class RequiresPlugin extends HKT[Either[String, *]]
^
two errors found

Also, adding newlines to the end of the files that currently don't have them would be lovely.

mbland avatar Dec 08 '25 16:12 mbland