Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion scala/private/phases/phase_compile.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,12 @@ def _phase_compile(
jars2labels = p.collect_jars.jars2labels.jars_to_labels
deps_providers = p.collect_jars.deps_providers
default_classpath = p.scalac_provider.default_classpath
plugins = ctx.attr.plugins

# Merge toolchain plugins with target-specific plugins
toolchain = ctx.toolchains["//scala:toolchain_type"]
toolchain_plugins = getattr(toolchain, "plugins", [])
plugins = toolchain_plugins + ctx.attr.plugins

additional_outputs = []
scalacopts = p.scalacopts

Expand Down
5 changes: 5 additions & 0 deletions scala/scala_toolchain.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ def _scala_toolchain_impl(ctx):

toolchain = platform_common.ToolchainInfo(
scalacopts = ctx.attr.scalacopts,
plugins = ctx.attr.plugins,
dep_providers = ctx.attr.dep_providers,
dependency_mode = dependency_mode,
strict_deps_mode = strict_deps_mode,
Expand Down Expand Up @@ -122,6 +123,10 @@ _scala_toolchain = rule(
_scala_toolchain_impl,
attrs = {
"scalacopts": attr.string_list(),
"plugins": attr.label_list(
doc = "Compiler plugins to be enabled for all scala targets using this toolchain",
allow_files = [".jar"],
),
"dep_providers": attr.label_list(
default = _default_dep_providers(),
providers = [_DepsInfo],
Expand Down
42 changes: 42 additions & 0 deletions test/toolchain_plugins/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
load("//scala:scala_toolchain.bzl", "scala_toolchain")
load("//scala:scala.bzl", "scala_library")

# Toolchain WITH the kind-projector plugin
scala_toolchain(
name = "with_plugin_impl",
plugins = ["@org_typelevel_kind_projector//jar"],
visibility = ["//visibility:public"],
)

toolchain(
name = "with_plugin",
toolchain = ":with_plugin_impl",
toolchain_type = "//scala:toolchain_type",
visibility = ["//visibility:public"],
)

# Toolchain WITHOUT the plugin (but otherwise identical)
scala_toolchain(
name = "without_plugin_impl",
# No plugins attribute
visibility = ["//visibility:public"],
)

toolchain(
name = "without_plugin",
toolchain = ":without_plugin_impl",
toolchain_type = "//scala:toolchain_type",
visibility = ["//visibility:public"],
)

# Test that requires kind-projector plugin
scala_library(
name = "requires_plugin",
srcs = ["RequiresPlugin.scala"],
)

# Test that doesn't require any plugin
scala_library(
name = "no_plugin_needed",
srcs = ["NoPlugin.scala"],
)
6 changes: 6 additions & 0 deletions test/toolchain_plugins/NoPlugin.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package test.toolchain_plugins

// Standard Scala - no plugin needed
class NoPlugin {
def hello: String = "This compiles without any plugin"
}
7 changes: 7 additions & 0 deletions test/toolchain_plugins/RequiresPlugin.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package test.toolchain_plugins

import scala.language.higherKinds

// This REQUIRES kind-projector plugin - uses the * syntax
class HKT[F[_]]
class RequiresPlugin extends HKT[Either[String, *]]